forked from jackokring/rub
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstddlg.pas
2777 lines (2522 loc) · 77.4 KB
/
stddlg.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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{*******************************************************}
{ Free Vision Runtime Library }
{ StdDlg Unit }
{ Version: 0.1.0 }
{ Release Date: July 23, 1998 }
{ }
{*******************************************************}
{ }
{ This unit is a port of Borland International's }
{ StdDlg.pas unit. It is for distribution with the }
{ Free Pascal (FPK) Compiler as part of the 32-bit }
{ Free Vision library. The unit is still fully }
{ functional under BP7 by using the tp compiler }
{ directive when rebuilding the library. }
{ }
{*******************************************************}
{ Revision History
1.1a (97/12/29)
- fixed bug in TFileDialog.HandleEvent that prevented the user from being
able to have an action taken automatically when the FileList was
selected and kbEnter pressed
1.1
- modified OpenNewFile to take a history list ID
- implemented OpenNewFile
1.0 (1992)
- original implementation }
unit StdDlg;
{
This unit has been modified to make some functions global, apply patches
from version 3.1 of the TVBUGS list, added TEditChDirDialog, and added
several new global functions and procedures.
}
{$i platform.inc}
{$ifdef PPC_FPC}
{$H-}
{$else}
{$F+,O+,E+,N+}
{$endif}
{$X+,R-,I-,Q-,V-}
{$ifndef OS_UNIX}
{$S-}
{$endif}
{$ifdef OS_DOS}
{$define HAS_DOS_DRIVES}
{$endif}
{$ifdef OS_WINDOWS}
{$define HAS_DOS_DRIVES}
{$endif}
{$ifdef OS_OS2}
{$define HAS_DOS_DRIVES}
{$endif}
{2.0 compatibility}
{$ifdef VER2_0}
{$macro on}
{$define resourcestring := const}
{$endif}
interface
uses
FVConsts, Objects, Drivers, Views, Dialogs, Validate, Dos;
const
MaxDir = 255; { Maximum length of a DirStr. }
MaxFName = 255; { Maximum length of a FNameStr. }
DirSeparator : Char = system.DirectorySeparator;
{$ifdef Unix}
AllFiles = '*';
{$else}
{$ifdef OS_AMIGA}
AllFiles = '*';
{$else}
AllFiles = '*.*';
{$endif}
{$endif}
type
{ TSearchRec }
{ Record used to store directory information by TFileDialog
This is a part of Dos.Searchrec for Bp !! }
TSearchRec =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
record
Attr: Longint;
Time: Longint;
Size: Longint;
Name: string[MaxFName];
end;
PSearchRec = ^TSearchRec;
type
{ TFileInputLine is a special input line that is used by }
{ TFileDialog that will update its contents in response to a }
{ cmFileFocused command from a TFileList. }
PFileInputLine = ^TFileInputLine;
TFileInputLine = object(TInputLine)
constructor Init(var Bounds: TRect; AMaxLen: Sw_Integer);
procedure HandleEvent(var Event: TEvent); virtual;
end;
{ TFileCollection is a collection of TSearchRec's. }
PFileCollection = ^TFileCollection;
TFileCollection = object(TSortedCollection)
function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
procedure FreeItem(Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
end;
{#Z+}
PFileValidator = ^TFileValidator;
{#Z-}
TFileValidator = Object(TValidator)
end; { of TFileValidator }
{ TSortedListBox is a TListBox that assumes it has a }
{ TStoredCollection instead of just a TCollection. It will }
{ perform an incremental search on the contents. }
PSortedListBox = ^TSortedListBox;
TSortedListBox = object(TListBox)
SearchPos: Byte;
{ShiftState: Byte;}
HandleDir : boolean;
constructor Init(var Bounds: TRect; ANumCols: Sw_Word;
AScrollBar: PScrollBar);
procedure HandleEvent(var Event: TEvent); virtual;
function GetKey(var S: String): Pointer; virtual;
procedure NewList(AList: PCollection); virtual;
end;
{ TFileList is a TSortedList box that assumes it contains }
{ a TFileCollection as its collection. It also communicates }
{ through broadcast messages to TFileInput and TInfoPane }
{ what file is currently selected. }
PFileList = ^TFileList;
TFileList = object(TSortedListBox)
constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
destructor Done; virtual;
function DataSize: Sw_Word; virtual;
procedure FocusItem(Item: Sw_Integer); virtual;
procedure GetData(var Rec); virtual;
function GetText(Item,MaxLen: Sw_Integer): String; virtual;
function GetKey(var S: String): Pointer; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure ReadDirectory(AWildCard: PathStr);
procedure SetData(var Rec); virtual;
end;
{ TFileInfoPane is a TView that displays the information }
{ about the currently selected file in the TFileList }
{ of a TFileDialog. }
PFileInfoPane = ^TFileInfoPane;
TFileInfoPane = object(TView)
S: TSearchRec;
constructor Init(var Bounds: TRect);
procedure Draw; virtual;
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
end;
{ TFileDialog is a standard file name input dialog }
TWildStr = PathStr;
const
fdOkButton = $0001; { Put an OK button in the dialog }
fdOpenButton = $0002; { Put an Open button in the dialog }
fdReplaceButton = $0004; { Put a Replace button in the dialog }
fdClearButton = $0008; { Put a Clear button in the dialog }
fdHelpButton = $0010; { Put a Help button in the dialog }
fdNoLoadDir = $0100; { Do not load the current directory }
{ contents into the dialog at Init. }
{ This means you intend to change the }
{ WildCard by using SetData or store }
{ the dialog on a stream. }
type
PFileHistory = ^TFileHistory;
TFileHistory = object(THistory)
CurDir : PString;
procedure HandleEvent(var Event: TEvent);virtual;
destructor Done; virtual;
procedure AdaptHistoryToDir(Dir : string);
end;
PFileDialog = ^TFileDialog;
TFileDialog = object(TDialog)
FileName: PFileInputLine;
FileList: PFileList;
FileHistory: PFileHistory;
WildCard: TWildStr;
Directory: PString;
constructor Init(AWildCard: TWildStr; const ATitle,
InputName: String; AOptions: Word; HistoryId: Byte);
constructor Load(var S: TStream);
destructor Done; virtual;
procedure GetData(var Rec); virtual;
procedure GetFileName(var S: PathStr);
procedure HandleEvent(var Event: TEvent); virtual;
procedure SetData(var Rec); virtual;
procedure Store(var S: TStream);
function Valid(Command: Word): Boolean; virtual;
private
procedure ReadDirectory;
end;
{ TDirEntry }
PDirEntry = ^TDirEntry;
TDirEntry = record
DisplayText: PString;
Directory: PString;
end; { of TDirEntry }
{ TDirCollection is a collection of TDirEntry's used by }
{ TDirListBox. }
PDirCollection = ^TDirCollection;
TDirCollection = object(TCollection)
function GetItem(var S: TStream): Pointer; virtual;
procedure FreeItem(Item: Pointer); virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
end;
{ TDirListBox displays a tree of directories for use in the }
{ TChDirDialog. }
PDirListBox = ^TDirListBox;
TDirListBox = object(TListBox)
Dir: DirStr;
Cur: Word;
constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
destructor Done; virtual;
function GetText(Item,MaxLen: Sw_Integer): String; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
function IsSelected(Item: Sw_Integer): Boolean; virtual;
procedure NewDirectory(var ADir: DirStr);
procedure SetState(AState: Word; Enable: Boolean); virtual;
end;
{ TChDirDialog is a standard change directory dialog. }
const
cdNormal = $0000; { Option to use dialog immediately }
cdNoLoadDir = $0001; { Option to init the dialog to store on a stream }
cdHelpButton = $0002; { Put a help button in the dialog }
type
PChDirDialog = ^TChDirDialog;
TChDirDialog = object(TDialog)
DirInput: PInputLine;
DirList: PDirListBox;
OkButton: PButton;
ChDirButton: PButton;
constructor Init(AOptions: Word; HistoryId: Sw_Word);
constructor Load(var S: TStream);
function DataSize: Sw_Word; virtual;
procedure GetData(var Rec); virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure SetData(var Rec); virtual;
procedure Store(var S: TStream);
function Valid(Command: Word): Boolean; virtual;
private
procedure SetUpDialog;
end;
PEditChDirDialog = ^TEditChDirDialog;
TEditChDirDialog = Object(TChDirDialog)
{ TEditChDirDialog allows setting/getting the starting directory. The
transfer record is a DirStr. }
function DataSize : Sw_Word; virtual;
procedure GetData (var Rec); virtual;
procedure SetData (var Rec); virtual;
end; { of TEditChDirDialog }
{#Z+}
PDirValidator = ^TDirValidator;
{#Z-}
TDirValidator = Object(TFilterValidator)
constructor Init;
function IsValid(const S: string): Boolean; virtual;
function IsValidInput(var S: string; SuppressFill: Boolean): Boolean;
virtual;
end; { of TDirValidator }
FileConfirmFunc = function (AFile : FNameStr) : Boolean;
{ Functions of type FileConfirmFunc's are used to prompt the end user for
confirmation of an operation.
FileConfirmFunc's should ask the user whether to perform the desired
action on the file named AFile. If the user elects to perform the
function FileConfirmFunc's return True, otherwise they return False.
Using FileConfirmFunc's allows routines to be coded independant of the
user interface implemented. OWL and TurboVision are supported through
conditional defines. If you do not use either user interface you must
compile this unit with the conditional define cdNoMessages and set all
FileConfirmFunc variables to a valid function prior to calling any
routines in this unit. }
{#X ReplaceFile DeleteFile }
var
ReplaceFile : FileConfirmFunc;
{ ReplaceFile returns True if the end user elects to replace the existing
file with the new file, otherwise it returns False.
ReplaceFile is only called when #CheckOnReplace# is True. }
{#X DeleteFile }
DeleteFile : FileConfirmFunc;
{ DeleteFile returns True if the end user elects to delete the file,
otherwise it returns False.
DeleteFile is only called when #CheckOnDelete# is True. }
{#X ReplaceFile }
const
CInfoPane = #30;
{ TStream registration records }
function Contains(S1, S2: String): Boolean;
{ Contains returns true if S1 contains any characters in S2. }
function DriveValid(Drive: Char): Boolean;
{ DriveValid returns True if Drive is a valid DOS drive. Drive valid works
by attempting to change the current directory to Drive, then restoring
the original directory. }
function ExtractDir(AFile: FNameStr): DirStr;
{ ExtractDir returns the path of AFile terminated with a trailing '\'. If
AFile contains no directory information, an empty string is returned. }
function ExtractFileName(AFile: FNameStr): NameStr;
{ ExtractFileName returns the file name without any directory or file
extension information. }
function Equal(const S1, S2: String; Count: Sw_word): Boolean;
{ Equal returns True if S1 equals S2 for up to Count characters. Equal is
case-insensitive. }
function FileExists (AFile : FNameStr) : Boolean;
{ FileExists looks for the file specified in AFile. If AFile is present
FileExists returns true, otherwise FileExists returns False.
The search is performed relative to the current system directory, but
other directories may be searched by prefacing a file name with a valid
directory path.
There is no check for a vaild file name or drive. Errrors are handled
internally and not reported in DosError. Critical errors are left to
the system's critical error handler. }
{#X OpenFile }
function GetCurDir: DirStr;
{ GetCurDir returns the current directory. The directory returned always
ends with a trailing backslash '\'. }
function GetCurDrive: Char;
{ GetCurDrive returns the letter of the current drive as reported by the
operating system. }
function IsWild(const S: String): Boolean;
{ IsWild returns True if S contains a question mark (?) or asterix (*). }
function IsList(const S: String): Boolean;
{ IsList returns True if S contains list separator (;) char }
function IsDir(const S: String): Boolean;
{ IsDir returns True if S is a valid DOS directory. }
{procedure MakeResources;}
{ MakeResources places a language specific version of all resources
needed for the StdDlg unit to function on the RezFile using the string
constants and variables in the Resource unit. The Resource unit and the
appropriate string lists must be initialized prior to calling this
procedure. }
function NoWildChars(S: String): String;
{ NoWildChars deletes the wild card characters ? and * from the string S
and returns the result. }
function OpenFile (var AFile : FNameStr; HistoryID : Byte) : Boolean;
{ OpenFile prompts the user to select a file using the file specifications
in AFile as the starting file and path. Wildcards are accepted. If the
user accepts a file OpenFile returns True, otherwise OpenFile returns
False.
Note: The file returned may or may not exist. }
function OpenNewFile (var AFile: FNameStr; HistoryID: Byte): Boolean;
{ OpenNewFile allows the user to select a directory from disk and enter a
new file name. If the file name entered is an existing file the user is
optionally prompted for confirmation of replacing the file based on the
value in #CheckOnReplace#. If a file name is successfully entered,
OpenNewFile returns True. }
{#X OpenFile }
function PathValid(var Path: PathStr): Boolean;
{ PathValid returns True if Path is a valid DOS path name. Path may be a
file or directory name. Trailing '\'s are removed. }
procedure RegisterStdDlg;
{ RegisterStdDlg registers all objects in the StdDlg unit for stream
usage. }
function SaveAs (var AFile : FNameStr; HistoryID : Word) : Boolean;
{ SaveAs prompts the user for a file name using AFile as a template. If
AFile already exists and CheckOnReplace is True, the user is prompted
to replace the file.
If a valid file name is entered SaveAs returns True, other SaveAs returns
False. }
function SelectDir (var ADir : DirStr; HistoryID : Byte) : Boolean;
{ SelectDir prompts the user to select a directory using ADir as the
starting directory. If a directory is selected, SelectDir returns True.
The directory returned is gauranteed to exist. }
function ShrinkPath (AFile : FNameStr; MaxLen : Byte) : FNameStr;
{ ShrinkPath returns a file name with a maximu length of MaxLen.
Internal directories are removed and replaced with elipses as needed to
make the file name fit in MaxLen.
AFile must be a valid path name. }
function StdDeleteFile (AFile : FNameStr) : Boolean;
{ StdDeleteFile returns True if the end user elects to delete the file,
otherwise it returns False.
DeleteFile is only called when CheckOnDelete is True. }
function StdReplaceFile (AFile : FNameStr) : Boolean;
{ StdReplaceFile returns True if the end user elects to replace the existing
AFile with the new AFile, otherwise it returns False.
ReplaceFile is only called when CheckOnReplace is True. }
function ValidFileName(var FileName: PathStr): Boolean;
{ ValidFileName returns True if FileName is a valid DOS file name. }
const
CheckOnReplace : Boolean = True;
{ CheckOnReplace is used by file functions. If a file exists, it is
optionally replaced based on the value of CheckOnReplace.
If CheckOnReplace is False the file is replaced without asking the
user. If CheckOnReplace is True, the end user is asked to replace the
file using a call to ReplaceFile.
CheckOnReplace is set to True by default. }
CheckOnDelete : Boolean = True;
{ CheckOnDelete is used by file and directory functions. If a file
exists, it is optionally deleted based on the value of CheckOnDelete.
If CheckOnDelete is False the file or directory is deleted without
asking the user. If CheckOnDelete is True, the end user is asked to
delete the file/directory using a call to DeleteFile.
CheckOnDelete is set to True by default. }
const
RFileInputLine: TStreamRec = (
ObjType: idFileInputLine;
VmtLink: Ofs(TypeOf(TFileInputLine)^);
Load: @TFileInputLine.Load;
Store: @TFileInputLine.Store
);
RFileCollection: TStreamRec = (
ObjType: idFileCollection;
VmtLink: Ofs(TypeOf(TFileCollection)^);
Load: @TFileCollection.Load;
Store: @TFileCollection.Store
);
RFileList: TStreamRec = (
ObjType: idFileList;
VmtLink: Ofs(TypeOf(TFileList)^);
Load: @TFileList.Load;
Store: @TFileList.Store
);
RFileInfoPane: TStreamRec = (
ObjType: idFileInfoPane;
VmtLink: Ofs(TypeOf(TFileInfoPane)^);
Load: @TFileInfoPane.Load;
Store: @TFileInfoPane.Store
);
RFileDialog: TStreamRec = (
ObjType: idFileDialog;
VmtLink: Ofs(TypeOf(TFileDialog)^);
Load: @TFileDialog.Load;
Store: @TFileDialog.Store
);
RDirCollection: TStreamRec = (
ObjType: idDirCollection;
VmtLink: Ofs(TypeOf(TDirCollection)^);
Load: @TDirCollection.Load;
Store: @TDirCollection.Store
);
RDirListBox: TStreamRec = (
ObjType: idDirListBox;
VmtLink: Ofs(TypeOf(TDirListBox)^);
Load: @TDirListBox.Load;
Store: @TDirListBox.Store
);
RChDirDialog: TStreamRec = (
ObjType: idChDirDialog;
VmtLink: Ofs(TypeOf(TChDirDialog)^);
Load: @TChDirDialog.Load;
Store: @TChDirDialog.Store
);
RSortedListBox: TStreamRec = (
ObjType: idSortedListBox;
VmtLink: Ofs(TypeOf(TSortedListBox)^);
Load: @TSortedListBox.Load;
Store: @TSortedListBox.Store
);
REditChDirDialog : TStreamRec = (
ObjType : idEditChDirDialog;
VmtLink : Ofs(TypeOf(TEditChDirDialog)^);
Load : @TEditChDirDialog.Load;
Store : @TEditChDirDialog.Store);
implementation
{****************************************************************************}
{ Local Declarations }
{****************************************************************************}
uses
App, {Memory,} HistList, MsgBox{, Resource};
type
PStringRec = record
{ PStringRec is needed for properly displaying PStrings using
MessageBox. }
AString : PString;
end;
resourcestring sChangeDirectory='Change Directory';
sDeleteFile='Delete file?'#13#10#13#3'%s';
sDirectory='Directory';
sDrives='Drives';
sInvalidDirectory='Invalid directory.';
sInvalidDriveOrDir='Invalid drive or directory.';
sInvalidFileName='Invalid file name.';
sOpen='Open';
sReplaceFile='Replace file?'#13#10#13#3'%s';
sSaveAs='Save As';
sTooManyFiles='Too many files.';
smApr='Apr';
smAug='Aug';
smDec='Dec';
smFeb='Feb';
smJan='Jan';
smJul='Jul';
smJun='Jun';
smMar='Mar';
smMay='May';
smNov='Nov';
smOct='Oct';
smSep='Sep';
slChDir='~C~hdir';
slClear='C~l~ear';
slDirectoryName='Directory ~n~ame';
slDirectoryTree='Directory ~t~ree';
slFiles='~F~iles';
slReplace='~R~eplace';
slRevert='~R~evert';
{****************************************************************************}
{ PathValid }
{****************************************************************************}
{$ifdef go32v2}
{$define NetDrive}
{$endif go32v2}
{$ifdef OS_WINDOWS}
{$define NetDrive}
{$endif OS_WINDOWS}
procedure RemoveDoubleDirSep(var ExpPath : PathStr);
var
p: longint;
{$ifdef NetDrive}
OneDirSepRemoved: boolean;
{$endif NetDrive}
begin
p:=pos(DirSeparator+DirSeparator,ExpPath);
{$ifdef NetDrive}
if p=1 then
begin
ExpPath:=Copy(ExpPath,1,high(ExpPath));
OneDirSepRemoved:=true;
p:=pos(DirSeparator+DirSeparator,ExpPath);
end
else
OneDirSepRemoved:=false;
{$endif NetDrive}
while p>0 do
begin
ExpPath:=Copy(ExpPath,1,p)+Copy(ExpPath,p+2,high(ExpPath));
p:=pos(DirSeparator+DirSeparator,ExpPath);
end;
{$ifdef NetDrive}
if OneDirSepRemoved then
ExpPath:=DirSeparator+ExpPath;
{$endif NetDrive}
end;
function PathValid (var Path: PathStr): Boolean;
var
ExpPath: PathStr;
SR: SearchRec;
begin
RemoveDoubleDirSep(Path);
ExpPath := FExpand(Path);
{$ifdef HAS_DOS_DRIVES}
if (Length(ExpPath) <= 3) then
PathValid := DriveValid(ExpPath[1])
else
{$endif}
begin
{ do not change '/' into '' }
if (Length(ExpPath)>1) and (ExpPath[Length(ExpPath)] = DirSeparator) then
Dec(ExpPath[0]);
// This function is called on current directories.
// If the current dir starts with a . on Linux it is is hidden.
// That's why we allow hidden dirs below (bug 6173)
FindFirst(ExpPath, Directory+hidden, SR);
PathValid := (DosError = 0) and (SR.Attr and Directory <> 0);
{$ifdef NetDrive}
if (DosError<>0) and (length(ExpPath)>2) and
(ExpPath[1]='\') and (ExpPath[2]='\')then
begin
{ Checking '\\machine\sharedfolder' directly always fails..
rather try '\\machine\sharedfolder\*' PM }
{$ifdef fpc}
FindClose(SR);
{$endif}
FindFirst(ExpPath+'\*',AnyFile,SR);
PathValid:=(DosError = 0);
end;
{$endif NetDrive}
{$ifdef fpc}
FindClose(SR);
{$endif}
end;
end;
{****************************************************************************}
{ TDirValidator Object }
{****************************************************************************}
{****************************************************************************}
{ TDirValidator.Init }
{****************************************************************************}
constructor TDirValidator.Init;
const { What should this list be? The commented one doesn't allow home,
end, right arrow, left arrow, Ctrl+XXXX, etc. }
Chars: TCharSet = ['A'..'Z','a'..'z','.','~',':','_','-'];
{ Chars: TCharSet = [#0..#255]; }
begin
Chars := Chars + [DirSeparator];
if not inherited Init(Chars) then
Fail;
end;
{****************************************************************************}
{ TDirValidator.IsValid }
{****************************************************************************}
function TDirValidator.IsValid(const S: string): Boolean;
begin
{ IsValid := False; }
IsValid := True;
end;
{****************************************************************************}
{ TDirValidator.IsValidInput }
{****************************************************************************}
function TDirValidator.IsValidInput(var S: string; SuppressFill: Boolean): Boolean;
begin
{ IsValid := False; }
IsValidInput := True;
end;
{****************************************************************************}
{ TFileInputLine Object }
{****************************************************************************}
{****************************************************************************}
{ TFileInputLine.Init }
{****************************************************************************}
constructor TFileInputLine.Init(var Bounds: TRect; AMaxLen: Sw_Integer);
begin
TInputLine.Init(Bounds, AMaxLen);
EventMask := EventMask or evBroadcast;
end;
{****************************************************************************}
{ TFileInputLine.HandleEvent }
{****************************************************************************}
procedure TFileInputLine.HandleEvent(var Event: TEvent);
begin
TInputLine.HandleEvent(Event);
if (Event.What = evBroadcast) and (Event.Command = cmFileFocused) and
(State and sfSelected = 0) then
begin
if PSearchRec(Event.InfoPtr)^.Attr and Directory <> 0 then
begin
Data^ := PSearchRec(Event.InfoPtr)^.Name + DirSeparator +
PFileDialog(Owner)^.WildCard;
{ PFileDialog(Owner)^.FileHistory^.AdaptHistoryToDir(
PSearchRec(Event.InfoPtr)^.Name+DirSeparator);}
end
else Data^ := PSearchRec(Event.InfoPtr)^.Name;
DrawView;
end;
end;
{****************************************************************************}
{ TFileCollection Object }
{****************************************************************************}
{****************************************************************************}
{ TFileCollection.Compare }
{****************************************************************************}
function uppername(const s : string) : string;
var
i : Sw_integer;
in_name : boolean;
begin
in_name:=true;
for i:=length(s) downto 1 do
if in_name and (s[i] in ['a'..'z']) then
uppername[i]:=char(byte(s[i])-32)
else
begin
uppername[i]:=s[i];
if s[i] = DirSeparator then
in_name:=false;
end;
uppername[0]:=s[0];
end;
function TFileCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
begin
if PSearchRec(Key1)^.Name = PSearchRec(Key2)^.Name then Compare := 0
else if PSearchRec(Key1)^.Name = '..' then Compare := 1
else if PSearchRec(Key2)^.Name = '..' then Compare := -1
else if (PSearchRec(Key1)^.Attr and Directory <> 0) and
(PSearchRec(Key2)^.Attr and Directory = 0) then Compare := 1
else if (PSearchRec(Key2)^.Attr and Directory <> 0) and
(PSearchRec(Key1)^.Attr and Directory = 0) then Compare := -1
else if UpperName(PSearchRec(Key1)^.Name) > UpperName(PSearchRec(Key2)^.Name) then
Compare := 1
{$ifdef unix}
else if UpperName(PSearchRec(Key1)^.Name) < UpperName(PSearchRec(Key2)^.Name) then
Compare := -1
else if PSearchRec(Key1)^.Name > PSearchRec(Key2)^.Name then
Compare := 1
{$endif def unix}
else
Compare := -1;
end;
{****************************************************************************}
{ TFileCollection.FreeItem }
{****************************************************************************}
procedure TFileCollection.FreeItem(Item: Pointer);
begin
Dispose(PSearchRec(Item));
end;
{****************************************************************************}
{ TFileCollection.GetItem }
{****************************************************************************}
function TFileCollection.GetItem(var S: TStream): Pointer;
var
Item: PSearchRec;
begin
New(Item);
S.Read(Item^, SizeOf(TSearchRec));
GetItem := Item;
end;
{****************************************************************************}
{ TFileCollection.PutItem }
{****************************************************************************}
procedure TFileCollection.PutItem(var S: TStream; Item: Pointer);
begin
S.Write(Item^, SizeOf(TSearchRec));
end;
{*****************************************************************************
TFileList
*****************************************************************************}
const
ListSeparator=';';
function MatchesMask(What, Mask: string): boolean;
function upper(const s : string) : string;
var
i : Sw_integer;
begin
for i:=1 to length(s) do
if s[i] in ['a'..'z'] then
upper[i]:=char(byte(s[i])-32)
else
upper[i]:=s[i];
upper[0]:=s[0];
end;
Function CmpStr(const hstr1,hstr2:string):boolean;
var
found : boolean;
i1,i2 : Sw_integer;
begin
i1:=0;
i2:=0;
if hstr1='' then
begin
CmpStr:=(hstr2='');
exit;
end;
found:=true;
repeat
inc(i1);
if (i1>length(hstr1)) then
break;
inc(i2);
if (i2>length(hstr2)) then
break;
case hstr1[i1] of
'?' :
found:=true;
'*' :
begin
found:=true;
if (i1=length(hstr1)) then
i2:=length(hstr2)
else
if (i1<length(hstr1)) and (hstr1[i1+1]<>hstr2[i2]) then
begin
if i2<length(hstr2) then
dec(i1)
end
else
if i2>1 then
dec(i2);
end;
else
found:=(hstr1[i1]=hstr2[i2]) or (hstr2[i2]='?');
end;
until not found;
if found then
begin
found:=(i2>=length(hstr2)) and
(
(i1>length(hstr1)) or
((i1=length(hstr1)) and
(hstr1[i1]='*'))
);
end;
CmpStr:=found;
end;
var
D1,D2 : DirStr;
N1,N2 : NameStr;
E1,E2 : Extstr;
begin
{$ifdef Unix}
FSplit(What,D1,N1,E1);
FSplit(Mask,D2,N2,E2);
{$else}
FSplit(Upper(What),D1,N1,E1);
FSplit(Upper(Mask),D2,N2,E2);
{$endif}
MatchesMask:=CmpStr(N2,N1) and CmpStr(E2,E1);
end;
function MatchesMaskList(What, MaskList: string): boolean;
var P: integer;
Match: boolean;
begin
Match:=false;
if What<>'' then
repeat
P:=Pos(ListSeparator, MaskList);
if P=0 then P:=length(MaskList)+1;
Match:=MatchesMask(What,copy(MaskList,1,P-1));
Delete(MaskList,1,P);
until Match or (MaskList='');
MatchesMaskList:=Match;
end;
constructor TFileList.Init(var Bounds: TRect; AScrollBar: PScrollBar);
begin
TSortedListBox.Init(Bounds, 2, AScrollBar);
end;
destructor TFileList.Done;
begin
if List <> nil then Dispose(List, Done);
TListBox.Done;
end;
function TFileList.DataSize: Sw_Word;
begin
DataSize := 0;
end;
procedure TFileList.FocusItem(Item: Sw_Integer);
begin
TSortedListBox.FocusItem(Item);
if (List^.Count > 0) then
Message(Owner, evBroadcast, cmFileFocused, List^.At(Item));
end;
procedure TFileList.GetData(var Rec);
begin
end;
function TFileList.GetKey(var S: String): Pointer;
const
SR: TSearchRec = ();
procedure UpStr(var S: String);
var
I: Sw_Integer;
begin
for I := 1 to Length(S) do S[I] := UpCase(S[I]);
end;
begin
if (HandleDir{ShiftState and $03 <> 0}) or ((S <> '') and (S[1]='.')) then
SR.Attr := Directory
else SR.Attr := 0;
SR.Name := S;
{$ifndef Unix}
UpStr(SR.Name);
{$endif Unix}
GetKey := @SR;
end;
function TFileList.GetText(Item,MaxLen: Sw_Integer): String;
var
S: String;
SR: PSearchRec;
begin
SR := PSearchRec(List^.At(Item));
S := SR^.Name;
if SR^.Attr and Directory <> 0 then
begin
S[Length(S)+1] := DirSeparator;