From 0395b36035a71cef7e3970a2b6995079e92bc108 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 25 Jan 2015 17:30:35 +0100 Subject: [PATCH] added custom property editors for filenames and paths activated in - custom tools editor: working dir + executable - project conf: doc output, object dir, output filename, etc --- lazproj/coedit.lpi | 7 +++- lazproj/coedit.lpr | 2 +- src/ce_dmdwrap.pas | 50 ++++++++++++++-------------- src/ce_inspectors.pas | 76 +++++++++++++++++++++++++++++++++++++++++++ src/ce_tools.pas | 10 +++--- 5 files changed, 113 insertions(+), 32 deletions(-) create mode 100644 src/ce_inspectors.pas diff --git a/lazproj/coedit.lpi b/lazproj/coedit.lpi index 859059e6..875c529b 100644 --- a/lazproj/coedit.lpi +++ b/lazproj/coedit.lpi @@ -140,7 +140,7 @@ - + @@ -358,6 +358,11 @@ + + + + + diff --git a/lazproj/coedit.lpr b/lazproj/coedit.lpr index a82cb151..3c51c451 100644 --- a/lazproj/coedit.lpr +++ b/lazproj/coedit.lpr @@ -8,7 +8,7 @@ uses {$ENDIF}{$ENDIF} Interfaces, Forms, lazcontrols, runtimetypeinfocontrols, ce_observer, ce_libman, ce_tools, ce_dcd, ce_main, ce_writableComponent, ce_options, ce_symstring, - ce_staticmacro, ce_icons, ce_dubwrap; + ce_staticmacro, ce_icons, ce_dubwrap, ce_inspectors; {$R *.res} diff --git a/src/ce_dmdwrap.pas b/src/ce_dmdwrap.pas index 88810d6b..fef678e6 100644 --- a/src/ce_dmdwrap.pas +++ b/src/ce_dmdwrap.pas @@ -5,7 +5,7 @@ unit ce_dmdwrap; interface uses - classes, sysutils, process, asyncprocess, ce_common; + classes, sysutils, process, asyncprocess, ce_common, ce_inspectors; (* @@ -39,18 +39,18 @@ type TDocOpts = class(TOptsGroup) private fGenDoc: boolean; - fDocDir: string; + fDocDir: TCEPathname; fGenJson: boolean; - fJsonFname: string; + fJsonFname: TCEFilename; procedure setGenDoc(const aValue: boolean); procedure setGenJSON(const aValue: boolean); - procedure setDocDir(const aValue: string); - procedure setJSONFile(const aValue: string); + procedure setDocDir(const aValue: TCEPathname); + procedure setJSONFile(const aValue: TCEFilename); published property generateDocumentation: boolean read fGenDoc write setGenDoc default false; property generateJSON: boolean read fGenJson write setGenJSON default false; - property DocumentationDirectory: string read fDocDir write setDocDir; - property JSONFilename: string read fJsonFname write setJSONFile; + property DocumentationDirectory: TCEPathname read fDocDir write setDocDir; + property JSONFilename: TCEFilename read fJsonFname write setJSONFile; public procedure assign(aValue: TPersistent); override; procedure getOpts(const aList: TStrings); override; @@ -208,18 +208,18 @@ type fIncl: TStringList; fImpt: TStringList; fExcl: TStringList; - fFname: string; - fObjDir: string; - procedure setFname(const aValue: string); - procedure setObjDir(const aValue: string); + fFname: TCEFilename; + fObjDir: TCEPathname; + procedure setFname(const aValue: TCEFilename); + procedure setObjDir(const aValue: TCEPathname); procedure setSrcs(aValue: TStringList); procedure setIncl(aValue: TStringList); procedure setImpt(aValue: TStringList); procedure setExcl(aValue: TStringList); procedure strLstChange(sender: TObject); published - property outputFilename: string read fFname write setFname; - property objectDirectory: string read fObjDir write setObjDir; + property outputFilename: TCEFilename read fFname write setFname; + property objectDirectory: TCEPathname read fObjDir write setObjDir; property Sources: TStringList read fExtraSrcs write setSrcs stored false; deprecated; property exclusions: TStringList read fExcl write setExcl; property extraSources: TStringList read fExtraSrcs write setSrcs; @@ -254,19 +254,19 @@ type *) TCustomProcOptions = class(TOptsGroup) private - fExecutable: string; - fWorkDir: string; + fExecutable: TCEFilename; + fWorkDir: TCEPathname; fOptions: TProcessOptions; fParameters: TStringList; fShowWin: TShowWindowOptions; - procedure setExecutable(const aValue: string); - procedure setWorkDir(const aValue: string); + procedure setExecutable(const aValue: TCEFilename); + procedure setWorkDir(const aValue: TCEPathname); procedure setOptions(const aValue: TProcessOptions); procedure setParameters(aValue: TStringList); procedure setShowWin(const aValue: TShowWindowOptions); protected - property executable: string read fExecutable write setExecutable; - property workingDirectory: string read fWorkDir write setWorkDir; + property executable: TCEFilename read fExecutable write setExecutable; + property workingDirectory: TCEPathname read fWorkDir write setWorkDir; property options: TProcessOptions read fOptions write setOptions; property parameters: TStringList read fParameters write setParameters; property showWindow: TShowWindowOptions read fShowWin write setShowWin; @@ -422,7 +422,7 @@ begin doChanged; end; -procedure TDocOpts.setDocDir(const aValue: string); +procedure TDocOpts.setDocDir(const aValue: TCEPathname); begin if fDocDir = aValue then exit; @@ -432,7 +432,7 @@ begin doChanged; end; -procedure TDocOpts.setJSONFile(const aValue: string); +procedure TDocOpts.setJSONFile(const aValue: TCEFilename); begin if fJsonFname = aValue then exit; @@ -887,7 +887,7 @@ begin inherited; end; -procedure TPathsOpts.setFname(const aValue: string); +procedure TPathsOpts.setFname(const aValue: TCEFilename); begin if fFname = aValue then exit; fFname := patchPlateformPath(aValue); @@ -895,7 +895,7 @@ begin doChanged; end; -procedure TPathsOpts.setObjDir(const aValue: string); +procedure TPathsOpts.setObjDir(const aValue: TCEPathname); begin if fObjDir = aValue then exit; fObjDir := patchPlateformPath(aValue); @@ -1045,14 +1045,14 @@ begin aProcess.StartupOptions := aProcess.StartupOptions + [suoUseShowWindow]; end; -procedure TCustomProcOptions.setExecutable(const aValue: string); +procedure TCustomProcOptions.setExecutable(const aValue: TCEFilename); begin if fExecutable = aValue then exit; fExecutable := aValue; doChanged; end; -procedure TCustomProcOptions.setWorkDir(const aValue: string); +procedure TCustomProcOptions.setWorkDir(const aValue: TCEPathname); begin if fWorkDir = aValue then exit; fWorkDir := aValue; diff --git a/src/ce_inspectors.pas b/src/ce_inspectors.pas new file mode 100644 index 00000000..6ccd14be --- /dev/null +++ b/src/ce_inspectors.pas @@ -0,0 +1,76 @@ +unit ce_inspectors; + +{$I ce_defines.inc} + +interface + +uses + Classes, SysUtils, Dialogs, PropEdits; + +type + + TCEPathname = type string; + TCEFilename = type string; + + TCustomPathType = (ptFile, ptFolder); + + TCECustomPathEditor = class(TStringPropertyEditor) + private + fType: TCustomPathType; + public + function GetAttributes: TPropertyAttributes; override; + procedure Edit; override; + end; + + TCEPathnameEditor = class(TCECustomPathEditor) + constructor Create(Hook: TPropertyEditorHook; APropCount: Integer); override; + end; + + TCEFilenameEditor = class(TCECustomPathEditor) + constructor Create(Hook: TPropertyEditorHook; APropCount: Integer); override; + end; + + +implementation + +function TCECustomPathEditor.GetAttributes: TPropertyAttributes; +begin + exit( inherited GetAttributes() + [paDialog]); +end; + +procedure TCECustomPathEditor.Edit; +var + newValue: string; +begin + case fType of + ptFile: + with TOpenDialog.create(nil) do try + InitialDir := ExtractFileName(GetValue); + FileName := GetValue; + if Execute then SetValue(FileName); + finally + free; + end; + ptFolder: + if SelectDirectory(GetPropInfo^.Name, GetValue, newValue) then + SetValue(newValue); + end; +end; + +constructor TCEPathnameEditor.Create(Hook: TPropertyEditorHook; APropCount: Integer); +begin + inherited; + fType := ptFolder; +end; + +constructor TCEFilenameEditor.Create(Hook: TPropertyEditorHook; APropCount: Integer); +begin + inherited; + fType := ptFile; +end; + +initialization + RegisterPropertyEditor(TypeInfo(TCEPathname), nil, '', TCEPathnameEditor); + RegisterPropertyEditor(TypeInfo(TCEFilename), nil, '', TCEfilenameEditor); +end. + diff --git a/src/ce_tools.pas b/src/ce_tools.pas index 40157acf..1ade2103 100644 --- a/src/ce_tools.pas +++ b/src/ce_tools.pas @@ -6,15 +6,15 @@ interface uses Classes, SysUtils, FileUtil, process, menus, - ce_common, ce_writableComponent, ce_interfaces, ce_observer; + ce_common, ce_writableComponent, ce_interfaces, ce_observer, ce_inspectors; type TCEToolItem = class(TCollectionItem) private fProcess: TCheckedAsyncProcess; - fExecutable: string; - fWorkingDir: string; + fExecutable: TCEFilename; + fWorkingDir: TCEPathname; fShowWin: TShowWindowOptions; fOpts: TProcessOptions; fParameters: TStringList; @@ -32,8 +32,8 @@ type published property toolAlias: string read fToolAlias write fToolAlias; property options: TProcessOptions read fOpts write fOpts; - property executable: string read fExecutable write fExecutable; - property workingDirectory: string read fWorkingDir write fWorkingDir; + property executable: TCEFilename read fExecutable write fExecutable; + property workingDirectory: TCEPathname read fWorkingDir write fWorkingDir; property parameters: TStringList read fParameters write setParameters; property showWindows: TShowWindowOptions read fShowWin write fShowWin; property queryParameters: boolean read fQueryParams write fQueryParams;