FreeLaunch
189 строк · 7.1 Кб
1{
2##########################################################################
3# FreeLaunch is a free links manager for Microsoft Windows #
4# #
5# Copyright (C) 2024 Alexey Tatuyko <feedback@ta2i4.ru> #
6# Copyright (C) 2019 Mykola Petrivskiy #
7# Copyright (C) 2010 Joker-jar <joker-jar@yandex.ru> #
8# #
9# This file is part of FreeLaunch. #
10# #
11# FreeLaunch is free software: you can redistribute it and/or modify #
12# it under the terms of the GNU General Public License as published by #
13# the Free Software Foundation, either version 3 of the License, or #
14# (at your option) any later version. #
15# #
16# FreeLaunch is distributed in the hope that it will be useful, #
17# but WITHOUT ANY WARRANTY; without even the implied warranty of #
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
19# GNU General Public License for more details. #
20# #
21# You should have received a copy of the GNU General Public License #
22# along with FreeLaunch. If not, see <http://www.gnu.org/licenses/>. #
23##########################################################################
24}
25
26unit ChangeIconFormModule;
27
28interface
29
30uses
31Winapi.Windows, Winapi.Messages, System.Math,
32System.SysUtils, System.Variants, System.Classes, System.IniFiles,
33Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,
34Vcl.StdCtrls, Vcl.ComCtrls,
35Vcl.Samples.Spin,
36FLData, FLFunctions, FLLanguage;
37
38type
39TChangeIconForm = class(TForm)
40GroupBox1: TGroupBox;
41Label1: TLabel;
42Label2: TLabel;
43CancelButton: TButton;
44OKButton: TButton;
45IcImage: TImage;
46Label3: TLabel;
47IndexEdit: TSpinEdit;
48RefProps: TButton;
49IconEdit: TButtonedEdit;
50NegativeBox: TCheckBox;
51procedure FormShow(Sender: TObject);
52procedure BrowseIconClick(Sender: TObject);
53procedure CancelButtonClick(Sender: TObject);
54procedure OKButtonClick(Sender: TObject);
55procedure FormClose(Sender: TObject; var Action: TCloseAction);
56procedure RefPropsClick(Sender: TObject);
57procedure IndexEditChange(Sender: TObject);
58private
59icindex, iconcount, ncount: integer;
60public
61procedure RefreshProps;
62end;
63
64var
65showform: Boolean = True;
66
67implementation
68
69uses
70FLaunchMainFormModule, ProgrammPropertiesFormModule, FilePropertiesFormModule,
71FLDialogs;
72
73{$R *.dfm}
74
75procedure TChangeIconForm.RefreshProps;
76begin
77icindex := 1;
78iconcount := GetIconCount(GetAbsolutePath(IconEdit.Text));
79ncount := GetNegativeCount(IconEdit.Text);
80if iconcount = 0 then iconcount := 1;
81Label3.Caption := Format(Language.IconSelect.LblOf, [iconcount]);
82IndexEdit.Value := icindex;
83IndexEdit.MaxValue := iconcount;
84IndexEdit.Enabled := iconcount > 1;
85NegativeBox.Enabled := (iconcount > 1) and (ncount > 1);
86NegativeBox.Checked := False;
87FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(IconEdit.Text),
88Pred(icindex));
89end;
90
91procedure TChangeIconForm.BrowseIconClick(Sender: TObject);
92var
93FileName: string;
94begin
95FileName := FileOrDirSelect(IconEdit.Text);
96if FileName <> IconEdit.Text then
97begin
98IconEdit.Text := FileName;
99RefreshProps;
100end;
101end;
102
103procedure TChangeIconForm.OKButtonClick(Sender: TObject);
104begin
105if PropertiesMode = 0 then
106begin
107ProgrammPropertiesFormModule.ic := IconEdit.Text;
108ProgrammPropertiesFormModule.iconindex := icindex +
109IfThen(icindex < 0, 1, -1);
110end;
111if PropertiesMode = 1 then
112begin
113FilePropertiesFormModule.ic := IconEdit.Text;
114FilePropertiesFormModule.iconindex := icindex +
115IfThen(icindex < 0, 1, -1);
116end;
117Close;
118end;
119
120procedure TChangeIconForm.RefPropsClick(Sender: TObject);
121begin
122RefreshProps;
123end;
124
125procedure TChangeIconForm.CancelButtonClick(Sender: TObject);
126begin
127Close;
128end;
129
130procedure TChangeIconForm.FormClose(Sender: TObject; var Action: TCloseAction);
131begin
132showform := True;
133Action := CAFree;
134end;
135
136procedure TChangeIconForm.FormShow(Sender: TObject);
137begin
138if AlwaysOnTop then FormStyle := fsStayOnTop;
139//--Loading language
140OKButton.Caption := Language.BtnOk;
141CancelButton.Caption := Language.BtnCancel;
142Caption := Language.IconSelect.Caption;
143Label1.Caption := Language.IconSelect.FileName + ':';
144Label2.Caption := Language.IconSelect.Index + ':';
145NegativeBox.Caption := Language.IconSelect.Negative;
146//---------------------------
147if PropertiesMode = 0 then begin
148IconEdit.Text := ProgrammPropertiesFormModule.ic;
149iconcount := GetIconCount(GetAbsolutePath(ProgrammPropertiesFormModule.Ic));
150icindex := ProgrammPropertiesFormModule.iconindex +
151IfThen(ProgrammPropertiesFormModule.iconindex < 0, -1, 1);
152ncount := GetNegativeCount(GetAbsolutePath(ProgrammPropertiesFormModule.Ic));
153end;
154if PropertiesMode = 1 then begin
155IconEdit.Text := FilePropertiesFormModule.ic;
156iconcount := GetIconCount(GetAbsolutePath(FilePropertiesFormModule.Ic));
157icindex := FilePropertiesFormModule.iconindex +
158IfThen(FilePropertiesFormModule.iconindex < 0, -1, 1);
159ncount := GetNegativeCount(GetAbsolutePath(ProgrammPropertiesFormModule.Ic));
160end;
161NegativeBox.Enabled := (iconcount > 1) and (ncount > 1);
162if iconcount = 0 then iconcount := 1;
163NegativeBox.Checked := (icindex < -1) and (ncount >= -icindex);
164Label3.Caption := Format(Language.IconSelect.LblOf, [IfThen(NegativeBox.Checked, ncount, iconcount)]);
165IndexEdit.Value := IfThen(icindex < 0, -icindex, icindex);
166if NegativeBox.Checked
167then IndexEdit.Enabled := ncount > 1
168else IndexEdit.Enabled := iconcount > 1;
169IndexEdit.MaxValue := IfThen(NegativeBox.Checked, ncount, iconcount);
170FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(IconEdit.Text), icindex + IfThen(icindex < 0, 1, -1));
171IconEdit.SetFocus;
172showform := False;
173end;
174
175procedure TChangeIconForm.IndexEditChange(Sender: TObject);
176begin
177if showform then Exit;
178Label3.Caption := Format(Language.IconSelect.LblOf, [IfThen(NegativeBox.Checked, ncount, iconcount)]);
179IndexEdit.MaxValue := IfThen(NegativeBox.Checked, ncount, iconcount);
180if NegativeBox.Checked and (IndexEdit.Value > ncount)
181then begin
182IndexEdit.Value := 1;
183IndexEdit.Enabled := ncount > 1;
184end;
185icindex := IfThen(NegativeBox.Checked, -IndexEdit.Value, IndexEdit.Value);
186FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(IconEdit.Text), icindex + IfThen(icindex < 0, 1, -1));
187end;
188
189end.
190