tools/icons_to_html: Minor refactoring of ini storage for IconTable project.

This commit is contained in:
wp_xyz 2022-08-06 12:15:29 +02:00
parent a76721ce2e
commit 0ddb329d2a
3 changed files with 44 additions and 26 deletions

View File

@ -28,7 +28,6 @@
</Target> </Target>
<SearchPaths> <SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/> <IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="D:\LazarusProg\rhsUnit\"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<CodeGeneration> <CodeGeneration>

View File

@ -13,7 +13,7 @@ object MainForm: TMainForm
OnShow = FormShow OnShow = FormShow
Position = poScreenCenter Position = poScreenCenter
ShowHint = True ShowHint = True
LCLVersion = '2.2.2.0' LCLVersion = '2.3.0.0'
object DirectoryEdit: TDirectoryEdit object DirectoryEdit: TDirectoryEdit
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = sbtnLastDirs AnchorSideTop.Control = sbtnLastDirs
@ -554,7 +554,7 @@ object MainForm: TMainForm
Height = 19 Height = 19
Hint = 'Creates an html page with dark background' Hint = 'Creates an html page with dark background'
Top = 483 Top = 483
Width = 78 Width = 76
BorderSpacing.Left = 15 BorderSpacing.Left = 15
Caption = 'Dark Mode' Caption = 'Dark Mode'
OnChange = cbDarkModeChange OnChange = cbDarkModeChange

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls, EditBtn, FileUtil, Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls, EditBtn, FileUtil,
LazUTF8, LazFileUtils, LCLIntf, Buttons, Menus, IniFiles, LazUTF8, LazFileUtils, LCLIntf, LCLType, Buttons, Menus, IniFiles,
SynEdit, SynHighlighterHTML; SynEdit, SynHighlighterHTML;
type type
@ -42,6 +42,7 @@ type
ImgDir: String; ImgDir: String;
Config: TIniFile; Config: TIniFile;
LastDirsMax: Integer; LastDirsMax: Integer;
function CalcIniFileName: String;
procedure InfoMsg(const AMsg: String); procedure InfoMsg(const AMsg: String);
procedure ErrorMsg(const AMsg: String); procedure ErrorMsg(const AMsg: String);
procedure UpdateLastDirs(D: String); procedure UpdateLastDirs(D: String);
@ -58,6 +59,11 @@ implementation
{ TMainForm } { TMainForm }
function TMainForm.CalcIniFileName: String;
begin
Result := Application.Location + 'IconTableConfig.ini';
end;
procedure TMainForm.FormCreate(Sender: TObject); procedure TMainForm.FormCreate(Sender: TObject);
var var
i: Integer; i: Integer;
@ -76,13 +82,23 @@ end;
procedure TMainForm.FormShow(Sender: TObject); procedure TMainForm.FormShow(Sender: TObject);
var var
i: Integer; i: Integer;
L, T, W, H: Integer;
R: TRect;
begin begin
Config := TIniFile.Create('IconTableConfig.ini'); Config := TIniFile.Create(CalcIniFileName);
try try
Top := Config.ReadInteger('Position', 'Top', 100); T := Config.ReadInteger('Position', 'Top', 100);
Left := Config.ReadInteger('Position', 'Left', 100); L := Config.ReadInteger('Position', 'Left', 100);
Width := Config.ReadInteger('Position', 'Width', 100); W := Config.ReadInteger('Position', 'Width', 100);
Height := Config.ReadInteger('Position', 'Height', 100); H := Config.ReadInteger('Position', 'Height', 100);
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 T + H > R.Bottom then T := R.Bottom - H - GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYSIZEFRAME);
SetBounds(L, T, W, H);
WindowState := wsNormal; WindowState := wsNormal;
Application.ProcessMessages; Application.ProcessMessages;
WindowState := TWindowState(Config.ReadInteger('Position', 'WindowState', 0)); WindowState := TWindowState(Config.ReadInteger('Position', 'WindowState', 0));
@ -117,18 +133,22 @@ begin
if WindowState = wsMinimized then if WindowState = wsMinimized then
WindowState := wsNormal; WindowState := wsNormal;
Config := TIniFile.Create('IconTableConfig.ini'); Config := TIniFile.Create(CalcIniFileName);
try try
Config.WriteInteger('Position', 'Top', RestoredTop); try
Config.WriteInteger('Position', 'Left', RestoredLeft); Config.WriteInteger('Position', 'Top', RestoredTop);
Config.WriteInteger('Position', 'Width', RestoredWidth); Config.WriteInteger('Position', 'Left', RestoredLeft);
Config.WriteInteger('Position', 'Height', RestoredHeight); Config.WriteInteger('Position', 'Width', RestoredWidth);
Config.WriteInteger('Position', 'WindowState', Integer(WindowState)); Config.WriteInteger('Position', 'Height', RestoredHeight);
Config.WriteInteger('Position', 'WindowState', Integer(WindowState));
for i := 0 to LastDirsMax do for i := 0 to LastDirsMax do
Config.WriteString('LastDirs', 'LastDir' + i.ToString, popLastDirs.Items[i].Caption); Config.WriteString('LastDirs', 'LastDir' + i.ToString, popLastDirs.Items[i].Caption);
Config.WriteBool('Options', 'DarkMode', cbDarkMode.Checked); Config.WriteBool('Options', 'DarkMode', cbDarkMode.Checked);
except
ErrorMsg('The configuration could not be saved.');
end;
finally finally
Config.Free; Config.Free;
end; end;
@ -372,16 +392,15 @@ var
i: Integer; i: Integer;
begin begin
i := popLastDirs.Items.IndexOfCaption(D); i := popLastDirs.Items.IndexOfCaption(D);
if i >-1 then if i > -1 then
popLastDirs.Items[i].MenuIndex := 0
else
begin begin
popLastDirs.Items[i].MenuIndex := 0; popLastDirs.Items[LastDirsMax].Caption := D;
Exit; popLastDirs.Items[LastDirsMax].Visible := True;
popLastDirs.Items[LastDirsMax].MenuIndex := 0;
end; end;
sbtnLastDirs.Enabled := popLastDirs.Items[0].Caption > '';
popLastDirs.Items[LastDirsMax].Caption := D;
popLastDirs.Items[LastDirsMax].Visible := True;
popLastDirs.Items[LastDirsMax].MenuIndex := 0;
sbtnLastDirs.Enabled := True;
end; end;
procedure TMainForm.InfoMsg(const AMsg: String); procedure TMainForm.InfoMsg(const AMsg: String);