From 5ad5e406de6c42ffca100b619c4a4e75b08a817d Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Mon, 21 Mar 2016 20:51:10 +0100 Subject: [PATCH] refactored the symbol expander as an ICESingleService --- src/ce_dmdwrap.pas | 83 +++++++++++++++++++++++----------------- src/ce_interfaces.pas | 22 +++++++++-- src/ce_main.pas | 8 ++-- src/ce_messages.pas | 24 ++++++------ src/ce_nativeproject.pas | 18 +++++---- src/ce_procinput.pas | 6 ++- src/ce_projinspect.pas | 12 +++--- src/ce_symstring.pas | 24 +++++++----- src/ce_todolist.pas | 2 +- src/ce_tools.pas | 14 ++++--- 10 files changed, 129 insertions(+), 84 deletions(-) diff --git a/src/ce_dmdwrap.pas b/src/ce_dmdwrap.pas index 78846090..85581680 100644 --- a/src/ce_dmdwrap.pas +++ b/src/ce_dmdwrap.pas @@ -5,8 +5,8 @@ unit ce_dmdwrap; interface uses - classes, sysutils, process, asyncprocess, ce_common, - ce_processes, ce_interfaces; + classes, sysutils, process, asyncprocess, + ce_common, ce_processes, ce_interfaces; (* @@ -29,9 +29,11 @@ type fOnChange: TNotifyEvent; procedure doChanged; protected + fSymStringExpander: ICESymStringExpander; property onChange: TNotifyEvent read fOnChange write fOnChange; public procedure getOpts(aList: TStrings; base: TOptsGroup = nil); virtual; abstract; + constructor create; virtual; end; (***************************************************************************** @@ -94,7 +96,7 @@ type property showHiddenAlloc: boolean read fVgc write setVgc default false; property showColumnsNumber: boolean read fCol write setCol default false; public - constructor create; + constructor create; override; procedure assign(aValue: TPersistent); override; procedure getOpts(aList: TStrings; base: TOptsGroup = nil); override; end; @@ -156,7 +158,7 @@ type //TODO-cmaintenace: remove deprecated props after next rlz property generateStackFrame: boolean write setGenStack stored false; deprecated; public - constructor create; + constructor create; override; destructor destroy; override; procedure assign(aValue: TPersistent); override; procedure getOpts(aList: TStrings; base: TOptsGroup = nil); override; @@ -195,7 +197,7 @@ type property codeviewDexts: boolean write setGenInfos stored false; deprecated; property codeviewCformat: boolean write setDbgC stored false; deprecated; public - constructor create; + constructor create; override; destructor destroy; override; procedure assign(aValue: TPersistent); override; procedure getOpts(aList: TStrings;base: TOptsGroup = nil); override; @@ -230,7 +232,7 @@ type property importStringPaths: TStringList read fImpStr write setImpt; property forceExtension: boolean read fForceExt write setForceExt default false; public - constructor create; + constructor create; override; destructor destroy; override; procedure assign(aValue: TPersistent); override; procedure getOpts(aList: TStrings; base: TOptsGroup = nil); override; @@ -249,7 +251,7 @@ type property coverage: boolean read fCov write setCov default false; property customOptions: TStringList read fCustom write setCustom; public - constructor create; + constructor create; override; destructor destroy; override; procedure assign(aValue: TPersistent); override; procedure getOpts(aList: TStrings; base: TOptsGroup = nil); override; @@ -281,7 +283,7 @@ type property showWindow: TShowWindowOptions read fShowWin write setShowWin default swoNone; property simpleCommands: TStringList read fCommands write setCommands; public - constructor create; + constructor create; override; destructor destroy; override; procedure assign(source: TPersistent); override; procedure getOpts(aList: TStrings; base: TOptsGroup = nil); override; @@ -324,6 +326,7 @@ type *) TCompilerConfiguration = class(TCollectionItem) private + fSymStringExpander: ICESymStringExpander; fName: string; fOnChanged: TNotifyEvent; fDocOpts: TDocOpts; @@ -376,8 +379,10 @@ type implementation -uses - ce_symstring; +constructor TOptsGroup.create; +begin + fSymStringExpander := getSymStringExpander; +end; procedure TOptsGroup.doChanged; begin @@ -396,9 +401,9 @@ begin if fGenJson then aList.Add('-X'); if fDocDir <> '' then - aList.Add('-Dd' + symbolExpander.get(fDocDir)); + aList.Add('-Dd' + fSymStringExpander.expand(fDocDir)); if fJsonFname <> '' then - aList.Add('-Xf' + symbolExpander.get(fJsonFname)); + aList.Add('-Xf' + fSymStringExpander.expand(fJsonFname)); end else begin baseopt := TDocOpts(base); @@ -407,17 +412,17 @@ begin if baseopt.fGenJson or fGenJson then aList.Add('-X'); if (baseopt.fDocDir <> '') and (fDocDir <> '') then - aList.Add('-Dd' + symbolExpander.get(fDocDir)) + aList.Add('-Dd' + fSymStringExpander.expand(fDocDir)) else if (fDocDir <> '') then - aList.Add('-Dd' + symbolExpander.get(fDocDir)) + aList.Add('-Dd' + fSymStringExpander.expand(fDocDir)) else if (baseopt.fDocDir <> '') then - aList.Add('-Dd' + symbolExpander.get(baseopt.fDocDir)); + aList.Add('-Dd' + fSymStringExpander.expand(baseopt.fDocDir)); if (baseopt.fJsonFname <> '') and (fJsonFname <> '') then - aList.Add('-Xf' + symbolExpander.get(fJsonFname)) + aList.Add('-Xf' + fSymStringExpander.expand(fJsonFname)) else if fJsonFname <> '' then - aList.Add('-Xf' + symbolExpander.get(fJsonFname)) + aList.Add('-Xf' + fSymStringExpander.expand(fJsonFname)) else if (baseopt.fJsonFname <> '') then - aList.Add('-Dd' + symbolExpander.get(baseopt.fJsonFname)); + aList.Add('-Dd' + fSymStringExpander.expand(baseopt.fJsonFname)); end; end; @@ -489,6 +494,7 @@ end; {$REGION TMsgOpts --------------------------------------------------------------} constructor TMsgOpts.create; begin + inherited; fDepHandling := TDepHandling.warning; fWarnings := true; end; @@ -607,6 +613,7 @@ end; {$REGION TOutputOpts -----------------------------------------------------------} constructor TOutputOpts.create; begin + inherited; fVerIds := TStringList.Create; fBoundsCheck := safeOnly; end; @@ -816,6 +823,7 @@ end; {$REGION TDebugOpts ------------------------------------------------------------} constructor TDebugOpts.create; begin + inherited; fDbgIdents := TStringList.Create; end; @@ -944,6 +952,7 @@ end; {$REGION TPathsOpts ------------------------------------------------------------} constructor TPathsOpts.create; begin + inherited; fExtraSrcs := TStringList.Create; fImpMod := TStringList.Create; fImpStr := TStringList.Create; @@ -979,7 +988,7 @@ begin begin if isStringDisabled(str) then continue; - sym := symbolExpander.get(str); + sym := fSymStringExpander.expand(str); if not listAsteriskPath(sym, aList, exts) then aList.Add(sym); end; @@ -987,13 +996,13 @@ begin exts.Free; end; for str in fImpMod do if not isStringDisabled(str) then - aList.Add('-I'+ symbolExpander.get(str)); + aList.Add('-I'+ fSymStringExpander.expand(str)); for str in fImpStr do if not isStringDisabled(str) then - aList.Add('-J'+ symbolExpander.get(str)); + aList.Add('-J'+ fSymStringExpander.expand(str)); if fFname <> '' then - aList.Add('-of' + symbolExpander.get(fFname)); + aList.Add('-of' + fSymStringExpander.expand(fFname)); if fObjDir <> '' then - aList.Add('-od' + symbolExpander.get(fObjDir)); + aList.Add('-od' + fSymStringExpander.expand(fObjDir)); end else begin baseopt := TPathsOpts(base); @@ -1006,7 +1015,7 @@ begin begin if isStringDisabled(str) then continue; - sym := symbolExpander.get(str); + sym := fSymStringExpander.expand(str); if not listAsteriskPath(sym, aList, exts) then aList.Add(sym); end; @@ -1017,22 +1026,22 @@ begin if fImpMod.Count = 0 then rightList := baseopt.fImpMod else rightList := fImpMod; for str in rightList do if not isStringDisabled(str) then - aList.Add('-I'+ symbolExpander.get(str)); + aList.Add('-I'+ fSymStringExpander.expand(str)); // if fImpStr.Count = 0 then rightList := baseopt.fImpStr else rightList := fImpStr; for str in rightList do if not isStringDisabled(str) then - aList.Add('-J'+ symbolExpander.get(str)); + aList.Add('-J'+ fSymStringExpander.expand(str)); // str := ''; if fFname <> '' then str := fFname else if baseopt.fFname <> '' then str := baseopt.fFname; - if str.isNotEmpty then aList.Add('-of' + symbolExpander.get(str)); + if str.isNotEmpty then aList.Add('-of' + fSymStringExpander.expand(str)); // str := ''; if fObjDir <> '' then str := fObjDir else if baseopt.fObjDir <> '' then str := baseopt.fObjDir; - if str.isNotEmpty then aList.Add('-od' + symbolExpander.get(str)); + if str.isNotEmpty then aList.Add('-od' + fSymStringExpander.expand(str)); end; end; @@ -1118,6 +1127,7 @@ end; {$REGION TOtherOpts ------------------------------------------------------------} constructor TOtherOpts.create; begin + inherited; fCustom := TStringList.Create; end; @@ -1163,7 +1173,7 @@ begin str2 := '-' + str1 else str2 := str1; - aList.AddText(symbolExpander.get(str2)); + aList.AddText(fSymStringExpander.expand(str2)); end; if fCov then aList.Add('-cov'); end else @@ -1179,7 +1189,7 @@ begin str2 := '-' + str1 else str2 := str1; - aList.AddText(symbolExpander.get(str2)); + aList.AddText(fSymStringExpander.expand(str2)); end; if baseopt.fCov or fCov then aList.Add('-cov'); end; @@ -1195,6 +1205,7 @@ end; {$REGION TCustomProcOptions ----------------------------------------------------} constructor TCustomProcOptions.create; begin + inherited; fParameters := TStringList.Create; fCommands := TStringList.Create; end; @@ -1230,7 +1241,7 @@ procedure TCustomProcOptions.setProcess(var aProcess: TProcess); begin //TODO-cNativeProjects: adapt TCustomProcOptions.setProcess to base/override system aProcess.Parameters.Clear; - aProcess.Parameters.AddText(symbolExpander.get(Parameters.Text)); + aProcess.Parameters.AddText(fSymStringExpander.expand(Parameters.Text)); aProcess.Executable := fExecutable; aProcess.ShowWindow := fShowWin; aProcess.Options := fOptions; @@ -1241,7 +1252,7 @@ end; procedure TCustomProcOptions.setProcess(var aProcess: TAsyncProcess); begin aProcess.Parameters.Clear; - aProcess.Parameters.AddText(symbolExpander.get(Parameters.Text)); + aProcess.Parameters.AddText(fSymStringExpander.expand(Parameters.Text)); aProcess.Executable := fExecutable; aProcess.ShowWindow := fShowWin; aProcess.Options := fOptions; @@ -1252,7 +1263,7 @@ end; procedure TCustomProcOptions.setProcess(var aProcess: TCheckedAsyncProcess); begin aProcess.Parameters.Clear; - aProcess.Parameters.AddText(symbolExpander.get(Parameters.Text)); + aProcess.Parameters.AddText(fSymStringExpander.expand(Parameters.Text)); aProcess.Executable := fExecutable; aProcess.ShowWindow := fShowWin; aProcess.Options := fOptions; @@ -1263,7 +1274,7 @@ end; procedure TCustomProcOptions.setProcess(var aProcess: TCEProcess); begin aProcess.Parameters.Clear; - aProcess.Parameters.AddText(symbolExpander.get(Parameters.Text)); + aProcess.Parameters.AddText(fSymStringExpander.expand(Parameters.Text)); aProcess.Executable := fExecutable; aProcess.ShowWindow := fShowWin; aProcess.Options := fOptions; @@ -1317,6 +1328,8 @@ constructor TCompilerConfiguration.create(aCollection: TCollection); begin inherited create(aCollection); + fSymStringExpander:= getSymStringExpander; + fDocOpts := TDocOpts.create; fDebugOpts := TDebugOpts.create; fMsgOpts := TMsgOpts.create; @@ -1414,7 +1427,7 @@ begin end; if fe and nme.isNotEmpty then begin - nme := symbolExpander.get(nme); + nme := fSymStringExpander.expand(nme); ext := nme.extractFileExt; nme := '-of' + nme; i := aList.IndexOf(nme); diff --git a/src/ce_interfaces.pas b/src/ce_interfaces.pas index dbba2399..8795bd94 100644 --- a/src/ce_interfaces.pas +++ b/src/ce_interfaces.pas @@ -293,6 +293,16 @@ type + (** + * Single service related to the expansion of Coedit "symbolic strings". + *) + ICESymStringExpander = interface(ICESingleService) + // expand all the symbols in value in result. + function expand(const value: string): string; + end; + + + { subject primitives: @@ -323,9 +333,10 @@ type Service getters: } function getMessageDisplay(var obj: ICEMessagesDisplay): ICEMessagesDisplay; - function getMessageDisplay: ICEMessagesDisplay; overload; - function getprocInputHandler: ICEProcInputHandler; overload; - function getMultiDocHandler: ICEMultiDocHandler; overload; + function getMessageDisplay: ICEMessagesDisplay; + function getprocInputHandler: ICEProcInputHandler; + function getMultiDocHandler: ICEMultiDocHandler; + function getSymStringExpander: ICESymStringExpander; implementation @@ -450,6 +461,11 @@ function getMultiDocHandler: ICEMultiDocHandler; begin exit(EntitiesConnector.getSingleService('ICEMultiDocHandler') as ICEMultiDocHandler); end; + +function getSymStringExpander: ICESymStringExpander; +begin + exit(EntitiesConnector.getSingleService('ICESymStringExpander') as ICESymStringExpander); +end; {$ENDREGION} end. diff --git a/src/ce_main.pas b/src/ce_main.pas index b1167b56..da22853f 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -200,6 +200,7 @@ type private + fSymStringExpander: ICESymStringExpander; fCovModUt: boolean; fDoc: TCESynMemo; fFirstTimeCoedit: boolean; @@ -427,7 +428,7 @@ implementation {$R *.lfm} uses - SynMacroRecorder, ce_symstring, ce_dcd; + SynMacroRecorder, ce_dcd; {$REGION TCEApplicationOptions ------------------------------------------------------} constructor TCEApplicationOptions.Create(AOwner: TComponent); @@ -777,6 +778,7 @@ begin // updateMainMenuProviders; EntitiesConnector.forceUpdate; + fSymStringExpander:= getSymStringExpander; // getCMdParams; if fNativeProject.isNil then @@ -1949,7 +1951,7 @@ begin if ( i > 18) then begin if firstlineFlags.upperCase[1..17] = '#!RUNNABLE-FLAGS:' then - firstlineFlags := symbolExpander.get(firstlineFlags[18..i]) + firstlineFlags := fSymStringExpander.expand(firstlineFlags[18..i]) else firstlineFlags:= ''; end else firstlineFlags:= ''; @@ -2016,7 +2018,7 @@ begin if runArgs.isNotEmpty then begin lst.Clear; - CommandToList(symbolExpander.get(runArgs), lst); + CommandToList(fSymStringExpander.expand(runArgs), lst); fRunProc.Parameters.AddStrings(lst); end; fRunProc.Executable := fname + exeExt; diff --git a/src/ce_messages.pas b/src/ce_messages.pas index 89c7915f..8295f1b8 100644 --- a/src/ce_messages.pas +++ b/src/ce_messages.pas @@ -8,8 +8,8 @@ uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, EditBtn, lcltype, ce_widget, ActnList, Menus, clipbrd, AnchorDocking, math, TreeFilterEdit, Buttons, process, GraphType, fgl, - ce_writableComponent, ce_common, ce_synmemo, ce_dlangutils, ce_interfaces, - ce_observer, ce_symstring, ce_processes, ce_sharedres, ce_stringrange; + ce_writableComponent, ce_common, ce_synmemo, ce_interfaces, ce_observer, + ce_processes, ce_sharedres, ce_stringrange; type @@ -105,6 +105,7 @@ type fToDemangle: TStringList; fToDemangleObjs: TFPList; fFiltering: boolean; + fSymStringExpander: ICESymStringExpander; function itemShouldBeVisible(item: TTreeNode; aCtxt: TCEAppMessageCtxt): boolean; procedure demanglerOutput(sender: TObject); procedure filterMessages(aCtxt: TCEAppMessageCtxt); @@ -150,6 +151,10 @@ type procedure optionedEvent(anEvent: TOptionEditorEvent); function optionedOptionsModified: boolean; // + function openFileFromDmdMessage(const aMessage: string): boolean; + function getLineFromMessage(const aMessage: string): TPoint; + function guessMessageKind(const aMessg: string): TCEAppMessageKind; + // function singleServiceName: string; procedure message(const aValue: string; aData: Pointer; aCtxt: TCEAppMessageCtxt; aKind: TCEAppMessageKind); procedure clearbyContext(aCtxt: TCEAppMessageCtxt); @@ -176,10 +181,6 @@ type destructor destroy; override; end; - function guessMessageKind(const aMessg: string): TCEAppMessageKind; - function getLineFromMessage(const aMessage: string): TPoint; - function openFileFromDmdMessage(const aMessage: string): boolean; - implementation {$R *.lfm} @@ -260,6 +261,7 @@ var begin fMaxMessCnt := 500; fCtxt := amcAll; + fSymStringExpander:= getSymStringExpander; // fActAutoSel := TAction.Create(self); fActAutoSel.Caption := 'Auto select message category'; @@ -973,7 +975,7 @@ begin list.EndUpdate; end; -function guessMessageKind(const aMessg: string): TCEAppMessageKind; +function TCEMessagesWidget.guessMessageKind(const aMessg: string): TCEAppMessageKind; var idt: string; rng: TStringRange; @@ -1013,7 +1015,7 @@ begin end; end; -function getLineFromMessage(const aMessage: string): TPoint; +function TCEMessagesWidget.getLineFromMessage(const aMessage: string): TPoint; var rng: TStringRange; lne: string; @@ -1031,7 +1033,7 @@ begin result.x := strToIntDef(col, -1); end; -function openFileFromDmdMessage(const aMessage: string): boolean; +function TCEMessagesWidget.openFileFromDmdMessage(const aMessage: string): boolean; var i: integer = 0; ident: string = ''; @@ -1063,13 +1065,13 @@ begin exit(true); end; // if fname relative to native project path or project filed 'root' - absName := expandFilenameEx(symbolExpander.get('') + DirectorySeparator, ident); + absName := expandFilenameEx(fSymStringExpander.expand('') + DirectorySeparator, ident); if absName.fileExists then begin getMultiDocHandler.openDocument(absName); exit(true); end; - absName := expandFilenameEx(symbolExpander.get('') + DirectorySeparator, ident); + absName := expandFilenameEx(fSymStringExpander.expand('') + DirectorySeparator, ident); if absName.fileExists then begin getMultiDocHandler.openDocument(absName); diff --git a/src/ce_nativeproject.pas b/src/ce_nativeproject.pas index 3386c128..60e76783 100644 --- a/src/ce_nativeproject.pas +++ b/src/ce_nativeproject.pas @@ -45,6 +45,7 @@ type fCanBeRun: boolean; fBaseConfig: TCompilerConfiguration; fCompiled: boolean; + fSymStringExpander: ICESymStringExpander; procedure updateOutFilename; procedure doChanged; procedure getBaseConfig; @@ -127,7 +128,7 @@ type implementation uses - controls, dialogs, ce_symstring, ce_libman, ce_dcd; + controls, dialogs, ce_libman, ce_dcd; var NativeProjectCompilerFilename: string = 'dmd'; @@ -136,6 +137,7 @@ var constructor TCENativeProject.create(aOwner: TComponent); begin inherited create(aOwner); + fSymStringExpander := getSymStringExpander; // fRunnerOldCwd := GetCurrentDirUTF8; fProjectSubject := TCEProjectSubject.create; @@ -403,7 +405,7 @@ begin // prepares the exclusions for i := 0 to currentConfiguration.pathsOptions.exclusions.Count-1 do begin - str := symbolExpander.get(currentConfiguration.pathsOptions.exclusions[i]); + str := fSymStringExpander.expand(currentConfiguration.pathsOptions.exclusions[i]); exc.Add(str) end; // sources @@ -620,7 +622,7 @@ begin // field is specified if fOutputFilename.isNotEmpty then begin - fOutputFilename := symbolExpander.get(fOutputFilename); + fOutputFilename := fSymStringExpander.expand(fOutputFilename); fOutputFilename := expandFilenameEx(fBasePath, fOutputFilename); {$IFDEF WINDOWS} // field is specified without ext or with a dot in the name. @@ -666,7 +668,7 @@ begin // for i := 0 to processInfo.simpleCommands.Count-1 do begin - pname := symbolExpander.get(processInfo.simpleCommands[i]); + pname := fSymStringExpander.expand(processInfo.simpleCommands[i]); proc := TProcess.Create(nil); lst := TStringList.Create; try @@ -689,7 +691,7 @@ begin exit(false); end; // - pname := symbolExpander.get(processInfo.executable); + pname := fSymStringExpander.expand(processInfo.executable); if (not exeInSysPath(pname)) and pname.isNotEmpty then exit(false) else if pname.isEmpty then @@ -701,11 +703,11 @@ begin proc.Executable := exeFullName(pname); j := proc.Parameters.Count-1; for i:= 0 to j do - proc.Parameters.AddText(symbolExpander.get(proc.Parameters[i])); + proc.Parameters.AddText(fSymStringExpander.expand(proc.Parameters[i])); for i:= 0 to j do proc.Parameters.Delete(0); if proc.CurrentDirectory.isNotEmpty then - proc.CurrentDirectory := symbolExpander.get(proc.CurrentDirectory); + proc.CurrentDirectory := fSymStringExpander.expand(proc.CurrentDirectory); // else cwd is set to project dir in compile() ensureNoPipeIfWait(proc); proc.Execute; @@ -799,7 +801,7 @@ begin i := 1; repeat prm := ExtractDelimited(i, runArgs, [' ']); - prm := symbolExpander.get(prm); + prm := fSymStringExpander.expand(prm); if prm.isNotEmpty then fRunner.Parameters.AddText(prm); Inc(i); diff --git a/src/ce_procinput.pas b/src/ce_procinput.pas index 64577d88..b4d463d3 100644 --- a/src/ce_procinput.pas +++ b/src/ce_procinput.pas @@ -26,6 +26,7 @@ type fMruPos: Integer; fMru: TCEMRUList; fProc: TProcess; + fSymStringExpander: ICESymStringExpander; procedure sendInput; // function singleServiceName: string; @@ -41,7 +42,7 @@ implementation {$R *.lfm} uses - ce_symstring, LCLType; + LCLType; const OptsFname = 'procinput.txt'; @@ -52,6 +53,7 @@ var fname: string; begin inherited; + fSymStringExpander:= getSymStringExpander; fMru := TCEMRUList.Create; fMru.maxCount := 25; EntitiesConnector.addSingleService(self); @@ -123,7 +125,7 @@ begin fMru.Insert(0,txtInp.Text); fMruPos := 0; if txtInp.Text <> '' then - inp := symbolExpander.get(txtInp.Text) + lineEnding + inp := fSymStringExpander.expand(txtInp.Text) + lineEnding else inp := txtInp.Text + lineEnding; fProc.Input.Write(inp[1], inp.length); diff --git a/src/ce_projinspect.pas b/src/ce_projinspect.pas index f0206e6c..db52eea6 100644 --- a/src/ce_projinspect.pas +++ b/src/ce_projinspect.pas @@ -42,6 +42,7 @@ type fImpsNode, fInclNode: TTreeNode; fXtraNode: TTreeNode; fLastFileOrFolder: string; + fSymStringExpander: ICESymStringExpander; procedure actUpdate(sender: TObject); procedure TreeDblClick(sender: TObject); procedure actOpenFileExecute(sender: TObject); @@ -65,12 +66,11 @@ type implementation {$R *.lfm} -uses - ce_symstring; - {$REGION Standard Comp/Obj------------------------------------------------------} constructor TCEProjectInspectWidget.create(aOwner: TComponent); begin + fSymStringExpander:= getSymStringExpander; + // fActOpenFile := TAction.Create(self); fActOpenFile.Caption := 'Open file in editor'; fActOpenFile.OnExecute := @actOpenFileExecute; @@ -447,7 +447,7 @@ begin if str.isEmpty then continue; fold := expandFilenameEx(fProject.basePath, str); - fold := symbolExpander.get(fold); + fold := fSymStringExpander.expand(fold); itm := Tree.Items.AddChild(fImpsNode, fold); itm.ImageIndex := 5; itm.SelectedIndex := 5; @@ -459,7 +459,7 @@ begin if str.isEmpty then continue; fold := expandFilenameEx(fProject.basePath, str); - fold := symbolExpander.get(fold); + fold := fSymStringExpander.expand(fold); itm := Tree.Items.AddChild(fInclNode, fold); itm.ImageIndex := 5; itm.SelectedIndex := 5; @@ -471,7 +471,7 @@ begin if str.isEmpty then continue; src := expandFilenameEx(fProject.basePath, str); - src := symbolExpander.get(src); + src := fSymStringExpander.expand(src); lst := TStringList.Create; try if listAsteriskPath(src, lst) then for src in lst do diff --git a/src/ce_symstring.pas b/src/ce_symstring.pas index e7add2de..d54b682d 100644 --- a/src/ce_symstring.pas +++ b/src/ce_symstring.pas @@ -25,7 +25,7 @@ type * TCESymbolExpander is designed to expand Coedit symbolic strings, * using the information collected from several observer interfaces. *) - TCESymbolExpander = class(ICEMultiDocObserver, ICEProjectObserver) + TCESymbolExpander = class(ICEMultiDocObserver, ICEProjectObserver, ICESymStringExpander) private fProj: TCENativeProject; fProjInterface: ICECommonProject; @@ -45,25 +45,26 @@ type procedure docClosing(aDoc: TCESynMemo); procedure docFocused(aDoc: TCESynMemo); procedure docChanged(aDoc: TCESynMemo); + // + function singleServiceName: string; + function expand(const value: string): string; public constructor Create; destructor Destroy; override; - // expands the symbols contained in symString - function get(const symString: string): string; end; -var - symbolExpander: TCESymbolExpander; - implementation uses Forms, SysUtils, Classes; +var + symbolExpander: TCESymbolExpander; {$REGION Standard Comp/Obj------------------------------------------------------} constructor TCESymbolExpander.Create; begin EntitiesConnector.addObserver(self); + EntitiesConnector.addSingleService(self); fNeedUpdate := true; // {$IFDEF UNIX} @@ -237,17 +238,22 @@ begin end; end; -function TCESymbolExpander.get(const symString: string): string; +function TCESymbolExpander.singleServiceName: string; +begin + exit('ICESymStringExpander'); +end; + +function TCESymbolExpander.expand(const value: string): string; var rng: TStringRange; sym: string; begin Result := ''; - if symString.isEmpty then + if value.isEmpty then exit; // updateSymbols; - rng := TStringRange.create(symString); + rng := TStringRange.create(value); while true do begin if rng.empty then diff --git a/src/ce_todolist.pas b/src/ce_todolist.pas index 1c2c9bda..302d0968 100644 --- a/src/ce_todolist.pas +++ b/src/ce_todolist.pas @@ -8,7 +8,7 @@ uses Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, strutils, Graphics, Dialogs, ExtCtrls, Menus, Buttons, ComCtrls, ce_widget, process, ce_common, ce_interfaces, ce_synmemo, ce_processes, - ce_nativeproject, ce_symstring, ce_writableComponent, ce_observer, ce_sharedres; + ce_nativeproject, ce_writableComponent, ce_observer, ce_sharedres; type diff --git a/src/ce_tools.pas b/src/ce_tools.pas index 5a1f7f25..6817794a 100644 --- a/src/ce_tools.pas +++ b/src/ce_tools.pas @@ -30,6 +30,7 @@ type fOutputToNext: boolean; fShortcut: TShortcut; fMsgs: ICEMessagesDisplay; + fSymStringExpander: ICESymStringExpander; procedure setParameters(value: TStringList); procedure processOutput(sender: TObject); procedure setToolAlias(value: string); @@ -107,7 +108,7 @@ var implementation uses - ce_symstring, dialogs; + dialogs; const toolsFname = 'tools.txt'; @@ -126,6 +127,8 @@ end; constructor TCEToolItem.create(ACollection: TCollection); begin inherited; + fSymStringExpander:= getSymStringExpander; + fMsgs := getMessageDisplay; fToolItems := TCEToolItems(ACollection); fToolAlias := format('', [ID]); fParameters := TStringList.create; @@ -203,16 +206,16 @@ begin fProcess.OnReadData:= @processOutput; fProcess.OnTerminate:= @processOutput; fProcess.Options := fOpts; - fProcess.Executable := exeFullName(symbolExpander.get(fExecutable)); + fProcess.Executable := exeFullName(fSymStringExpander.expand(fExecutable)); fProcess.ShowWindow := fShowWin; - fProcess.CurrentDirectory := symbolExpander.get(fWorkingDir); + fProcess.CurrentDirectory := fSymStringExpander.expand(fWorkingDir); for prm in fParameters do if not isStringDisabled(prm) then - fProcess.Parameters.AddText(symbolExpander.get(prm)); + fProcess.Parameters.AddText(fSymStringExpander.expand(prm)); if fQueryParams then begin prm := ''; if InputQuery('Parameters', '', prm) then - if prm.isNotEmpty then fProcess.Parameters.AddText(symbolExpander.get(prm)); + if prm.isNotEmpty then fProcess.Parameters.AddText(fSymStringExpander.expand(prm)); end; ensureNoPipeIfWait(fProcess); // @@ -241,7 +244,6 @@ var begin if ((not fOutputToNext) or fNextToolAlias.isEmpty) and (poUsePipes in options) then begin - getMessageDisplay(fMsgs); lst := TStringList.Create; try fProcess.getFullLines(lst);