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;
fWorkingDir: string;
fShowWin: TShowWindowOptions;
fProcess: TProcess;
function getParameters: TStringList;
fOpts: TProcessOptions;
fParameters: TStringList;
fName: string;
procedure setParameters(const aValue: TStringList);
published
property name: string read fName write fName;
property options: TProcessOptions read fOpts write fOpts;
property executable: string read fExecutable write fExecutable;
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;
public
constructor create(ACollection: TCollection); override;
destructor destroy; override;
//
property process: TProcess read fProcess;
procedure execute;
end;
TCETools = class(TCollection)
TCETools = class(TComponent)
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
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;
implementation
uses
CEMainForm;
ce_main, ce_messages;
constructor TCEToolItem.create(ACollection: TCollection);
begin
inherited;
fProcess := TProcess.Create(nil);
fName := format('<tool %d>', [ID]);
fParameters := TStringList.create;
end;
destructor TCEToolItem.destroy;
begin
fProcess.Free;
fParameters.Free;
inherited;
end;
function TCEToolItem.getParameters: TStringList;
begin
result := fProcess.Parameters;
end;
procedure TCEToolItem.setParameters(const aValue: TStringList);
begin
fProcess.Parameters.Assign(aValue);
fParameters.Assign(aValue);
end;
procedure TCEToolItem.execute;
var
i: Integer;
proc: TProcess;
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;
constructor TCETools.create(itemClass: TCollectionItem) override;
constructor TCETools.create(aOwner: TComponent);
begin
inherited create(itemClass);
inherited;
fTools := TCollection.Create(TCEToolItem);
end;
function TCETools.getItem(index: Integer): TCEToolItem;
destructor TCETools.destroy;
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.

View File

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

View File

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

View File

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

View File

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