-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathPropertyFile.pas
279 lines (251 loc) · 8.24 KB
/
PropertyFile.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
{
Copyright (C) 2006-2009 Matteo Salvi and Shannara
Website: http://www.salvadorsoftware.com/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
}
unit PropertyFile;
{$MODE Delphi}
interface
uses
SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,
ulNodeDataTypes, FileUtil;
type
{ TfrmPropertyFile }
TfrmPropertyFile = class(TForm)
btnOk: TButton;
btnCancel: TButton;
OpenDialog1: TOpenDialog;
PageControl1: TPageControl;
tsInfo1: TTabSheet;
lbInfo1: TLabel;
lbName: TLabel;
edtName: TEdit;
tsInfo2: TTabSheet;
lbPathIcon: TLabel;
lbAutoExecute: TLabel;
lbWindowState: TLabel;
lbWorkingDir: TLabel;
edtPathIcon: TEdit;
btnBrowseIcon: TButton;
cxAutoExecute: TComboBox;
cxWindowState: TComboBox;
edtWorkingDir: TEdit;
btnBrowseWorkingDir: TButton;
lbPathExe: TLabel;
edtPathExe: TEdit;
edtParameters: TEdit;
lbParameters: TLabel;
btnBrowseExe: TButton;
lbInfo2: TLabel;
lbActionOnExe: TLabel;
cxActionOnExe: TComboBox;
cbDontInsertMRU: TCheckBox;
cbShortcutDesktop: TCheckBox;
cbHideSoftware: TCheckBox;
btnChangeOrder: TButton;
cbDontInsertMFU: TCheckBox;
procedure Browse(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnOkClick(Sender: TObject);
procedure edtNameEnter(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure edtPathExeExit(Sender: TObject);
procedure btnChangeOrderClick(Sender: TObject);
procedure cxAutoExecuteChange(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
FNodeData: PBaseData;
procedure LoadNodeData(AData: TvFileNodeData);
procedure SaveNodeData(AData: TvFileNodeData);
public
{ Public declarations }
class function Edit(AOwner: TComponent; NodeData: PBaseData): TModalResult;
end;
var
frmPropertyFile : TfrmPropertyFile;
implementation
{$R *.lfm}
uses
AppConfig, ulEnumerations, udImages, ulSysUtils, ulExeUtils, OrderSoftware,
Main, ulCommonUtils;
class function TfrmPropertyFile.Edit(AOwner: TComponent; NodeData: PBaseData): TModalResult;
begin
Result := mrNone;
if not Assigned(NodeData) then
ShowMessage(msgErrGeneric)
else with TfrmPropertyFile.Create(AOwner) do
try
FNodeData := NodeData;
LoadNodeData(TvFileNodeData(NodeData.Data));
FormStyle := frmMain.FormStyle;
ShowModal;
if ModalResult = mrOK then
SaveNodeData(TvFileNodeData(NodeData.Data));
Result := ModalResult;
finally
Free;
end;
end;
procedure TfrmPropertyFile.LoadNodeData(AData: TvFileNodeData);
begin
edtName.Text := AData.name;
edtPathExe.Text := AData.PathExe;
if not(FileFolderPageWebExists(AData.PathAbsoluteExe)) then
begin
edtPathExe.Font.Color := clRed;
edtPathExe.Hint := msgFileNotFound;
end;
edtParameters.Text := AData.Parameters;
edtWorkingDir.Text := AData.WorkingDir;
edtPathIcon.Text := AData.PathIcon;
cxActionOnExe.ItemIndex := Ord(AData.ActionOnExe);
cxAutoExecute.ItemIndex := Ord(AData.Autorun);
btnChangeOrder.Enabled := (cxAutoExecute.ItemIndex <> 0);
//Window State
if (AData.WindowState <> -1) and Not(AData.WindowState >= 4) then
cxWindowState.ItemIndex := AData.WindowState
else
cxWindowState.ItemIndex := 0;
//Others
cbDontInsertMRU.Checked := AData.NoMRU;
cbDontInsertMFU.Checked := AData.NoMFU;
cbShortcutDesktop.Checked := AData.ShortcutDesktop;
cbHideSoftware.Checked := AData.HideFromMenu;
end;
procedure TfrmPropertyFile.SaveNodeData(AData: TvFileNodeData);
begin
if (edtPathExe.Text = '') then
edtPathExe.Text := CONST_PATH_DRIVE;
AData.Name := StringReplace(edtName.Text, '&&', '&', [rfIgnoreCase,rfReplaceAll]);
AData.Name := StringReplace(AData.Name, '&', '&&', [rfIgnoreCase,rfReplaceAll]);
AData.PathExe := edtPathExe.Text;
AData.Parameters := edtParameters.Text;
//Advanced
AData.WorkingDir := edtWorkingDir.Text;
AData.PathIcon := edtPathIcon.Text;
AData.ActionOnExe := TActionOnExecution(cxActionOnExe.ItemIndex);
AData.Autorun := TAutorunType(cxAutoExecute.ItemIndex);
//Others
AData.NoMRU := cbDontInsertMRU.Checked;
AData.NoMFU := cbDontInsertMFU.Checked;
AData.HideFromMenu := cbHideSoftware.Checked;
AData.WindowState := cxWindowState.ItemIndex;
AData.ShortcutDesktop := cbShortcutDesktop.Checked;
ImagesDM.DeleteCacheIcon(AData);
AData.ImageIndex := ImagesDM.GetIconIndex(TvBaseNodeData(AData));
AData.Changed := true;
end;
procedure TfrmPropertyFile.Browse(Sender: TObject);
var
PathTemp : String;
begin
if (sender = btnBrowseExe) then
begin
OpenDialog1.Filter := 'Executables (*.exe)|*.exe|All files|*.*';
OpenDialog1.InitialDir := ExtractFileDir(RelativeToAbsolute(edtPathExe.Text));
end;
if (sender = btnBrowseIcon) then
begin
OpenDialog1.Filter := 'Files supported (*.ico;*.exe)|*.ico;*.exe|All files|*.*';
OpenDialog1.InitialDir := ExtractFileDir(RelativeToAbsolute(edtPathIcon.Text));
end;
if (sender = btnBrowseExe) or (sender = btnBrowseIcon) then
begin
if (OpenDialog1.Execute) then
begin
PathTemp := AbsoluteToRelative(OpenDialog1.FileName);
{ TODO -oMatteo -c : Get automatically its name from exe (like PStart) 26/07/2010 22:02:57 }
if (sender = btnBrowseExe) then
begin
edtPathExe.text := PathTemp;
edtPathExe.Font.Color := clWindowText;
edtPathExe.Hint := '';
end;
if (sender = btnBrowseIcon) then
edtPathIcon.text := PathTemp;
end;
end;
if sender = btnBrowseWorkingDir then
begin
PathTemp := BrowseForFolder('', RelativeToAbsolute(edtWorkingDir.Text));
if (PathTemp <> '') then
edtWorkingDir.Text := AbsoluteToRelative(PathTemp);
end;
SetCurrentDirUTF8(SUITE_WORKING_PATH);
end;
procedure TfrmPropertyFile.btnCancelClick(Sender: TObject);
begin
close;
end;
procedure TfrmPropertyFile.btnChangeOrderClick(Sender: TObject);
begin
//Autorun
with TvFileNodeData(FNodeData.Data) do
begin
Autorun := TAutorunType(cxAutoExecute.ItemIndex);
try
Application.CreateForm(TfrmOrderSoftware, frmOrderSoftware);
frmOrderSoftware.FormStyle := Self.FormStyle;
frmOrderSoftware.AutorunType := Autorun;
frmOrderSoftware.showmodal;
finally
frmOrderSoftware.Free;
end;
end;
end;
procedure TfrmPropertyFile.btnOkClick(Sender: TObject);
begin
CheckPropertyName(edtName);
end;
procedure TfrmPropertyFile.edtNameEnter(Sender: TObject);
begin
TEdit(Sender).Color := clDefault;
end;
procedure TfrmPropertyFile.cxAutoExecuteChange(Sender: TObject);
begin
btnChangeOrder.Enabled := (cxAutoExecute.ItemIndex <> 0);
end;
procedure TfrmPropertyFile.edtPathExeExit(Sender: TObject);
var
PathTemp : String;
begin
PathTemp := RelativeToAbsolute(edtPathExe.Text);
if Not(FileFolderPageWebExists(PathTemp)) then
begin
//File not found - Change font color with red
edtPathExe.Font.Color := clRed;
edtPathExe.Hint := msgFileNotFound;
end
else begin
//File found - Change font color with black
edtPathExe.Font.Color := clBlack;
edtPathExe.Hint := '';
end;
end;
procedure TfrmPropertyFile.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
CanClose := ((ModalResult = mrOK) and (Trim(edtName.Text) <> ''))
or (ModalResult = mrCancel);
end;
procedure TfrmPropertyFile.FormCreate(Sender: TObject);
begin
PageControl1.ActivePageIndex := 0;
try
except
on E : Exception do
ShowMessageFmt(msgErrGeneric,[E.ClassName,E.Message]);
end;
end;
end.