| 1 | unit LazIDEReg;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, LazIDEIntf, ProjectIntf, FormEditingIntf, WebPage, Forms,
|
|---|
| 7 | Controls;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 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 |
|
|---|
| 29 | resourcestring
|
|---|
| 30 | SWebPageTitle = 'CoolWeb page';
|
|---|
| 31 | SWebPageDescription = '';
|
|---|
| 32 | SCGIAppTitle = 'CoolWeb application';
|
|---|
| 33 | SCGIAppDescription = '';
|
|---|
| 34 |
|
|---|
| 35 | var
|
|---|
| 36 | FileDescriptorWebPage: TFileDescWebPage;
|
|---|
| 37 | CGIAppDescriptor: TCGIApplicationDescriptor;
|
|---|
| 38 |
|
|---|
| 39 | procedure Register;
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | implementation
|
|---|
| 43 |
|
|---|
| 44 | procedure Register;
|
|---|
| 45 | begin
|
|---|
| 46 | FileDescriptorWebPage := TFileDescWebPage.Create;
|
|---|
| 47 | RegisterProjectFileDescriptor(FileDescriptorWebPage);
|
|---|
| 48 | CGIAppDescriptor := TCGIApplicationDescriptor.Create;
|
|---|
| 49 | RegisterProjectDescriptor(CGIAppDescriptor);
|
|---|
| 50 | FormEditingHook.RegisterDesignerBaseClass(TWebPage);
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | { TFileDescWebPage }
|
|---|
| 54 |
|
|---|
| 55 | constructor TFileDescWebPage.Create;
|
|---|
| 56 | begin
|
|---|
| 57 | inherited Create;
|
|---|
| 58 | Name := 'CoolWeb page';
|
|---|
| 59 | ResourceClass := TWebPage;
|
|---|
| 60 | UseCreateFormStatements := False;
|
|---|
| 61 | end;
|
|---|
| 62 |
|
|---|
| 63 | function TFileDescWebPage.GetInterfaceUsesSection: string;
|
|---|
| 64 | begin
|
|---|
| 65 | Result := inherited GetInterfaceUsesSection;
|
|---|
| 66 | Result := Result + ', UWebPage, UHTTPServer';
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 | function TFileDescWebPage.GetLocalizedName: string;
|
|---|
| 70 | begin
|
|---|
| 71 | Result := SWebPageTitle;
|
|---|
| 72 | end;
|
|---|
| 73 |
|
|---|
| 74 | function TFileDescWebPage.GetLocalizedDescription: string;
|
|---|
| 75 | begin
|
|---|
| 76 | Result := SWebPageDescription;
|
|---|
| 77 | end;
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | { TCGIApplicationDescriptor }
|
|---|
| 81 |
|
|---|
| 82 | constructor TCGIApplicationDescriptor.Create;
|
|---|
| 83 | begin
|
|---|
| 84 | inherited Create;
|
|---|
| 85 | Name := 'CoolWeb CGI Application';
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | function TCGIApplicationDescriptor.GetLocalizedName: string;
|
|---|
| 89 | begin
|
|---|
| 90 | Result := SCGIAppTitle;
|
|---|
| 91 | end;
|
|---|
| 92 |
|
|---|
| 93 | function TCGIApplicationDescriptor.GetLocalizedDescription: string;
|
|---|
| 94 | begin
|
|---|
| 95 | Result := SCGIAppDescription;
|
|---|
| 96 | end;
|
|---|
| 97 |
|
|---|
| 98 | function TCGIApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;
|
|---|
| 99 | var
|
|---|
| 100 | NewSource: TStringList;
|
|---|
| 101 | MainFile: TLazProjectFile;
|
|---|
| 102 | begin
|
|---|
| 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;
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | function TCGIApplicationDescriptor.CreateStartFiles(AProject: TLazProject): TModalResult;
|
|---|
| 152 | begin
|
|---|
| 153 | LazarusIDE.DoNewEditorFile(FileDescriptorWebPage, '', '',
|
|---|
| 154 | [nfIsPartOfProject, nfOpenInEditor, nfCreateDefaultSrc]);
|
|---|
| 155 | Result := mrOK;
|
|---|
| 156 | end;
|
|---|
| 157 |
|
|---|
| 158 | end.
|
|---|
| 159 |
|
|---|