forked from douglasimcabral/pyscripter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdlgNewFile.pas
157 lines (140 loc) · 4.7 KB
/
dlgNewFile.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
unit dlgNewFile;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
Dialogs, VirtualTrees, cFileTemplates,
SpTBXDkPanels, SpTBXControls, dlgPyIDEBase,
SpTBXItem, SpTBXSkins, MPCommonObjects, MPCommonUtilities, EasyListview,
cThemedVirtualStringTree;
type
TNewFileDialog = class(TPyIDEDlgBase)
Panel1: TSpTBXPanel;
Panel2: TSpTBXPanel;
Panel3: TSpTBXPanel;
tvCategories: TVirtualStringTree;
Label1: TSpTBXLabel;
Panel4: TSpTBXPanel;
Label2: TSpTBXLabel;
btnCancel: TSpTBXButton;
btnCreate: TSpTBXButton;
btnManageTemplates: TSpTBXButton;
Splitter1: TSpTBXSplitter;
lvTemplates: TEasyListview;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure tvCategoriesGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure FormShow(Sender: TObject);
procedure tvCategoriesChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure btnManageTemplatesClick(Sender: TObject);
procedure btnCreateClick(Sender: TObject);
procedure lvTemplatesItemDblClick(Sender: TCustomEasyListview;
Button: TCommonMouseButton; MousePos: TPoint; HitInfo: TEasyHitInfoItem);
procedure lvTemplatesItemSelectionsChanged(Sender: TCustomEasyListview);
private
{ Private declarations }
public
{ Public declarations }
Categories : TStringList;
SelectedTemplate : TFileTemplate;
procedure SetUp;
end;
implementation
uses
ShellAPI, dmCommands;
{$R *.dfm}
procedure TNewFileDialog.btnCreateClick(Sender: TObject);
begin
if Assigned(lvTemplates.Selection.First()) then begin
SelectedTemplate := TFileTemplate(lvTemplates.Selection.First.Data);
ModalResult := mrOK;
end;
end;
procedure TNewFileDialog.btnManageTemplatesClick(Sender: TObject);
begin
CommandsDataModule.actFileTemplatesExecute(Self);
SetUp;
end;
procedure TNewFileDialog.FormCreate(Sender: TObject);
begin
inherited;
Categories := TStringList.Create;
Categories.CaseSensitive := False;
lvTemplates.ImagesLarge := LargeSysImages;
tvCategories.SkinTree;
end;
procedure TNewFileDialog.FormDestroy(Sender: TObject);
begin
Categories.Free;
end;
procedure TNewFileDialog.FormShow(Sender: TObject);
begin
SetUp;
end;
procedure TNewFileDialog.lvTemplatesItemDblClick(Sender: TCustomEasyListview;
Button: TCommonMouseButton; MousePos: TPoint; HitInfo: TEasyHitInfoItem);
begin
btnCreateClick(Self);
end;
procedure TNewFileDialog.lvTemplatesItemSelectionsChanged(
Sender: TCustomEasyListview);
begin
btnCreate.Enabled := Assigned(lvTemplates.Selection.First());
end;
procedure TNewFileDialog.SetUp;
var
i : integer;
begin
Categories.Clear;
tvCategories.Clear;
lvTemplates.Items.Clear;
for i := 0 to FileTemplates.Count - 1 do
if Categories.IndexOf(TFileTemplate(FileTemplates[i]).Category) < 0 then
Categories.Add(TFileTemplate(FileTemplates[i]).Category);
tvCategories.RootNodeCount := Categories.Count;
if Categories.Count > 0 then
tvCategories.Selected[tvCategories.RootNode.FirstChild] := True;
end;
procedure TNewFileDialog.tvCategoriesChange(Sender: TBaseVirtualTree;
Node: PVirtualNode);
Var
i, Index : integer;
FileTemplate : TFileTemplate;
FName : string;
FileInfo: TSHFileInfo;
begin
if Assigned(Node) and (vsSelected in Node.States) then begin
lvTemplates.Items.Clear;
Index := Node.Index;
for i := 0 to FileTemplates.Count - 1 do begin
FileTemplate := FileTemplates[i] as TFileTemplate;
if CompareText(Categories[Index], FileTemplate.Category) = 0 then begin
with lvTemplates.Items.Add do begin
Caption := FileTemplate.Name;
Data := FileTemplate;
FName := '.' + FileTemplate.Extension;
if SHGetFileInfo(PChar(FName),
FILE_ATTRIBUTE_NORMAL,
FileInfo,
SizeOf( FileInfo),
SHGFI_USEFILEATTRIBUTES or
SHGFI_LARGEICON or
SHGFI_ICON or
SHGFI_SYSICONINDEX) > 0
then
ImageIndex := FileInfo.iIcon
else
ImageIndex := 0;
end;
end;
end;
end;
end;
procedure TNewFileDialog.tvCategoriesGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: string);
begin
if TextType = ttNormal then
CellText := Categories[Node.Index]
end;
end.