IdeIntf: New notify handler RunFinished. Issue #32617, patch from Pascal Riekenberg.

git-svn-id: trunk@56254 -
This commit is contained in:
juha 2017-10-31 21:13:40 +00:00
parent 98765f8769
commit 0e07a10a03
5 changed files with 86 additions and 7 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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

View File

@ -1250,6 +1250,7 @@ begin
FPrevShownWindow:=0;
if (OldState<>dsIdle)
then begin
MainIDE.DoCallRunFinishedHandler;
if EnvironmentOptions.DebuggerShowStopMessage
then begin
MsgResult:=IDEQuestionDialog(lisExecutionStopped,

View File

@ -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;

56
ide/notifyprocessend.pas Normal file
View File

@ -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.