| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- (* _ _
- * | |__ _ __ ___ ___ | | __
- * | '_ \| '__/ _ \ / _ \| |/ /
- * | |_) | | | (_) | (_) | <
- * |_.__/|_| \___/ \___/|_|\_\
- *
- * Microframework which helps to develop web Pascal applications.
- *
- * Copyright (c) 2012-2021 Silvio Clecio <[email protected]>
- *
- * Brook framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * Brook framework is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Brook framework; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *)
- { Integrates Brook to Delphi or Lazarus IDE. }
- unit BrookIDEIntegration;
- {$I BrookDefines.inc}
- {$IFDEF FPC}
- {$WARN 5024 OFF}
- {$ENDIF}
- interface
- uses
- SysUtils,
- Classes,
- TypInfo,
- Dialogs,
- {$IFDEF LCL}
- PropEdits,
- ComponentEditors,
- {$ELSE}
- DesignIntf,
- DesignEditors,
- ColnEdit,
- {$ENDIF}
- libsagui,
- BrookUtility;
- resourcestring
- SBrookSelectLibraryTitle = 'Select library ...';
- SBrookSharedLibraryFilter = 'Shared libraries (%s)|%s|All files (*.*)|*.*';
- SBrookURLEntryPointsEditor = 'URL entry-points editor ...';
- SBrookURLRoutesEditor = 'URL routes editor ...';
- type
- { TBrookLibraryNamePropertyEditor }
- TBrookLibraryNamePropertyEditor = class(
- {$IFDEF LCL}TFileNamePropertyEditor{$ELSE}TStringProperty{$ENDIF})
- public
- {$IFDEF LCL}
- function GetVerbCount: Integer; override;
- function GetVerb(AIndex: Integer): string; override;
- procedure ExecuteVerb(AIndex: Integer); override;
- {$ENDIF}
- function GetFilter: string;{$IFDEF LCL}override{$ELSE}virtual{$ENDIF};
- function GetDialogTitle: string;{$IFDEF LCL}override{$ELSE}virtual{$ENDIF};
- {$IFNDEF LCL}
- function CreateFileDialog: TOpenDialog; virtual;
- procedure Edit; override;
- function GetAttributes: TPropertyAttributes; override;
- function GetDialogOptions: TOpenOptions; virtual;
- function GetInitialDirectory: string; virtual;
- procedure SetFileName(const AFileName: string); virtual;
- {$ENDIF}
- end;
- { TBrookHTTPRequestMethodsPropertyEditor }
- TBrookHTTPRequestMethodsPropertyEditor = class(TSetProperty)
- public
- procedure GetProperties(AProc:
- {$IFDEF LCL}TGetPropEditProc{$ELSE}TGetPropProc{$ENDIF}); override;
- end;
- { TBrookLibraryNameComponentEditor }
- TBrookLibraryNameComponentEditor = class(TDefaultEditor)
- public
- procedure Edit; override;
- function GetVerb(AIndex: Integer): string; override;
- {$IFNDEF LCL}
- function GetVerbCount: Integer; override;
- {$ENDIF}
- procedure ExecuteVerb(AIndex: Integer); override;
- end;
- { TBrookOnMathExtensionComponentEditor }
- TBrookOnMathExtensionComponentEditor = class(TDefaultEditor)
- protected
- procedure EditProperty(const AProperty:
- {$IFDEF LCL}TPropertyEditor{$ELSE}IProperty{$ENDIF};
- var AContinue: Boolean); override;
- end;
- { TBrookOnHTTPRequestComponentEditor }
- TBrookOnHTTPRequestComponentEditor = class(TDefaultEditor)
- protected
- procedure EditProperty(const AProperty:
- {$IFDEF LCL}TPropertyEditor{$ELSE}IProperty{$ENDIF};
- var AContinue: Boolean); override;
- end;
- { TBrookURLRouterComponentEditor }
- TBrookURLRouterComponentEditor = class(TComponentEditor)
- public
- procedure ExecuteVerb(AIndex: Integer); override;
- function GetVerb(AIndex: Integer): string; override;
- function GetVerbCount: Integer; override;
- end;
- { TBrookURLEntryPointsComponentEditor }
- TBrookURLEntryPointsComponentEditor = class(TComponentEditor)
- public
- procedure ExecuteVerb(AIndex: Integer); override;
- function GetVerb(AIndex: Integer): string; override;
- function GetVerbCount: Integer; override;
- end;
- {$R BrookTardigradeIcons.res}
- procedure Register;
- implementation
- uses
- BrookLibraryLoader,
- BrookLogger,
- BrookMathExpression,
- BrookMediaTypes,
- BrookURLEntryPoints,
- BrookURLRouter,
- BrookHTTPServer;
- {$IFNDEF LCL}
- type
- TLocalSetElementProperty = class(TSetElementProperty)
- public
- constructor Create(AParent: TPropertyEditor; AElement: Integer); reintroduce;
- end;
- constructor TLocalSetElementProperty.Create(AParent: TPropertyEditor;
- AElement: Integer);
- begin
- inherited Create(AParent, AElement);
- end;
- function BrookHTTPRequestMethodsPropertyMapper(AObj: TPersistent;
- APropInfo: PPropInfo): TPropertyEditorClass;
- begin
- if Assigned(AObj) and (AObj is TBrookURLRoute) and
- SameText(APropInfo.NameFld.ToString, 'Methods') then
- Exit(TBrookHTTPRequestMethodsPropertyEditor);
- Result := nil;
- end;
- {$ENDIF}
- procedure Register;
- begin
- RegisterComponents('Brook', [
- TBrookLibraryLoader,
- TBrookLogger,
- TBrookMathExpression,
- TBrookMIME,
- TBrookURLEntryPoints,
- TBrookURLRouter,
- TBrookHTTPServer
- ]);
- RegisterPropertyEditor(TypeInfo(TFileName), TBrookLibraryLoader,
- 'LibraryName', TBrookLibraryNamePropertyEditor);
- {$IFDEF LCL}
- RegisterPropertyEditor(TypeInfo(TFileName), TBrookMIME,
- 'FileName', TFileNamePropertyEditor);
- RegisterPropertyEditor(TypeInfo(string), TBrookHTTPServerSecurity,
- 'PrivatePassword', TPasswordStringPropertyEditor);
- RegisterPropertyEditor(TypeInfo(TBrookHTTPRequestMethods), nil, '',
- TBrookHTTPRequestMethodsPropertyEditor);
- RegisterPropertyEditor(TypeInfo(string), TBrookHTTPServer, 'UploadsDir',
- TDirectoryPropertyEditor);
- {$ELSE}
- RegisterPropertyMapper(BrookHTTPRequestMethodsPropertyMapper);
- {$ENDIF}
- RegisterComponentEditor(TBrookLibraryLoader, TBrookLibraryNameComponentEditor);
- RegisterComponentEditor(TBrookMathExpression, TBrookOnMathExtensionComponentEditor);
- RegisterComponentEditor(TBrookURLEntryPoints, TBrookURLEntryPointsComponentEditor);
- RegisterComponentEditor(TBrookURLRouter, TBrookURLRouterComponentEditor);
- RegisterComponentEditor(TBrookHTTPServer, TBrookOnHTTPRequestComponentEditor);
- end;
- {$IFDEF LCL}
- { TBrookLibraryNamePropertyEditor }
- function TBrookLibraryNamePropertyEditor.GetVerbCount: Integer;
- begin
- Result := 1;
- end;
- function TBrookLibraryNamePropertyEditor.GetVerb(AIndex: Integer): string;
- begin
- Result := SBrookSelectLibraryTitle;
- end;
- procedure TBrookLibraryNamePropertyEditor.ExecuteVerb(AIndex: Integer);
- begin
- Edit;
- end;
- {$ENDIF}
- function TBrookLibraryNamePropertyEditor.GetFilter: string;
- var
- VSharedSuffix: string;
- begin
- VSharedSuffix := Concat('*.', SharedSuffix);
- Result := Format(SBrookSharedLibraryFilter, [VSharedSuffix,
- {$IFDEF LINUX}Concat({$ENDIF}VSharedSuffix
- {$IFDEF LINUX}, ';', VSharedSuffix, '.*'){$ENDIF}]);
- end;
- function TBrookLibraryNamePropertyEditor.GetDialogTitle: string;
- begin
- Result := SBrookSelectLibraryTitle;
- end;
- {$IFNDEF LCL}
- function TBrookLibraryNamePropertyEditor.CreateFileDialog: TOpenDialog;
- begin
- Result := TOpenDialog.Create(nil);
- end;
- procedure TBrookLibraryNamePropertyEditor.Edit;
- begin
- with CreateFileDialog do
- try
- Filter := GetFilter;
- Options := GetDialogOptions;
- FileName := GetStrValue;
- InitialDir := GetInitialDirectory;
- Title := GetDialogTitle;
- if Execute then
- SetFileName(FileName);
- finally
- Free;
- end;
- end;
- function TBrookLibraryNamePropertyEditor.GetAttributes: TPropertyAttributes;
- begin
- Result := [paDialog, paRevertable];
- end;
- function TBrookLibraryNamePropertyEditor.GetDialogOptions: TOpenOptions;
- begin
- Result := [ofEnableSizing];
- end;
- function TBrookLibraryNamePropertyEditor.GetInitialDirectory: string;
- begin
- Result := '';
- end;
- procedure TBrookLibraryNamePropertyEditor.SetFileName(
- const AFileName: string);
- begin
- SetStrValue(AFileName);
- end;
- {$ENDIF}
- { TBrookHTTPRequestMethodsPropertyEditor }
- procedure TBrookHTTPRequestMethodsPropertyEditor.GetProperties(
- AProc:{$IFDEF LCL}TGetPropEditProc{$ELSE}TGetPropProc{$ENDIF});
- var
- M: TBrookHTTPRequestMethod;
- {$IFNDEF LCL}
- P: IProperty;
- {$ENDIF}
- begin
- for M := Succ(Low(TBrookHTTPRequestMethod)) to High(TBrookHTTPRequestMethod) do
- {$IFDEF LCL}
- AProc(TSetElementProperty.Create(Self, Ord(M)));
- {$ELSE}
- begin
- P := TLocalSetElementProperty.Create(Self, Ord(M));
- AProc(P);
- P := nil;
- end;
- {$ENDIF}
- end;
- { TBrookLibraryNameComponentEditor }
- procedure TBrookLibraryNameComponentEditor.Edit;
- var
- VDialog: TOpenDialog;
- VLibraryLoader: TBrookLibraryLoader;
- VPropertyEditor: TBrookLibraryNamePropertyEditor;
- begin
- VLibraryLoader := Component as TBrookLibraryLoader;
- if not Assigned(VLibraryLoader) then
- Exit;
- VPropertyEditor := TBrookLibraryNamePropertyEditor.Create(nil, 0);
- VDialog := VPropertyEditor.CreateFileDialog;
- try
- VDialog.Filter := VPropertyEditor.GetFilter;
- VDialog.Options := VPropertyEditor.GetDialogOptions;
- VDialog.InitialDir := VPropertyEditor.GetInitialDirectory;
- VDialog.Title := VPropertyEditor.GetDialogTitle;
- VDialog.FileName := VLibraryLoader.LibraryName;
- if VDialog.Execute then
- begin
- VLibraryLoader.LibraryName := VDialog.FileName;
- Designer.Modified;
- end;
- finally
- VPropertyEditor.Free;
- end;
- end;
- function TBrookLibraryNameComponentEditor.GetVerb(
- AIndex: Integer): string;
- begin
- Result := SBrookSelectLibraryTitle;
- end;
- {$IFNDEF LCL}
- function TBrookLibraryNameComponentEditor.GetVerbCount: Integer;
- begin
- Result := 1;
- end;
- {$ENDIF}
- procedure TBrookLibraryNameComponentEditor.ExecuteVerb(AIndex: Integer);
- begin
- Edit;
- end;
- { TBrookOnMathExtensionComponentEditor }
- procedure TBrookOnMathExtensionComponentEditor.EditProperty(const AProperty:
- {$IFDEF LCL}TPropertyEditor{$ELSE}IProperty{$ENDIF}; var AContinue: Boolean);
- begin
- if SameText(AProperty.GetName, 'OnExtension') then
- inherited EditProperty(AProperty, AContinue);
- end;
- { TBrookOnHTTPRequestComponentEditor }
- procedure TBrookOnHTTPRequestComponentEditor.EditProperty(const AProperty:
- {$IFDEF LCL}TPropertyEditor{$ELSE}IProperty{$ENDIF}; var AContinue: Boolean);
- begin
- if SameText(AProperty.GetName, 'OnRequest') then
- inherited EditProperty(AProperty, AContinue);
- end;
- { TBrookURLRouterComponentEditor }
- procedure TBrookURLRouterComponentEditor.ExecuteVerb(AIndex: Integer);
- var
- VRouter: TBrookURLRouter;
- begin
- VRouter := GetComponent as TBrookURLRouter;
- {$IFDEF LCL}
- EditCollection(
- {$ELSE}
- ShowCollectionEditor(Designer,
- {$ENDIF}
- VRouter, VRouter.Routes, 'Routes');
- end;
- function TBrookURLRouterComponentEditor.GetVerb(AIndex: Integer): string;
- begin
- Result := SBrookURLRoutesEditor;
- end;
- function TBrookURLRouterComponentEditor.GetVerbCount: Integer;
- begin
- Result := 1;
- end;
- { TBrookURLEntryPointsComponentEditor }
- procedure TBrookURLEntryPointsComponentEditor.ExecuteVerb(AIndex: Integer);
- var
- VEntryPoints: TBrookURLEntryPoints;
- begin
- VEntryPoints := GetComponent as TBrookURLEntryPoints;
- {$IFDEF LCL}
- EditCollection(
- {$ELSE}
- ShowCollectionEditor(Designer,
- {$ENDIF}
- VEntryPoints, VEntryPoints.List, 'List');
- end;
- function TBrookURLEntryPointsComponentEditor.GetVerb(AIndex: Integer): string;
- begin
- Result := SBrookURLEntryPointsEditor;
- end;
- function TBrookURLEntryPointsComponentEditor.GetVerbCount: Integer;
- begin
- Result := 1;
- end;
- end.
|