diff --git a/src/plugins/coreplugin/editormanager/editorwindow.cpp b/src/plugins/coreplugin/editormanager/editorwindow.cpp index 3e23a7285ed..fbd60ebc15b 100644 --- a/src/plugins/coreplugin/editormanager/editorwindow.cpp +++ b/src/plugins/coreplugin/editormanager/editorwindow.cpp @@ -47,9 +47,11 @@ EditorWindow::EditorWindow(QWidget *parent) : static int windowId = 0; + const Utils::Id windowContext + = Utils::Id("EditorManager.ExternalWindow.").withSuffix(++windowId); ICore::registerWindow(this, - Context(Utils::Id("EditorManager.ExternalWindow.").withSuffix(++windowId), - Constants::C_EDITORMANAGER)); + Context(windowContext, Constants::C_EDITORMANAGER), + Context(windowContext)); connect(m_area, &EditorArea::windowTitleNeedsUpdate, this, &EditorWindow::updateWindowTitle); diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index abee4c08ab0..ef11fd6d161 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -1011,14 +1011,15 @@ void ICore::removeAdditionalContext(const Context &context) Registers a \a window with the specified \a context. Registered windows are shown in the \uicontrol Window menu and get registered for the various window related actions, like the minimize, zoom, fullscreen and close - actions. + actions. The context for the actions is \a context by default, but can be + overridden with \a actionContext. Whenever the application focus is in \a window, its \a context is made active. */ -void ICore::registerWindow(QWidget *window, const Context &context) +void ICore::registerWindow(QWidget *window, const Context &context, const Context &actionContext) { - new WindowSupport(window, context); // deletes itself when widget is destroyed + new WindowSupport(window, context, actionContext); // deletes itself when widget is destroyed } /*! diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h index 215cb94ba86..8c713e156f4 100644 --- a/src/plugins/coreplugin/icore.h +++ b/src/plugins/coreplugin/icore.h @@ -98,7 +98,9 @@ public: static void addContextObject(IContext *context); static void removeContextObject(IContext *context); - static void registerWindow(QWidget *window, const Context &context); + static void registerWindow(QWidget *window, + const Context &context, + const Context &actionContext = {}); static void restartTrimmer(); enum OpenFilesFlags { diff --git a/src/plugins/coreplugin/windowsupport.cpp b/src/plugins/coreplugin/windowsupport.cpp index 4cbfb57d038..25ab34793c7 100644 --- a/src/plugins/coreplugin/windowsupport.cpp +++ b/src/plugins/coreplugin/windowsupport.cpp @@ -28,9 +28,9 @@ namespace Internal { Q_GLOBAL_STATIC(WindowList, m_windowList) -WindowSupport::WindowSupport(QWidget *window, const Context &context) - : QObject(window), - m_window(window) +WindowSupport::WindowSupport(QWidget *window, const Context &context, const Context &actionContext) + : QObject(window) + , m_window(window) { m_window->installEventFilter(this); @@ -38,14 +38,15 @@ WindowSupport::WindowSupport(QWidget *window, const Context &context) m_contextObject->setWidget(window); m_contextObject->setContext(context); ICore::addContextObject(m_contextObject); + const Context ac = actionContext.isEmpty() ? context : actionContext; if (useMacShortcuts) { m_minimizeAction = new QAction(this); - ActionManager::registerAction(m_minimizeAction, Constants::MINIMIZE_WINDOW, context); + ActionManager::registerAction(m_minimizeAction, Constants::MINIMIZE_WINDOW, ac); connect(m_minimizeAction, &QAction::triggered, m_window, &QWidget::showMinimized); m_zoomAction = new QAction(this); - ActionManager::registerAction(m_zoomAction, Constants::ZOOM_WINDOW, context); + ActionManager::registerAction(m_zoomAction, Constants::ZOOM_WINDOW, ac); connect(m_zoomAction, &QAction::triggered, m_window, [this] { if (m_window->isMaximized()) { // similar to QWidget::showMaximized @@ -58,13 +59,13 @@ WindowSupport::WindowSupport(QWidget *window, const Context &context) }); m_closeAction = new QAction(this); - ActionManager::registerAction(m_closeAction, Constants::CLOSE_WINDOW, context); + ActionManager::registerAction(m_closeAction, Constants::CLOSE_WINDOW, ac); connect(m_closeAction, &QAction::triggered, m_window, &QWidget::close, Qt::QueuedConnection); } m_toggleFullScreenAction = new QAction(this); updateFullScreenAction(); - ActionManager::registerAction(m_toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN, context); + ActionManager::registerAction(m_toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN, ac); connect(m_toggleFullScreenAction, &QAction::triggered, this, &WindowSupport::toggleFullScreen); m_windowList->addWindow(window); diff --git a/src/plugins/coreplugin/windowsupport.h b/src/plugins/coreplugin/windowsupport.h index c1b48d39179..bfdc969ffb0 100644 --- a/src/plugins/coreplugin/windowsupport.h +++ b/src/plugins/coreplugin/windowsupport.h @@ -40,7 +40,7 @@ class WindowSupport : public QObject { Q_OBJECT public: - WindowSupport(QWidget *window, const Context &context); + WindowSupport(QWidget *window, const Context &context, const Context &actionContext = {}); ~WindowSupport() override; void setCloseActionEnabled(bool enabled);