forked from mesjetiu/PacmanXG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msefiledialog.pas
executable file
·2416 lines (2241 loc) · 69.2 KB
/
msefiledialog.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
{ MSEgui Copyright (c) 1999-2012 by Martin Schreiber
See the file COPYING.MSE, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty o
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
unit msefiledialog;
{$ifdef FPC}{$mode objfpc}{$h+}{$endif}
interface
uses
mseglob,mseguiglob,msegui,mseforms,Classes,mseclasses,msewidgets,msegrids,
mselistbrowser,mseedit,msesimplewidgets,msedataedits,msedialog,msetypes,
msestrings,msesystypes,msesys,msedispwidgets,msedatalist,msestat,msestatfile,
msebitmap,msedatanodes,msefileutils,msedropdownlist,mseevent,msegraphedits,
mseeditglob,msesplitter,msemenus,msegridsglob,msegraphics,msegraphutils,
mseifiglob{,mseapplication},msewidgetgrid,mseimage,
(*patch by Alexandre Minoshi*)mseformatpngread, mseformatjpgread,
mseformatxpmread,mseformatbmpicoread,mseformatpnmread,mseformattgaread,
registry(*End of patch*);
const
defaultlistviewoptionsfile = defaultlistviewoptions + [lvo_readonly];
type
tfilelistitem = class(tlistitem)
private
protected
public
constructor create(const aowner: tcustomitemlist); override;
end;
pfilelistitem = ^tfilelistitem;
tfileitemlist = class(titemviewlist)
protected
procedure createitem(out item: tlistitem); override;
end;
getfileiconeventty = procedure(const sender: tobject; const ainfo: fileinfoty;
var imagelist: timagelist; var imagenr: integer) of object;
tfilelistview = class(tlistview)
private
ffilelist: tfiledatalist;
foptionsfile: filelistviewoptionsty;
fmaskar: filenamearty;
fdirectory: filenamety;
ffilecount: integer;
fincludeattrib,fexcludeattrib: fileattributesty;
fonlistread: notifyeventty;
ffocusmoved: boolean;
fongetfileicon: getfileiconeventty;
foncheckfile: checkfileeventty;
procedure filelistchanged(const sender: tobject);
procedure setfilelist(const Value: tfiledatalist);
function getpath: msestring;
procedure setpath(const Value: msestring);
procedure setdirectory(const Value: msestring);
function getmask: filenamety;
procedure setmask(const value: filenamety);
function getselectednames: filenamearty;
procedure setselectednames(const avalue: filenamearty);
function getchecksubdir: boolean;
procedure setchecksubdir(const avalue: boolean);
procedure setoptionsfile(const avalue: filelistviewoptionsty);
procedure checkcasesensitive;
protected
foptionsdir: dirstreamoptionsty;
fcaseinsensitive: boolean;
// procedure setoptions(const Value: listviewoptionsty); override;
procedure docellevent(var info: celleventinfoty); override;
public
constructor create(aowner: tcomponent); override;
destructor destroy; override;
procedure readlist;
procedure updir;
function filecount: integer;
property directory: filenamety read fdirectory write setdirectory;
property includeattrib: fileattributesty read fincludeattrib
write fincludeattrib default [fa_all];
property excludeattrib: fileattributesty read fexcludeattrib
write fexcludeattrib default [fa_hidden];
property maskar: filenamearty read fmaskar write fmaskar; //nil -> all
property mask: filenamety read getmask write setmask; //'' -> all
property path: filenamety read getpath write setpath;
//calls readlist
property selectednames: filenamearty read getselectednames write setselectednames;
property checksubdir: boolean read getchecksubdir write setchecksubdir;
published
property options default defaultlistviewoptionsfile;
property optionsfile: filelistviewoptionsty read foptionsfile
write setoptionsfile default defaultfilelistviewoptions;
property filelist: tfiledatalist read ffilelist write setfilelist;
property onlistread: notifyeventty read fonlistread write fonlistread;
property ongetfileicon: getfileiconeventty read fongetfileicon
write fongetfileicon;
property oncheckfile: checkfileeventty read foncheckfile write foncheckfile;
end;
const
defaulthistorymaxcount = 10;
type
filedialogoptionty = (fdo_filtercasesensitive, //flvo_maskcasesensitive
fdo_filtercaseinsensitive, //flvo_maskcaseinsensitive
fdo_save,
fdo_dispname,fdo_dispnoext,fdo_sysfilename,fdo_params,
fdo_directory,fdo_file,
fdo_absolute,fdo_relative,fdo_quotesingle,
fdo_link, //links lastdir of controllers with same group
fdo_checkexist,fdo_acceptempty,fdo_single,
fdo_chdir,fdo_savelastdir,
fdo_checksubdir);
filedialogoptionsty = set of filedialogoptionty;
const
defaultfiledialogoptions = [fdo_savelastdir];
type
filedialogkindty = (fdk_none,fdk_open,fdk_save,fdk_new);
tfiledialogcontroller = class;
filedialogbeforeexecuteeventty = procedure(const sender: tfiledialogcontroller;
var dialogkind: filedialogkindty; var aresult: modalresultty) of object;
filedialogafterexecuteeventty = procedure(const sender: tfiledialogcontroller;
var aresult: modalresultty) of object;
tfiledialogcontroller = class(tlinkedpersistent)
private
fowner: tmsecomponent;
fgroup: integer;
fonchange: proceventty;
ffilenames: filenamearty;
ffilterlist: tdoublemsestringdatalist;
ffilter: filenamety;
ffilterindex: integer;
fcolwidth: integer;
fwindowrect: rectty;
fhistorymaxcount: integer;
fhistory: msestringarty;
fcaptionopen: msestring;
fcaptionsave: msestring;
fcaptionnew: msestring;
finclude: fileattributesty;
fexclude: fileattributesty;
fonbeforeexecute: filedialogbeforeexecuteeventty;
fonafterexecute: filedialogafterexecuteeventty;
fongetfilename: setstringeventty;
fongetfileicon: getfileiconeventty;
foncheckfile: checkfileeventty;
fimagelist: timagelist;
fparams: msestring;
procedure setfilterlist(const Value: tdoublemsestringdatalist);
procedure sethistorymaxcount(const Value: integer);
function getfilename: filenamety;
procedure setfilename(const avalue: filenamety);
procedure dochange;
procedure setdefaultext(const avalue: filenamety);
procedure setoptions(Value: filedialogoptionsty);
procedure checklink;
procedure setlastdir(const avalue: filenamety);
procedure setimagelist(const avalue: timagelist);
function getsyscommandline: filenamety;
protected
flastdir: filenamety;
fdefaultext: filenamety;
foptions: filedialogoptionsty;
public
constructor create(const aowner: tmsecomponent = nil;
const onchange: proceventty = nil); reintroduce;
destructor destroy; override;
procedure readstatvalue(const reader: tstatreader);
procedure readstatstate(const reader: tstatreader);
procedure readstatoptions(const reader: tstatreader);
procedure writestatvalue(const writer: tstatwriter);
procedure writestatstate(const writer: tstatwriter);
procedure writestatoptions(const writer: tstatwriter);
function actcaption(const dialogkind: filedialogkindty): msestring;
function execute(dialogkind: filedialogkindty = fdk_none): modalresultty; overload;
//fdk_none -> use options fdo_save
function execute(dialogkind: filedialogkindty; const acaption: msestring;
aoptions: filedialogoptionsty): modalresultty; overload;
function execute(const dialogkind: filedialogkindty;
const acaption: msestring): modalresultty; overload;
function execute(const dialogkind: filedialogkindty;
const aoptions: filedialogoptionsty): modalresultty; overload;
function execute(var avalue: filenamety;
dialogkind: filedialogkindty = fdk_none): boolean; overload;
function execute(var avalue: filenamety; const dialogkind: filedialogkindty;
const acaption: msestring): boolean; overload;
function execute(var avalue: filenamety; const dialogkind: filedialogkindty;
const acaption: msestring;
aoptions: filedialogoptionsty): boolean; overload;
procedure clear;
procedure componentevent(const event: tcomponentevent);
property history: msestringarty read fhistory write fhistory;
property filenames: filenamearty read ffilenames write ffilenames;
property syscommandline: filenamety read getsyscommandline;
property params: msestring read fparams;
published
property filename: filenamety read getfilename write setfilename;
property lastdir: filenamety read flastdir write setlastdir;
property filter: filenamety read ffilter write ffilter;
property filterlist: tdoublemsestringdatalist read ffilterlist write setfilterlist;
property filterindex: integer read ffilterindex write ffilterindex default 0;
property include: fileattributesty read finclude write finclude default [fa_all];
property exclude: fileattributesty read fexclude write fexclude default [fa_hidden];
property colwidth: integer read fcolwidth write fcolwidth default 0;
property defaultext: filenamety read fdefaultext write setdefaultext;
property options: filedialogoptionsty read foptions write setoptions
default defaultfiledialogoptions;
property historymaxcount: integer read fhistorymaxcount
write sethistorymaxcount default defaulthistorymaxcount;
property captionopen: msestring read fcaptionopen write fcaptionopen;
property captionsave: msestring read fcaptionsave write fcaptionsave;
property captionnew: msestring read fcaptionnew write fcaptionnew;
property group: integer read fgroup write fgroup default 0;
property imagelist: timagelist read fimagelist write setimagelist;
property ongetfilename: setstringeventty read fongetfilename write fongetfilename;
property ongetfileicon: getfileiconeventty read fongetfileicon
write fongetfileicon;
property oncheckfile: checkfileeventty read foncheckfile write foncheckfile;
property onbeforeexecute: filedialogbeforeexecuteeventty
read fonbeforeexecute write fonbeforeexecute;
property onafterexecute: filedialogafterexecuteeventty
read fonafterexecute write fonafterexecute;
end;
const
defaultfiledialogoptionsedit = defaultoptionsedit+
[oe_savevalue,oe_savestate,oe_saveoptions];
type
tfiledialog = class(tdialog,istatfile)
private
fcontroller: tfiledialogcontroller;
fstatvarname: msestring;
fstatfile: tstatfile;
fdialogkind: filedialogkindty;
foptionsedit: optionseditty;
procedure setcontroller(const value: tfiledialogcontroller);
procedure setstatfile(const Value: tstatfile);
protected
//istatfile
procedure dostatread(const reader: tstatreader);
procedure dostatwrite(const writer: tstatwriter);
procedure statreading;
procedure statread;
function getstatvarname: msestring;
public
constructor create(aowner: tcomponent); override;
destructor destroy; override;
function execute: modalresultty; overload; override;
function execute(const akind: filedialogkindty): modalresultty;
reintroduce; overload;
function execute(const akind: filedialogkindty;
const aoptions: filedialogoptionsty): modalresultty;
reintroduce; overload;
procedure componentevent(const event: tcomponentevent); override;
published
property statfile: tstatfile read fstatfile write setstatfile;
property statvarname: msestring read getstatvarname write fstatvarname;
property controller: tfiledialogcontroller read fcontroller write setcontroller;
property dialogkind: filedialogkindty read fdialogkind write fdialogkind
default fdk_none;
property optionsedit: optionseditty read foptionsedit write foptionsedit
default defaultfiledialogoptionsedit;
end;
tcustomfilenameedit = class;
tfilenameeditcontroller = class(tstringdialogcontroller)
protected
function execute(var avalue: msestring): boolean; override;
public
constructor create(const aowner: tcustomfilenameedit);
end;
tcustomfilenameedit = class(tcustomdialogstringed)
private
fcontroller: tfiledialogcontroller;
// fdialogkind: filedialogkindty;
procedure setcontroller(const avalue: tfiledialogcontroller);
function getsysvalue: filenamety;
procedure setsysvalue(const avalue: filenamety);
protected
function createdialogcontroller: tstringdialogcontroller; override;
procedure texttovalue(var accept: boolean; const quiet: boolean); override;
// function execute(var avalue: msestring): boolean; override;
procedure updatedisptext(var avalue: msestring); override;
function getvaluetext: msestring; override;
procedure readstatvalue(const reader: tstatreader); override;
procedure readstatstate(const reader: tstatreader); override;
procedure readstatoptions(const reader: tstatreader); override;
procedure writestatvalue(const writer: tstatwriter); override;
procedure writestatstate(const writer: tstatwriter); override;
procedure writestatoptions(const writer: tstatwriter); override;
procedure valuechanged; override;
procedure updatecopytoclipboard(var atext: msestring); override;
procedure updatepastefromclipboard(var atext: msestring); override;
public
constructor create(aowner: tcomponent); override;
destructor destroy; override;
procedure componentevent(const event: tcomponentevent); override;
property controller: tfiledialogcontroller read fcontroller write setcontroller;
property sysvalue: filenamety read getsysvalue write setsysvalue;
published
// property dialogkind: filedialogkindty read fdialogkind write fdialogkind default fdk_open;
end;
tfilenameedit = class(tcustomfilenameedit)
published
property frame;
property passwordchar;
property maxlength;
property value;
property onsetvalue;
property controller;
end;
dirdropdowneditoptionty = (ddeo_showhiddenfiles,ddeo_checksubdir);
dirdropdowneditoptionsty = set of dirdropdowneditoptionty;
tdirdropdownedit = class(tdropdownwidgetedit)
private
foptions: dirdropdowneditoptionsty;
function getshowhiddenfiles: boolean;
procedure setshowhiddenfiles(const avalue: boolean);
function getchecksubdir: boolean;
procedure setchecksubdir(const avalue: boolean);
protected
procedure createdropdownwidget(const atext: msestring;
out awidget: twidget); override;
function getdropdowntext(const awidget: twidget): msestring; override;
procedure pathchanged(const sender: tobject);
procedure doafterclosedropdown; override;
procedure updatecopytoclipboard(var atext: msestring); override;
procedure updatepastefromclipboard(var atext: msestring); override;
public
property showhiddenfiles: boolean read getshowhiddenfiles
write setshowhiddenfiles;
property checksubdir: boolean read getchecksubdir
write setchecksubdir;
published
property options: dirdropdowneditoptionsty read foptions
write foptions default [];
end;
tfiledialogfo = class(tmseform)
cancel: tbutton;
listview: tfilelistview;
ok: tbutton;
namecont: tgroupbox;
tspacer1: tspacer;
bucont: tspacer;
tspacer4: tspacer;
up: tbutton;
createdir: tbutton;
filename: thistoryedit;
filter: tdropdownlistedit;
dir: tdirdropdownedit;
tspacer3: tspacer;
tscrollbox1: tscrollbox;
tstringgrid1: tstringgrid;
timage1: timage;
tspacer2: tspacer;
tmemoedit1: tmemoedit;
tbooleanedit1: tbooleanedit;
showhidden: tbooleanedit;
sort: tbutton;
tspacer5: tspacer;
tpopupmenu1: tpopupmenu;
procedure createdironexecute(const sender: TObject);
procedure listviewselectionchanged(const sender: tcustomlistview);
procedure listviewitemevent(const sender: tcustomlistview;
const index: Integer; var info: celleventinfoty);
procedure listviewonkeydown(const sender: twidget; var info: keyeventinfoty);
procedure upaction(const sender: TObject);
procedure dironsetvalue(const sender: TObject; var avalue: mseString;
var accept: Boolean);
procedure filenamesetvalue(const sender: TObject; var avalue: mseString;
var accept: Boolean);
procedure listviewonlistread(const sender: tobject);
procedure filteronafterclosedropdown(const sender: tobject);
procedure filteronsetvalue(const sender: tobject; var avalue: msestring; var accept: boolean);
procedure filepathentered(const sender: tobject);
procedure okonexecute(const sender: tobject);
procedure foonchildscaled(const sender: TObject);
procedure showhiddenonsetvalue(const sender: TObject; var avalue: Boolean;
var accept: Boolean);
procedure formoncreate(const sender: TObject);
procedure dirshowhint(const sender: TObject; var info: hintinfoty);
procedure copytolip(const sender: TObject; var avalue: msestring);
procedure pastefromclip(const sender: TObject; var avalue: msestring);
procedure on_show(const sender: TObject);
procedure on_cellevent(const sender: TObject; var info: celleventinfoty);
procedure on_showsort(const sender: TObject);
procedure on_sortbyname(const sender: TObject);
procedure on_sortbytime(const sender: TObject);
procedure on_sortbytype(const sender: TObject);
procedure on_sortbysize(const sender: TObject);
private
{ Private declarations }
fselectednames: filenamearty;
procedure updatefiltertext;
// function readlist: boolean; //true if ok
function tryreadlist(const adir: filenamety): boolean;
//restores old dir on error
procedure changedir(const adir: filenamety);
public
dialogoptions: filedialogoptionsty;
defaultext: filenamety;
filenames: filenamearty;
{ Public declarations }
end;
function filedialog(var afilenames: filenamearty;
const aoptions: filedialogoptionsty;
const acaption: msestring; //'' -> 'Open' or 'Save'
const filterdesc: array of msestring;
const filtermask: array of msestring;
const adefaultext: filenamety = '';
const filterindex: pinteger = nil; //nil -> 0
const filter: pfilenamety = nil; //nil -> unused
const colwidth: pinteger = nil; //nil -> default
const includeattrib: fileattributesty = [fa_all];
const excludeattrib: fileattributesty = [fa_hidden];
const history: pmsestringarty = nil;
const historymaxcount: integer = defaulthistorymaxcount;
const imagelist: timagelist = nil;
const ongetfileicon: getfileiconeventty = nil;
const oncheckfile: checkfileeventty = nil
): modalresultty; overload;
//theadsave
function filedialog(var afilename: filenamety;
const aoptions: filedialogoptionsty;
const acaption: msestring;
const filterdesc: array of msestring;
const filtermask: array of msestring;
const adefaultext: filenamety = '';
const filterindex: pinteger = nil; //nil -> 0
const filter: pfilenamety = nil; //nil -> unused
const colwidth: pinteger = nil; //nil -> default
const includeattrib: fileattributesty = [fa_all];
const excludeattrib: fileattributesty = [fa_hidden];
const history: pmsestringarty = nil;
const historymaxcount: integer = defaulthistorymaxcount;
const imagelist: timagelist = nil;
const ongetfileicon: getfileiconeventty = nil;
const oncheckfile: checkfileeventty = nil
): modalresultty; overload;
//theadsave
procedure getfileicon(const info: fileinfoty; var imagelist: timagelist;
out imagenr: integer);
procedure updatefileinfo(const item: tlistitem; const info: fileinfoty;
const withicon: boolean);
implementation
uses
msefiledialog_mfm,sysutils,msebits,
msestringenter,msedirtree,msefiledialogres,msekeyboard,
msestockobjects,msesysintf,msearrayutils;
procedure getfileicon(const info: fileinfoty; var imagelist: timagelist;
out imagenr: integer);
begin
with info do begin
// imagelist:= nil;
imagenr:= -1;
if fis_typevalid in state then begin
case extinfo1.filetype of
ft_dir: begin
if fis_diropen in state then begin
filedialogres.getfileicon(fdi_diropen,imagelist,imagenr);
end
else begin
if fis_hasentry in state then begin
filedialogres.getfileicon(fdi_direntry,imagelist,imagenr);
end
else begin
filedialogres.getfileicon(fdi_dir,imagelist,imagenr);
end;
end;
end;
ft_reg,ft_lnk: begin
filedialogres.getfileicon(fdi_file,imagelist,imagenr);
end;
end;
end;
end;
end;
procedure updatefileinfo(const item: tlistitem; const info: fileinfoty;
const withicon: boolean);
var
aimagelist: timagelist;
aimagenr: integer;
begin
aimagelist:= item.imagelist;
item.caption:= info.name;
if withicon then begin
getfileicon(info,aimagelist,aimagenr);
item.imagelist:= aimagelist;
if aimagelist <> nil then begin
item.imagenr:= aimagenr;
end;
end;
end;
function filedialog1(dialog: tfiledialogfo; var afilenames: filenamearty;
const filterdesc: array of msestring;
const filtermask: array of msestring;
const filterindex: pinteger;
const afilter: pfilenamety; //nil -> unused
const colwidth: pinteger; //nil -> default
const includeattrib: fileattributesty;
const excludeattrib: fileattributesty;
const history: pmsestringarty;
const historymaxcount: integer;
const acaption: msestring;
const aoptions: filedialogoptionsty;
const adefaultext: filenamety;
const imagelist: timagelist;
const ongetfileicon: getfileiconeventty;
const oncheckfile: checkfileeventty
): modalresultty;
var
int1: integer;
begin
with dialog do begin
dir.checksubdir:= fdo_checksubdir in aoptions;
listview.checksubdir:= fdo_checksubdir in aoptions;
dialogoptions:= aoptions;
if fdo_filtercasesensitive in aoptions then begin
listview.optionsfile:= listview.optionsfile + [flvo_maskcasesensitive];
end;
if fdo_filtercaseinsensitive in aoptions then begin
listview.optionsfile:= listview.optionsfile + [flvo_maskcaseinsensitive];
end;
if fdo_single in aoptions then begin
listview.options:= listview.options - [lvo_multiselect];
end;
defaultext:= adefaultext;
caption:= acaption;
listview.includeattrib:= includeattrib;
listview.excludeattrib:= excludeattrib;
listview.itemlist.imagelist:= imagelist;
if imagelist <> nil then begin
listview.itemlist.imagesize:= imagelist.size;
end;
listview.ongetfileicon:= ongetfileicon;
listview.oncheckfile:= oncheckfile;
filter.dropdown.cols[0].count:= high(filtermask) + 1;
for int1:= 0 to high(filtermask) do begin
if (int1 <= high(filterdesc)) and (filterdesc[int1] <> '') then begin
filter.dropdown.cols[0][int1]:= filterdesc[int1] + ' ('+
filtermask[int1] + ')';
end
else begin
filter.dropdown.cols[0][int1]:= filtermask[int1];
end;
end;
filter.dropdown.cols[1].assignopenarray(filtermask);
if filterindex <> nil then begin
filter.dropdown.itemindex:= filterindex^;
end
else begin
filter.dropdown.itemindex:= 0;
end;
if (afilter = nil) or (afilter^ = '') or
(filter.dropdown.itemindex >= 0) and
(afilter^ = filter.dropdown.cols[1][filter.dropdown.itemindex]) then begin
updatefiltertext;
end
else begin
filter.value:= afilter^;
listview.mask:= afilter^;
end;
if history <> nil then begin
filename.dropdown.valuelist.asarray:= history^;
filename.dropdown.historymaxcount:= historymaxcount;
end
else begin
filename.dropdown.options:= [deo_disabled];
end;
if (high(afilenames) = 0) and (fdo_directory in aoptions) then begin
filename.value:= filepath(afilenames[0]);
end
else begin
filename.value:= quotefilename(afilenames);
end;
if (colwidth <> nil) and (colwidth^ <> 0) then begin
listview.cellwidth:= colwidth^;
end;
filename.checkvalue;
showhidden.value:= not (fa_hidden in excludeattrib);
show(true);
result:= window.modalresult;
if (colwidth <> nil) then begin
colwidth^:= listview.cellwidth;
end;
if result = mr_ok then begin
afilenames:= filenames;
if filterindex <> nil then begin
filterindex^:= filter.dropdown.itemindex;
end;
if afilter <> nil then begin
afilter^:= listview.mask;
end;
if high(afilenames) = 0 then begin
filename.dropdown.savehistoryvalue(afilenames[0]);
end;
if history <> nil then begin
history^:= filename.dropdown.valuelist.asarray;
end;
if fdo_chdir in aoptions then begin
setcurrentdirmse(listview.directory);
end;
end;
end;
end;
function filedialog(var afilenames: filenamearty;
const aoptions: filedialogoptionsty;
const acaption: msestring;
const filterdesc: array of msestring;
const filtermask: array of msestring;
const adefaultext: filenamety = '';
const filterindex: pinteger = nil;
const filter: pfilenamety = nil; //nil -> unused
const colwidth: pinteger = nil; //nil -> default
const includeattrib: fileattributesty = [fa_all];
const excludeattrib: fileattributesty = [fa_hidden];
const history: pmsestringarty = nil;
const historymaxcount: integer = defaulthistorymaxcount;
const imagelist: timagelist = nil;
const ongetfileicon: getfileiconeventty = nil;
const oncheckfile: checkfileeventty = nil
): modalresultty;
var
dialog: tfiledialogfo;
str1: msestring;
begin
application.lock;
try
dialog:= tfiledialogfo.create(nil);
if acaption = '' then begin
with stockobjects do begin
if fdo_save in aoptions then begin
str1:= captions[sc_save];
end
else begin
str1:= captions[sc_open];
end;
end;
end
else begin
str1:= acaption;
end;
try
result:= filedialog1(dialog,afilenames,filterdesc,filtermask,
filterindex,filter,colwidth,
includeattrib,excludeattrib,history,historymaxcount,str1,aoptions,
adefaultext,imagelist,ongetfileicon,oncheckfile);
finally
dialog.Free;
end;
finally
application.unlock;
end;
end;
function filedialog(var afilename: filenamety;
const aoptions: filedialogoptionsty;
const acaption: msestring;
const filterdesc: array of msestring;
const filtermask: array of msestring;
const adefaultext: filenamety = '';
const filterindex: pinteger = nil;
const filter: pfilenamety = nil; //nil -> unused
const colwidth: pinteger = nil; //nil -> default
const includeattrib: fileattributesty = [fa_all];
const excludeattrib: fileattributesty = [fa_hidden];
const history: pmsestringarty = nil;
const historymaxcount: integer = defaulthistorymaxcount;
const imagelist: timagelist = nil;
const ongetfileicon: getfileiconeventty = nil;
const oncheckfile: checkfileeventty = nil
): modalresultty;
var
ar1: filenamearty;
begin
setlength(ar1,1);
ar1[0]:= afilename;
result:= filedialog(ar1,aoptions,acaption,filterdesc,filtermask,adefaultext,
filterindex,
filter,colwidth,includeattrib,excludeattrib,history,historymaxcount,
imagelist,ongetfileicon,oncheckfile);
if result = mr_ok then begin
if (high(ar1) > 0) or (fdo_quotesingle in aoptions) then begin
afilename:= quotefilename(ar1);
end
else begin
if high(ar1) = 0 then begin
afilename:= ar1[0];
end
else begin
afilename:= '';
end;
end;
end;
end;
{ tfilelistview }
constructor tfilelistview.create(aowner: tcomponent);
begin
fcaseinsensitive:= filesystemiscaseinsensitive;
fincludeattrib:= [fa_all];
fexcludeattrib:= [fa_hidden];
fitemlist:= tfileitemlist.create(self);
foptionsfile:= defaultfilelistviewoptions;
ffilelist:= tfiledatalist.create;
ffilelist.onchange:= {$ifdef FPC}@{$endif}filelistchanged;
inherited;
options:= defaultlistviewoptionsfile;
checkcasesensitive;
end;
destructor tfilelistview.destroy;
begin
inherited;
ffilelist.Free;
end;
procedure tfilelistview.checkcasesensitive;
begin
fcaseinsensitive:= filesystemiscaseinsensitive;
if flvo_maskcasesensitive in foptionsfile then begin
fcaseinsensitive:= false;
end;
if flvo_maskcaseinsensitive in foptionsfile then begin
fcaseinsensitive:= true;
end;
// options:= options; //set casesensitive
end;
{
procedure tfilelistview.setoptions(const Value: listviewoptionsty);
begin
if fcaseinsensitive then begin
inherited setoptions(value - [lvo_casesensitive]);
end
else begin
inherited setoptions(value + [lvo_casesensitive]);
end;
end;
}
procedure tfilelistview.docellevent(var info: celleventinfoty);
var
index: integer;
begin
with info do begin
if iscellclick(info,[ccr_buttonpress]) then begin
options:= options + [lvo_focusselect];
end;
case eventkind of
cek_enter: begin
if ffocusmoved then begin
options:= options + [lvo_focusselect];
end
else begin
ffocusmoved:= true;
end;
inherited;
end;
cek_select: begin
index:= celltoindex(cell,false);
if index >= 0 then begin
if (flvo_nofileselect in foptionsfile) and
(ffilelist[index].extinfo1.filetype <> ft_dir) then begin
accept:= false;
end
else begin
if (flvo_nodirselect in foptionsfile) and
(ffilelist[index].extinfo1.filetype = ft_dir) then begin
accept:= false;
end;
end;
inherited;
end
else begin
inherited;
end;
end;
else begin
inherited;
end;
end;
end;
end;
procedure tfilelistview.filelistchanged(const sender: tobject);
var
int1: integer;
po1: pfilelistitem;
po2: pfileinfoty;
imlist1: timagelist;
imnr1: integer;
bo1: boolean;
begin
options:= options - [lvo_focusselect];
ffocusmoved:= false;
with ffilelist do begin
self.beginupdate;
self.fitemlist.beginupdate;
try
self.fitemlist.clear;
self.fitemlist.count:= count;
po1:= pfilelistitem(self.fitemlist.datapo);
po2:= pfileinfoty(datapo);
bo1:= checksubdir;
for int1:= 0 to count - 1 do begin
if bo1 and (po2^.extinfo1.filetype = ft_dir) and
dirhasentries(path+'/'+po2^.name,includeattrib,excludeattrib) then begin
include(po2^.state,fis_hasentry);
end;
updatefileinfo(po1^,po2^,true);
if assigned(fongetfileicon) then begin
imlist1:= po1^.imagelist;
imnr1:= po1^.imagenr;
fongetfileicon(self,po2^,imlist1,imnr1);
po1^.imagelist:= imlist1;
po1^.imagenr:= imnr1;
end;
inc(po1);
inc(po2);
end;
finally
self.fitemlist.endupdate;
self.endupdate;
end;
end;
end;
function tfilelistview.getselectednames: msestringarty;
var
int1,int2: integer;
begin
int2:=0;
result:= nil;
for int1:= 0 to ffilelist.count - 1 do begin
if fitemlist[int1].selected then begin
additem(result,ffilelist[int1].name,int2);
end;
end;
setlength(result,int2);
end;
procedure tfilelistview.setselectednames(const avalue: filenamearty);
var
int1: integer;
item1: tlistitem;
po1: plistitematy;
// cell1: gridcoordty;
begin
po1:= fitemlist.datapo;
fitemlist.beginupdate;
try
for int1:= 0 to fitemlist.count - 1 do begin
po1^[int1].selected:= false;
end;
for int1:= 0 to high(avalue) do begin
item1:= finditembycaption(avalue[int1]);
if item1 <> nil then begin
item1.selected:= true;
end;
end;
finally
fitemlist.endupdate;
end;
{
for int1:= 0 to high(avalue) do begin
if findcellbycaption(avalue[int1],cell1) then begin
fdatacols.selected[cell1]:= true;
end;
end;
}
// focuscell(cell1);
end;
procedure tfilelistview.setfilelist(const Value: tfiledatalist);
begin
if ffilelist <> value then begin
ffilelist.Assign(value);
end;
end;
procedure tfilelistview.readlist;
var
int1: integer;
po1: pfileinfoty;
level1: fileinfolevelty;
begin
beginupdate;
try
defocuscell;
fdatacols.clearselection;
ffilelist.clear;
ffilecount:= 0;
level1:= fil_type;
if assigned(foncheckfile) then begin
level1:= fil_ext2;
end;
if fmaskar = nil then begin
ffilelist.adddirectory(fdirectory,level1,fmaskar,
fincludeattrib,fexcludeattrib,foptionsdir,
foncheckfile);
if ffilelist.count > 0 then begin
po1:= ffilelist.itempo(0);
for int1:= 0 to ffilelist.count - 1 do begin
if not (fa_dir in po1^.extinfo1.attributes) then begin
inc(ffilecount);
end;
inc(po1);
end;
end;
end
else begin
if (fincludeattrib = [fa_all]) or not(fa_dir in fincludeattrib) then begin
ffilelist.adddirectory(fdirectory,level1,nil,[fa_dir],
fexcludeattrib*[fa_hidden],foptionsdir,foncheckfile);
int1:= ffilelist.count;
ffilelist.adddirectory(fdirectory,level1,fmaskar,fincludeattrib,
fexcludeattrib+[fa_dir],foptionsdir,foncheckfile);
ffilecount:= ffilelist.count - int1;
end
else begin
ffilelist.adddirectory(fdirectory,level1,fmaskar,
fincludeattrib,fexcludeattrib,foptionsdir,foncheckfile);
ffilecount:= ffilelist.count;
end;
end;
finally
endupdate;
end;
if assigned(fonlistread) then begin
fonlistread(self);
end;
end;
procedure tfilelistview.updir;
var
str1: msestring;
int1: integer;
begin
str1:= removelastdir(fdirectory,fdirectory);
if str1 <> '' then begin
readlist;
int1:= ffilelist.indexof(str1);
if int1 >= 0 then begin
focuscell(indextocell(int1),fca_focusin);
end;
end;
end;
procedure tfilelistview.setdirectory(const Value: msestring);
begin
fdirectory:= filepath(value,fk_dir);
end;
function tfilelistview.getpath: msestring;
begin
if fmaskar = nil then begin
result:= filepath(fdirectory);
end
else begin
result:= filepath(fdirectory,fmaskar[0]);
end;
end;
procedure tfilelistview.setpath(const Value: filenamety);
var
str1: msestring;
begin
splitfilepath(value,fdirectory,str1);
mask:= str1;
readlist;
end;
procedure tfilelistview.setmask(const value: filenamety);
begin
unquotefilename(value,fmaskar);
end;
function tfilelistview.getmask: filenamety;