tools, add a option to ask a confirmation, close #140

This commit is contained in:
Basile Burg 2017-04-29 10:17:01 +02:00
parent 63a5a68670
commit 359f107213
No known key found for this signature in database
GPG Key ID: 1868039F415CB8CF
1 changed files with 12 additions and 6 deletions

View File

@ -5,9 +5,9 @@ unit ce_tools;
interface interface
uses uses
Classes, SysUtils, LazFileUtils, process, menus, ce_processes, Classes, SysUtils, LazFileUtils, process, menus, ce_processes, controls,
ce_common, ce_writableComponent, ce_interfaces, ce_observer, ce_inspectors, ce_common, ce_writableComponent, ce_interfaces, ce_observer, ce_inspectors,
ce_synmemo; ce_synmemo, ce_dialogs;
type type
@ -33,6 +33,7 @@ type
fMsgs: ICEMessagesDisplay; fMsgs: ICEMessagesDisplay;
fSymStringExpander: ICESymStringExpander; fSymStringExpander: ICESymStringExpander;
fPipeInputKind: TPipeInputKind; fPipeInputKind: TPipeInputKind;
fAskConfirmation: boolean;
procedure setParameters(value: TStringList); procedure setParameters(value: TStringList);
procedure processOutput(sender: TObject); procedure processOutput(sender: TObject);
procedure setToolAlias(value: string); procedure setToolAlias(value: string);
@ -49,11 +50,11 @@ type
property nextToolAlias: string read fNextToolAlias write fNextToolAlias; property nextToolAlias: string read fNextToolAlias write fNextToolAlias;
property outputToNext: boolean read fOutputToNext write fOutputToNext; property outputToNext: boolean read fOutputToNext write fOutputToNext;
property pipeInputKind: TPipeInputKind read fPipeInputKind write fPipeInputKind; property pipeInputKind: TPipeInputKind read fPipeInputKind write fPipeInputKind;
property askConfirmation: boolean read fAskConfirmation write fAskConfirmation;
public public
constructor create(ACollection: TCollection); override; constructor create(ACollection: TCollection); override;
destructor destroy; override; destructor destroy; override;
procedure assign(Source: TPersistent); override; procedure assign(Source: TPersistent); override;
//
procedure execute(previous: TCEToolItem); procedure execute(previous: TCEToolItem);
property process: TCEProcess read fProcess; property process: TCEProcess read fProcess;
end; end;
@ -148,7 +149,6 @@ begin
if Source is TCEToolItem then if Source is TCEToolItem then
begin begin
tool := TCEToolItem(Source); tool := TCEToolItem(Source);
//
toolAlias := tool.toolAlias; toolAlias := tool.toolAlias;
queryParameters := tool.queryParameters; queryParameters := tool.queryParameters;
clearMessages := tool.clearMessages; clearMessages := tool.clearMessages;
@ -157,6 +157,7 @@ begin
workingDirectory := tool.workingDirectory; workingDirectory := tool.workingDirectory;
showWindows := tool.showWindows; showWindows := tool.showWindows;
pipeInputKind := tool.pipeInputKind; pipeInputKind := tool.pipeInputKind;
askConfirmation := tool.askConfirmation;
parameters.Assign(tool.parameters); parameters.Assign(tool.parameters);
end end
else inherited; else inherited;
@ -185,16 +186,21 @@ var
prm: string; prm: string;
inp: string; inp: string;
old: string; old: string;
const
confSpec = 'Are you sure you want to execute the "%s" tool ?';
begin begin
ce_processes.killProcess(fProcess); ce_processes.killProcess(fProcess);
//
if fMsgs = nil then if fMsgs = nil then
fMsgs := getMessageDisplay; fMsgs := getMessageDisplay;
if fClearMessages then if fClearMessages then
fMsgs.clearByContext(amcMisc); fMsgs.clearByContext(amcMisc);
if fSymStringExpander = nil then if fSymStringExpander = nil then
fSymStringExpander:= getSymStringExpander; fSymStringExpander:= getSymStringExpander;
//
if askConfirmation and (dlgOkCancel(format(confSpec, [toolAlias])) <> mrOk) then
exit;
old := GetCurrentDirUTF8; old := GetCurrentDirUTF8;
fProcess := TCEProcess.Create(nil); fProcess := TCEProcess.Create(nil);
fProcess.OnReadData:= @processOutput; fProcess.OnReadData:= @processOutput;