refactored ce_customtools, global variable put off the less and less "main" form

This commit is contained in:
Basile Burg 2014-11-26 18:33:51 +01:00
parent 9a939ac470
commit fc98121147
6 changed files with 42 additions and 57 deletions

View File

@ -6,7 +6,7 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads} {$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$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; ce_dcd, ce_observer, ce_main, ce_writableComponent, ce_options, ce_symstring;
{$R *.res} {$R *.res}

View File

@ -5,8 +5,8 @@ unit ce_customtools;
interface interface
uses uses
Classes, SysUtils, process, asyncprocess, ce_common, ce_writableComponent, Classes, SysUtils, FileUtil, process, asyncprocess,
ce_interfaces, ce_observer; ce_common, ce_writableComponent, ce_interfaces, ce_observer;
type type
@ -53,6 +53,12 @@ type
property tool[index: integer]: TCEToolItem read getTool; property tool[index: integer]: TCEToolItem read getTool;
end; end;
const
toolsFname = 'tools.txt';
Var
CustomTools: TCETools;
implementation implementation
uses uses
@ -114,13 +120,19 @@ begin
end; end;
constructor TCETools.create(aOwner: TComponent); constructor TCETools.create(aOwner: TComponent);
var
fname: string;
begin begin
inherited; inherited;
fTools := TCollection.Create(TCEToolItem); fTools := TCollection.Create(TCEToolItem);
fname := getDocPath + toolsFname;
if fileExists(fname) then loadFromFile(fname)
end; end;
destructor TCETools.destroy; destructor TCETools.destroy;
begin begin
forceDirectory(getDocPath);
saveToFile(getDocPath + toolsFname);
fTools.Free; fTools.Free;
inherited; inherited;
end; end;
@ -142,4 +154,7 @@ end;
initialization initialization
RegisterClasses([TCEToolItem, TCETools]); RegisterClasses([TCEToolItem, TCETools]);
CustomTools := TCETools.create(nil);
finalization
CustomTools.Free;
end. end.

View File

@ -5,7 +5,7 @@ unit ce_libman;
interface interface
uses uses
Classes, SysUtils, ce_common, ce_writableComponent, ce_dcd; Classes, SysUtils, FileUtil, ce_common, ce_writableComponent, ce_dcd;
type type
@ -45,19 +45,30 @@ type
procedure updateDCD; procedure updateDCD;
end; end;
const
libFname = 'libraryManager.txt';
var var
LibMan: TLibraryManager; LibMan: TLibraryManager;
implementation implementation
constructor TLibraryManager.create(aOwner: TComponent); constructor TLibraryManager.create(aOwner: TComponent);
var
fName: string;
begin begin
inherited; inherited;
fCol := TCollection.Create(TLibraryItem); fCol := TCollection.Create(TLibraryItem);
fname := getDocPath + libFname;
if fileExists(fname) then loadFromFile(fname);
end; end;
destructor TLibraryManager.destroy; destructor TLibraryManager.destroy;
var
fName: string;
begin begin
forceDirectory(getDocPath);
LibMan.saveToFile(getDocPath + libFname);
fCol.Free; fCol.Free;
inherited; inherited;
end; end;

View File

@ -10,7 +10,7 @@ uses
Dialogs, Menus, ActnList, ExtCtrls, process, XMLPropStorage, dynlibs, Dialogs, Menus, ActnList, ExtCtrls, process, XMLPropStorage, dynlibs,
ce_common, ce_dmdwrap, ce_project, ce_dcd, ce_plugin, ce_synmemo, ce_widget, 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_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; ce_observer, ce_writableComponent, ce_toolseditor, ce_procinput, ce_cdbcmd;
type type
@ -193,7 +193,6 @@ type
{$IFDEF WIN32} {$IFDEF WIN32}
fCdbWidg: TCECdbWidget; fCdbWidg: TCECdbWidget;
{$ENDIF} {$ENDIF}
fTools: TCETools;
fRunProc: TCheckedAsyncProcess; fRunProc: TCheckedAsyncProcess;
@ -221,8 +220,6 @@ type
//Init - Fina //Init - Fina
procedure getCMdParams; procedure getCMdParams;
procedure checkCompilo; procedure checkCompilo;
procedure InitLibMan;
procedure InitTools;
procedure InitMRUs; procedure InitMRUs;
procedure InitWidgets; procedure InitWidgets;
procedure InitPlugins; procedure InitPlugins;
@ -278,7 +275,6 @@ type
procedure openFile(const aFilename: string); procedure openFile(const aFilename: string);
// //
property WidgetList: TCEWidgetList read fWidgList; property WidgetList: TCEWidgetList read fWidgList;
property CustomTools: TCETools read fTools;
end; end;
procedure PlugDispatchToHost(aPlugin: TCEPlugin; opCode: LongWord; data0: Integer; data1, data2: Pointer); cdecl; procedure PlugDispatchToHost(aPlugin: TCEPlugin; opCode: LongWord; data0: Integer; data1, data2: Pointer); cdecl;
@ -301,9 +297,6 @@ begin
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
// //
InitMRUs; InitMRUs;
InitLibMan;
InitTools;
//
InitWidgets; InitWidgets;
InitDocking; InitDocking;
InitSettings; InitSettings;
@ -374,25 +367,6 @@ begin
end; end;
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; procedure TCEMainForm.InitMRUs;
begin begin
fProjMru := TMruFileList.Create; fProjMru := TMruFileList.Create;
@ -576,8 +550,6 @@ begin
opts := TCEOptions.create(nil); opts := TCEOptions.create(nil);
try try
forceDirectory(getDocPath); forceDirectory(getDocPath);
LibMan.saveToFile(getDocPath + 'libraryManager.txt');
fTools.saveToFile(getDocPath + 'tools.txt');
opts.saveToFile(getDocPath + 'options2.txt'); opts.saveToFile(getDocPath + 'options2.txt');
finally finally
opts.Free; opts.Free;
@ -1538,7 +1510,6 @@ procedure TCEMainForm.newProj;
begin begin
fProject := TCEProject.Create(nil); fProject := TCEProject.Create(nil);
fProject.Name := 'CurrentProject'; fProject.Name := 'CurrentProject';
fProject.libraryManager := LibMan;
end; end;
procedure TCEMainForm.saveProj; procedure TCEMainForm.saveProj;

View File

@ -9,7 +9,7 @@ uses
LclProc, LclProc,
{$ENDIF} {$ENDIF}
Classes, SysUtils, process, asyncprocess, strUtils, ce_common, ce_writableComponent, Classes, SysUtils, process, asyncprocess, strUtils, ce_common, ce_writableComponent,
ce_dmdwrap, ce_libman, ce_observer; ce_dmdwrap, ce_observer;
type type
@ -31,7 +31,6 @@ type
fOptsColl: TCollection; fOptsColl: TCollection;
fSrcs, fSrcsCop: TStringList; fSrcs, fSrcsCop: TStringList;
fConfIx: Integer; fConfIx: Integer;
fLibMan: TLibraryManager;
fChangedCount: NativeInt; fChangedCount: NativeInt;
fProjectSubject: TCECustomSubject; fProjectSubject: TCECustomSubject;
fRunner: TCheckedAsyncProcess; fRunner: TCheckedAsyncProcess;
@ -80,7 +79,6 @@ type
function runProject(const runArgs: string = ''): Boolean; function runProject(const runArgs: string = ''): Boolean;
function compileProject: Boolean; function compileProject: Boolean;
// //
property libraryManager: TLibraryManager read fLibMan write fLibMan;
property configuration[ix: integer]: TCompilerConfiguration read getConfig; property configuration[ix: integer]: TCompilerConfiguration read getConfig;
property currentConfiguration: TCompilerConfiguration read getCurrConf; property currentConfiguration: TCompilerConfiguration read getCurrConf;
property onChange: TNotifyEvent read fOnChange write fOnChange; property onChange: TNotifyEvent read fOnChange write fOnChange;
@ -92,7 +90,7 @@ type
implementation implementation
uses uses
ce_interfaces, controls, dialogs, ce_symstring; ce_interfaces, controls, dialogs, ce_symstring, ce_libman;
constructor TCEProject.create(aOwner: TComponent); constructor TCEProject.create(aOwner: TComponent);
begin begin
@ -321,11 +319,8 @@ begin
aList.Add(abs); // process.inc ln 249. double quotes are added if there's a space. aList.Add(abs); // process.inc ln 249. double quotes are added if there's a space.
end; end;
// //
if fLibMan <> nil then LibMan.getLibFiles(fLibAliases, aList);
begin LibMan.getLibSources(fLibAliases, aList);
fLibMan.getLibFiles(fLibAliases, aList);
fLibMan.getLibSources(fLibAliases, aList);
end;
// //
TCompilerConfiguration(fOptsColl.Items[fConfIx]).getOpts(aList); TCompilerConfiguration(fOptsColl.Items[fConfIx]).getOpts(aList);
end; end;

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs,
ExtCtrls, Menus, Buttons, StdCtrls, ce_widget; ExtCtrls, Menus, Buttons, StdCtrls, ce_widget, ce_customtools;
type type
@ -34,9 +34,6 @@ type
implementation implementation
{$R *.lfm} {$R *.lfm}
uses
ce_main;
constructor TCEToolsEditorWidget.create(aOwner: TComponent); constructor TCEToolsEditorWidget.create(aOwner: TComponent);
begin begin
inherited; inherited;
@ -47,7 +44,7 @@ procedure TCEToolsEditorWidget.updateNames;
var var
i: Integer; i: Integer;
begin 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; lstTools.Items.Strings[i] := CustomTools.tool[i].toolAlias;
end; end;
@ -59,7 +56,7 @@ begin
propsEd.ItemIndex := -1; propsEd.ItemIndex := -1;
lstTools.Clear; 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); lstTools.AddItem(CustomTools.tool[i].toolAlias, nil);
if lstTools.Count > 0 then if lstTools.Count > 0 then
lstTools.ItemIndex := 0; lstTools.ItemIndex := 0;
@ -70,22 +67,20 @@ procedure TCEToolsEditorWidget.lstToolsSelectionChange(Sender: TObject;
begin begin
if lstTools.ItemIndex = -1 then if lstTools.ItemIndex = -1 then
exit; exit;
propsEd.TIObject := CustomTools.tool[lstTools.ItemIndex];
propsEd.TIObject := CEMainForm.CustomTools.tool[lstTools.ItemIndex];
end; end;
procedure TCEToolsEditorWidget.propsEdModified(Sender: TObject); procedure TCEToolsEditorWidget.propsEdModified(Sender: TObject);
begin begin
if propsEd.ItemIndex = -1 then if propsEd.ItemIndex = -1 then
exit; exit;
//
if propsEd.Rows[propsEd.ItemIndex].Name = 'toolAlias' then if propsEd.Rows[propsEd.ItemIndex].Name = 'toolAlias' then
updateNames; updateNames;
end; end;
procedure TCEToolsEditorWidget.BtnAddToolClick(Sender: TObject); procedure TCEToolsEditorWidget.BtnAddToolClick(Sender: TObject);
begin begin
CEMainForm.CustomTools.addTool; CustomTools.addTool;
DataToGui; DataToGui;
end; end;
@ -93,8 +88,7 @@ procedure TCEToolsEditorWidget.btnRemToolClick(Sender: TObject);
begin begin
if lstTools.ItemIndex = -1 then if lstTools.ItemIndex = -1 then
exit; exit;
// CustomTools.tools.Delete(lstTools.ItemIndex);
CEMainForm.CustomTools.tools.Delete(lstTools.ItemIndex);
DataToGui; DataToGui;
end; end;
@ -102,8 +96,7 @@ procedure TCEToolsEditorWidget.btnRunClick(Sender: TObject);
begin begin
if lstTools.ItemIndex = -1 then if lstTools.ItemIndex = -1 then
exit; exit;
// CustomTools.tool[lstTools.ItemIndex].execute;
CEMainForm.CustomTools.tool[lstTools.ItemIndex].execute;
end; end;
end. end.