From 2b63ae02b5f151647a5118d981aa95edc3510bd6 Mon Sep 17 00:00:00 2001 From: wp_xyz Date: Sun, 7 Aug 2022 23:21:07 +0200 Subject: [PATCH] tools/icons_to_html: Minor refactoring. --- tools/icons_to_html/main.lfm | 4 +-- tools/icons_to_html/main.pas | 52 ++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tools/icons_to_html/main.lfm b/tools/icons_to_html/main.lfm index 1746b72549..8562832339 100644 --- a/tools/icons_to_html/main.lfm +++ b/tools/icons_to_html/main.lfm @@ -6,14 +6,11 @@ object MainForm: TMainForm Caption = 'IconTable' ClientHeight = 515 ClientWidth = 600 - Constraints.MinHeight = 515 - Constraints.MinWidth = 600 OnClose = FormClose OnCreate = FormCreate OnShow = FormShow Position = poScreenCenter ShowHint = True - LCLVersion = '2.3.0.0' object DirectoryEdit: TDirectoryEdit AnchorSideLeft.Control = Owner AnchorSideTop.Control = sbtnLastDirs @@ -556,6 +553,7 @@ object MainForm: TMainForm Top = 483 Width = 76 BorderSpacing.Left = 15 + BorderSpacing.Right = 15 Caption = 'Dark Mode' OnChange = cbDarkModeChange TabOrder = 2 diff --git a/tools/icons_to_html/main.pas b/tools/icons_to_html/main.pas index 5ac34c389c..8071f3b3ca 100644 --- a/tools/icons_to_html/main.pas +++ b/tools/icons_to_html/main.pas @@ -32,17 +32,15 @@ type procedure bbtnShowClick(Sender: TObject); procedure cbDarkModeChange(Sender: TObject); procedure DirectoryEditChange(Sender: TObject); - procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); + procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure LastDirClick(Sender: TObject); procedure sbtnLastDirsClick(Sender: TObject); private - fn: String; ImgDir: String; - Config: TIniFile; LastDirsMax: Integer; - function CalcIniFileName: String; + function GetIniFileName: String; procedure InfoMsg(const AMsg: String); procedure ErrorMsg(const AMsg: String); procedure UpdateLastDirs(D: String); @@ -57,18 +55,18 @@ implementation {$R *.lfm} +const + LE2 = LineEnding + LineEnding; + { TMainForm } -function TMainForm.CalcIniFileName: String; -begin - Result := Application.Location + 'IconTableConfig.ini'; -end; - procedure TMainForm.FormCreate(Sender: TObject); var i: Integer; MenItem: TMenuItem; begin + Position := poScreenCenter; + LastDirsMax := 9; for i := 0 to LastDirsMax do begin @@ -84,19 +82,26 @@ var i: Integer; L, T, W, H: Integer; R: TRect; + Config: TIniFile; begin - Config := TIniFile.Create(CalcIniFileName); + Constraints.MinWidth := cbDarkMode.Left + cbDarkMode.Width + cbDarkMode.BorderSpacing.Right + + bbtnClose.Left + bbtnClose.Width - bbtnCreateHTML.Left + bbtnClose.BorderSpacing.Right; + Constraints.MinHeight := Constraints.MinWidth * 2 div 3; + + Position := poDesigned; + + Config := TIniFile.Create(GetIniFileName); try - T := Config.ReadInteger('Position', 'Top', 100); - L := Config.ReadInteger('Position', 'Left', 100); - W := Config.ReadInteger('Position', 'Width', 100); - H := Config.ReadInteger('Position', 'Height', 100); + T := Config.ReadInteger('Position', 'Top', Top); + L := Config.ReadInteger('Position', 'Left', Left); + W := Config.ReadInteger('Position', 'Width', Width); + H := Config.ReadInteger('Position', 'Height', Height); R := Screen.WorkAreaRect; if W > R.Width then W := R.Width; if H > R.Height then H := R.Height; if L < R.Left then L := R.Left; if T < R.Top then T := R.Top; - if L + W > R.Right then L := R.Right - W - GetSystemMetrics(SM_CYSIZEFRAME); + if L + W > R.Right then L := R.Right - W - GetSystemMetrics(SM_CXSIZEFRAME); if T + H > R.Bottom then T := R.Bottom - H - GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYSIZEFRAME); SetBounds(L, T, W, H); WindowState := wsNormal; @@ -129,11 +134,12 @@ end; procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); var i: Integer; + Config: TIniFile; begin if WindowState = wsMinimized then WindowState := wsNormal; - Config := TIniFile.Create(CalcIniFileName); + Config := TIniFile.Create(GetIniFileName); try try Config.WriteInteger('Position', 'Top', RestoredTop); @@ -147,13 +153,19 @@ begin Config.WriteBool('Options', 'DarkMode', cbDarkMode.Checked); except - ErrorMsg('The configuration could not be saved.'); + on E: Exception do + ErrorMsg('The configuration could not be saved.' + LE2 + E.Message); end; finally Config.Free; end; end; +function TMainForm.GetIniFileName: String; +begin + Result := Application.Location + 'IconTableConfig.ini'; +end; + procedure TMainForm.cbDarkModeChange(Sender: TObject); begin bbtnSave.Enabled := False; @@ -330,6 +342,8 @@ begin end; procedure TMainForm.bbtnSaveClick(Sender: TObject); +var + fn: String; begin fn := ImgDir + 'IconTable.html'; try @@ -343,6 +357,8 @@ begin end; procedure TMainForm.bbtnShowClick(Sender: TObject); +var + fn: String; begin fn := ImgDir + 'IconTable.html'; if FileExists(fn) then @@ -364,6 +380,8 @@ begin end else bbtnCreateHTML.Enabled := False; + bbtnSave.Enabled := False; + bbtnShow.Enabled := False; end; procedure TMainForm.LastDirClick(Sender: TObject);