cocoa: adding menu hijack specific handling of quite menu command. bug #36265

git-svn-id: trunk@62215 -
This commit is contained in:
dmitry 2019-11-07 04:04:38 +00:00
parent 2fd870c40a
commit 3930aa1772
2 changed files with 14 additions and 0 deletions

View File

@ -243,6 +243,12 @@ var
// The icon would have to be changed manually. By default LCL behaviour is used
CocoaIconUse: Boolean = false;
{$ifdef COCOALOOPHIJACK}
// The flag is set to true once hi-jacked loop is finished (at the end of app)
// The flag is checked in Menus to avoid "double" Cmd+Q menu
LoopHiJackEnded : Boolean = false;
{$endif}
function CocoaScrollBarSetScrollInfo(bar: TCocoaScrollBar; const ScrollInfo: TScrollInfo): Integer;
function CocoaScrollBarGetScrollInfo(bar: TCocoaScrollBar; var ScrollInfo: TScrollInfo): Boolean;
procedure NSScrollerGetScrollInfo(docSz, pageSz: CGFloat; rl: NSSCroller; Var ScrollInfo: TScrollInfo);
@ -597,6 +603,7 @@ begin
Result := nil;
aloop();
stop(nil); // this should stop the main loop
LoopHiJackEnded := true;
exit;
end;
{$endif}

View File

@ -18,6 +18,7 @@ unit CocoaWSMenus;
{$mode objfpc}{$H+}
{$modeswitch objectivec2}
{$include cocoadefines.inc}
interface
@ -440,6 +441,12 @@ end;
procedure TCocoaMenuItem_Quit.lclItemSelected(sender: id);
begin
{$ifdef COCOALOOPHIJACK}
// see bug #36265. if hot-key (Cmd+Q) is used the menu item
// would be called once. 1) in LCL controlled loop 2) after the loop finished
// The following if statement prevents "double" form close
if LoopHiJackEnded then Exit;
{$endif}
// Should be used instead of Application.Terminate to allow events to be sent, see bug 32148
Application.MainForm.Close;
end;