From d391c0c74e515964cef64b4f16a92b39932ac134 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 9 Nov 2023 12:04:30 +0100 Subject: [PATCH] Core: Use Core::Action for 'About...' stuff ... and add the necessary Action::setMenuRole() Change-Id: I2bb309ae115c1e015ff848e0712327360ead23cd Reviewed-by: Christian Stenger --- .../actionmanager/actionmanager.cpp | 7 +++ .../coreplugin/actionmanager/actionmanager.h | 8 +-- src/plugins/coreplugin/icore.cpp | 52 +++++++++---------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/plugins/coreplugin/actionmanager/actionmanager.cpp b/src/plugins/coreplugin/actionmanager/actionmanager.cpp index 0462c4de658..a0e907576d5 100644 --- a/src/plugins/coreplugin/actionmanager/actionmanager.cpp +++ b/src/plugins/coreplugin/actionmanager/actionmanager.cpp @@ -203,6 +203,13 @@ void Action::setCheckable(bool on) d->command->action()->setCheckable(on); } +void Action::setMenuRole(QAction::MenuRole role) +{ + d->action.setMenuRole(role); + if (d->command) + d->command->action()->setMenuRole(role); +} + Command *Action::command() const { d->ensureCommand(); diff --git a/src/plugins/coreplugin/actionmanager/actionmanager.h b/src/plugins/coreplugin/actionmanager/actionmanager.h index 7a735737d99..d51e5845fdf 100644 --- a/src/plugins/coreplugin/actionmanager/actionmanager.h +++ b/src/plugins/coreplugin/actionmanager/actionmanager.h @@ -8,16 +8,11 @@ #include "../icontext.h" #include "command.h" -#include +#include #include #include -QT_BEGIN_NAMESPACE -class QAction; -class QString; -QT_END_NAMESPACE - namespace Core { class ActionContainer; @@ -55,6 +50,7 @@ public: void setChecked(bool on); void setVisible(bool on); void setCheckable(bool on); + void setMenuRole(QAction::MenuRole role); Command *command() const; QAction *commandAction() const; diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index 45afbfafd4f..237d1eb34c9 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -339,6 +339,9 @@ public: QAction *m_setModeSelectorStyleIconsOnlyAction = nullptr; QAction *m_themeAction = nullptr; + Action m_aboutIdeAction; + Action m_aboutPluginsAction; + QToolButton *m_toggleLeftSideBarButton = nullptr; QToolButton *m_toggleRightSideBarButton = nullptr; QList> m_preCloseListeners; @@ -1885,35 +1888,30 @@ void ICorePrivate::registerDefaultActions() mhelp->addSeparator(Constants::G_HELP_ABOUT); // About IDE Action - icon = Icon::fromTheme("help-about"); - if (HostOsInfo::isMacHost()) - tmpaction = new QAction(icon, - Tr::tr("About &%1").arg(QGuiApplication::applicationDisplayName()), - this); // it's convention not to add dots to the about menu - else - tmpaction - = new QAction(icon, - Tr::tr("About &%1...").arg(QGuiApplication::applicationDisplayName()), - this); - tmpaction->setMenuRole(QAction::AboutRole); - cmd = ActionManager::registerAction(tmpaction, Constants::ABOUT_QTCREATOR); - mhelp->addAction(cmd, Constants::G_HELP_ABOUT); - tmpaction->setEnabled(true); - connect(tmpaction, &QAction::triggered, this, &ICorePrivate::aboutQtCreator); + m_aboutIdeAction.setId(Constants::ABOUT_QTCREATOR); + m_aboutIdeAction.setIcon(Icon::fromTheme("help-about")); + m_aboutIdeAction.setText( + (HostOsInfo::isMacHost() ? Tr::tr("About &%1") : Tr::tr("About &%1...")) + .arg(QGuiApplication::applicationDisplayName())); + m_aboutIdeAction.setMenuRole(QAction::AboutRole); + m_aboutIdeAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); + m_aboutIdeAction.setEnabled(true); + m_aboutIdeAction.setOnTriggered(this, [this] { aboutQtCreator(); }); + + // About Plugins Action + m_aboutPluginsAction.setId(Constants::ABOUT_PLUGINS); + m_aboutPluginsAction.setText(Tr::tr("About &Plugins...")); + m_aboutPluginsAction.setMenuRole(QAction::ApplicationSpecificRole); + m_aboutPluginsAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); + m_aboutPluginsAction.setEnabled(true); + m_aboutPluginsAction.setOnTriggered(this, [this] { aboutPlugins(); }); - //About Plugins Action - tmpaction = new QAction(Tr::tr("About &Plugins..."), this); - tmpaction->setMenuRole(QAction::ApplicationSpecificRole); - cmd = ActionManager::registerAction(tmpaction, Constants::ABOUT_PLUGINS); - mhelp->addAction(cmd, Constants::G_HELP_ABOUT); - tmpaction->setEnabled(true); - connect(tmpaction, &QAction::triggered, this, &ICorePrivate::aboutPlugins); // About Qt Action - // tmpaction = new QAction(Tr::tr("About &Qt..."), this); - // cmd = ActionManager::registerAction(tmpaction, Constants:: ABOUT_QT); - // mhelp->addAction(cmd, Constants::G_HELP_ABOUT); - // tmpaction->setEnabled(true); - // connect(tmpaction, &QAction::triggered, qApp, &QApplication::aboutQt); + // aboutQtAction.setId(Constants:: ABOUT_QT); + // aboutQtAction.setText(Tr::tr("About &Qt..."), this); + // aboutQtAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); + // aboutQtAction.setEnabled(true); + // aboutQtAction.setOnTriggered(this, &QApplication::aboutQt); // Change Log Action tmpaction = new QAction(Tr::tr("Change Log..."), this);