-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTDIRLIST.INC
311 lines (286 loc) · 9.33 KB
/
TDIRLIST.INC
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
{ Copyright 2015 Jerome Shidel }
(*
This project and related files are subject to either the terms
specified in the included LICENSE.TXT file or the GNU GPLv2.0.
*)
{ ---TTDirList --- }
{$IFDEF INTERFACE}
const
class_TDirList = 'TDirList';
class_TDirItem = 'TDirItem';
type
PDirItem = ^TDirItem;
TDirItem = object (TListItem)
private
public { protected }
function ObjectClass ( AName : String ) : String; virtual;
public { protected }
Attr : byte;
public
end;
PDirList = ^TDirList;
TDirList = object(TListView)
public { protected }
function ObjectClass ( AName : String ) : String; virtual;
public { protected }
FValid : boolean;
FFilter, FDir, FTextParent, FTextSubDir : String;
FFileAttrs : array[0..5] of TTextAttrs;
public
constructor Create(AParent : PControl; AName : String);
procedure SetDir(AValue : String); virtual;
function GetDir : String; virtual;
procedure SetFilter(AValue : String); virtual;
procedure ApplyLanguage( AConfig : PConfigFile ); virtual;
procedure ApplyTheme( AConfig : PConfigFile ); virtual;
function GetItemAttr(var AItem, ASubItem : PListItem; AColumn, AState : integer) : integer; virtual;
function DirSizeStr(AValue : LongInt) : string; virtual;
function DirDateStr(AValue : LongInt) : string; virtual;
function DirTimeStr(AValue : LongInt) : string; virtual;
function DirWhenStr(AValue : LongInt) : string; virtual;
end;
{$ENDIF}
{$IFDEF IMPLEMENTATION}
function TDirItem.ObjectClass(AName : String) : String;
begin
if (AName = '') or (AName = class_TDirItem) then
ObjectClass := class_TDirItem
else
ObjectClass := inherited ObjectClass(AName);
end;
{--- TDirList ---}
function TDirList.ObjectClass(AName : String) : String;
begin
if (AName = '') or (AName = class_TDirList) then
ObjectClass := class_TDirList
else
ObjectClass := inherited ObjectClass(AName);
end;
constructor TDirList.Create(AParent : PControl; AName : String);
var
I : integer;
begin
inherited Create(AParent, AName);
SetSorted(False);
FValid := False;
FDir := Dir('');
FFilter := 'All Files (*.*)';
FTextParent := '<PARENT>';
FTextSubDir := '<SUBDIR>';
for I := 0 to 5 do
FFileAttrs[I] := FNAttr;
FFileAttrs[0].Normal := (FFileAttrs[0].Normal and $F0) or $07;
FFileAttrs[1].Normal := (FFileAttrs[1].Normal and $F0) or $0D;
FFileAttrs[2].Normal := (FFileAttrs[2].Normal and $F0) or $0F;
FFileAttrs[3].Normal := (FFileAttrs[3].Normal and $F0) or $0C;
FFileAttrs[4].Normal := (FFileAttrs[4].Normal and $F0) or $08;
FFileAttrs[5].Normal := (FFileAttrs[5].Normal and $F0) or $0B;
for I := 0 to 4 do
with FFileAttrs[I] do
if GetBlink then
begin
Hover := (Normal and $80) shr 4 + (Normal and $07) shl 4;
Focused := (Normal and $07) + $08 + (Normal and $07) shl 4;
Click := $09 or ((Normal and $80) shr 4) + (Normal and $07) shl 4;
end
else
begin
Hover := (Normal and $80) shr 4 + (Normal and $0F) shl 4;
Focused := (Normal and $07) + $08 + (Normal and $07) shl 4;
Click := $09 or ((Normal and $80) shr 4) + (Normal and $07) shl 4;
end;
end;
procedure TDirList.SetDir(AValue : String);
var
Search : TSearchRec;
Temp : TDirItem;
Item : PDirItem;
S, C, A : String;
I : integer;
begin
ClearItems;
if Assigned(FColumns) then begin
FColumns^[0].Width := FRBounds.Width - 1;
for I := 1 to FColumnCount - 1 do
Dec(FColumns^[0].Width, FColumns^[I].Width);
end;
Temp.Create('DIR');
Temp.Sorted := True;
AValue := Dir(AValue);
FDir := AValue;
FindFirst(AValue + '*.*', faAnyFile, Search);
FValid := DosError = 0;
while DosError = erNone do begin
if (Search.Attr and faDirectory = faDirectory) then begin
if (Search.Name = '.') then begin
{ ignored }
end else if (Search.Name = '..') then begin
if Length(AValue) > 3 then begin
Item := New(PDirItem, Create(Search.Name));
if (FColumnCount > 0) then
Item^.Add(New(PDirItem, Create(FTextParent)));
Item^.Attr := Search.Attr;
Temp.Add(Item);
end
end else begin
Item := New(PDirItem, Create(Search.Name));
if (FColumnCount > 0) then
Item^.Add(New(PDirItem, Create(FTextSubDir)));
Item^.Attr := Search.Attr;
Temp.Add(Item);
end;
end;
FindNext(Search);
end;
while Assigned(Temp.First) do
FItems.Add(Temp.First);
S := Copy(FFilter, Pos('(', FFilter) + 1, Length(FFilter));
S := Copy(S, 1, Pos(')', S) - 1);
while S <> '' do begin
C := PullStr(';', S);
FindFirst(AValue + C, faAnyFile, Search);
FValid := DosError = 0;
while DosError = erNone do begin
if (Search.Attr and faDirectory <> faDirectory) then begin
if Search.Attr and faHidden <> faHidden then
Item := New(PDirItem, Create(Search.Name))
else
Item := New(PDirItem, Create(lcase(Search.Name)));
Item^.Add(New(PDirItem, Create(DirSizeStr(Search.Size))));
A := 'rash';
Item^.Attr := Search.Attr;
if Search.Attr and faReadOnly <> faReadOnly then A[1] := '.';
if Search.Attr and faArchive <> faArchive then A[2] := '.';
if Search.Attr and faSystem <> faSystem then A[3] := '.';
if Search.Attr and faHidden <> faHidden then A[4] := '.';
Item^.Add(New(PDirItem, Create(A)));
Item^.Add(New(PDirItem, Create(DirDateStr(Search.Time))));
Item^.Add(New(PDirItem, Create(DirTimeStr(Search.Time))));
Item^.Add(New(PDirItem, Create(DirWhenStr(Search.Time))));
{GetMem(Item^.Data, Sizeof(TSearchRec));
TSearchRec(Item^.Data^) := Search; }
Temp.Add(Item);
end;
FindNext(Search);
end;
while Assigned(Temp.First) do
FItems.Add(Temp.First);
end;
Temp.Destroy;
AdjustSize;
Update;
end;
function TDirList.GetDir : String;
begin
GetDir := FDir;
end;
procedure TDirList.SetFilter(AValue : String);
begin
if AValue = FFilter then exit;
FFilter := AValue;
SetDir(FDir);
end;
function TDirList.GetItemAttr(var AItem, ASubItem : PListItem; AColumn, AState : integer) : integer;
var
I : integer;
begin
if (FColumnCount = 0) or (not Assigned(AItem)) then
case AState of
1 : GetItemAttr := FNAttr.Hover;
2 : GetItemAttr := FNAttr.Click;
3 : GetItemAttr := FNAttr.Focused;
-1 : GetItemAttr := FNAttr.Disabled;
else
GetItemAttr := Normal;
end
else
I := 0;
if PDirItem(AItem)^.Attr and faArchive = faArchive then I := 2;
if PDirItem(AItem)^.Attr and faReadOnly = faReadOnly then I := 1;
if PDirItem(AItem)^.Attr and faSystem = faSystem then I := 3;
if PDirItem(AItem)^.Attr and faHidden = faHidden then I := 4;
if PDirItem(AItem)^.Attr and faDirectory = faDirectory then I := 5;
case AState of
1 : GetItemAttr := FFileAttrs[I].Hover;
2 : GetItemAttr := FFileAttrs[I].Click;
3 : GetItemAttr := FFileAttrs[I].Focused;
-1 : GetItemAttr := FFileAttrs[I].Disabled;
else
GetItemAttr := FFileAttrs[I].Normal;
end;
end;
procedure TDirList.ApplyTheme( AConfig : PConfigFile );
var
I : integer;
begin
inherited ApplyTheme ( AConfig );
if Assigned(FColumns) then begin
AConfig^.GetInts('COLORS.NORMAL', FFileAttrs[0], SizeOf(TTextAttrs) div SizeOf(Integer));
AConfig^.GetInts('COLORS.READONLY', FFileAttrs[1], SizeOf(TTextAttrs) div SizeOf(Integer));
AConfig^.GetInts('COLORS.ARCHIVE', FFileAttrs[2], SizeOf(TTextAttrs) div SizeOf(Integer));
AConfig^.GetInts('COLORS.SYSTEM', FFileAttrs[3], SizeOf(TTextAttrs) div SizeOf(Integer));
AConfig^.GetInts('COLORS.HIDDEN', FFileAttrs[4], SizeOf(TTextAttrs) div SizeOf(Integer));
AConfig^.GetInts('COLORS.DIRECTORY', FFileAttrs[5], SizeOf(TTextAttrs) div SizeOf(Integer));
end;
end;
procedure TDirList.ApplyLanguage( AConfig : PConfigFile );
var
I : integer;
begin
inherited ApplyLanguage ( AConfig );
if Assigned(FColumns) then begin
FTextParent := AConfig^.GetValue(GetPathID + '.PARENT', FTextParent );
FTextSubDir := AConfig^.GetValue(GetPathID + '.SUBDIR', FTextSubDir );
end;
end;
function TDirList.DirSizeStr(AValue : LongInt) : String;
begin
DirSizeStr := Comma(IntStr(AValue));
end;
function TDirList.DirDateStr(AValue : LongInt) : string;
var
DT : TDateTime;
FD : array[0..2] of TFormatData;
begin
Unpacktime(AValue, DT);
FD[0].ID := FmtInteger;
FD[0].IntegerValue := DT.Year;
FD[1].ID := FmtInteger;
FD[1].IntegerValue := DT.Month;
FD[2].ID := FmtInteger;
FD[2].IntegerValue := DT.Day;
DirDateStr := FormatStr(Application^.FFileDateFmt, FD, 3);
end;
function TDirList.DirTimeStr(AValue : LongInt) : string;
var
DT : TDateTime;
FD : array[0..4] of TFormatData;
begin
Unpacktime(AValue, DT);
FD[0].ID := FmtInteger;
FD[0].IntegerValue := DT.Hour;
FD[2].ID := FmtInteger;
FD[2].IntegerValue := DT.Min;
FD[3].ID := FmtInteger;
FD[3].IntegerValue := DT.Sec;
FD[4].ID := FmtBoolean;
FD[4].BooleanValue := DT.Hour >= 12;
if DT.Hour >= 12 then DT.Hour := DT.Hour - 12;
if DT.Hour = 0 then DT.Hour := 12;
FD[1].ID := FmtInteger;
FD[1].IntegerValue := DT.Hour;
DirTimeStr := FormatStr(Application^.FFileTimeFmt, FD, 5);
end;
function TDirList.DirWhenStr(AValue : LongInt) : string;
var
DT : TDateTime;
Y, M, D, W : word;
begin
Unpacktime(AValue, DT);
GetDate(Y, M, D, W);
if (DT.Year = Y) and (DT.Month = M) and (DT.Day = D) then
DirWhenStr := DirTimeStr(AValue)
else
DirWhenStr := DirDateStr(AValue);
end;
{$ENDIF}