From 6e8087a1b1ea3beb07317f1331cfb13a16722e9b Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 31 Oct 2022 15:27:26 +0100 Subject: [PATCH] macOS: Fix missing "Search" item in help menu Define the menu as the help menu directly in the the NSApplication, since the OS built-in heuristics based on the menu name easily fails. Fixes: QTCREATORBUG-24751 Change-Id: I9aa50a46099e295ec0c38ee8a9e88d75d41c74ad Reviewed-by: Timur Pocheptsov Reviewed-by: Qt CI Bot --- src/libs/utils/theme/theme.cpp | 7 +++++++ src/libs/utils/theme/theme.h | 3 +++ src/libs/utils/theme/theme_mac.h | 7 +++++++ src/libs/utils/theme/theme_mac.mm | 7 ++++++- src/plugins/coreplugin/mainwindow.cpp | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp index 0d0908c539a..54676b709cb 100644 --- a/src/libs/utils/theme/theme.cpp +++ b/src/libs/utils/theme/theme.cpp @@ -253,6 +253,13 @@ void Theme::setInitialPalette(Theme *initTheme) initialPalette(); } +void Theme::setHelpMenu(QMenu *menu) +{ +#ifdef Q_OS_MACOS + Internal::setMacOSHelpMenu(menu); +#endif +} + QPalette Theme::initialPalette() { static QPalette palette = copyPalette(QApplication::palette()); diff --git a/src/libs/utils/theme/theme.h b/src/libs/utils/theme/theme.h index effd69aa1f2..e60dc8417fd 100644 --- a/src/libs/utils/theme/theme.h +++ b/src/libs/utils/theme/theme.h @@ -9,6 +9,7 @@ #include QT_BEGIN_NAMESPACE +class QMenu; class QPalette; class QSettings; QT_END_NAMESPACE @@ -473,6 +474,8 @@ public: static void setInitialPalette(Theme *initTheme); + static void setHelpMenu(QMenu *menu); + protected: Theme(Theme *originTheme, QObject *parent = nullptr); ThemePrivate *d; diff --git a/src/libs/utils/theme/theme_mac.h b/src/libs/utils/theme/theme_mac.h index d64e92b164e..27eecd19fba 100644 --- a/src/libs/utils/theme/theme_mac.h +++ b/src/libs/utils/theme/theme_mac.h @@ -3,11 +3,18 @@ #pragma once +#include + +QT_BEGIN_NAMESPACE +class QMenu; +QT_END_NAMESPACE + namespace Utils { namespace Internal { void forceMacAppearance(bool dark); bool currentAppearanceIsDark(); +void setMacOSHelpMenu(QMenu *menu); } // Internal } // Utils diff --git a/src/libs/utils/theme/theme_mac.mm b/src/libs/utils/theme/theme_mac.mm index ea59bfb17e9..d732d7e4a9c 100644 --- a/src/libs/utils/theme/theme_mac.mm +++ b/src/libs/utils/theme/theme_mac.mm @@ -3,7 +3,7 @@ #include "theme_mac.h" -#include +#include #include #include @@ -47,5 +47,10 @@ bool currentAppearanceIsDark() return !currentAppearanceMatches(false /*==light*/); } +void setMacOSHelpMenu(QMenu *menu) +{ + NSApp.helpMenu = menu->toNSMenu(); +} + } // Internal } // Utils diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 54c0b38a72c..e71b0b1fc2f 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -514,6 +514,7 @@ void MainWindow::registerDefaultContainers() ac = ActionManager::createMenu(Constants::M_HELP); menubar->addMenu(ac, Constants::G_HELP); ac->menu()->setTitle(tr("&Help")); + Theme::setHelpMenu(ac->menu()); ac->appendGroup(Constants::G_HELP_HELP); ac->appendGroup(Constants::G_HELP_SUPPORT); ac->appendGroup(Constants::G_HELP_ABOUT);