From fc9812114740cdc768a9b91308564f2fb652ad08 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 26 Nov 2014 18:33:51 +0100 Subject: [PATCH] refactored ce_customtools, global variable put off the less and less "main" form --- lazproj/coedit.lpr | 2 +- src/ce_customtools.pas | 19 +++++++++++++++++-- src/ce_libman.pas | 13 ++++++++++++- src/ce_main.pas | 31 +------------------------------ src/ce_project.pas | 13 ++++--------- src/ce_toolseditor.pas | 21 +++++++-------------- 6 files changed, 42 insertions(+), 57 deletions(-) diff --git a/lazproj/coedit.lpr b/lazproj/coedit.lpr index 5c955a55..ee7b6e66 100644 --- a/lazproj/coedit.lpr +++ b/lazproj/coedit.lpr @@ -6,7 +6,7 @@ uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} - Interfaces, Forms, lazcontrols, runtimetypeinfocontrols, + Interfaces, Forms, lazcontrols, runtimetypeinfocontrols, ce_libman, ce_customtools, ce_dcd, ce_observer, ce_main, ce_writableComponent, ce_options, ce_symstring; {$R *.res} diff --git a/src/ce_customtools.pas b/src/ce_customtools.pas index a69c56ce..6de7b1d2 100644 --- a/src/ce_customtools.pas +++ b/src/ce_customtools.pas @@ -5,8 +5,8 @@ unit ce_customtools; interface uses - Classes, SysUtils, process, asyncprocess, ce_common, ce_writableComponent, - ce_interfaces, ce_observer; + Classes, SysUtils, FileUtil, process, asyncprocess, + ce_common, ce_writableComponent, ce_interfaces, ce_observer; type @@ -53,6 +53,12 @@ type property tool[index: integer]: TCEToolItem read getTool; end; +const + toolsFname = 'tools.txt'; + +Var + CustomTools: TCETools; + implementation uses @@ -114,13 +120,19 @@ begin end; constructor TCETools.create(aOwner: TComponent); +var + fname: string; begin inherited; fTools := TCollection.Create(TCEToolItem); + fname := getDocPath + toolsFname; + if fileExists(fname) then loadFromFile(fname) end; destructor TCETools.destroy; begin + forceDirectory(getDocPath); + saveToFile(getDocPath + toolsFname); fTools.Free; inherited; end; @@ -142,4 +154,7 @@ end; initialization RegisterClasses([TCEToolItem, TCETools]); + CustomTools := TCETools.create(nil); +finalization + CustomTools.Free; end. diff --git a/src/ce_libman.pas b/src/ce_libman.pas index 6b548f3e..a301c387 100644 --- a/src/ce_libman.pas +++ b/src/ce_libman.pas @@ -5,7 +5,7 @@ unit ce_libman; interface uses - Classes, SysUtils, ce_common, ce_writableComponent, ce_dcd; + Classes, SysUtils, FileUtil, ce_common, ce_writableComponent, ce_dcd; type @@ -45,19 +45,30 @@ type procedure updateDCD; end; +const + libFname = 'libraryManager.txt'; + var LibMan: TLibraryManager; implementation constructor TLibraryManager.create(aOwner: TComponent); +var + fName: string; begin inherited; fCol := TCollection.Create(TLibraryItem); + fname := getDocPath + libFname; + if fileExists(fname) then loadFromFile(fname); end; destructor TLibraryManager.destroy; +var + fName: string; begin + forceDirectory(getDocPath); + LibMan.saveToFile(getDocPath + libFname); fCol.Free; inherited; end; diff --git a/src/ce_main.pas b/src/ce_main.pas index 2c78983c..ba6025b6 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -10,7 +10,7 @@ uses Dialogs, Menus, ActnList, ExtCtrls, process, XMLPropStorage, dynlibs, ce_common, ce_dmdwrap, ce_project, ce_dcd, ce_plugin, ce_synmemo, ce_widget, ce_messages, ce_interfaces, ce_editor, ce_projinspect, ce_projconf, ce_search, - ce_staticexplorer, ce_miniexplorer, ce_libman, ce_libmaneditor, ce_customtools, + ce_staticexplorer, ce_miniexplorer, ce_libman, ce_libmaneditor, ce_observer, ce_writableComponent, ce_toolseditor, ce_procinput, ce_cdbcmd; type @@ -193,7 +193,6 @@ type {$IFDEF WIN32} fCdbWidg: TCECdbWidget; {$ENDIF} - fTools: TCETools; fRunProc: TCheckedAsyncProcess; @@ -221,8 +220,6 @@ type //Init - Fina procedure getCMdParams; procedure checkCompilo; - procedure InitLibMan; - procedure InitTools; procedure InitMRUs; procedure InitWidgets; procedure InitPlugins; @@ -278,7 +275,6 @@ type procedure openFile(const aFilename: string); // property WidgetList: TCEWidgetList read fWidgList; - property CustomTools: TCETools read fTools; end; procedure PlugDispatchToHost(aPlugin: TCEPlugin; opCode: LongWord; data0: Integer; data1, data2: Pointer); cdecl; @@ -301,9 +297,6 @@ begin EntitiesConnector.addObserver(self); // InitMRUs; - InitLibMan; - InitTools; - // InitWidgets; InitDocking; InitSettings; @@ -374,25 +367,6 @@ begin end; end; -procedure TCEMainForm.InitLibMan; -var - fname: string; -begin - fname := getDocPath + 'libraryManager.txt'; - if fileExists(fname) then - LibMan.loadFromFile(fname); -end; - -procedure TCEMainForm.InitTools; -var - fname: string; -begin - fTools := TCETools.create(self); - fname := getDocPath + 'tools.txt'; - if fileExists(fname) then - fTools.loadFromFile(fname); -end; - procedure TCEMainForm.InitMRUs; begin fProjMru := TMruFileList.Create; @@ -576,8 +550,6 @@ begin opts := TCEOptions.create(nil); try forceDirectory(getDocPath); - LibMan.saveToFile(getDocPath + 'libraryManager.txt'); - fTools.saveToFile(getDocPath + 'tools.txt'); opts.saveToFile(getDocPath + 'options2.txt'); finally opts.Free; @@ -1538,7 +1510,6 @@ procedure TCEMainForm.newProj; begin fProject := TCEProject.Create(nil); fProject.Name := 'CurrentProject'; - fProject.libraryManager := LibMan; end; procedure TCEMainForm.saveProj; diff --git a/src/ce_project.pas b/src/ce_project.pas index fe87c11d..26e8c85b 100644 --- a/src/ce_project.pas +++ b/src/ce_project.pas @@ -9,7 +9,7 @@ uses LclProc, {$ENDIF} Classes, SysUtils, process, asyncprocess, strUtils, ce_common, ce_writableComponent, - ce_dmdwrap, ce_libman, ce_observer; + ce_dmdwrap, ce_observer; type @@ -31,7 +31,6 @@ type fOptsColl: TCollection; fSrcs, fSrcsCop: TStringList; fConfIx: Integer; - fLibMan: TLibraryManager; fChangedCount: NativeInt; fProjectSubject: TCECustomSubject; fRunner: TCheckedAsyncProcess; @@ -80,7 +79,6 @@ type function runProject(const runArgs: string = ''): Boolean; function compileProject: Boolean; // - property libraryManager: TLibraryManager read fLibMan write fLibMan; property configuration[ix: integer]: TCompilerConfiguration read getConfig; property currentConfiguration: TCompilerConfiguration read getCurrConf; property onChange: TNotifyEvent read fOnChange write fOnChange; @@ -92,7 +90,7 @@ type implementation uses - ce_interfaces, controls, dialogs, ce_symstring; + ce_interfaces, controls, dialogs, ce_symstring, ce_libman; constructor TCEProject.create(aOwner: TComponent); begin @@ -321,11 +319,8 @@ begin aList.Add(abs); // process.inc ln 249. double quotes are added if there's a space. end; // - if fLibMan <> nil then - begin - fLibMan.getLibFiles(fLibAliases, aList); - fLibMan.getLibSources(fLibAliases, aList); - end; + LibMan.getLibFiles(fLibAliases, aList); + LibMan.getLibSources(fLibAliases, aList); // TCompilerConfiguration(fOptsColl.Items[fConfIx]).getOpts(aList); end; diff --git a/src/ce_toolseditor.pas b/src/ce_toolseditor.pas index 477dc21c..a735af62 100644 --- a/src/ce_toolseditor.pas +++ b/src/ce_toolseditor.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs, - ExtCtrls, Menus, Buttons, StdCtrls, ce_widget; + ExtCtrls, Menus, Buttons, StdCtrls, ce_widget, ce_customtools; type @@ -34,9 +34,6 @@ type implementation {$R *.lfm} -uses - ce_main; - constructor TCEToolsEditorWidget.create(aOwner: TComponent); begin inherited; @@ -47,7 +44,7 @@ procedure TCEToolsEditorWidget.updateNames; var i: Integer; begin - with CEMainForm do for i := 0 to CustomTools.tools.Count-1 do + for i := 0 to CustomTools.tools.Count-1 do lstTools.Items.Strings[i] := CustomTools.tool[i].toolAlias; end; @@ -59,7 +56,7 @@ begin propsEd.ItemIndex := -1; lstTools.Clear; // - with CEMainForm do for i := 0 to CustomTools.tools.Count-1 do + for i := 0 to CustomTools.tools.Count-1 do lstTools.AddItem(CustomTools.tool[i].toolAlias, nil); if lstTools.Count > 0 then lstTools.ItemIndex := 0; @@ -70,22 +67,20 @@ procedure TCEToolsEditorWidget.lstToolsSelectionChange(Sender: TObject; begin if lstTools.ItemIndex = -1 then exit; - - propsEd.TIObject := CEMainForm.CustomTools.tool[lstTools.ItemIndex]; + propsEd.TIObject := CustomTools.tool[lstTools.ItemIndex]; end; procedure TCEToolsEditorWidget.propsEdModified(Sender: TObject); begin if propsEd.ItemIndex = -1 then exit; - // if propsEd.Rows[propsEd.ItemIndex].Name = 'toolAlias' then updateNames; end; procedure TCEToolsEditorWidget.BtnAddToolClick(Sender: TObject); begin - CEMainForm.CustomTools.addTool; + CustomTools.addTool; DataToGui; end; @@ -93,8 +88,7 @@ procedure TCEToolsEditorWidget.btnRemToolClick(Sender: TObject); begin if lstTools.ItemIndex = -1 then exit; - // - CEMainForm.CustomTools.tools.Delete(lstTools.ItemIndex); + CustomTools.tools.Delete(lstTools.ItemIndex); DataToGui; end; @@ -102,8 +96,7 @@ procedure TCEToolsEditorWidget.btnRunClick(Sender: TObject); begin if lstTools.ItemIndex = -1 then exit; - // - CEMainForm.CustomTools.tool[lstTools.ItemIndex].execute; + CustomTools.tool[lstTools.ItemIndex].execute; end; end.