source: trunk/Packages/CoolWeb/LazIDEReg.pas

Last change on this file was 151, checked in by chronos, 5 months ago
File size: 3.8 KB
Line 
1unit LazIDEReg;
2
3interface
4
5uses
6 Classes, SysUtils, LazIDEIntf, ProjectIntf, FormEditingIntf, WebPage, Forms,
7 Controls;
8
9type
10 { TFileDescWebPage }
11
12 TFileDescWebPage = class(TFileDescPascalUnitWithResource)
13 public
14 constructor Create; override;
15 function GetInterfaceUsesSection: string; override;
16 function GetLocalizedName: string; override;
17 function GetLocalizedDescription: string; override;
18 end;
19
20 TCGIApplicationDescriptor = class(TProjectDescriptor)
21 public
22 constructor Create; override;
23 function GetLocalizedName: string; override;
24 function GetLocalizedDescription: string; override;
25 function InitProject(AProject: TLazProject): TModalResult; override;
26 function CreateStartFiles(AProject: TLazProject): TModalResult; override;
27 end;
28
29resourcestring
30 SWebPageTitle = 'CoolWeb page';
31 SWebPageDescription = '';
32 SCGIAppTitle = 'CoolWeb application';
33 SCGIAppDescription = '';
34
35var
36 FileDescriptorWebPage: TFileDescWebPage;
37 CGIAppDescriptor: TCGIApplicationDescriptor;
38
39procedure Register;
40
41
42implementation
43
44procedure Register;
45begin
46 FileDescriptorWebPage := TFileDescWebPage.Create;
47 RegisterProjectFileDescriptor(FileDescriptorWebPage);
48 CGIAppDescriptor := TCGIApplicationDescriptor.Create;
49 RegisterProjectDescriptor(CGIAppDescriptor);
50 FormEditingHook.RegisterDesignerBaseClass(TWebPage);
51end;
52
53{ TFileDescWebPage }
54
55constructor TFileDescWebPage.Create;
56begin
57 inherited Create;
58 Name := 'CoolWeb page';
59 ResourceClass := TWebPage;
60 UseCreateFormStatements := False;
61end;
62
63function TFileDescWebPage.GetInterfaceUsesSection: string;
64begin
65 Result := inherited GetInterfaceUsesSection;
66 Result := Result + ', UWebPage, UHTTPServer';
67end;
68
69function TFileDescWebPage.GetLocalizedName: string;
70begin
71 Result := SWebPageTitle;
72end;
73
74function TFileDescWebPage.GetLocalizedDescription: string;
75begin
76 Result := SWebPageDescription;
77end;
78
79
80{ TCGIApplicationDescriptor }
81
82constructor TCGIApplicationDescriptor.Create;
83begin
84 inherited Create;
85 Name := 'CoolWeb CGI Application';
86end;
87
88function TCGIApplicationDescriptor.GetLocalizedName: string;
89begin
90 Result := SCGIAppTitle;
91end;
92
93function TCGIApplicationDescriptor.GetLocalizedDescription: string;
94begin
95 Result := SCGIAppDescription;
96end;
97
98function TCGIApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;
99var
100 NewSource: TStringList;
101 MainFile: TLazProjectFile;
102begin
103 inherited InitProject(AProject);
104
105 MainFile := AProject.CreateProjectFile('cgiapp1.lpr');
106 MainFile.IsPartOfProject := True;
107 AProject.AddFile(MainFile, False);
108 AProject.MainFileID := 0;
109
110 // Create program source
111 try
112 NewSource := TStringList.Create;
113 with NewSource do begin
114 Add('program CGIApp1;');
115 Add('');
116 Add('{$mode objfpc}{$H+}');
117 Add('');
118 Add('uses');
119 Add(' Interfaces, Forms, UWebApp, UWebPage;');
120 Add('');
121 Add('var');
122 Add(' Application: TWebApp;');
123 Add('begin');
124 Add(' Application := TWebApp.Create(nil);');
125 Add(' with Application do');
126 Add(' try');
127 Add(' Initialize;');
128 Add(' RegisterPage(TWebPage1, WebPage1, '''');');
129 Add(' Run;');
130 Add(' finally');
131 Add(' Free;');
132 Add(' end;');
133 Add('end.');
134 Add('');
135 end;
136 AProject.MainFile.SetSourceText(NewSource.Text);
137 finally
138 NewSource.Free;
139 end;
140
141 // add
142 AProject.AddPackageDependency('FCL');
143 AProject.AddPackageDependency('LCL');
144 AProject.AddPackageDependency('CoolWeb');
145
146 // compiler options
147 AProject.LazCompilerOptions.UseLineInfoUnit := True;
148 Result := mrOK;
149end;
150
151function TCGIApplicationDescriptor.CreateStartFiles(AProject: TLazProject): TModalResult;
152begin
153 LazarusIDE.DoNewEditorFile(FileDescriptorWebPage, '', '',
154 [nfIsPartOfProject, nfOpenInEditor, nfCreateDefaultSrc]);
155 Result := mrOK;
156end;
157
158end.
159
Note: See TracBrowser for help on using the repository browser.