-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathESoft.Launcher.RecentItems.pas
272 lines (229 loc) · 7.42 KB
/
ESoft.Launcher.RecentItems.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
Unit ESoft.Launcher.RecentItems;
{ ---------------------------------------------------------- }
{ Developed by Muhammad Ajmal p }
{ ---------------------------------------------------------- }
Interface
Uses
Vcl.StdCtrls,
Winapi.Windows,
System.Classes,
IniFiles,
System.SysUtils,
ShellApi,
Vcl.Graphics,
Generics.Collections,
ESoft.Utils;
Type
IEApplication = Interface
Function GetActualName: String;
Function GetISFixedParameter: Boolean;
Function GetRunAsAdmin: TCheckBoxState;
Procedure SetRunAsAdmin(Const aValue: TCheckBoxState);
Function GetFixedParameter: String;
Function GetLastUsedParamName: String;
Procedure SetLastUsedParamName(Const aValue: String);
Procedure RunExecutable(aParameter: String = '');
Function UnZip: Boolean;
Function CopyFromSourceFolder: Boolean;
Function GetIcon: TIcon;
Property ActualName: String Read GetActualName;
Property Icon: TIcon Read GetIcon;
Property ISFixedParameter: Boolean Read GetISFixedParameter;
Property FixedParameter: String Read GetFixedParameter;
Property LastUsedParamName: String Read GetLastUsedParamName Write SetLastUsedParamName;
Property RunAsAdmin: TCheckBoxState Read GetRunAsAdmin Write SetRunAsAdmin;
End;
TERecentItems = Class; // Forward declaration { Ajmal }
TERecentItem = Class(TInterfacedObject, IEApplication)
Strict Private
FRunAsAdmin: TCheckBoxState;
FOwner: TERecentItems;
FName: String;
FSourceFolder: String;
FExecutableName: String;
FParameters: TStringList;
FIcon: TIcon;
Procedure OnParamChange(aSender: TObject);
Function GetActualName: String;
Function GetISFixedParameter: Boolean;
Function GetFixedParameter: String;
Function GetLastUsedParamName: String;
procedure SetLastUsedParamName(const aValue: String);
Function GetRunAsAdmin: TCheckBoxState;
Procedure SetRunAsAdmin(Const aValue: TCheckBoxState);
Function GetIcon: TIcon;
Function GetParameter: TStringList;
Public
Constructor Create(Const aOwner: TERecentItems; Const aName: String; Const aSourceFolder: String = ''; Const aExecutableName: String = '');
Destructor Destroy; Override;
Procedure RunExecutable(aParameter: String = '');
Function UnZip: Boolean;
Function CopyFromSourceFolder: Boolean;
Property ActualName: String Read GetActualName;
Property Name: String Read FName;
Property SourceFolder: String Read FSourceFolder Write FSourceFolder;
Property ExecutableName: String Read FExecutableName Write FExecutableName;
Property Parameter: TStringList Read GetParameter;
Property Icon: TIcon Read GetIcon;
Property RunAsAdmin: TCheckBoxState Read GetRunAsAdmin Write SetRunAsAdmin;
End;
TERecentItems = Class(TObjectList<TERecentItem>)
Strict Private
FOnChange: TNotifyEvent;
Private
Procedure DoChange(Const aItem: TERecentItem);
Public
Function Contains(Const aName: String): Boolean;
Function IndexOf(Const aName: String): Integer;
Function AddItem(Const aName: String; Const aSourceFolder: String = ''; Const aExecutableName: String = ''): TERecentItem;
Published
Property OnChange: TNotifyEvent Read FOnChange Write FOnChange;
End;
Implementation
{ TERecentItem }
Uses
UnitMDIMain;
Function TERecentItem.CopyFromSourceFolder: Boolean;
Begin
Result := True;
End;
Constructor TERecentItem.Create(Const aOwner: TERecentItems; Const aName, aSourceFolder, aExecutableName: String);
Begin
FOwner := aOwner;
FName := aName;
FSourceFolder := aSourceFolder;
FExecutableName := aExecutableName;
End;
Destructor TERecentItem.Destroy;
Begin
EFreeAndNil(FParameters);
EFreeAndNil(FIcon);
Inherited;
End;
Function TERecentItem.GetActualName: String;
Begin
Result := Name;
End;
Function TERecentItem.GetFixedParameter: String;
Begin
// For recent items, Parameters are fixed always from the previous used list. { Ajmal }
Result := '';
End;
Function TERecentItem.GetIcon: TIcon;
Var
sFileName: String;
Begin
Result := Nil;
sFileName := IncludeTrailingBackslash(SourceFolder) + ExecutableName;
EFreeAndNil(FIcon);
// Check for file extention 1st. If it's a network folder, then we skip it first since folder won't have extension { Ajmal }
If ExtractFileExt(sFileName) = '' Then
Exit;
If Not FileExists(sFileName) Then
Exit;
FIcon := TIcon.Create;
Try
FetchIcon(sFileName, FIcon);
Result := FIcon;
Except
EFreeAndNil(FIcon);
// Do nothing, it's not mandatory to have icon { Ajmal }
End;
End;
Function TERecentItem.GetISFixedParameter: Boolean;
Begin
// For recent items, Parameters are fixed always from the previous used list. { Ajmal }
Result := True;
End;
Function TERecentItem.GetLastUsedParamName: String;
Begin
// For recent items, Parameters are fixed always from the previous used list. { Ajmal }
Result := '';
End;
Function TERecentItem.GetParameter: TStringList;
Begin
If Not Assigned(FParameters) Then
Begin
FParameters := TStringList.Create;
FParameters.Duplicates := dupIgnore;
FParameters.Sorted := True;
FParameters.OnChange := OnParamChange;
End;
Result := FParameters;
End;
Function TERecentItem.GetRunAsAdmin: TCheckBoxState;
Begin
Result := FRunAsAdmin;
End;
Procedure TERecentItem.OnParamChange(aSender: TObject);
Begin
// For the 1st one, AddItem will call the DoChange { Ajmal }
If Parameter.Count > 1 Then
FOwner.DoChange(Self);
End;
Procedure TERecentItem.RunExecutable(aParameter: String);
Begin
If (aParameter = '') And (Parameter.Count > 0) Then
aParameter := Parameter[0];
FormMDIMain.RunApplication(
Name,
ExecutableName,
aParameter,
SourceFolder,
False,
RunAsAdmin
);
End;
Procedure TERecentItem.SetLastUsedParamName(const aValue: String);
Begin
// For recent items, Parameters are fixed always from the previous used list. { Ajmal }
End;
Procedure TERecentItem.SetRunAsAdmin(const aValue: TCheckBoxState);
Begin
FRunAsAdmin := aValue;
End;
Function TERecentItem.UnZip: Boolean;
Begin
Result := True;
End;
{ TERecentItems }
Function TERecentItems.AddItem(Const aName, aSourceFolder, aExecutableName: String): TERecentItem;
Var
iIndex: Integer;
Begin
Result := Nil;
iIndex := IndexOf(aName);
If iIndex <> -1 Then
Begin
Result := Items[iIndex];
Move(iIndex, 0);
If iIndex <> IndexOf(aName) Then
DoChange(Result);
Exit;
End;
Result := TERecentItem.Create(Self, aName, aSourceFolder, aExecutableName);
Insert(0, Result);
DoChange(Result);
End;
Function TERecentItems.Contains(Const aName: String): Boolean;
Begin
Result := IndexOf(aName) <> -1;
End;
Procedure TERecentItems.DoChange(Const aItem: TERecentItem);
Begin
If Assigned(FOnChange) Then
FOnChange(aItem);
End;
Function TERecentItems.IndexOf(Const aName: String): Integer;
Var
iCntr: Integer;
Begin
Result := -1;
For iCntr := 0 To Pred(Count) Do
Begin
If SameText(Items[iCntr].Name, aName) Then
Exit(iCntr);
End;
End;
End.