forked from qt-creator/qt-creator
EditorManager: Avoid warnings about already registered actions
When opening new editor windows, we want the _window_ to have the EditorManager context as well as the individual window context, but the window _actions_ (close, etc) may only be registered for the individual window context. Add the corresponding option to ICore::registerWindow et al. Change-Id: I67d0a6b386603e0047a77dfb357c207e7ffe99e6 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -47,9 +47,11 @@ EditorWindow::EditorWindow(QWidget *parent) :
|
|||||||
|
|
||||||
static int windowId = 0;
|
static int windowId = 0;
|
||||||
|
|
||||||
|
const Utils::Id windowContext
|
||||||
|
= Utils::Id("EditorManager.ExternalWindow.").withSuffix(++windowId);
|
||||||
ICore::registerWindow(this,
|
ICore::registerWindow(this,
|
||||||
Context(Utils::Id("EditorManager.ExternalWindow.").withSuffix(++windowId),
|
Context(windowContext, Constants::C_EDITORMANAGER),
|
||||||
Constants::C_EDITORMANAGER));
|
Context(windowContext));
|
||||||
|
|
||||||
connect(m_area, &EditorArea::windowTitleNeedsUpdate,
|
connect(m_area, &EditorArea::windowTitleNeedsUpdate,
|
||||||
this, &EditorWindow::updateWindowTitle);
|
this, &EditorWindow::updateWindowTitle);
|
||||||
|
|||||||
@@ -1011,14 +1011,15 @@ void ICore::removeAdditionalContext(const Context &context)
|
|||||||
Registers a \a window with the specified \a context. Registered windows are
|
Registers a \a window with the specified \a context. Registered windows are
|
||||||
shown in the \uicontrol Window menu and get registered for the various
|
shown in the \uicontrol Window menu and get registered for the various
|
||||||
window related actions, like the minimize, zoom, fullscreen and close
|
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
|
Whenever the application focus is in \a window, its \a context is made
|
||||||
active.
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -98,7 +98,9 @@ public:
|
|||||||
static void addContextObject(IContext *context);
|
static void addContextObject(IContext *context);
|
||||||
static void removeContextObject(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();
|
static void restartTrimmer();
|
||||||
|
|
||||||
enum OpenFilesFlags {
|
enum OpenFilesFlags {
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ namespace Internal {
|
|||||||
|
|
||||||
Q_GLOBAL_STATIC(WindowList, m_windowList)
|
Q_GLOBAL_STATIC(WindowList, m_windowList)
|
||||||
|
|
||||||
WindowSupport::WindowSupport(QWidget *window, const Context &context)
|
WindowSupport::WindowSupport(QWidget *window, const Context &context, const Context &actionContext)
|
||||||
: QObject(window),
|
: QObject(window)
|
||||||
m_window(window)
|
, m_window(window)
|
||||||
{
|
{
|
||||||
m_window->installEventFilter(this);
|
m_window->installEventFilter(this);
|
||||||
|
|
||||||
@@ -38,14 +38,15 @@ WindowSupport::WindowSupport(QWidget *window, const Context &context)
|
|||||||
m_contextObject->setWidget(window);
|
m_contextObject->setWidget(window);
|
||||||
m_contextObject->setContext(context);
|
m_contextObject->setContext(context);
|
||||||
ICore::addContextObject(m_contextObject);
|
ICore::addContextObject(m_contextObject);
|
||||||
|
const Context ac = actionContext.isEmpty() ? context : actionContext;
|
||||||
|
|
||||||
if (useMacShortcuts) {
|
if (useMacShortcuts) {
|
||||||
m_minimizeAction = new QAction(this);
|
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);
|
connect(m_minimizeAction, &QAction::triggered, m_window, &QWidget::showMinimized);
|
||||||
|
|
||||||
m_zoomAction = new QAction(this);
|
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] {
|
connect(m_zoomAction, &QAction::triggered, m_window, [this] {
|
||||||
if (m_window->isMaximized()) {
|
if (m_window->isMaximized()) {
|
||||||
// similar to QWidget::showMaximized
|
// similar to QWidget::showMaximized
|
||||||
@@ -58,13 +59,13 @@ WindowSupport::WindowSupport(QWidget *window, const Context &context)
|
|||||||
});
|
});
|
||||||
|
|
||||||
m_closeAction = new QAction(this);
|
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);
|
connect(m_closeAction, &QAction::triggered, m_window, &QWidget::close, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_toggleFullScreenAction = new QAction(this);
|
m_toggleFullScreenAction = new QAction(this);
|
||||||
updateFullScreenAction();
|
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);
|
connect(m_toggleFullScreenAction, &QAction::triggered, this, &WindowSupport::toggleFullScreen);
|
||||||
|
|
||||||
m_windowList->addWindow(window);
|
m_windowList->addWindow(window);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class WindowSupport : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
WindowSupport(QWidget *window, const Context &context);
|
WindowSupport(QWidget *window, const Context &context, const Context &actionContext = {});
|
||||||
~WindowSupport() override;
|
~WindowSupport() override;
|
||||||
|
|
||||||
void setCloseActionEnabled(bool enabled);
|
void setCloseActionEnabled(bool enabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user