FreeLaunch
218 строк · 7.6 Кб
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 FilePropertiesFormModule;
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
38TFilePropertiesForm = class(TForm)
39PageControl1: TPageControl;
40TabSheet1: TTabSheet;
41Label1: TLabel;
42Label4: TLabel;
43DescrEdit: TEdit;
44Label7: TLabel;
45WStyleBox: TComboBox;
46Bevel1: TBevel;
47Label5: TLabel;
48Bevel2: TBevel;
49Bevel3: TBevel;
50Label6: TLabel;
51IcImage: TImage;
52ChangeIconButton: TButton;
53QuesCheckBox: TCheckBox;
54OKButton: TButton;
55CancelButton: TButton;
56HideCheckBox: TCheckBox;
57Label9: TLabel;
58CommandEdit: TButtonedEdit;
59RefProps: TButton;
60WorkFolderEdit: TButtonedEdit;
61procedure FormShow(Sender: TObject);
62procedure BrowseExecClick(Sender: TObject);
63procedure OKButtonClick(Sender: TObject);
64procedure ChangeIconButtonClick(Sender: TObject);
65procedure RefPropsClick(Sender: TObject);
66procedure CommandEditChange(Sender: TObject);
67procedure WorkFolderClick(Sender: TObject);
68private
69Link: TLink;
70public
71procedure RefreshProps;
72class function Execute(ALink: TLink): TLink;
73end;
74
75var
76ic: string;
77iconindex: integer;
78
79implementation
80
81uses
82FLaunchMainFormModule, FLDialogs;
83
84{$R *.dfm}
85
86procedure TFilePropertiesForm.ChangeIconButtonClick(Sender: TObject);
87var
88frm: TChangeIconForm;
89begin
90Application.CreateForm(TChangeIconForm, frm);
91frm.ShowModal;
92FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(ic), iconindex);
93end;
94
95procedure TFilePropertiesForm.CommandEditChange(Sender: TObject);
96begin
97OKButton.Enabled := FileExists(GetAbsolutePath(CommandEdit.Text)) or DirectoryExists(GetAbsolutePath(CommandEdit.Text));
98end;
99
100class function TFilePropertiesForm.Execute(ALink: TLink): TLink;
101begin
102with TFilePropertiesForm.Create(Application.MainForm) do
103try
104Link := ALink;
105ShowModal;
106finally
107Result := Link;
108Free;
109end;
110end;
111
112procedure TFilePropertiesForm.OKButtonClick(Sender: TObject);
113begin
114if (not FileExists(GetAbsolutePath(CommandEdit.Text))) and (not DirectoryExists(GetAbsolutePath(CommandEdit.Text))) then
115begin
116fillchar(Link, sizeof(TLink), 0);
117exit;
118end;
119Link.active := true;
120Link.ltype := 1;
121Link.exec := CommandEdit.Text;
122Link.workdir := WorkFolderEdit.Text;
123Link.descr := DescrEdit.Text;
124Link.icon := ic;
125Link.iconindex := iconindex;
126Link.ques := QuesCheckBox.Checked;
127Link.hide := HideCheckBox.Checked;
128Link.wst := WStyleBox.ItemIndex;
129end;
130
131procedure TFilePropertiesForm.RefPropsClick(Sender: TObject);
132begin
133RefreshProps;
134end;
135
136procedure TFilePropertiesForm.FormShow(Sender: TObject);
137begin
138if AlwaysOnTop then FormStyle := fsStayOnTop;
139//--Loading language
140OKButton.Caption := Language.BtnOk;
141CancelButton.Caption := Language.BtnCancel;
142PageControl1.Pages[0].Caption := Language.Properties.Caption;
143Caption := Language.Properties.Caption;
144Label9.Caption := Language.Properties.Folder + ':';
145Label1.Caption := Language.Properties.LblObject + ':';
146Label4.Caption := Language.Properties.Description + ':';
147Label7.Caption := Language.Properties.View + ':';
148WStyleBox.Items.Add(Language.Properties.ViewNormal);
149WStyleBox.Items.Add(Language.Properties.ViewMax);
150WStyleBox.Items.Add(Language.Properties.ViewMin);
151WStyleBox.Items.Add(Language.Properties.ViewHidden);
152CommandEdit.RightButton.Hint := Language.Properties.BeHint;
153RefProps.Hint := Language.Properties.RpHint;
154Label5.Caption := Language.Properties.Options;
155Bevel2.Left := Label5.Left + Label5.Width + 7;
156Bevel2.Width := TabSheet1.Width - Bevel2.Left - 7;
157Label6.Caption := Language.Properties.Icon;
158Bevel3.Left := Label6.Left + Label6.Width + 7;
159Bevel3.Width := TabSheet1.Width - Bevel3.Left - 7;
160ChangeIconButton.Caption := Language.Properties.Change;
161QuesCheckBox.Caption := Language.Properties.ChbQuestion;
162HideCheckBox.Caption := Language.Properties.ChbHide;
163
164CommandEdit.Text := Link.exec;
165WorkFolderEdit.Text := Link.workdir;
166DescrEdit.Text := Link.descr;
167ic := Link.icon;
168iconindex := Link.iconindex;
169QuesCheckBox.Checked := Link.ques;
170HideCheckBox.Checked := Link.hide;
171WStyleBox.ItemIndex := Link.wst;
172FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(Link.icon),
173Link.iconindex);
174CommandEditChange(nil);
175end;
176
177procedure TFilePropertiesForm.RefreshProps;
178var
179lnkinfo: TShellLinkInfoStruct;
180begin
181if (not FileExists(GetAbsolutePath(CommandEdit.Text))) and (not DirectoryExists(GetAbsolutePath(CommandEdit.Text))) then exit;
182
183if extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower = '.lnk' then
184begin
185StrPLCopy(lnkinfo.FullPathAndNameOfLinkFile, GetAbsolutePath(CommandEdit.Text), MAX_PATH - 1);
186GetLinkInfo(@lnkinfo);
187CommandEdit.Text := lnkinfo.FullPathAndNameOfFileToExecute;
188Ic := lnkinfo.FullPathAndNameOfFileContiningIcon;
189if Ic = '' then Ic := CommandEdit.Text;
190iconindex := lnkinfo.IconIndex;
191WorkFolderEdit.Text := lnkinfo.FullPathAndNameOfWorkingDirectroy;
192DescrEdit.Text := lnkinfo.Description;
193end
194else
195begin
196//ext := extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower;
197//if not IsExecutable(ext) then exit;
198Ic := CommandEdit.Text;
199//ParamsEdit.Text := '';
200DescrEdit.Text := '';
201iconindex := 0;
202end;
203if DescrEdit.Text = '' then
204DescrEdit.Text := ExtractFileName(GetAbsolutePath(CommandEdit.Text));
205FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(Ic), iconindex);
206end;
207
208procedure TFilePropertiesForm.WorkFolderClick(Sender: TObject);
209begin
210WorkFolderEdit.Text := ExtractFileDir(FileOrDirSelect(WorkFolderEdit.Text));
211end;
212
213procedure TFilePropertiesForm.BrowseExecClick(Sender: TObject);
214begin
215CommandEdit.Text := FileOrDirSelect(CommandEdit.Text);
216end;
217
218end.
219