From 0e07a10a03896ecfc1378e9d93d39c6e7a3205db Mon Sep 17 00:00:00 2001 From: juha Date: Tue, 31 Oct 2017 21:13:40 +0000 Subject: [PATCH] IdeIntf: New notify handler RunFinished. Issue #32617, patch from Pascal Riekenberg. git-svn-id: trunk@56254 - --- .gitattributes | 1 + components/ideintf/lazideintf.pas | 27 +++++++++++++-- ide/debugmanager.pas | 1 + ide/main.pp | 8 ++--- ide/notifyprocessend.pas | 56 +++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 ide/notifyprocessend.pas diff --git a/.gitattributes b/.gitattributes index 1a827e662c..d8e29aed2f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6592,6 +6592,7 @@ ide/newdialog.lfm svneol=native#text/plain ide/newdialog.pas svneol=native#text/pascal ide/newprojectdlg.lfm svneol=native#text/plain ide/newprojectdlg.pp svneol=native#text/pascal +ide/notifyprocessend.pas svneol=native#text/pascal ide/objectlists.pas svneol=native#text/pascal ide/patheditordlg.lfm svneol=native#text/pascal ide/patheditordlg.pas svneol=native#text/pascal diff --git a/components/ideintf/lazideintf.pas b/components/ideintf/lazideintf.pas index 73a40cfe4a..1e92ad8a79 100644 --- a/components/ideintf/lazideintf.pas +++ b/components/ideintf/lazideintf.pas @@ -246,7 +246,8 @@ type lihtGetFPCFrontEndPath, // called when the IDE gets the path of the 'fpc' front end tool lihtShowDesignerFormOfSource, // called after showing a designer form for code editor (AEditor can be nil!) lihtShowSourceOfActiveDesignerForm, // called after showing a code of designer form - lihtChangeToolStatus//called when IDEToolStatus has changed (e.g. itNone->itBuilder etc.) + lihtChangeToolStatus, //called when IDEToolStatus has changed (e.g. itNone->itBuilder etc.) + lihtRunFinished //called when ran program finishes ); TLazToolStatus = ( @@ -377,6 +378,7 @@ type function GetProjectFileForProjectEditor(AEditor: TSourceEditorInterface): TLazProjectFile; virtual; abstract; function DoCallProjectChangedHandler(HandlerType: TLazarusIDEHandlerType; AProject: TLazProject): TModalResult; + procedure DoCallRunFinishedHandler; function DoAddUnitToProject(AEditor: TSourceEditorInterface): TModalResult; virtual; abstract; // configs @@ -512,8 +514,7 @@ type function CallHandlerGetFPCFrontEndParams(Sender: TObject; var Params: string): boolean; procedure AddHandlerGetFPCFrontEndPath( const Handler: TGetFPCFrontEndPath; AsLast: boolean = false); - procedure RemoveHandlerGetFPCFrontEndPath( - const Handler: TGetFPCFrontEndPath); + procedure RemoveHandlerGetFPCFrontEndPath(const Handler: TGetFPCFrontEndPath); function CallHandlerGetFPCFrontEndPath(Sender: TObject; var Path: string): boolean; procedure AddHandlerOnShowDesignerFormOfSource( const OnShowDesignerFormOfSourceEvent: TShowDesignerFormOfSourceFunction; @@ -530,6 +531,9 @@ type AsLast: boolean = false); procedure RemoveHandlerOnChangeToolStatus( const OnChangeToolStatus: TLazToolStatusChangeEvent); + procedure AddHandlerOnRunFinished(const OnRunFinishedEvent: TNotifyEvent; + AsLast: boolean = false); + procedure RemoveHandlerOnRunFinished(const OnRunFinishedEvent: TNotifyEvent); property IDEStarted: boolean read FIDEStarted; property IDEIsClosing: boolean read FIDEIsClosing; @@ -765,6 +769,11 @@ begin end; end; +procedure TLazIDEInterface.DoCallRunFinishedHandler; +begin + DoCallNotifyHandler(lihtRunFinished); +end; + procedure TLazIDEInterface.RemoveAllHandlersOfObject(AnObject: TObject); var HandlerType: TLazarusIDEHandlerType; @@ -995,6 +1004,18 @@ begin RemoveHandler(lihtChangeToolStatus,TMethod(OnChangeToolStatus)); end; +procedure TLazIDEInterface.AddHandlerOnRunFinished( + const OnRunFinishedEvent: TNotifyEvent; AsLast: boolean); +begin + AddHandler(lihtRunFinished,TMethod(OnRunFinishedEvent),AsLast); +end; + +procedure TLazIDEInterface.RemoveHandlerOnRunFinished( + const OnRunFinishedEvent: TNotifyEvent); +begin + RemoveHandler(lihtRunFinished,TMethod(OnRunFinishedEvent)); +end; + function TLazIDEInterface.CallHandlerGetFPCFrontEndPath(Sender: TObject; var Path: string): boolean; var diff --git a/ide/debugmanager.pas b/ide/debugmanager.pas index 05fed5ccd3..6134de829e 100644 --- a/ide/debugmanager.pas +++ b/ide/debugmanager.pas @@ -1250,6 +1250,7 @@ begin FPrevShownWindow:=0; if (OldState<>dsIdle) then begin + MainIDE.DoCallRunFinishedHandler; if EnvironmentOptions.DebuggerShowStopMessage then begin MsgResult:=IDEQuestionDialog(lisExecutionStopped, diff --git a/ide/main.pp b/ide/main.pp index 20588ab201..7b32821b27 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -59,7 +59,7 @@ uses MemCheck, {$ENDIF} // fpc packages - Math, Classes, SysUtils, TypInfo, types, strutils, Laz_AVL_Tree, + Math, Classes, SysUtils, TypInfo, types, strutils, process, Laz_AVL_Tree, // LCL LCLProc, LCLType, LCLIntf, LResources, HelpIntfs, InterfaceBase, LCLPlatformDef, ComCtrls, Forms, Buttons, Menus, Controls, GraphType, Graphics, ExtCtrls, @@ -155,7 +155,7 @@ uses CleanDirDlg, CodeContextForm, AboutFrm, CompatibilityRestrictions, RestrictionBrowser, ProjectWizardDlg, IDECmdLine, IDEGuiCmdLine, CodeExplOpts, EditorMacroListViewer, SourceFileManager, EditorToolbarStatic, - IDEInstances, process, + IDEInstances, NotifyProcessEnd, // main ide MainBar, MainIntf, MainBase; @@ -7092,8 +7092,8 @@ begin Exit(mrNone); end; - Process.Execute; - finally + TNotifyProcessEnd.Create(Process, @DoCallRunFinishedHandler); + except Process.Free; end; end; diff --git a/ide/notifyprocessend.pas b/ide/notifyprocessend.pas new file mode 100644 index 0000000000..6b967d0361 --- /dev/null +++ b/ide/notifyprocessend.pas @@ -0,0 +1,56 @@ +{ + ***************************************************************************** + See the file COPYING.modifiedLGPL.txt, included in this distribution, + for details about the license. + ***************************************************************************** + + Author: Pascal Riekenberg + + Abstract: + Provides a general classes for calling an event when a process ends +} +unit NotifyProcessEnd; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, process; + +type + { TNotifyProcessEnd } + + TNotifyProcessEnd = class(TThread) + private + fEvent: TThreadMethod; + fProcess: TProcess; + protected + procedure Execute; override; + public + constructor Create(pProcess: TProcess; pEvent: TThreadMethod); + end; + +implementation + +{ TNotifyProcessEnd } + +procedure TNotifyProcessEnd.Execute; +begin + fProcess.Execute; + Synchronize(fEvent); + fProcess.Free; +end; + +constructor TNotifyProcessEnd.Create(pProcess: TProcess; pEvent: TThreadMethod); +begin + inherited Create(True); + fProcess := pProcess; + fProcess.Options := fProcess.Options + [poWaitOnExit]; + fEvent := pEvent; + FreeOnTerminate := True; + Start; +end; + +end. +