From 68743b90f0155e4e6891c7717d584a9ecae204b5 Mon Sep 17 00:00:00 2001 From: danieleteti Date: Wed, 24 Feb 2016 22:37:13 +0100 Subject: [PATCH] Added the following parameters and features to the IDEExpert: ActionFiltersMethods ConfigurationBlock ServerPort Minor Fixes --- .../DMVC.Expert.CodeGen.NewControllerUnit.pas | 121 ++++--- .../DMVC.Expert.CodeGen.NewDMVCProject.pas | 74 +++-- ideexpert/DMVC.Expert.CodeGen.Templates.pas | 298 ++++++++++-------- .../DMVC.Expert.Forms.NewProjectWizard.dfm | 68 ++-- .../DMVC.Expert.Forms.NewProjectWizard.pas | 39 ++- ideexpert/DMVC.Expert.Forms.NewUnitWizard.dfm | 31 +- ideexpert/DMVC.Expert.Forms.NewUnitWizard.pas | 8 + ideexpert/DMVC.Expert.NewUnitWizardEx.pas | 5 +- ideexpert/DMVC.Expert.ProjectWizardEx.pas | 11 +- 9 files changed, 406 insertions(+), 249 deletions(-) diff --git a/ideexpert/DMVC.Expert.CodeGen.NewControllerUnit.pas b/ideexpert/DMVC.Expert.CodeGen.NewControllerUnit.pas index 77c689cd..b5adc696 100644 --- a/ideexpert/DMVC.Expert.CodeGen.NewControllerUnit.pas +++ b/ideexpert/DMVC.Expert.CodeGen.NewControllerUnit.pas @@ -1,32 +1,32 @@ -{***************************************************************************} -{ } -{ Delphi MVC Framework } -{ } -{ Copyright (c) 2010-2015 Daniele Teti and the DMVCFramework Team } -{ } -{ https://github.com/danieleteti/delphimvcframework } -{ } -{***************************************************************************} -{ } -{ Licensed under the Apache License, Version 2.0 (the "License"); } -{ you may not use this file except in compliance with the License. } -{ You may obtain a copy of the License at } -{ } -{ http://www.apache.org/licenses/LICENSE-2.0 } -{ } -{ Unless required by applicable law or agreed to in writing, software } -{ distributed under the License is distributed on an "AS IS" BASIS, } -{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. } -{ See the License for the specific language governing permissions and } -{ limitations under the License. } -{ } -{ This IDE expert is based off of the one included with the DUnitX } -{ project. Original source by Robert Love. Adapted by Nick Hodges. } -{ } -{ The DUnitX project is run by Vincent Parrett and can be found at: } -{ } -{ https://github.com/VSoftTechnologies/DUnitX } -{***************************************************************************} +{ *************************************************************************** } +{ } +{ Delphi MVC Framework } +{ } +{ Copyright (c) 2010-2015 Daniele Teti and the DMVCFramework Team } +{ } +{ https://github.com/danieleteti/delphimvcframework } +{ } +{ *************************************************************************** } +{ } +{ Licensed under the Apache License, Version 2.0 (the "License"); } +{ you may not use this file except in compliance with the License. } +{ You may obtain a copy of the License at } +{ } +{ http://www.apache.org/licenses/LICENSE-2.0 } +{ } +{ Unless required by applicable law or agreed to in writing, software } +{ distributed under the License is distributed on an "AS IS" BASIS, } +{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. } +{ See the License for the specific language governing permissions and } +{ limitations under the License. } +{ } +{ This IDE expert is based off of the one included with the DUnitX } +{ project. Original source by Robert Love. Adapted by Nick Hodges. } +{ } +{ The DUnitX project is run by Vincent Parrett and can be found at: } +{ } +{ https://github.com/VSoftTechnologies/DUnitX } +{ *************************************************************************** } unit DMVC.Expert.CodeGen.NewControllerUnit; @@ -39,11 +39,15 @@ uses type TNewControllerUnitEx = class(TNewUnit) protected - FCreateIndexMethod : Boolean; - FControllerClassName : String; - function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile; override; + FCreateIndexMethod: Boolean; + FCreateActionFiltersMethods: Boolean; + FControllerClassName: String; + function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string) + : IOTAFile; override; public - constructor Create(const aCreateIndexMethod : boolean; const AControllerClassName: String; const APersonality : String = '' ); + constructor Create(const aCreateIndexMethod, aCreateActionFiltersMethods + : Boolean; const AControllerClassName: String; + const APersonality: String = ''); end; implementation @@ -54,8 +58,9 @@ uses DMVC.Expert.CodeGen.Templates, DMVC.Expert.CodeGen.SourceFile; - -constructor TNewControllerUnitEx.Create(const aCreateIndexMethod : boolean; const AControllerClassName : String; const APersonality : String = '' ); +constructor TNewControllerUnitEx.Create(const aCreateIndexMethod, + aCreateActionFiltersMethods: Boolean; const AControllerClassName: String; + const APersonality: String = ''); begin Assert(Length(AControllerClassName) > 0); FAncestorName := ''; @@ -64,10 +69,12 @@ begin FIntfFileName := ''; FControllerClassName := AControllerClassName; FCreateIndexMethod := aCreateIndexMethod; + FCreateActionFiltersMethods := aCreateActionFiltersMethods; Personality := APersonality; end; -function TNewControllerUnitEx.NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile; +function TNewControllerUnitEx.NewImplSource(const ModuleIdent, FormIdent, + AncestorIdent: string): IOTAFile; var lUnitIdent: string; lFormName: string; @@ -75,21 +82,35 @@ var lIndexMethodIntf: string; lIndexMethodImpl: string; lControllerUnit: string; - begin - lControllerUnit := sControllerUnit; - lIndexMethodIntf := sIndexMethodIntf; - lIndexMethodImpl := Format(sIndexMethodImpl,[FControllerClassName]); + lActionFiltersMethodsIntf: string; + lActionFiltersMethodsImpl: string; +begin + lControllerUnit := sControllerUnit; + lIndexMethodIntf := sIndexMethodIntf; + lIndexMethodImpl := Format(sIndexMethodImpl, [FControllerClassName]); - if not FCreateIndexMethod then - begin - lIndexMethodIntf := ''; - lIndexMethodImpl := ''; - end; - // http://stackoverflow.com/questions/4196412/how-do-you-retrieve-a-new-unit-name-from-delphis-open-tools-api - // So using method mentioned by Marco Cantu. - (BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName( '', lUnitIdent, lFormName, lFileName); - Result := TSourceFile.Create(sControllerUnit, [lUnitIdent, FControllerClassName, lIndexMethodIntf, lIndexMethodImpl]); + if not FCreateIndexMethod then + begin + lIndexMethodIntf := ''; + lIndexMethodImpl := ''; + end; + + lActionFiltersMethodsIntf := sActionFiltersIntf; + lActionFiltersMethodsImpl := Format(sActionFiltersImpl, + [FControllerClassName]); + + if not FCreateActionFiltersMethods then + begin + lActionFiltersMethodsIntf := ''; + lActionFiltersMethodsImpl := ''; + end; + + // http://stackoverflow.com/questions/4196412/how-do-you-retrieve-a-new-unit-name-from-delphis-open-tools-api + // So using method mentioned by Marco Cantu. + (BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName('', + lUnitIdent, lFormName, lFileName); + Result := TSourceFile.Create(sControllerUnit, + [lUnitIdent, FControllerClassName, lIndexMethodIntf, lIndexMethodImpl, lActionFiltersMethodsIntf, lActionFiltersMethodsImpl]); end; - end. diff --git a/ideexpert/DMVC.Expert.CodeGen.NewDMVCProject.pas b/ideexpert/DMVC.Expert.CodeGen.NewDMVCProject.pas index 16adc12a..674cfad7 100644 --- a/ideexpert/DMVC.Expert.CodeGen.NewDMVCProject.pas +++ b/ideexpert/DMVC.Expert.CodeGen.NewDMVCProject.pas @@ -1,32 +1,32 @@ -{***************************************************************************} -{ } -{ Delphi MVC Framework } -{ } -{ Copyright (c) 2010-2015 Daniele Teti and the DMVCFramework Team } -{ } -{ https://github.com/danieleteti/delphimvcframework } -{ } -{***************************************************************************} -{ } -{ Licensed under the Apache License, Version 2.0 (the "License"); } -{ you may not use this file except in compliance with the License. } -{ You may obtain a copy of the License at } -{ } -{ http://www.apache.org/licenses/LICENSE-2.0 } -{ } -{ Unless required by applicable law or agreed to in writing, software } -{ distributed under the License is distributed on an "AS IS" BASIS, } -{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. } -{ See the License for the specific language governing permissions and } -{ limitations under the License. } -{ } -{ This IDE expert is based off of the one included with the DUnitX } -{ project. Original source by Robert Love. Adapted by Nick Hodges. } -{ } -{ The DUnitX project is run by Vincent Parrett and can be found at: } -{ } -{ https://github.com/VSoftTechnologies/DUnitX } -{***************************************************************************} +{ *************************************************************************** } +{ } +{ Delphi MVC Framework } +{ } +{ Copyright (c) 2010-2015 Daniele Teti and the DMVCFramework Team } +{ } +{ https://github.com/danieleteti/delphimvcframework } +{ } +{ *************************************************************************** } +{ } +{ Licensed under the Apache License, Version 2.0 (the "License"); } +{ you may not use this file except in compliance with the License. } +{ You may obtain a copy of the License at } +{ } +{ http://www.apache.org/licenses/LICENSE-2.0 } +{ } +{ Unless required by applicable law or agreed to in writing, software } +{ distributed under the License is distributed on an "AS IS" BASIS, } +{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. } +{ See the License for the specific language governing permissions and } +{ limitations under the License. } +{ } +{ This IDE expert is based off of the one included with the DUnitX } +{ project. Original source by Robert Love. Adapted by Nick Hodges. } +{ } +{ The DUnitX project is run by Vincent Parrett and can be found at: } +{ } +{ https://github.com/VSoftTechnologies/DUnitX } +{ *************************************************************************** } unit DMVC.Expert.CodeGen.NewDMVCProject; @@ -38,12 +38,16 @@ uses type TDMVCProjectFile = class(TNewProjectEx) + private + FDefaultPort: Integer; + procedure SetDefaultPort(const Value: Integer); protected function NewProjectSource(const ProjectName: string): IOTAFile; override; function GetFrameworkType: string; override; public constructor Create; overload; constructor Create(const APersonality: string); overload; + property DefaultPort: Integer read FDefaultPort write SetDefaultPort; end; implementation @@ -55,9 +59,10 @@ uses constructor TDMVCProjectFile.Create; begin - //TODO: Figure out how to make this be DMVCProjectX where X is the next available. - //Return Blank and the project will be 'ProjectX.dpr' where X is the next available number + // TODO: Figure out how to make this be DMVCProjectX where X is the next available. + // Return Blank and the project will be 'ProjectX.dpr' where X is the next available number FFileName := ''; + FDefaultPort := 0; end; constructor TDMVCProjectFile.Create(const APersonality: string); @@ -73,7 +78,12 @@ end; function TDMVCProjectFile.NewProjectSource(const ProjectName: string): IOTAFile; begin - Result := TSourceFile.Create(sDMVCDPR, [ProjectName]); + Result := TSourceFile.Create(sDMVCDPR, [ProjectName, FDefaultPort]); +end; + +procedure TDMVCProjectFile.SetDefaultPort(const Value: Integer); +begin + FDefaultPort := Value; end; end. diff --git a/ideexpert/DMVC.Expert.CodeGen.Templates.pas b/ideexpert/DMVC.Expert.CodeGen.Templates.pas index b1c76678..713a3e19 100644 --- a/ideexpert/DMVC.Expert.CodeGen.Templates.pas +++ b/ideexpert/DMVC.Expert.CodeGen.Templates.pas @@ -35,104 +35,131 @@ interface resourcestring { Delphi template code } - - sDMVCDPR = 'program %0:s;'#13#10 + -#13#10 + -' {$APPTYPE CONSOLE}'#13#10 + -''#13#10 + -'uses'#13#10 + -' System.SysUtils,'#13#10 + -' Winapi.Windows,'#13#10 + -' Winapi.ShellAPI,'#13#10 + -' Web.WebReq,'#13#10 + -' Web.WebBroker,'#13#10 + -' IdHTTPWebBrokerBridge;'#13#10 + -''#13#10 + -'{$R *.res}'#13#10 + -#13#10 + -'procedure RunServer(APort: Integer);'#13#10 + -'var'#13#10 + -' LInputRecord: TInputRecord;'#13#10 + -' LEvent: DWord;'#13#10 + -' LHandle: THandle;'#13#10 + -' LServer: TIdHTTPWebBrokerBridge;'#13#10 + -'begin'#13#10 + -' Writeln(Format(''Starting HTTP Server or port %%d'', [APort]));'#13#10 + -' LServer := TIdHTTPWebBrokerBridge.Create(nil);'#13#10 + -' try'#13#10 + -' LServer.DefaultPort := APort;'#13#10 + -' LServer.Active := True;'#13#10 + -' ShellExecute(0, ''open'', pChar(''http://localhost:'' + inttostr(APort)), nil, nil, SW_SHOWMAXIMIZED);'#13#10 + -' Writeln(''Press ESC to stop the server'');'#13#10 + -' LHandle := GetStdHandle(STD_INPUT_HANDLE);'#13#10 + -' while True do'#13#10 + -' begin'#13#10 + -' Win32Check(ReadConsoleInput(LHandle, LInputRecord, 1, LEvent));'#13#10 + -' if (LInputRecord.EventType = KEY_EVENT) and'#13#10 + -' LInputRecord.Event.KeyEvent.bKeyDown and'#13#10 + -' (LInputRecord.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE) then'#13#10 + -' break;'#13#10 + -' end;'#13#10 + -' finally'#13#10 + -' LServer.Free;'#13#10 + -' end;'#13#10 + -'end;'#13#10 + -#13#10 + -'begin'#13#10 + -' ReportMemoryLeaksOnShutdown := True;'#13#10 + -' try'#13#10 + -' if WebRequestHandler <> nil then'#13#10 + -' WebRequestHandler.WebModuleClass := WebModuleClass;'#13#10 + -' WebRequestHandlerProc.MaxConnections := 1024;'#13#10 + -' RunServer(3000);'#13#10 + -' except'#13#10 + -' on E: Exception do'#13#10 + -' Writeln(E.ClassName, '': '', E.Message);'#13#10 + -' end;'#13#10 + -'end.'#13#10; +//0 - project name +//1 - http/s port + sDMVCDPR = 'program %0:s;' + sLineBreak + +sLineBreak + +' {$APPTYPE CONSOLE}' + sLineBreak + +'' + sLineBreak + +'uses' + sLineBreak + +' System.SysUtils,' + sLineBreak + +' Winapi.Windows,' + sLineBreak + +' Winapi.ShellAPI,' + sLineBreak + +' Web.WebReq,' + sLineBreak + +' Web.WebBroker,' + sLineBreak + +' IdHTTPWebBrokerBridge;' + sLineBreak + +'' + sLineBreak + +'{$R *.res}' + sLineBreak + +sLineBreak + +'procedure RunServer(APort: Integer);' + sLineBreak + +'var' + sLineBreak + +' LInputRecord: TInputRecord;' + sLineBreak + +' LEvent: DWord;' + sLineBreak + +' LHandle: THandle;' + sLineBreak + +' LServer: TIdHTTPWebBrokerBridge;' + sLineBreak + +'begin' + sLineBreak + +' Writeln(''** DMVCFramework Server **'');' + sLineBreak + +' Writeln(Format(''Starting HTTP Server or port %%d'', [APort]));' + sLineBreak + +' LServer := TIdHTTPWebBrokerBridge.Create(nil);' + sLineBreak + +' try' + sLineBreak + +' LServer.DefaultPort := APort;' + sLineBreak + +' LServer.Active := True;' + sLineBreak + +' ShellExecute(0, ''open'', pChar(''http://localhost:'' + inttostr(APort)), nil, nil, SW_SHOWMAXIMIZED);' + sLineBreak + +' Writeln(''Press ESC to stop the server'');' + sLineBreak + +' LHandle := GetStdHandle(STD_INPUT_HANDLE);' + sLineBreak + +' while True do' + sLineBreak + +' begin' + sLineBreak + +' Win32Check(ReadConsoleInput(LHandle, LInputRecord, 1, LEvent));' + sLineBreak + +' if (LInputRecord.EventType = KEY_EVENT) and' + sLineBreak + +' LInputRecord.Event.KeyEvent.bKeyDown and' + sLineBreak + +' (LInputRecord.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE) then' + sLineBreak + +' break;' + sLineBreak + +' end;' + sLineBreak + +' finally' + sLineBreak + +' LServer.Free;' + sLineBreak + +' end;' + sLineBreak + +'end;' + sLineBreak + +sLineBreak + +'begin' + sLineBreak + +' ReportMemoryLeaksOnShutdown := True;' + sLineBreak + +' try' + sLineBreak + +' if WebRequestHandler <> nil then' + sLineBreak + +' WebRequestHandler.WebModuleClass := WebModuleClass;' + sLineBreak + +' WebRequestHandlerProc.MaxConnections := 1024;' + sLineBreak + +' RunServer(%1:d);' + sLineBreak + +' except' + sLineBreak + +' on E: Exception do' + sLineBreak + +' Writeln(E.ClassName, '': '', E.Message);' + sLineBreak + +' end;' + sLineBreak + +'end.' + sLineBreak; // 0 - Unit Name // 1 - Class Name // 2 - Index Method - Interface // 3 - Index Method - Implementation - sControllerUnit = 'unit %0:s;'#13#10 + - #13#10 + - 'interface'#13#10 + - #13#10 + - 'uses'#13#10 + - ' MVCFramework;'#13#10 + - #13#10 + - 'type'#13#10 + - #13#10 + - ' [MVCPath(''/'')]'#13#10 + - ' %1:s = class(TMVCController) '#13#10 + - ' public'#13#10 + + // 4 - Action Filters - Interface + // 5 - Action Filters - Implementation + sControllerUnit = 'unit %0:s;' + sLineBreak + + sLineBreak + + 'interface' + sLineBreak + + sLineBreak + + 'uses' + sLineBreak + + ' MVCFramework;' + sLineBreak + + sLineBreak + + 'type' + sLineBreak + + sLineBreak + + ' [MVCPath(''/'')]' + sLineBreak + + ' %1:s = class(TMVCController) ' + sLineBreak + + ' public' + sLineBreak + '%2:s' + - ' end;'#13#10 + - #13#10 + - 'implementation'#13#10 + - #13#10 + - '%3:s'#13#10 + - #13#10 + - 'end.'#13#10; + '%4:s' + + ' end;' + sLineBreak + + sLineBreak + + 'implementation' + sLineBreak + + sLineBreak + + '%3:s' + sLineBreak + + '%5:s' + sLineBreak + + sLineBreak + + 'end.' + sLineBreak; sIndexMethodIntf = -' [MVCPath(''/'')]'#13#10 + -' [MVCHTTPMethod([httpGET])]'#13#10 + -' procedure Index(ctx: TWebContext);'#13#10; +' [MVCPath(''/'')]' + sLineBreak + +' [MVCHTTPMethod([httpGET])]' + sLineBreak + +' procedure Index(ctx: TWebContext);' + sLineBreak; // 0 - Class Name sIndexMethodImpl = - 'procedure %0:s.Index(ctx: TWebContext);'#13#10 + - 'begin'#13#10 + - ' Render(''Hello World'');'#13#10 + - #13#10 + + 'procedure %0:s.Index(ctx: TWebContext);' + sLineBreak + + 'begin' + sLineBreak + + ' Render(''Hello World'');' + sLineBreak + + sLineBreak + 'end;'; +sActionFiltersIntf = +' procedure OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean); override;' + sLineBreak + +' procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;' + sLineBreak; + +sActionFiltersImpl = +'procedure %0:s.OnAfterAction(Context: TWebContext; const AActionName: string); ' + sLineBreak + +'begin' + sLineBreak + +' { Executed after each action }' + sLineBreak + +' inherited;' + sLineBreak + +'end;' + sLineBreak + +sLineBreak + +'procedure %0:s.OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean);' + sLineBreak + +'begin' + sLineBreak + +' { Executed before each action' + sLineBreak + +' if handled is true (or an exception is raised) the actual' + sLineBreak + +' action will not be called }' + sLineBreak + +' inherited;' + sLineBreak + +'end;' + sLineBreak; + + sDefaultControllerName = 'TMyController'; sDefaultWebModuleName = 'TMyWebModule'; + sDefaultServerPort = '8080'; // 0 = unit name @@ -140,54 +167,73 @@ resourcestring // 2 = controller unit // 3 - controller class name sWebModuleUnit = -'unit %0:s;'#13#10 + -''#13#10 + -'interface'#13#10 + -#13#10 + -'uses System.SysUtils,'#13#10 + -' System.Classes,'#13#10 + -' Web.HTTPApp,'#13#10 + -' MVCFramework;'#13#10 + -#13#10 + -'type'#13#10 + -' %1:s = class(TWebModule)'#13#10 + -' procedure WebModuleCreate(Sender: TObject);'#13#10 + -' procedure WebModuleDestroy(Sender: TObject);'#13#10 + -' private'#13#10 + -' MVC: TMVCEngine;'#13#10 + -' public'#13#10 + -' { Public declarations }'#13#10 + -' end;'#13#10 + -#13#10 + -'var'#13#10 + -' WebModuleClass: TComponentClass = %1:s;'#13#10 + -#13#10 + -'implementation'#13#10 + -#13#10 + -'{$R *.dfm}'#13#10 + -#13#10 + -'uses %2:s;'#13#10 + -#13#10 + -'procedure %1:s.WebModuleCreate(Sender: TObject);'#13#10 + -'begin'#13#10 + -' MVC := TMVCEngine.Create(Self);'#13#10 + -' MVC.AddController(%3:s);'#13#10 + -'end;'#13#10 + -#13#10 + -'procedure %1:s.WebModuleDestroy(Sender: TObject);'#13#10 + -'begin'#13#10 + -' MVC.Free;'#13#10 + -'end;'#13#10 + -#13#10 + -'end.'#13#10; +'unit %0:s;' + sLineBreak + +'' + sLineBreak + +'interface' + sLineBreak + +sLineBreak + +'uses System.SysUtils,' + sLineBreak + +' System.Classes,' + sLineBreak + +' Web.HTTPApp,' + sLineBreak + +' MVCFramework;' + sLineBreak + +sLineBreak + +'type' + sLineBreak + +' %1:s = class(TWebModule)' + sLineBreak + +' procedure WebModuleCreate(Sender: TObject);' + sLineBreak + +' procedure WebModuleDestroy(Sender: TObject);' + sLineBreak + +' private' + sLineBreak + +' FMVC: TMVCEngine;' + sLineBreak + +' public' + sLineBreak + +' { Public declarations }' + sLineBreak + +' end;' + sLineBreak + +sLineBreak + +'var' + sLineBreak + +' WebModuleClass: TComponentClass = %1:s;' + sLineBreak + +sLineBreak + +'implementation' + sLineBreak + +sLineBreak + +'{$R *.dfm}' + sLineBreak + +sLineBreak + +'uses %2:s, MVCFramework.Commons;' + sLineBreak + +sLineBreak + +'procedure %1:s.WebModuleCreate(Sender: TObject);' + sLineBreak + +'begin' + sLineBreak + +' FMVC := TMVCEngine.Create(Self,' + sLineBreak + +' procedure(Config: TMVCConfig)' + sLineBreak + +' begin' + sLineBreak + +' //enable static files' + sLineBreak + +' Config[TMVCConfigKey.DocumentRoot] := ExtractFilePath(GetModuleName(HInstance)) + ''\www'';' + sLineBreak + +' // session timeout (0 means session cookie)' + sLineBreak + +' Config[TMVCConfigKey.SessionTimeout] := ''0'';' + sLineBreak + +' //default content-type' + sLineBreak + +' Config[TMVCConfigKey.DefaultContentType] := TMVCConstants.DEFAULT_CONTENT_TYPE;' + sLineBreak + +' //default content charset' + sLineBreak + +' Config[TMVCConfigKey.DefaultContentCharset] := TMVCConstants.DEFAULT_CONTENT_CHARSET;' + sLineBreak + +' //unhandled actions are permitted?' + sLineBreak + +' Config[TMVCConfigKey.AllowUnhandledAction] := ''false'';' + sLineBreak + +' //default view file extension' + sLineBreak + +' Config[TMVCConfigKey.DefaultViewFileExtension] := ''html'';' + sLineBreak + +' //view path' + sLineBreak + +' Config[TMVCConfigKey.ViewPath] := ''templates'';' +sLineBreak + +' //Enable STOMP messaging controller' + sLineBreak + +' Config[TMVCConfigKey.Messaging] := ''false'';' + sLineBreak + +' end);' + sLineBreak + +' FMVC.AddController(%3:s);' + sLineBreak + +'end;' + sLineBreak + +sLineBreak + +'procedure %1:s.WebModuleDestroy(Sender: TObject);' + sLineBreak + +'begin' + sLineBreak + +' FMVC.Free;' + sLineBreak + +'end;' + sLineBreak + +sLineBreak + +'end.' + sLineBreak; sWebModuleDFM = -'object %0:s: %1:s'#13#10 + -' OldCreateOrder = False'#13#10 + -' OnCreate = WebModuleCreate'#13#10 + -' Height = 230'#13#10 + -' Width = 415'#13#10 + +'object %0:s: %1:s' + sLineBreak + +' OldCreateOrder = False' + sLineBreak + +' OnCreate = WebModuleCreate' + sLineBreak + +' Height = 230' + sLineBreak + +' Width = 415' + sLineBreak + 'end'; implementation diff --git a/ideexpert/DMVC.Expert.Forms.NewProjectWizard.dfm b/ideexpert/DMVC.Expert.Forms.NewProjectWizard.dfm index 2eae431f..a49eef8d 100644 --- a/ideexpert/DMVC.Expert.Forms.NewProjectWizard.dfm +++ b/ideexpert/DMVC.Expert.Forms.NewProjectWizard.dfm @@ -1,9 +1,9 @@ object frmDMVCNewProject: TfrmDMVCNewProject Left = 0 Top = 0 - Caption = 'New DUnitX Project Wizard' - ClientHeight = 311 - ClientWidth = 284 + Caption = 'New DMVCFramework Project Wizard' + ClientHeight = 394 + ClientWidth = 336 Color = clBtnFace Constraints.MinHeight = 145 Constraints.MinWidth = 250 @@ -16,8 +16,8 @@ object frmDMVCNewProject: TfrmDMVCNewProject Position = poMainFormCenter OnCreate = FormCreate DesignSize = ( - 284 - 311) + 336 + 394) PixelsPerInch = 96 TextHeight = 13 object lblWbModule: TLabel @@ -27,20 +27,27 @@ object frmDMVCNewProject: TfrmDMVCNewProject Height = 13 Caption = 'WebModule Class Name' end + object Label2: TLabel + Left = 24 + Top = 298 + Width = 55 + Height = 13 + Caption = 'Server Port' + end object gbControllerUnitOptions: TGroupBox Left = 8 Top = 144 - Width = 268 - Height = 121 + Width = 320 + Height = 137 Anchors = [akLeft, akTop, akRight] Caption = 'Controller Unit Options' TabOrder = 2 DesignSize = ( - 268 - 121) + 320 + 137) object lblClassName: TLabel Left = 16 - Top = 54 + Top = 86 Width = 105 Height = 13 Caption = 'Controller Class Name' @@ -55,7 +62,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject object chkCreateIndexMethod: TCheckBox Left = 16 Top = 31 - Width = 236 + Width = 288 Height = 17 Anchors = [akLeft, akTop, akRight] Caption = 'Create Index Method' @@ -65,16 +72,27 @@ object frmDMVCNewProject: TfrmDMVCNewProject end object edtClassName: TEdit Left = 16 - Top = 73 - Width = 236 + Top = 105 + Width = 288 Height = 21 Anchors = [akLeft, akTop, akRight] TabOrder = 1 end + object chkCreateActionFiltersMethods: TCheckBox + Left = 16 + Top = 54 + Width = 288 + Height = 17 + Anchors = [akLeft, akTop, akRight] + Caption = 'Create Action Filters Methods' + Checked = True + State = cbChecked + TabOrder = 2 + end end object btnOK: TButton - Left = 120 - Top = 278 + Left = 172 + Top = 361 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -84,8 +102,8 @@ object frmDMVCNewProject: TfrmDMVCNewProject TabOrder = 3 end object btnCancel: TButton - Left = 201 - Top = 278 + Left = 253 + Top = 361 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -97,7 +115,7 @@ object frmDMVCNewProject: TfrmDMVCNewProject object chkCreateControllerUnit: TCheckBox Left = 24 Top = 107 - Width = 217 + Width = 269 Height = 17 Anchors = [akLeft, akTop, akRight] Caption = 'Create Controller Unit' @@ -108,8 +126,8 @@ object frmDMVCNewProject: TfrmDMVCNewProject end object chkAddToProjectGroup: TCheckBox Left = 24 - Top = 10 - Width = 268 + Top = 8 + Width = 320 Height = 17 Anchors = [akLeft, akTop, akRight] Caption = 'Add to Existing Project Group' @@ -120,8 +138,16 @@ object frmDMVCNewProject: TfrmDMVCNewProject object edtWebModuleName: TEdit Left = 24 Top = 64 - Width = 236 + Width = 288 Height = 21 TabOrder = 5 end + object edtServerPort: TEdit + Left = 24 + Top = 317 + Width = 65 + Height = 21 + TabOrder = 6 + TextHint = '8080' + end end diff --git a/ideexpert/DMVC.Expert.Forms.NewProjectWizard.pas b/ideexpert/DMVC.Expert.Forms.NewProjectWizard.pas index 83a87f26..5bcc841d 100644 --- a/ideexpert/DMVC.Expert.Forms.NewProjectWizard.pas +++ b/ideexpert/DMVC.Expert.Forms.NewProjectWizard.pas @@ -27,6 +27,9 @@ type edtWebModuleName: TEdit; Label1: TLabel; lblWbModule: TLabel; + chkCreateActionFiltersMethods: TCheckBox; + edtServerPort: TEdit; + Label2: TLabel; procedure chkCreateControllerUnitClick(Sender: TObject); procedure FormCreate(Sender: TObject); private @@ -36,14 +39,19 @@ type function GetCreateControllerUnit: boolean; function GetControllerClassName: string; function GetWebModuleClassName: string; + function GetCreateActionFiltersMethods: boolean; + function GetServerPort: Integer; public { Public declarations } // Read Only Properties to extract values without having to know control values. property ControllerClassName: string read GetControllerClassName; - property CreateControllerUnit: Boolean read GetCreateControllerUnit; - property AddToProjectGroup: Boolean read GetAddToProjectGroup; - property CreateIndexMethod: Boolean read GetCreateIndexMethod; + property CreateControllerUnit: boolean read GetCreateControllerUnit; + property AddToProjectGroup: boolean read GetAddToProjectGroup; + property CreateIndexMethod: boolean read GetCreateIndexMethod; + property CreateActionFiltersMethods: boolean + read GetCreateActionFiltersMethods; property WebModuleClassName: string read GetWebModuleClassName; + property ServerPort: Integer read GetServerPort; end; var @@ -67,6 +75,7 @@ procedure TfrmDMVCNewProject.FormCreate(Sender: TObject); begin edtClassName.TextHint := sDefaultControllerName; edtWebModuleName.TextHint := sDefaultWebModuleName; + edtServerPort.TextHint := sDefaultServerPort; end; function TfrmDMVCNewProject.GetAddToProjectGroup: boolean; @@ -79,17 +88,36 @@ begin Result := chkCreateIndexMethod.Checked; end; +function TfrmDMVCNewProject.GetServerPort: Integer; +var + lServerPort: Integer; +begin + Result := StrToInt(sDefaultServerPort); + if (Trim(edtServerPort.Text) <> '') and TryStrToInt(edtServerPort.Text, + lServerPort) then + begin + if (lServerPort > 0) and (lServerPort < 65535) then + Result := lServerPort; + end; +end; + function TfrmDMVCNewProject.GetWebModuleClassName: string; begin if Trim(edtWebModuleName.Text) = '' then begin Result := sDefaultWebModuleName - end else + end + else begin Result := Trim(edtWebModuleName.Text); end; end; +function TfrmDMVCNewProject.GetCreateActionFiltersMethods: boolean; +begin + Result := chkCreateActionFiltersMethods.Checked; +end; + function TfrmDMVCNewProject.GetCreateControllerUnit: boolean; begin Result := chkCreateControllerUnit.Checked; @@ -100,7 +128,8 @@ begin if Trim(edtClassName.Text) = '' then begin Result := sDefaultControllerName - end else + end + else begin Result := Trim(edtClassName.Text); end; diff --git a/ideexpert/DMVC.Expert.Forms.NewUnitWizard.dfm b/ideexpert/DMVC.Expert.Forms.NewUnitWizard.dfm index 73301da5..0ca7cb67 100644 --- a/ideexpert/DMVC.Expert.Forms.NewUnitWizard.dfm +++ b/ideexpert/DMVC.Expert.Forms.NewUnitWizard.dfm @@ -2,7 +2,7 @@ object frmDMVCNewUnit: TfrmDMVCNewUnit Left = 0 Top = 0 Caption = 'New DMVC Controller Unit Wizard' - ClientHeight = 163 + ClientHeight = 199 ClientWidth = 262 Color = clBtnFace Constraints.MinHeight = 145 @@ -17,30 +17,30 @@ object frmDMVCNewUnit: TfrmDMVCNewUnit OnCreate = FormCreate DesignSize = ( 262 - 163) + 199) PixelsPerInch = 96 TextHeight = 13 object GroupBox1: TGroupBox Left = 8 Top = 8 Width = 246 - Height = 113 + Height = 152 Anchors = [akLeft, akTop, akRight] Caption = 'Controller Unit Options' TabOrder = 0 DesignSize = ( 246 - 113) + 152) object lblClassName: TLabel Left = 16 - Top = 70 + Top = 94 Width = 105 Height = 13 Caption = 'Controller Class Name' end object edtClassName: TEdit - Left = 16 - Top = 89 + Left = 14 + Top = 113 Width = 220 Height = 21 Anchors = [akLeft, akTop, akRight] @@ -57,10 +57,21 @@ object frmDMVCNewUnit: TfrmDMVCNewUnit State = cbChecked TabOrder = 0 end + object chkCreateActionFiltersMethods: TCheckBox + Left = 16 + Top = 55 + Width = 236 + Height = 17 + Anchors = [akLeft, akTop, akRight] + Caption = 'Create Action Filters Methods' + Checked = True + State = cbChecked + TabOrder = 2 + end end object btnOK: TButton Left = 98 - Top = 130 + Top = 166 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -68,10 +79,11 @@ object frmDMVCNewUnit: TfrmDMVCNewUnit Default = True ModalResult = 1 TabOrder = 1 + ExplicitTop = 130 end object btnCancel: TButton Left = 179 - Top = 130 + Top = 166 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -79,5 +91,6 @@ object frmDMVCNewUnit: TfrmDMVCNewUnit Caption = 'Cancel' ModalResult = 2 TabOrder = 2 + ExplicitTop = 130 end end diff --git a/ideexpert/DMVC.Expert.Forms.NewUnitWizard.pas b/ideexpert/DMVC.Expert.Forms.NewUnitWizard.pas index b44c7080..4974c156 100644 --- a/ideexpert/DMVC.Expert.Forms.NewUnitWizard.pas +++ b/ideexpert/DMVC.Expert.Forms.NewUnitWizard.pas @@ -52,15 +52,18 @@ type lblClassName: TLabel; edtClassName: TEdit; chkCreateIndexMethod: TCheckBox; + chkCreateActionFiltersMethods: TCheckBox; procedure FormCreate(Sender: TObject); private function GetCreateIndexMethod: boolean; function GetControllerClassName: string; + function GetCreateActionFiltersMethods: boolean; { Private declarations } public { Public declarations } property ControllerClassName : string read GetControllerClassName; property CreateIndexMethod : boolean read GetCreateIndexMethod; + property CreateActionFiltersMethods: boolean read GetCreateActionFiltersMethods; end; @@ -79,6 +82,11 @@ begin edtClassName.TextHint := sDefaultControllerName; end; +function TfrmDMVCNewUnit.GetCreateActionFiltersMethods: boolean; +begin + Result := chkCreateActionFiltersMethods.Checked; +end; + function TfrmDMVCNewUnit.GetCreateIndexMethod: boolean; begin Result := chkCreateIndexMethod.Checked; diff --git a/ideexpert/DMVC.Expert.NewUnitWizardEx.pas b/ideexpert/DMVC.Expert.NewUnitWizardEx.pas index 3a0496f0..1d305c13 100644 --- a/ideexpert/DMVC.Expert.NewUnitWizardEx.pas +++ b/ideexpert/DMVC.Expert.NewUnitWizardEx.pas @@ -55,13 +55,13 @@ uses resourcestring sNewDMVCUnitCaption = 'DMVC Unit'; - sNewDMVCProjectHint = 'Create New DMVC Controller Unit'; + sNewDMVCProjectHint = 'Create New DelphiMVCFramework Controller Unit'; class procedure TDMVCNewUnitWizard.RegisterDMVCNewUnitWizard(const aPersonality: string); begin RegisterPackageWizard(TExpertsRepositoryProjectWizardWithProc.Create(aPersonality, sNewDMVCProjectHint, sNewDMVCUnitCaption, 'DMVC.Wizard.NewUnitWizard', // do not localize - 'DMVC', 'DMVC Team - https://github.com/danieleteti/delphimvcframework', // do not localize + 'DMVC', 'DelphiMVCFramework Team - https://github.com/danieleteti/delphimvcframework', // do not localize procedure var WizardForm : TfrmDMVCNewUnit; @@ -77,6 +77,7 @@ begin Project := GetActiveProject; ControllerUnit := ModuleServices.CreateModule( TNewControllerUnitEx.Create(WizardForm.CreateIndexMethod, + WizardForm.CreateActionFiltersMethods, WizardForm.ControllerClassName, aPersonality)); if Project <> nil then diff --git a/ideexpert/DMVC.Expert.ProjectWizardEx.pas b/ideexpert/DMVC.Expert.ProjectWizardEx.pas index 591758e6..5faa9050 100644 --- a/ideexpert/DMVC.Expert.ProjectWizardEx.pas +++ b/ideexpert/DMVC.Expert.ProjectWizardEx.pas @@ -61,8 +61,8 @@ uses ExpertsRepository; resourcestring - sNewDMVCProjectCaption = 'DMVC Project'; - sNewDMVCProjectHint = 'Create New DMVC Project with Controller'; + sNewDMVCProjectCaption = 'DelphiMVCFramework Project'; + sNewDMVCProjectHint = 'Create New DelphiMVCFramework Project with Controller'; { TDUnitXNewProjectWizard } @@ -86,6 +86,7 @@ begin WebModuleUnit : IOTAModule; ControllerCreator : IOTACreator; WebModuleCreator : IOTAModuleCreator; + lProjectSourceCreator: IOTACreator; begin WizardForm := TfrmDMVCNewProject.Create(Application); try @@ -98,7 +99,9 @@ begin ModuleServices := (BorlandIDEServices as IOTAModuleServices); // Create Project Source - ModuleServices.CreateModule(TDMVCProjectFile.Create(APersonality)); + lProjectSourceCreator := TDMVCProjectFile.Create(APersonality); + TDMVCProjectFile(lProjectSourceCreator).DefaultPort := WizardForm.ServerPort; + ModuleServices.CreateModule(lProjectSourceCreator); Project := GetActiveProject; Config := (Project.ProjectOptions as IOTAProjectOptionsConfigurations).BaseConfiguration; @@ -108,7 +111,7 @@ begin // Create Controller Unit if WizardForm.CreateControllerUnit then begin - ControllerCreator := TNewControllerUnitEx.Create(WizardForm.CreateIndexMethod, WizardForm.ControllerClassName, aPersonality); + ControllerCreator := TNewControllerUnitEx.Create(WizardForm.CreateIndexMethod, WizardForm.CreateActionFiltersMethods, WizardForm.ControllerClassName, aPersonality); ControllerUnit := ModuleServices.CreateModule(ControllerCreator); if Project <> nil then begin