From 3930aa1772e3b2c3e13a3d43653053e009eac25b Mon Sep 17 00:00:00 2001 From: dmitry Date: Thu, 7 Nov 2019 04:04:38 +0000 Subject: [PATCH] cocoa: adding menu hijack specific handling of quite menu command. bug #36265 git-svn-id: trunk@62215 - --- lcl/interfaces/cocoa/cocoaint.pas | 7 +++++++ lcl/interfaces/cocoa/cocoawsmenus.pas | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 19d13e9fb2..776ba126d6 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -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} diff --git a/lcl/interfaces/cocoa/cocoawsmenus.pas b/lcl/interfaces/cocoa/cocoawsmenus.pas index a5f8ebaee0..e713fe1669 100644 --- a/lcl/interfaces/cocoa/cocoawsmenus.pas +++ b/lcl/interfaces/cocoa/cocoawsmenus.pas @@ -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;