-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMain.pas
969 lines (898 loc) · 28.9 KB
/
Main.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
{
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 Main;
{$MODE Delphi}
interface
uses
Windows, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus,
ComCtrls, VirtualTrees, ActiveX, AppConfig, ulNodeDataTypes, ulCommonClasses,
UDImages, ASuiteForm, LCLIntf, FileUtil, win32int, InterfaceBase,
StdCtrls, EditBtn, Buttons, ASuiteControls, Sensor;
type
{ TfrmMain }
TfrmMain = class(TASuiteForm)
edtSearch: TASuiteEdit;
miCheckUpdates: TMenuItem;
miStatistics: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
sbtnSearch: TSpeedButton;
vstList: TVirtualStringTree;
pcList: TPageControl;
tbList: TTabSheet;
tbSearch: TTabSheet;
vstSearch: TVirtualStringTree;
MainMenu: TMainMenu;
miFile: TMenuItem;
miHelp: TMenuItem;
N2: TMenuItem;
miOptions1: TMenuItem;
miImportList: TMenuItem;
miExit1: TMenuItem;
miInfoASuite: TMenuItem;
miEdit: TMenuItem;
miAddCat1: TMenuItem;
miAddSw1: TMenuItem;
miDelete1: TMenuItem;
N8: TMenuItem;
miProperty1: TMenuItem;
pmWindow: TPopupMenu;
miAddCat2: TMenuItem;
miAddSw2: TMenuItem;
miDelete2: TMenuItem;
N6: TMenuItem;
miProperty2: TMenuItem;
miAddFolder2: TMenuItem;
miAddFolder1: TMenuItem;
miSaveList1: TMenuItem;
miRunSelectedSw: TMenuItem;
miOpenFolderSw: TMenuItem;
N9: TMenuItem;
miAddSeparator2: TMenuItem;
miAddSeparator1: TMenuItem;
N3: TMenuItem;
miSortList: TMenuItem;
miExportList: TMenuItem;
N4: TMenuItem;
N1: TMenuItem;
SaveDialog1: TSaveDialog;
miSortItems: TMenuItem;
N5: TMenuItem;
miCopy2: TMenuItem;
miCut2: TMenuItem;
miPaste2: TMenuItem;
N10: TMenuItem;
miN11: TMenuItem;
miCut1: TMenuItem;
miCopy1: TMenuItem;
miPaste1: TMenuItem;
pmSearch: TPopupMenu;
miSearchName: TMenuItem;
miSearchExePath: TMenuItem;
miSearchIconPath: TMenuItem;
miSearchWorkingDirPath: TMenuItem;
miSearchParameters: TMenuItem;
procedure FormChangeBounds(Sender: TObject);
procedure FormWindowStateChange(Sender: TObject);
procedure miOptionsClick(Sender: TObject);
procedure miStatisticsClick(Sender: TObject);
procedure OpenFolderSw(Sender: TObject);
procedure pcListChange(Sender: TObject);
procedure miImportListClick(Sender: TObject);
procedure miSaveListClick(Sender: TObject);
procedure vstListDragDrop(Sender: TBaseVirtualTree;
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
Shift: TShiftState; const Pt: TPoint; var Effect: LongWord;
Mode: TDropMode);
procedure vstListDragOver(Sender: TBaseVirtualTree; Source: TObject;
Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode;
var Effect: Integer; var Accept: Boolean);
procedure ShowProperty(Sender: TObject);
procedure DeleteSwCat(Sender: TObject);
procedure AddFolder(Sender: TObject);
procedure AddSoftware(Sender: TObject);
procedure AddCategory(Sender: TObject);
procedure vstSearchGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure vstListGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
procedure vstListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure miExitClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure RunExe(Sender: TObject);
procedure RunSingleClick(Sender: TObject);
procedure pmWindowPopup(Sender: TObject);
procedure miRunSelectedSwClick(Sender: TObject);
procedure miAddSeparator2Click(Sender: TObject);
procedure vstSearchGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
procedure vstSearchCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vstListCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure miSortListClick(Sender: TObject);
procedure miExportListClick(Sender: TObject);
procedure vstListPaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
procedure FormDestroy(Sender: TObject);
procedure miSortItemsClick(Sender: TObject);
procedure vstListKeyPress(Sender: TObject; var Key: Char);
procedure miCopy2Click(Sender: TObject);
procedure miPaste2Click(Sender: TObject);
procedure miCut2Click(Sender: TObject);
procedure vstListSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
procedure vstListLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
procedure miEditClick(Sender: TObject);
procedure miInfoASuiteClick(Sender: TObject);
procedure btnedtSearchRightButtonClick(Sender: TObject);
procedure ChangeSearchTextHint(Sender: TObject);
procedure vstListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstListNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: string);
procedure btnedtSearchKeyPress(Sender: TObject; var Key: Char);
procedure vstListExpanding(Sender: TBaseVirtualTree; Node: PVirtualNode;
var Allowed: Boolean);
procedure vstSearchHeaderClick(Sender: TVTHeader; Column: TColumnIndex;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
procedure ExecuteFileOrOpenFolder(TreeView: TBaseVirtualTree;ExecuteFile: Boolean);
function GetActiveTree: TBaseVirtualTree;
procedure LoadGlyphs;
procedure RunAutorun;
public
{ Public declarations }
procedure ShowMainForm(Sender: TObject);
end;
var
frmMain : TfrmMain;
FormSensors : Array[0..3] of TfrmSensor;
implementation
uses
Option, PropertyFile, PropertyCat, About, ulCommonUtils, ulEnumerations,
udClassicMenu, PropertySeparator, ulExeUtils, ImportList, Stats, ulAppConfig,
ulTreeView, ulSQLite, ulDatabase;
{$R *.lfm}
procedure TfrmMain.btnedtSearchKeyPress(Sender: TObject; var Key: Char);
begin
if Ord(Key) = VK_RETURN then
btnedtSearchRightButtonClick(Sender);
end;
procedure TfrmMain.btnedtSearchRightButtonClick(Sender: TObject);
var
NodeData: PBaseData;
begin
vstSearch.Clear;
if Length(edtSearch.Text) > 0 then
begin
New(NodeData);
NodeData.Data := CreateNodeData(vtdtFile);
with TvFileNodeData(NodeData.Data) do
begin
case SearchType of
stName : Name := edtSearch.Text;
stPathExe : PathExe := edtSearch.Text;
stPathIcon : PathIcon := edtSearch.Text;
stWorkingDir : WorkingDir := edtSearch.Text;
stParameters : Parameters := edtSearch.Text;
end;
end;
vstList.IterateSubtree(nil, IterateSubtreeProcs.FindNode, NodeData.Data, [], True);
FreeAndNil(NodeData.Data);
Dispose(NodeData);
end;
end;
procedure TfrmMain.DeleteSwCat(Sender: TObject);
var
Nodes: TNodeArray;
I: Integer;
begin
if (vstList.GetFirstSelected <> nil) and (MessageDlg((msgConfirm),mtWarning, [mbYes,mbNo], 0) = mrYes) then
begin
//Run actions (ex. remove node from MRU list) before delete nodes
Nodes := vstList.GetSortedSelection(true);
//Initialize dataset for remove data from sqlite database
DBManager.CreateDataSetRemoveItems;
for I := High(Nodes) downto 0 do
vstList.IterateSubtree(Nodes[I],IterateSubtreeProcs.BeforeDeleteNode,nil,[],False);
//Apply database's updates
DBManager.ApplyUpdatesRemoveItems;
//Delete nodes and refresh list
vstList.DeleteSelectedNodes;
RefreshList(vstList);
end;
end;
procedure TfrmMain.miSaveListClick(Sender: TObject);
var
Result : Boolean;
begin
Result := SaveASuiteSQLite(vstList, true);
if Result then
showmessage(msgSaveCompleted)
else
showmessage(msgErrSave);
end;
procedure TfrmMain.ChangeSearchTextHint(Sender: TObject);
begin
if (Sender is TMenuItem) then
begin
//Set new placeholder and SearchType
edtSearch.PlaceHolder := StringReplace((Sender as TMenuItem).Caption, '&', '', []);
(Sender as TMenuItem).Checked := True;
SearchType := TSearchType((Sender as TMenuItem).Tag);
end;
end;
procedure TfrmMain.AddCategory(Sender: TObject);
begin
AddNode(vstList,vtdtCategory);
end;
procedure TfrmMain.AddFolder(Sender: TObject);
begin
AddNode(vstList,vtdtFolder);
end;
procedure TfrmMain.AddSoftware(Sender: TObject);
begin
AddNode(vstList,vtdtFile);
end;
procedure TfrmMain.miAddSeparator2Click(Sender: TObject);
begin
AddNode(vstList,vtdtSeparator);
end;
procedure TfrmMain.miCopy2Click(Sender: TObject);
begin
vstList.CopyToClipBoard;
end;
procedure TfrmMain.miCut2Click(Sender: TObject);
begin
vstList.CutToClipBoard;
end;
procedure TfrmMain.OpenFolderSw(Sender: TObject);
var
TreeView : TBaseVirtualTree;
begin
TreeView := GetActiveTree;
//Show file's folder
ExecuteFileOrOpenFolder(TreeView, false);
end;
procedure TfrmMain.RunExe(Sender: TObject);
var
NodeData : TvBaseNodeData;
Node : PVirtualNode;
begin
if (Sender is TBaseVirtualTree) then
begin
//Check if user click on node or expand button (+/-)
if Not(ClickOnButtonTree((Sender as TBaseVirtualTree))) then
ExecuteFileOrOpenFolder((Sender as TBaseVirtualTree), true);
end;
end;
procedure TfrmMain.miImportListClick(Sender: TObject);
begin
try
Application.CreateForm(TfrmImportList, frmImportList);
frmImportList.FormStyle := Self.FormStyle;
frmImportList.ShowModal;
finally
frmImportList.Free;
RefreshList(vstList);
end;
end;
procedure TfrmMain.miInfoASuiteClick(Sender: TObject);
begin
if not IsFormOpen('frmAbout') then
Application.CreateForm(TfrmAbout, frmAbout);
frmAbout.show;
end;
procedure TfrmMain.miRunSelectedSwClick(Sender: TObject);
begin
if pcList.ActivePageIndex = PG_LIST then
RunExe(vstList)
else
RunExe(vstSearch);
end;
procedure TfrmMain.miOptionsClick(Sender: TObject);
begin
if not IsFormOpen('frmOption') then
try
Application.CreateForm(TfrmOption, frmOption);
frmOption.FormStyle := Self.FormStyle;
frmOption.showmodal;
finally
frmOption.Free;
end
else
frmOption.show;
RefreshList(vstList);
end;
procedure TfrmMain.miStatisticsClick(Sender: TObject);
var
frmStats:TfrmStats;
begin
try
frmStats:=TfrmStats.Create(self);
frmStats.ShowModal();
finally
frmStats.Free;
end;
end;
procedure TfrmMain.FormChangeBounds(Sender: TObject);
begin
if not(StartUpTime) then
Config.Changed := true;
end;
procedure TfrmMain.FormWindowStateChange(Sender: TObject);
begin
if WindowState = wsMinimized then
begin
//Cancel minimize frmMain
WindowState := wsNormal;
//Hide frmMain and taskbar icon
Hide;
ShowInTaskBar := stNever;
end;
end;
procedure TfrmMain.miPaste2Click(Sender: TObject);
var
NodeData : PBaseData;
begin
NodeData := vstList.GetNodeData(vstList.FocusedNode);
if Assigned(NodeData) then
begin
if NodeData.Data.DataType = vtdtCategory then
vstList.DefaultPasteMode := amAddChildLast
else
vstList.DefaultPasteMode := amInsertAfter;
end
else
vstList.DefaultPasteMode := amAddChildLast;
vstList.PasteFromClipboard;
vstList.Expanded[vstList.FocusedNode] := True;
RefreshList(vstList);
end;
procedure TfrmMain.miSortItemsClick(Sender: TObject);
begin
vstList.Sort(vstList.GetFirstSelected,0,sdAscending,True);
RefreshList(vstList);
end;
procedure TfrmMain.miSortListClick(Sender: TObject);
begin
vstList.SortTree(0,sdAscending,True);
RefreshList(vstList);
end;
procedure TfrmMain.pcListChange(Sender: TObject);
var
ActiveTab : Boolean;
begin
ActiveTab := pcList.ActivePageIndex = PG_LIST;
//Set property Visible for some components
miEdit.Visible := ActiveTab;
miSortItems.Visible := ActiveTab;
miAddCat2.Visible := ActiveTab;
miAddSw2.Visible := ActiveTab;
miAddFolder2.Visible := ActiveTab;
miAddSeparator2.Visible := ActiveTab;
miDelete2.Visible := ActiveTab;
miCut2.Visible := ActiveTab;
miCopy2.Visible := ActiveTab;
miPaste2.Visible := ActiveTab;
//Separator
N9.Visible := ActiveTab;
N5.Visible := ActiveTab;
N10.Visible := ActiveTab;
end;
procedure TfrmMain.pmWindowPopup(Sender: TObject);
var
NodeData : PBaseData;
Point : TPoint;
HitInfo : ThitInfo;
TreeView : TBaseVirtualTree;
begin
GetCursorPos(Point);
Point := vstList.ScreenToClient(Point);
vstList.GetHitTestInfoAt(Point.X,Point.Y,true,HitInfo);
//If user clicks on empty area of vstList
if Not(hiOnItem in hitinfo.HitPositions) then
begin
//Set nil vstList.FocusedNode
vstList.Selected[vstList.FocusedNode] := False;
vstList.FocusedNode := nil;
end;
//Enable/disable item window menu
if (Assigned(vstList.FocusedNode) and (pcList.ActivePageIndex = PG_LIST)) or
(Assigned(vstSearch.FocusedNode) and (pcList.ActivePageIndex = PG_Search)) then
begin
TreeView := GetActiveTree;
NodeData := GetNodeDataEx(TreeView.FocusedNode, TreeView, vstSearch, vstList);
miProperty2.Enabled := true;
if (NodeData.Data.DataType <> vtdtCategory) then
miRunSelectedSw.Enabled := true;
if (NodeData.Data.DataType <> vtdtFile) then
miOpenFolderSw.Enabled := false;
if (NodeData.Data.DataType <> vtdtSeparator) then
miRunSelectedSw.Enabled := true;
case NodeData.Data.DataType of
vtdtCategory : miRunSelectedSw.Enabled := false;
vtdtFile : miOpenFolderSw.Enabled := true;
vtdtSeparator : miRunSelectedSw.Enabled := false;
end;
end
else begin
miRunSelectedSw.Enabled := false;
miOpenFolderSw.Enabled := false;
end;
miPaste2.Enabled := IsFormatInClipBoard(CF_VIRTUALTREE);
end;
procedure TfrmMain.vstSearchCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
Data1, Data2, CatData1, CatData2: PBaseData;
CatName1, CatName2 : String;
begin
Data1 := GetNodeDataSearch(Node1,vstSearch,vstList);
Data2 := GetNodeDataSearch(Node2,vstSearch,vstList);
if (Not Assigned(Data1)) or (Not Assigned(Data2)) then
Result := 0
else
if Column = 0 then
Result := CompareText(Data1.Data.Name, Data2.Data.Name)
else begin
CatData1 := vstList.GetNodeData(Data1.pNode.Parent);
CatData2 := vstList.GetNodeData(Data2.pNode.Parent);
if Assigned(CatData1) then
CatName1 := CatData1.Data.Name
else
CatName1 := '';
if Assigned(CatData2) then
CatName2 := CatData2.Data.Name
else
CatName2 := '';
Result := CompareText(CatName1, CatName2)
end;
end;
procedure TfrmMain.vstSearchGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
var
NodeData : TvBaseNodeData;
begin
NodeData := GetNodeDataSearch(Node,vstSearch,vstList).Data;
ImageIndex := NodeData.ImageIndex;
if Column = 1 then
ImageIndex := -1;
end;
procedure TfrmMain.vstSearchGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
NodeData, CatData : PBaseData;
begin
NodeData := GetNodeDataSearch(Node,vstSearch,vstList);
if Column = 0 then
CellText := NodeData.Data.Name;
if Column = 1 then
if (NodeData.pNode.Parent <> vstList.RootNode) then
begin
CatData := vstList.GetNodeData(NodeData.pNode.Parent);
CellText := CatData.Data.Name;
end
else
CellText := '';
end;
procedure TfrmMain.vstSearchHeaderClick(Sender: TVTHeader;
Column: TColumnIndex; Button: TMouseButton; Shift: TShiftState; X, Y: Integer
);
begin
vstSearch.SortTree(Column,Sender.SortDirection,True);
if Sender.SortDirection = sdAscending then
Sender.SortDirection := sdDescending
else
Sender.SortDirection := sdAscending
end;
procedure TfrmMain.ShowMainForm(Sender: TObject);
begin
ShowWindow(Application.MainFormHandle, SW_RESTORE);
end;
procedure TfrmMain.ExecuteFileOrOpenFolder(TreeView: TBaseVirtualTree;ExecuteFile: Boolean);
var
Node : PVirtualNode;
NodeData : TvBaseNodeData;
begin
//First selected node
Node := TreeView.GetFirstSelected;
while Assigned(Node) do
begin
//Get Node data
NodeData := PBaseData(GetNodeDataEx(Node, TreeView, vstSearch, vstList)).Data;
//Check if node type is a file
if (NodeData is TvFileNodeData) then
begin
//If ExecuteFile = true, execute it
if ExecuteFile then
TvFileNodeData(NodeData).Execute(vstList, false)
else //Else open file's folder
TvFileNodeData(NodeData).OpenExtractedFolder;
end;
//Next selected node
Node := TreeView.GetNextSelected(node);
end;
end;
procedure TfrmMain.vstListGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
var
NodeData : PvBaseNodeData;
begin
NodeData := Sender.GetNodeData(Node);
ImageIndex := NodeData.ImageIndex;
if Column = 1 then
ImageIndex := -1;
end;
procedure TfrmMain.vstListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
NodeData : PBaseData;
I : Byte;
str : string;
begin
NodeData := Sender.GetNodeData(Node);
if NodeData.Data.DataType = vtdtSeparator then
begin
I := 40 - (Length(NodeData.Data.Name));
str := '----------------------';
if I >= 10 then
SetLength(str, I div 2)
else
SetLength(str, 5);
CellText := str + ' ' + NodeData.Data.Name + ' ' + str;
end
else
CellText := StringReplace(NodeData.Data.Name, '&&', '&', [rfIgnoreCase,rfReplaceAll]);
end;
procedure TfrmMain.vstListKeyPress(Sender: TObject; var Key: Char);
begin
if Ord(Key) = VK_RETURN then
RunExe(Sender);
end;
procedure TfrmMain.vstListLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
var
DataDest,DataSource: PBaseData;
begin
//Create a new PBaseData as source
New(DataSource);
Stream.ReadBuffer(DataSource^,SizeOf(rBaseData));
//Copy source's properties in DataDest
DataDest := vstList.GetNodeData(Node);
DataDest.Data := CreateNodeData(DataSource.Data.DataType);
//Copy DataSource in DataDest
case DataSource.Data.DataType of
vtdtCategory : TvCategoryNodeData(DataDest.Data).Copy(DataSource.Data);
vtdtFile : TvFileNodeData(DataDest.Data).Copy(DataSource.Data);
vtdtFolder : TvFileNodeData(DataDest.Data).Copy(DataSource.Data);
vtdtSeparator : TvSeparatorNodeData(DataDest.Data).Copy(DataSource.Data);
end;
//Set some personal record fields
DataDest.pNode := Node;
DataDest.Data.ParentNode := Node.Parent;
//Icon
DataDest.Data.ImageIndex := ImagesDM.GetIconIndex(DataDest.Data);
FreeMem(DataSource);
end;
procedure TfrmMain.vstListNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: string);
var
NodeData : PBaseData;
begin
NodeData := Sender.GetNodeData(Node);
if Assigned(NodeData) then
NodeData.Data.Name := NewText;
end;
procedure TfrmMain.vstListPaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
begin
with TargetCanvas do
begin
Font.Name := Config.TVFont.Name;
Font.Style := Config.TVFont.Style;
Font.Size := Config.TVFont.Size;
if Not(Sender.Selected[Node]) then
Font.Color := Config.TVFont.Color;
end;
end;
procedure TfrmMain.vstListSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
var
Data: PBaseData;
begin
Data := vstList.GetNodeData(Node);
Stream.WriteBuffer(Data^,SizeOf(rBaseData));
end;
procedure TfrmMain.RunSingleClick(Sender: TObject);
begin
if (Sender is TBaseVirtualTree) then
if Not(ClickOnButtonTree((Sender as TBaseVirtualTree))) then
if (Config.RunSingleClick) then
RunExe(Sender);
end;
procedure TfrmMain.vstListCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
Data1, Data2: PBaseData;
begin
Data1 := vstList.GetNodeData(Node1);
Data2 := vstList.GetNodeData(Node2);
if (Not Assigned(Data1)) or (Not Assigned(Data2)) then
Result := 0
else
if (Data1.Data.DataType = vtdtCategory) <> (Data2.Data.DataType = vtdtCategory) then
begin
if Data1.Data.DataType = vtdtCategory then
Result := -1
else
Result := 1
end
else
Result := CompareText(Data1.Data.Name, Data2.Data.Name);
end;
procedure TfrmMain.vstListDragDrop(Sender: TBaseVirtualTree;
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
Shift: TShiftState; const Pt: TPoint; var Effect: LongWord; Mode: TDropMode);
var
I : integer;
NodeData : PBaseData;
AttachMode : TVTNodeAttachMode;
begin
case Mode of
dmAbove : AttachMode := amInsertBefore;
dmOnNode : AttachMode := amAddChildLast;
dmBelow : AttachMode := amInsertAfter;
else
AttachMode := amNowhere;
end;
if Assigned(DataObject) then
begin
NodeData := Sender.GetNodeData(Sender.DropTargetNode);
if Mode = dmOnNode then
begin
//Check if DropMode is in a vtdtCategory (so expand it, before drop item)
//or another item type (set amNowhere as AttachMode)
if NodeData.Data.DataType <> vtdtCategory then
AttachMode := amNowhere
else
vstList.Expanded[Sender.DropTargetNode] := True;
end;
try
for I := 0 to High(Formats) - 1 do
begin
//Files
if Formats[I] = CF_HDROP then
DragDropFiles(Sender,DataObject, AttachMode, Mode)
else //VirtualTree Nodes
if Formats[I] = CF_VIRTUALTREE then
Sender.ProcessDrop(DataObject, Sender.DropTargetNode, Effect, AttachMode)
else //Text
if Formats[I] = CF_TEXT then
DragDropText(Sender,DataObject, AttachMode, Mode);
end;
except
on E : Exception do
ShowMessageFmt(msgErrGeneric,[E.ClassName,E.Message]);
end;
RefreshList(vstList);
end;
end;
procedure TfrmMain.vstListDragOver(Sender: TBaseVirtualTree; Source: TObject;
Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode;
var Effect: Integer; var Accept: Boolean);
begin
accept := true;
end;
procedure TfrmMain.vstListExpanding(Sender: TBaseVirtualTree;
Node: PVirtualNode; var Allowed: Boolean);
begin
GetChildNodesIcons(Sender, Node);
end;
procedure TfrmMain.vstListFreeNode(Sender: TBaseVirtualTree;
Node: PVirtualNode);
var
NodeData : PBaseData;
begin
NodeData := Sender.GetNodeData(Node);
FreeAndNil(NodeData.Data);
end;
function TfrmMain.GetActiveTree: TBaseVirtualTree;
begin
case pcList.ActivePageIndex of
PG_LIST : Result := vstList;
PG_SEARCH : Result := vstSearch;
else Result := nil;
end;
end;
procedure TfrmMain.LoadGlyphs;
begin
//Set IcoImages
//Set submenuimages to three MainMenu's subitems
miFile.SubMenuImages := ImagesDM.IcoImages;
miEdit.SubMenuImages := ImagesDM.IcoImages;
miHelp.SubMenuImages := ImagesDM.IcoImages;
vstList.Images := ImagesDM.IcoImages;
vstSearch.Images := ImagesDM.IcoImages;
pmSearch.Images := ImagesDM.IcoImages;
pmWindow.Images := ImagesDM.IcoImages;
//Set MainMenu's ImageIndexes
miSaveList1.ImageIndex := IMG_Save;
miOptions1.ImageIndex := IMG_Options;
miAddCat1.ImageIndex := IMG_AddCat;
miAddSw1.ImageIndex := IMG_AddFile;
miAddFolder1.ImageIndex := IMG_AddFolder;
miCut1.ImageIndex := IMG_Cut;
miCopy1.ImageIndex := IMG_Copy;
miPaste1.ImageIndex := IMG_Paste;
miDelete1.ImageIndex := IMG_Delete;
miProperty1.ImageIndex := IMG_Property;
miInfoASuite.ImageIndex := IMG_Help;
//Set PopUpMenu's ImageIndexes
miRunSelectedSw.ImageIndex := IMG_Run;
miAddCat2.ImageIndex := IMG_AddCat;
miAddSw2.ImageIndex := IMG_AddFile;
miAddFolder2.ImageIndex := IMG_AddFolder;
miCut2.ImageIndex := IMG_Cut;
miCopy2.ImageIndex := IMG_Copy;
miPaste2.ImageIndex := IMG_Paste;
miDelete2.ImageIndex := IMG_Delete;
miProperty2.ImageIndex := IMG_Property;
//Set Search's ImageIndexes
ImagesDM.IcoImages.GetBitmap(IMG_Search,sbtnSearch.Glyph);
end;
procedure TfrmMain.RunAutorun;
var
NodeData : TvFileNodeData;
I : Integer;
begin
//Autorun - Execute software
for I := 0 to ASuiteStartUpApp.Count - 1 do
begin
NodeData := ASuiteStartUpApp[I];
if (Config.Autorun) then
begin
if (NodeData.Autorun = atSingleInstance) then
begin
if not IsProcessExists(ExtractFileName(NodeData.PathAbsoluteExe)) then
NodeData.Execute(vstList,true);
end
else if (NodeData.Autorun = atAlwaysOnStart) then
NodeData.Execute(vstList,true);
end;
end;
end;
procedure TfrmMain.ShowProperty(Sender: TObject);
var
Node : PVirtualNode;
NodeData : PBaseData;
OK : Boolean;
TreeView : TBaseVirtualTree;
begin
TreeView := GetActiveTree;
NodeData := GetNodeDataEx(TreeView.FocusedNode, TreeView, vstSearch, vstList);
if Assigned(NodeData) then
begin
case NodeData.Data.DataType of
vtdtFile : OK := (TfrmPropertyFile.Edit(Self, NodeData) = mrOK);
vtdtCategory : OK := (TfrmPropertyCat.Edit(Self, NodeData) = mrOK);
vtdtSeparator : OK := (TfrmPropertySeparator.Edit(Self, NodeData) = mrOK);
else OK := False;
end;
if Ok then
RefreshList(vstList);
end;
end;
procedure TfrmMain.miEditClick(Sender: TObject);
begin
miPaste1.Enabled := IsFormatInClipBoard(CF_VIRTUALTREE);
end;
procedure TfrmMain.miExitClick(Sender: TObject);
begin
ShutdownTime := True;
Close;
end;
procedure TfrmMain.miExportListClick(Sender: TObject);
begin
if (SaveDialog1.Execute) then
begin
SaveASuiteSQLite(vstList,true);
Windows.CopyFile(PChar(DBManager.DBFileName),PChar(SaveDialog1.FileName),false)
end;
SetCurrentDirUTF8(SUITE_WORKING_PATH);
end;
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
var
I : Integer;
NodeData : TvFileNodeData;
begin
//Autorun - Execute software
for I := 0 to ASuiteShutdownApp.Count - 1 do
begin
NodeData := TvFileNodeData(ASuiteShutdownApp[I]);
if (Config.Autorun) then
NodeData.Execute(vstList,true);
end;
//Execute actions on asuite's shutdown (inside vstList)
vstList.IterateSubtree(nil, IterateSubtreeProcs.ActionsOnShutdown, nil, [], True);
SaveASuiteSQLite(vstList,true);
end;
procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Not(Config.TrayIcon) then
CanClose := True
else
CanClose := (ShutdownTime or SessionEnding);
//If user close window (not ASuite), hide form and taskbar icon
if not (CanClose) then
begin
//Hide frmMain and taskbar icon
Hide;
ShowInTaskBar := stNever;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
pcList.ActivePageIndex := PG_LIST;
//Create TNodeLists for autorun
ASuiteStartUpApp := TAutorunItemList.Create;
ASuiteShutdownApp := TAutorunItemList.Create;
//Set NodeDataSize for trees
vstList.NodeDataSize := SizeOf(rBaseData);
vstSearch.NodeDataSize := SizeOf(TTreeDataX);
//Read Only Mode
with Config do
begin
ReadOnlyMode := GetDriveType(PChar(SUITE_DRIVE)) = DRIVE_CDROM;
if (ReadOnlyMode) then
begin
Cache := False;
Backup := False;
MRU := False;
miOptions1.Enabled := False;
miSaveList1.Enabled := False;
end;
end;
//Loading icons
LoadGlyphs;
//List & Options
LoadASuiteSQLite(vstList, false);
RunAutorun;
StartUpTime := false;
//Get placeholder for edtSearch
edtSearch.PlaceHolder := StringReplace(miSearchName.Caption, '&', '', []);
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
//Fix memory leaks
FreeAndNil(MRUList);
FreeAndNil(MFUList);
FreeAndNil(ASuiteStartUpApp);
FreeAndNil(ASuiteShutdownApp);
Config.Destroy;
end;
end.