source: trunk/StudioModules/LDModulePascal/ULDModulePascal.pas

Last change on this file was 18, checked in by chronos, 12 years ago
  • Used external packages are now stored in uncompressed form rather in zipped files. This allow better package version synchronisation.
File size: 5.2 KB
Line 
1unit ULDModulePascal;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, UModularSystem, USource, UProject;
9
10type
11 { TProjectTemplateConsoleApp }
12
13 TProjectTemplateConsoleApp = class(TFileTemplate)
14 constructor Create; override;
15 function Execute: TSource; override;
16 end;
17
18 { TProjectTemplateGUIApp }
19
20 TProjectTemplateGUIApp = class(TFileTemplate)
21 constructor Create; override;
22 function Execute: TSource; override;
23 end;
24
25 { TProjectTemplatePackage }
26
27 TProjectTemplatePackage = class(TFileTemplate)
28 constructor Create; override;
29 function Execute: TSource; override;
30 end;
31
32 { TProjectTemplateUnit }
33
34 TProjectTemplateUnit = class(TFileTemplate)
35 constructor Create; override;
36 function Execute: TSource; override;
37 end;
38
39 { TPascalSourceType }
40
41 TPascalSourceType = class(TSourceType)
42 constructor Create; override;
43 end;
44
45 { TLDModulePascal }
46
47 TLDModulePascal = class(TModule)
48 private
49 PasFileType: TPascalSourceType;
50 ProjectTemplateConsoleApp: TProjectTemplateConsoleApp;
51 ProjectTemplateGUIApp: TProjectTemplateGUIApp;
52 ProjectTemplateUnit: TProjectTemplateUnit;
53 public
54 constructor Create(Owner: TComponent); override;
55 procedure Install; override;
56 procedure Uninstall; override;
57 end;
58
59
60implementation
61
62uses
63 ULDStudioAPI, ULDModuleBasic;
64
65resourcestring
66 SPascal = 'Pascal';
67
68{ TPascalSourceType }
69
70constructor TPascalSourceType.Create;
71begin
72 inherited Create;
73 Extension := '.pas';
74 Title := 'Pascal source';
75end;
76
77{ TLDModulePascal }
78
79constructor TLDModulePascal.Create(Owner: TComponent);
80begin
81 inherited;
82 Identification := 'Pascal';
83 Title := SPascal;
84 Version := '0.1';
85 License := 'GNU/LGPLv3';
86end;
87
88procedure TLDModulePascal.Install;
89begin
90 with TLDStudioAPI(API) do begin
91 PasFileType := TPascalSourceType.Create;
92 RegisterFileType(PasFileType);
93 ProjectTemplateConsoleApp := TProjectTemplateConsoleApp.Create;
94 RegisterFileTemplate(ProjectTemplateConsoleApp);
95 ProjectTemplateGUIApp := TProjectTemplateGUIApp.Create;
96 RegisterFileTemplate(ProjectTemplateGUIApp);
97 ProjectTemplateUnit := TProjectTemplateUnit.Create;
98 RegisterFileTemplate(ProjectTemplateUnit);
99 end;
100 inherited Install;
101end;
102
103procedure TLDModulePascal.Uninstall;
104begin
105 inherited Uninstall;
106 with TLDStudioAPI(API) do begin
107 RegisterFileTemplate(ProjectTemplateUnit);
108 FreeAndNil(ProjectTemplateUnit);
109 UnregisterFileTemplate(ProjectTemplateGUIApp);
110 FreeAndNil(ProjectTemplateGUIApp);
111 UnregisterFileTemplate(ProjectTemplateConsoleApp);
112 FreeAndNil(ProjectTemplateConsoleApp);
113 UnregisterFileType(PasFileType);
114 FreeAndNil(PasFileType);
115 end;
116end;
117
118resourcestring
119 SConsoleApplication = 'Console application';
120 SUnit = 'Unit';
121 SPackage = 'Package';
122 SGUIApplication = 'GUI application';
123
124{ TProjectTemplateUnit }
125
126constructor TProjectTemplateUnit.Create;
127begin
128 inherited Create;
129 Name := SUnit;
130 //FileTypeClass := TSourceText;
131end;
132
133function TProjectTemplateUnit.Execute: TSource;
134var
135 NewFile: TSource;
136begin
137 //inherited InitProject(Project);
138 Result := TSourceText.Create;
139 Result.Name := 'Unit1.pas';
140 with TSourceText(Result), Content do begin
141 Add('unit Unit1;');
142 Add('');
143 Add('interface');
144 Add('');
145 Add('implementation');
146 Add('');
147 Add('end.');
148 Loaded := True;
149 end;
150end;
151
152{ TProjectTemplatePackage }
153
154constructor TProjectTemplatePackage.Create;
155begin
156 inherited Create;
157 Name := SPackage;
158end;
159
160function TProjectTemplatePackage.Execute: TSource;
161var
162 NewFile: TSourceText;
163begin
164{ Result := TProject.Create;
165 Result.Name := 'Package1';
166 NewFile := TSourceText.Create;
167 NewFile.Name := 'Package1.bpl';
168 with NewFile.Content do begin
169 Add('package Package1;');
170 Add('');
171 Add('requires');
172 Add(' RTL;');
173 Add('');
174 Add('end.');
175 end;
176 TProject(Result).Files.Add();
177 TProject(Result).MainSource := NewFile;
178}end;
179
180{ TProjectTemplateGUIApp }
181
182constructor TProjectTemplateGUIApp.Create;
183begin
184 inherited Create;
185 Name := SGUIApplication;
186end;
187
188function TProjectTemplateGUIApp.Execute: TSource;
189var
190 NewFile: TProjectFile;
191begin
192{ inherited InitProject(Project);
193 NewFile := Project.Files.AddFile('Project1.dpr');
194 with NewFile.Source do begin
195 Add('program Project1;');
196 Add('');
197 Add('uses');
198 Add(' GUI;');
199 Add('');
200 Add('var');
201 Add(' Application: TApplication');
202 Add('begin');
203 Add(' Application := TApplication.Create;');
204 Add(' Application.Run;');
205 Add(' Application.Free;');
206 Add('end.');
207 end;
208 Project.MainSource := NewFile;
209}end;
210
211{ TProjectTemplateConsoleApp }
212
213constructor TProjectTemplateConsoleApp.Create;
214begin
215 inherited Create;
216 Name := SConsoleApplication;
217end;
218
219function TProjectTemplateConsoleApp.Execute: TSource;
220var
221 NewFile: TProjectFile;
222begin
223{ inherited InitProject(Project);
224 NewFile := Project.Files.AddFile('Project1.dpr');
225 with NewFile.Source do begin
226 Add('program Project1;');
227 Add('');
228 Add('begin');
229 Add('end.');
230 end;
231 Project.MainSource := NewFile;}
232end;
233
234
235end.
236
Note: See TracBrowser for help on using the repository browser.