forked from pyscripter/pyscripter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cFileTemplates.pas
256 lines (229 loc) · 6.99 KB
/
cFileTemplates.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
{-----------------------------------------------------------------------------
Unit Name: cFileTemplates
Author: Kiriakos Vlahos
Date: 08-Aug-2006
Purpose: Data Structures for File Templates
History:
-----------------------------------------------------------------------------}
unit cFileTemplates;
interface
Uses
Classes, SysUtils, Contnrs, JvAppStorage;
Type
TFileTemplate = class(TInterfacedPersistent, IJvAppStorageHandler)
protected
// IJvAppStorageHandler implementation
procedure ReadFromAppStorage(AppStorage: TJvCustomAppStorage; const BasePath: string);
procedure WriteToAppStorage(AppStorage: TJvCustomAppStorage; const BasePath: string);
public
Name: string;
Template: string;
Extension: string;
Category: string;
Highlighter : string;
procedure Assign(Source: TPersistent); override;
end;
TFileTemplates = class(TObjectList)
function CreateListItem(Sender: TJvCustomAppStorage; const Path: string;
Index: Integer): TPersistent;
procedure AddPythonTemplate;
procedure AddCythonTemplate;
procedure AddHTMLTemplate;
procedure AddCSSTemplate;
procedure AddXMLTemplate;
procedure AddJSTemplate;
procedure AddPHPTemplate;
procedure AddPlainTextTemplate;
procedure Assign(Source: TFileTemplates);
function TemplateByName(const Name : string) : TFileTemplate;
end;
var
FileTemplates : TFileTemplates;
implementation
uses StringResources, gnugettext;
{ TFileTemplate }
procedure TFileTemplate.Assign(Source: TPersistent);
begin
if Source is TFileTemplate then begin
Name := TFileTemplate(Source).Name;
Template := TFileTemplate(Source).Template;
Extension := TFileTemplate(Source).Extension;
Category := TFileTemplate(Source).Category;
Highlighter := TFileTemplate(Source).Highlighter;
end else
inherited;
end;
procedure TFileTemplate.ReadFromAppStorage(AppStorage: TJvCustomAppStorage;
const BasePath: string);
Var
SL : TStringList;
begin
Name := AppStorage.ReadString(BasePath+'\Name', '');
Highlighter := AppStorage.ReadString(BasePath+'\Highlighter', '');
Extension := AppStorage.ReadString(BasePath+'\Extension', '');
Category := AppStorage.ReadString(BasePath+'\Category', '');
SL := TStringList.Create;
try
AppStorage.ReadStringList(BasePath+'\Template', SL);
Template := SL.Text;
finally
SL.Free;
end;
end;
procedure TFileTemplate.WriteToAppStorage(AppStorage: TJvCustomAppStorage;
const BasePath: string);
Var
SL : TStringList;
begin
AppStorage.WriteString(BasePath+'\Name', Name);
AppStorage.WriteString(BasePath+'\Highlighter', Highlighter);
AppStorage.WriteString(BasePath+'\Extension', Extension);
AppStorage.WriteString(BasePath+'\Category', Category);
SL := TStringList.Create;
try
SL.Text := Template;
AppStorage.WriteStringList(BasePath+'\Template', SL);
finally
SL.Free;
end;
end;
{ TFileTemplates }
procedure TFileTemplates.AddCSSTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SCSSFileTemplateName);
FileTemplate.Extension := 'css';
FileTemplate.Category := _(SFileTemplateCategoryInternet);
FileTemplate.Highlighter := 'CSS';
FileTemplate.Template := SCSSFileTemplate;
Add(FileTemplate);
end;
procedure TFileTemplates.AddCythonTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SCythonTemplateName);
FileTemplate.Extension := 'pyx';
FileTemplate.Category := 'Python';
FileTemplate.Highlighter := 'Cython';
FileTemplate.Template := _(SPythonFileTemplate);
Add(FileTemplate);
end;
procedure TFileTemplates.AddHTMLTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SHTMLFileTemplateName);
FileTemplate.Extension := 'htm';
FileTemplate.Category := _(SFileTemplateCategoryInternet);
FileTemplate.Highlighter := 'HTML';
FileTemplate.Template := SHTMLFileTemplate;
Add(FileTemplate);
end;
procedure TFileTemplates.AddJSTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SJSTemplateName);
FileTemplate.Extension := 'js';
FileTemplate.Category := _(SFileTemplateCategoryOther);
FileTemplate.Highlighter := 'JavaScript';
FileTemplate.Template := '';
Add(FileTemplate);
end;
procedure TFileTemplates.AddPHPTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SPHPTemplateName);
FileTemplate.Extension := 'xml';
FileTemplate.Category := _(SFileTemplateCategoryOther);
FileTemplate.Highlighter := 'XML';
FileTemplate.Template := '';
Add(FileTemplate);
end;
procedure TFileTemplates.AddPlainTextTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(STextFileTemplateName);
FileTemplate.Extension := 'txt';
FileTemplate.Category := _(SFileTemplateCategoryOther);
FileTemplate.Highlighter := '';
FileTemplate.Template := '';
Add(FileTemplate);
end;
procedure TFileTemplates.AddPythonTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SPythonTemplateName);
FileTemplate.Extension := 'py';
FileTemplate.Category := 'Python';
FileTemplate.Highlighter := 'Python';
FileTemplate.Template := _(SPythonFileTemplate);
Add(FileTemplate);
end;
procedure TFileTemplates.AddXMLTemplate;
Var
FileTemplate : TFileTemplate;
begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Name := _(SXMLTemplateName);
FileTemplate.Extension := 'xml';
FileTemplate.Category := _(SFileTemplateCategoryInternet);
FileTemplate.Highlighter := 'XML';
FileTemplate.Template := SXMLFileTemplate;
Add(FileTemplate);
end;
procedure TFileTemplates.Assign(Source: TFileTemplates);
var
i : Integer;
FileTemplate: TFileTemplate;
begin
Clear;
for i := 0 to Source.Count - 1 do begin
FileTemplate := TFileTemplate.Create;
FileTemplate.Assign(Source[i] as TFileTemplate);
Add(FileTemplate)
end;
end;
function TFileTemplates.CreateListItem(Sender: TJvCustomAppStorage;
const Path: string; Index: Integer): TPersistent;
begin
Result := TFileTemplate.Create;
end;
function TFileTemplates.TemplateByName(const Name: string): TFileTemplate;
var
i: Integer;
begin
Result := nil;
for i := 0 to Count - 1 do
if TFileTemplate(Items[i]).Name = Name then begin
Result := TFileTemplate(Items[i]);
break;
end;
end;
initialization
FileTemplates := TFileTemplates.Create(True);
with FileTemplates do begin
AddPythonTemplate;
AddCythonTemplate;
AddHTMLTemplate;
AddXMLTemplate;
AddCSSTemplate;
AddJSTemplate;
AddPHPTemplate;
AddPlainTextTemplate;
end
finalization
FileTemplates.Free;
end.