FreeLaunch
274 строки · 9.4 Кб
1{
2##########################################################################
3# FreeLaunch is a free links manager for Microsoft Windows #
4# #
5# Copyright (C) 2023 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 ProgrammPropertiesFormModule;
27
28interface
29
30uses
31Winapi.Windows, Winapi.Messages, Winapi.ShellAPI,
32System.SysUtils, System.Variants, System.Classes, System.IniFiles,
33Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls,
34Vcl.ExtCtrls, Vcl.StdCtrls,
35ChangeIconFormModule, FLData, FLFunctions, FLLanguage;
36
37type
38TProgrammPropertiesForm = class(TForm)
39PageControl1: TPageControl;
40TabSheet1: TTabSheet;
41Label1: TLabel;
42Label2: TLabel;
43Label4: TLabel;
44ParamsEdit: TEdit;
45DescrEdit: TEdit;
46Label3: TLabel;
47PriorBox: TComboBox;
48Bevel1: TBevel;
49Label5: TLabel;
50Bevel2: TBevel;
51Bevel3: TBevel;
52Label6: TLabel;
53IcImage: TImage;
54ChangeIconButton: TButton;
55QuesCheckBox: TCheckBox;
56Label7: TLabel;
57WStyleBox: TComboBox;
58OKButton: TButton;
59CancelButton: TButton;
60DropBox: TCheckBox;
61DropParamsEdit: TEdit;
62Label8: TLabel;
63HideCheckBox: TCheckBox;
64Label9: TLabel;
65RefProps: TButton;
66CommandEdit: TButtonedEdit;
67AdminBox: TCheckBox;
68WorkFolderEdit: TButtonedEdit;
69procedure FormShow(Sender: TObject);
70procedure BrowseExecClick(Sender: TObject);
71procedure OKButtonClick(Sender: TObject);
72procedure ChangeIconButtonClick(Sender: TObject);
73procedure DropBoxClick(Sender: TObject);
74procedure RefPropsClick(Sender: TObject);
75procedure CommandEditChange(Sender: TObject);
76procedure WorkFolderClick(Sender: TObject);
77private
78Link: TLink;
79public
80procedure RefreshProps;
81class function Execute(ALink: TLink): TLink;
82end;
83
84var
85ic: string;
86iconindex: integer;
87
88implementation
89
90uses
91FLaunchMainFormModule, FLDialogs;
92
93{$R *.dfm}
94
95procedure TProgrammPropertiesForm.ChangeIconButtonClick(Sender: TObject);
96var
97frm: TChangeIconForm;
98begin
99Application.CreateForm(TChangeIconForm, frm);
100frm.ShowModal;
101FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(ic), iconindex);
102end;
103
104procedure TProgrammPropertiesForm.CommandEditChange(Sender: TObject);
105var
106ext: string;
107begin
108ext := extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower;
109OKButton.Enabled := FileExists(GetAbsolutePath(CommandEdit.Text)) and IsExecutable(ext);
110end;
111
112procedure TProgrammPropertiesForm.OKButtonClick(Sender: TObject);
113begin
114if (not fileexists(GetAbsolutePath(CommandEdit.Text))) then
115begin
116fillchar(Link, sizeof(TLink), 0);
117exit;
118end;
119link.active := true;
120link.ltype := 0;
121link.exec := CommandEdit.Text;
122link.workdir := WorkFolderEdit.Text;
123link.params := ParamsEdit.Text;
124link.dropfiles := DropBox.Checked;
125link.dropparams := DropParamsEdit.Text;
126link.descr := DescrEdit.Text;
127link.icon := ic;
128link.iconindex := iconindex;
129link.ques := QuesCheckBox.Checked;
130link.hide := HideCheckBox.Checked;
131link.pr := PriorBox.ItemIndex;
132link.wst := WStyleBox.ItemIndex;
133Link.IsAdmin := AdminBox.Checked;
134end;
135
136procedure TProgrammPropertiesForm.RefPropsClick(Sender: TObject);
137begin
138RefreshProps;
139end;
140
141procedure TProgrammPropertiesForm.DropBoxClick(Sender: TObject);
142begin
143Label8.Enabled := DropBox.Checked;
144DropParamsEdit.Enabled := DropBox.Checked;
145if DropBox.Checked then
146begin
147if DropParamsEdit.Text = '' then
148DropParamsEdit.Text := '"%1"';
149DropParamsEdit.SetFocus;
150end;
151end;
152
153class function TProgrammPropertiesForm.Execute(ALink: TLink): TLink;
154begin
155with TProgrammPropertiesForm.Create(Application.MainForm) do
156try
157Link := ALink;
158ShowModal;
159finally
160Result := Link;
161Free;
162end;
163end;
164
165procedure TProgrammPropertiesForm.FormShow(Sender: TObject);
166begin
167if AlwaysOnTop then FormStyle := fsStayOnTop;
168//--Loading language
169OKButton.Caption := Language.BtnOk;
170CancelButton.Caption := Language.BtnCancel;
171PageControl1.Pages[0].Caption := Language.Properties.Caption;
172Caption := Language.Properties.Caption;
173Label9.Caption := Language.Properties.Folder + ':';
174Label1.Caption := Language.Properties.LblObject + ':';
175Label2.Caption := Language.Properties.Parameters + ':';
176Label8.Caption := Label2.Caption;
177Label4.Caption := Language.Properties.Description + ':';
178Label3.Caption := Language.Properties.Priority + ':';
179PriorBox.Items.Add(Language.Properties.PriorityNormal);
180PriorBox.Items.Add(Language.Properties.PriorityHigh);
181PriorBox.Items.Add(Language.Properties.PriorityIdle);
182PriorBox.Items.Add(Language.Properties.PriorityRealTime);
183PriorBox.Items.Add(Language.Properties.PriorityBelowNormal);
184PriorBox.Items.Add(Language.Properties.PriorityAboveNormal);
185Label7.Caption := Language.Properties.View + ':';
186WStyleBox.Items.Add(Language.Properties.ViewNormal);
187WStyleBox.Items.Add(Language.Properties.ViewMax);
188WStyleBox.Items.Add(Language.Properties.ViewMin);
189WStyleBox.Items.Add(Language.Properties.ViewHidden);
190CommandEdit.RightButton.Hint := Language.Properties.BeHint;
191RefProps.Hint := Language.Properties.RpHint;
192Label5.Caption := Language.Properties.Options;
193Bevel2.Left := Label5.Left + Label5.Width + 7;
194Bevel2.Width := TabSheet1.Width - Bevel2.Left - 7;
195Label6.Caption := Language.Properties.Icon;
196Bevel3.Left := Label6.Left + Label6.Width + 7;
197Bevel3.Width := TabSheet1.Width - Bevel3.Left - 7;
198ChangeIconButton.Caption := Language.Properties.Change;
199DropBox.Caption := Language.Properties.ChbDrop;
200QuesCheckBox.Caption := Language.Properties.ChbQuestion;
201HideCheckBox.Caption := Language.Properties.ChbHide;
202AdminBox.Caption := Language.Properties.ChbAdmin;
203
204CommandEdit.Text := Link.exec;
205WorkFolderEdit.Text := Link.workdir;
206ParamsEdit.Text := Link.params;
207DropBox.Checked := Link.dropfiles;
208DropBoxClick(nil);
209DropParamsEdit.Text := Link.dropparams;
210DescrEdit.Text := Link.descr;
211ic := Link.icon;
212iconindex := Link.iconindex;
213QuesCheckBox.Checked := Link.ques;
214HideCheckBox.Checked := Link.hide;
215PriorBox.ItemIndex := Link.pr;
216WStyleBox.ItemIndex := Link.wst;
217AdminBox.Checked := Link.IsAdmin;
218FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(Link.icon),
219Link.iconindex);
220CommandEditChange(nil);
221end;
222
223procedure TProgrammPropertiesForm.RefreshProps;
224var
225lnkinfo: TShellLinkInfoStruct;
226FName: string;
227ext: string;
228begin
229if (not fileexists(GetAbsolutePath(CommandEdit.Text))) then exit;
230
231if extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower = '.lnk' then
232begin
233StrPLCopy(lnkinfo.FullPathAndNameOfLinkFile, GetAbsolutePath(CommandEdit.Text), MAX_PATH - 1);
234GetLinkInfo(@lnkinfo);
235FName := lnkinfo.FullPathAndNameOfFileToExecute;
236ext := extractfileext(FName).ToLower;
237if not IsExecutable(ext) then
238exit;
239CommandEdit.Text := FName;
240Ic := lnkinfo.FullPathAndNameOfFileContiningIcon;
241if Ic = '' then Ic := CommandEdit.Text;
242iconindex := lnkinfo.IconIndex;
243WorkFolderEdit.Text := lnkinfo.FullPathAndNameOfWorkingDirectroy;
244ParamsEdit.Text := lnkinfo.ParamStringsOfFileToExecute;
245DescrEdit.Text := lnkinfo.Description;
246end
247else
248begin
249ext := extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower;
250if not IsExecutable(ext) then
251Exit;
252Ic := CommandEdit.Text;
253//ParamsEdit.Text := '';
254DescrEdit.Text := '';
255iconindex := 0;
256end;
257if DescrEdit.Text = '' then
258DescrEdit.Text := GetFileDescription(GetAbsolutePath(CommandEdit.Text));
259if DescrEdit.Text = '' then
260DescrEdit.Text := ExtractFileNameNoExt(GetAbsolutePath(CommandEdit.Text));
261FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(Ic), iconindex);
262end;
263
264procedure TProgrammPropertiesForm.WorkFolderClick(Sender: TObject);
265begin
266WorkFolderEdit.Text := ExtractFileDir(FileOrDirSelect(WorkFolderEdit.Text));
267end;
268
269procedure TProgrammPropertiesForm.BrowseExecClick(Sender: TObject);
270begin
271CommandEdit.Text := ProgramSelect(CommandEdit.Text);
272end;
273
274end.
275