TCETools class, data part of the custom tools

This commit is contained in:
Basile Burg 2014-08-18 06:03:05 +02:00
parent 3d887a3669
commit 094a7d7ece
5 changed files with 118 additions and 35 deletions

View File

@ -14,72 +14,137 @@ type
fExecutable: string; fExecutable: string;
fWorkingDir: string; fWorkingDir: string;
fShowWin: TShowWindowOptions; fShowWin: TShowWindowOptions;
fProcess: TProcess; fOpts: TProcessOptions;
function getParameters: TStringList; fParameters: TStringList;
fName: string;
procedure setParameters(const aValue: TStringList); procedure setParameters(const aValue: TStringList);
published published
property name: string read fName write fName;
property options: TProcessOptions read fOpts write fOpts;
property executable: string read fExecutable write fExecutable; property executable: string read fExecutable write fExecutable;
property workingDirectory: string read fWorkingDir write fWorkingDir; property workingDirectory: string read fWorkingDir write fWorkingDir;
property parameters: TStringList read getParameters write setParameters; property parameters: TStringList read fParameters write setParameters;
property showWindows: TShowWindowOptions read fShowWin write fShowWin; property showWindows: TShowWindowOptions read fShowWin write fShowWin;
public public
constructor create(ACollection: TCollection); override; constructor create(ACollection: TCollection); override;
destructor destroy; override; destructor destroy; override;
// //
property process: TProcess read fProcess;
procedure execute; procedure execute;
end; end;
TCETools = class(TCollection) TCETools = class(TComponent)
private private
function getItem(index: Integer): TCEToolItem; fTools: TCollection;
function getTool(index: Integer): TCEToolItem;
procedure setTools(const aValue: TCollection);
procedure readerPropNoFound(Reader: TReader; Instance: TPersistent;
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
procedure readerError(Reader: TReader; const Message: string;
var Handled: Boolean);
published
property tools: TCollection read fTools write setTools;
public public
constructor create(itemClass: TCollectionItem) override; constructor create(aOwner: TComponent); override;
destructor destroy; override;
procedure saveToFile(const aFilename: string);
procedure loadFromFile(const aFilename: string);
// //
property tool[index: integer]: TCEToolItem read getItem; function addTool: TCEToolItem;
property tool[index: integer]: TCEToolItem read getTool;
end; end;
implementation implementation
uses uses
CEMainForm; ce_main, ce_messages;
constructor TCEToolItem.create(ACollection: TCollection); constructor TCEToolItem.create(ACollection: TCollection);
begin begin
inherited; inherited;
fProcess := TProcess.Create(nil); fName := format('<tool %d>', [ID]);
fParameters := TStringList.create;
end; end;
destructor TCEToolItem.destroy; destructor TCEToolItem.destroy;
begin begin
fProcess.Free; fParameters.Free;
inherited; inherited;
end; end;
function TCEToolItem.getParameters: TStringList;
begin
result := fProcess.Parameters;
end;
procedure TCEToolItem.setParameters(const aValue: TStringList); procedure TCEToolItem.setParameters(const aValue: TStringList);
begin begin
fProcess.Parameters.Assign(aValue); fParameters.Assign(aValue);
end; end;
procedure TCEToolItem.execute; procedure TCEToolItem.execute;
var
i: Integer;
proc: TProcess;
begin begin
proc := TProcess.Create(nil);
try
proc.Options := fOpts;
proc.Executable := CEMainForm.expandSymbolicString(fExecutable);
proc.ShowWindow := fShowWin;
proc.CurrentDirectory := CEMainForm.expandSymbolicString(fWorkingDir);
proc.Parameters.Clear;
for i:= 0 to fParameters.Count-1 do
proc.Parameters.Add(CEMainForm.expandSymbolicString(fParameters.Strings[i]));
proc.Options := proc.Options - [poUsePipes, poWaitOnExit];
proc.Execute;
finally
proc.Free;
end;
end; end;
constructor TCETools.create(itemClass: TCollectionItem) override; constructor TCETools.create(aOwner: TComponent);
begin begin
inherited create(itemClass); inherited;
fTools := TCollection.Create(TCEToolItem);
end; end;
function TCETools.getItem(index: Integer): TCEToolItem; destructor TCETools.destroy;
begin begin
exit(TCEToolItem(Items[index])); fTools.Free;
inherited;
end;
procedure TCETools.setTools(const aValue: TCollection);
begin
fTools.Assign(aValue);
end;
function TCETools.getTool(index: Integer): TCEToolItem;
begin
result := TCEToolItem(fTools.Items[index]);
end;
function TCETools.addTool: TCEToolItem;
begin
result := TCEToolItem(fTools.Add);
end;
procedure TCETools.readerPropNoFound(Reader: TReader; Instance: TPersistent;
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
begin
Skip := true;
Handled := false;
end;
procedure TCETools.readerError(Reader: TReader; const Message: string;
var Handled: Boolean);
begin
Handled := true;
end;
procedure TCETools.loadFromFile(const aFilename: string);
begin
loadCompFromTxtFile(self, aFilename, @readerPropNoFound, @readerError);
end;
procedure TCETools.saveToFile(const aFilename: string);
begin
saveCompToTxtFile(self, aFilename);
end; end;
end. end.

View File

@ -73,7 +73,6 @@ begin
DCD_server.ShowWindow := swoHIDE; DCD_server.ShowWindow := swoHIDE;
end; end;
//TODO-cfeature:remove import, e.g: when libman entries are modified.
procedure addDcdImport(const aFilename: string); procedure addDcdImport(const aFilename: string);
begin begin
if not dcdOn then exit; if not dcdOn then exit;

View File

@ -707,7 +707,8 @@ var
idt: string; idt: string;
begin begin
if fDbg then aList.Add('-debug'); if fDbg then aList.Add('-debug');
if fDbgLevel <> 0 then aList.Add('-debug=' + intToStr(fDbgLevel)); if fDbgLevel <> 0 then
aList.Add('-debug=' + intToStr(fDbgLevel));
for idt in fDbgIdents do for idt in fDbgIdents do
aList.Add('-debug=' + idt); aList.Add('-debug=' + idt);
if fDbgD then aList.Add('-g'); if fDbgD then aList.Add('-g');
@ -811,8 +812,10 @@ begin
aList.Add('-I'+ str); aList.Add('-I'+ str);
for str in fImpt do if str <> '' then for str in fImpt do if str <> '' then
aList.Add('-J'+ str); aList.Add('-J'+ str);
if fFname <> '' then aList.Add('-of' + fFname); if fFname <> '' then
if fObjDir <> '' then aList.Add('-od' + fObjDir); aList.Add('-of' + fFname);
if fObjDir <> '' then
aList.Add('-od' + fObjDir);
end; end;
procedure TPathsOpts.assign(aValue: TPersistent); procedure TPathsOpts.assign(aValue: TPersistent);
@ -1077,9 +1080,11 @@ end;
procedure TCompilerConfiguration.setName(const aValue: string); procedure TCompilerConfiguration.setName(const aValue: string);
begin begin
if fName = aValue then exit; if fName = aValue then
exit;
fName := aValue; fName := aValue;
if fName = '' then fName := nameFromID; if fName = '' then
fName := nameFromID;
Changed(true); Changed(true);
doChanged; doChanged;
end; end;

View File

@ -10,14 +10,17 @@ uses
Dialogs, Menus, ActnList, ExtCtrls, process, XMLPropStorage, ComCtrls, dynlibs, Dialogs, Menus, ActnList, ExtCtrls, process, XMLPropStorage, ComCtrls, 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_widgettypes, ce_editor, ce_projinspect, ce_projconf, ce_search, ce_messages, ce_widgettypes, ce_editor, ce_projinspect, ce_projconf, ce_search,
ce_staticexplorer, ce_miniexplorer, ce_libman, ce_libmaneditor; ce_staticexplorer, ce_miniexplorer, ce_libman, ce_libmaneditor, ce_customtools;
type type
TCEMainForm = class; TCEMainForm = class;
//TODO-cfeature: options // TODO-cfeature: input handling
//TODO-cwidget: options editor // TODO-cfeature: options
// TODO-cwidget: options editor
// TODO-cwidget: custom tools editor
// TODO-cfeature: tools menu
(** (**
* Encapsulates the options in a writable component. * Encapsulates the options in a writable component.
*) *)
@ -223,11 +226,13 @@ type
fProjMru: TMruFileList; fProjMru: TMruFileList;
fFileMru: TMruFileList; fFileMru: TMruFileList;
fLibMan: TLibraryManager; fLibMan: TLibraryManager;
fTools: TCETools;
//Init - Fina //Init - Fina
procedure getCMdParams; procedure getCMdParams;
procedure checkCompilo; procedure checkCompilo;
procedure InitLibMan; procedure InitLibMan;
procedure InitTools;
procedure InitMRUs; procedure InitMRUs;
procedure InitWidgets; procedure InitWidgets;
procedure InitPlugins; procedure InitPlugins;
@ -306,6 +311,7 @@ begin
// //
InitMRUs; InitMRUs;
InitLibMan; InitLibMan;
InitTools;
InitWidgets; InitWidgets;
InitDocking; InitDocking;
InitSettings; InitSettings;
@ -313,7 +319,6 @@ begin
newProj; newProj;
checkCompilo; checkCompilo;
getCMdParams; getCMdParams;
end; end;
procedure TCEMainForm.checkCompilo; procedure TCEMainForm.checkCompilo;
@ -383,6 +388,16 @@ begin
fLibMan.loadFromFile(fname); fLibMan.loadFromFile(fname);
end; 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;
@ -552,6 +567,7 @@ begin
try try
forceDirectory(getDocPath); forceDirectory(getDocPath);
fLibMan.saveToFile(getDocPath + 'libraryManager.txt'); fLibMan.saveToFile(getDocPath + 'libraryManager.txt');
fTools.saveToFile(getDocPath + 'tools.txt');
opts.saveToFile(getDocPath + 'options.txt'); opts.saveToFile(getDocPath + 'options.txt');
finally finally
opts.Free; opts.Free;
@ -1236,7 +1252,6 @@ begin
end; end;
end; end;
// TODO-cfeature: input handling
procedure TCEMainForm.compileAndRunFile(const edIndex: NativeInt; const runArgs: string = ''); procedure TCEMainForm.compileAndRunFile(const edIndex: NativeInt; const runArgs: string = '');
var var
editor: TCESynMemo; editor: TCESynMemo;

View File

@ -67,5 +67,4 @@ type
end; end;
implementation implementation
end. end.