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