From 0cb3aaf4e0cde59f7318ffe26e093e2a3f5fbdfd Mon Sep 17 00:00:00 2001 From: Pale Moon Date: Thu, 30 Nov 2017 21:23:30 +0100 Subject: [PATCH] Mac: Re-initialize the Native Application Menu on run. This resolves #1511. --- widget/cocoa/nsAppShell.mm | 2 ++ widget/cocoa/nsMenuBarX.h | 1 + widget/cocoa/nsMenuBarX.mm | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/widget/cocoa/nsAppShell.mm b/widget/cocoa/nsAppShell.mm index 4b8db6144c..6f2b572ccf 100644 --- a/widget/cocoa/nsAppShell.mm +++ b/widget/cocoa/nsAppShell.mm @@ -28,6 +28,7 @@ #include "nsCocoaFeatures.h" #include "nsCocoaUtils.h" #include "nsChildView.h" +#include "nsMenuBarX.h" #include "nsToolkit.h" #include "TextInputHandler.h" #include "mozilla/HangMonitor.h" @@ -647,6 +648,7 @@ nsAppShell::Run(void) mStarted = true; AddScreenWakeLockListener(); + nsMenuBarX::ResetNativeApplicationMenu(); NS_OBJC_TRY_ABORT([NSApp run]); diff --git a/widget/cocoa/nsMenuBarX.h b/widget/cocoa/nsMenuBarX.h index 339b8a5f9d..dfe99a4068 100644 --- a/widget/cocoa/nsMenuBarX.h +++ b/widget/cocoa/nsMenuBarX.h @@ -127,6 +127,7 @@ public: void ForceUpdateNativeMenuAt(const nsAString& indexString); void ForceNativeMenuReload(); // used for testing static char GetLocalizedAccelKey(const char *shortcutID); + static void ResetNativeApplicationMenu(); protected: void ConstructNativeMenus(); diff --git a/widget/cocoa/nsMenuBarX.mm b/widget/cocoa/nsMenuBarX.mm index 4d973f8d58..3cef3ff3a9 100644 --- a/widget/cocoa/nsMenuBarX.mm +++ b/widget/cocoa/nsMenuBarX.mm @@ -498,6 +498,14 @@ char nsMenuBarX::GetLocalizedAccelKey(const char *shortcutID) return retval; } +/* static */ +void nsMenuBarX::ResetNativeApplicationMenu() +{ + [sApplicationMenu removeAllItems]; + [sApplicationMenu release]; + sApplicationMenu = nil; +} + // Hide the item in the menu by setting the 'hidden' attribute. Returns it in |outHiddenNode| so // the caller can hang onto it if they so choose. It is acceptable to pass nsull // for |outHiddenNode| if the caller doesn't care about the hidden node.