Fix context of Locator input

- In the main window, the locator input (actually the status bar)
  visually feels like being part of the mode widget, so give
  it its context.
- In extra editor windows, the whole editor window should have
  "editor manager" context, so that is also active for the locator
  input.

Task-number: QTCREATORBUG-20626
Task-number: QTCREATORBUG-20071
Change-Id: Ib68d6a8177446572ea59c3cc057eca0706173e11
Reviewed-by: Xing Xiong
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-07-10 15:49:50 +02:00
parent 735aeb3e38
commit 8fa449126c
13 changed files with 66 additions and 16 deletions

View File

@@ -181,7 +181,7 @@ void DesignMode::currentEditorChanged(IEditor *editor)
if (!mimeEditorAvailable) {
setActiveContext(Context());
if (ModeManager::currentMode() == id())
if (ModeManager::currentModeId() == id())
ModeManager::activateMode(Constants::MODE_EDIT);
setEnabled(false);
d->m_currentEditor = nullptr;
@@ -214,7 +214,7 @@ void DesignMode::setActiveContext(const Context &context)
if (d->m_activeContext == context)
return;
if (ModeManager::currentMode() == id())
if (ModeManager::currentModeId() == id())
ICore::updateAdditionalContexts(d->m_activeContext, context);
d->m_activeContext = context;

View File

@@ -29,6 +29,7 @@
#include "editormanager_p.h"
#include <aggregation/aggregate.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/locator/locatormanager.h>
@@ -67,7 +68,10 @@ EditorWindow::EditorWindow(QWidget *parent) :
resize(QSize(800, 600));
static int windowId = 0;
ICore::registerWindow(this, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId)));
ICore::registerWindow(this,
Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId),
Constants::C_EDITORMANAGER));
connect(m_area, &EditorArea::windowTitleNeedsUpdate,
this, &EditorWindow::updateWindowTitle);

View File

@@ -531,6 +531,11 @@ QWidget *ICore::currentContextWidget()
return context ? context->widget() : nullptr;
}
IContext *ICore::contextObject(QWidget *widget)
{
return m_mainwindow->contextObject(widget);
}
QMainWindow *ICore::mainWindow()
{

View File

@@ -112,6 +112,7 @@ public:
static IContext *currentContextObject();
static QWidget *currentContextWidget();
static IContext *contextObject(QWidget *widget);
// Adds and removes additional active contexts, these contexts are appended
// to the currently active contexts.
static void updateAdditionalContexts(const Context &remove, const Context &add,

View File

@@ -125,7 +125,7 @@ ModeManager::~ModeManager()
m_instance = nullptr;
}
Id ModeManager::currentMode()
Id ModeManager::currentModeId()
{
int currentIndex = d->m_modeStack->currentIndex();
if (currentIndex < 0)
@@ -222,7 +222,7 @@ void ModeManagerPrivate::enabledStateChanged(IMode *mode)
d->m_modeStack->setTabEnabled(index, mode->isEnabled());
// Make sure we leave any disabled mode to prevent possible crashes:
if (mode->id() == ModeManager::currentMode() && !mode->isEnabled()) {
if (mode->id() == ModeManager::currentModeId() && !mode->isEnabled()) {
// This assumes that there is always at least one enabled mode.
for (int i = 0; i < d->m_modes.count(); ++i) {
if (d->m_modes.at(i) != mode &&
@@ -298,7 +298,7 @@ void ModeManager::currentTabChanged(int index)
void ModeManager::setFocusToCurrentMode()
{
IMode *mode = findMode(currentMode());
IMode *mode = findMode(currentModeId());
QTC_ASSERT(mode, return);
QWidget *widget = mode->widget();
if (widget) {
@@ -336,4 +336,10 @@ ModeManager *ModeManager::instance()
return m_instance;
}
IMode *ModeManager::currentMode()
{
const int currentIndex = d->m_modeStack->currentIndex();
return currentIndex < 0 ? nullptr : d->m_modes.at(currentIndex);
}
} // namespace Core

View File

@@ -54,7 +54,8 @@ public:
static ModeManager *instance();
static Id currentMode();
static IMode *currentMode();
static Id currentModeId();
static void addAction(QAction *action, int priority);
static void addProjectSelector(QAction *action);

View File

@@ -68,7 +68,7 @@ OutputPanePlaceHolder::OutputPanePlaceHolder(Id mode, QSplitter *parent)
this, &OutputPanePlaceHolder::currentModeChanged);
// if this is part of a lazily created mode widget,
// we need to check if this is the current placeholder
currentModeChanged(ModeManager::currentMode());
currentModeChanged(ModeManager::currentModeId());
}
OutputPanePlaceHolder::~OutputPanePlaceHolder()

View File

@@ -25,8 +25,10 @@
#include "statusbarmanager.h"
#include "imode.h"
#include "mainwindow.h"
#include "minisplitter.h"
#include "modemanager.h"
#include <utils/qtcassert.h>
@@ -45,6 +47,17 @@ static QPointer<QSplitter> m_splitter;
static QList<QPointer<QWidget>> m_statusBarWidgets;
static QList<QPointer<IContext>> m_contexts;
/*!
Context that always returns the context of the active's mode widget (if available).
*/
class StatusBarContext : public IContext
{
public:
StatusBarContext(QObject *parent);
Context context() const final;
};
static QWidget *createWidget(QWidget *parent)
{
QWidget *w = new QWidget(parent);
@@ -85,6 +98,10 @@ static void createStatusBarManager()
bar->insertPermanentWidget(1, rightCornerWidget);
m_statusBarWidgets.append(rightCornerWidget);
auto context = new StatusBarContext(bar);
context->setWidget(bar);
ICore::addContextObject(context);
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, [] {
QSettings *s = ICore::settings();
s->beginGroup(QLatin1String(kSettingsGroup));
@@ -152,4 +169,20 @@ void StatusBarManager::restoreSettings()
m_splitter->setSizes(QList<int>() << leftSplitWidth << (sum - leftSplitWidth));
}
StatusBarContext::StatusBarContext(QObject *parent)
: IContext(parent)
{
}
Context StatusBarContext::context() const
{
IMode *currentMode = ModeManager::currentMode();
QWidget *modeWidget = currentMode ? currentMode->widget() : nullptr;
if (modeWidget) {
if (IContext *context = ICore::contextObject(modeWidget))
return context->context();
}
return Context();
}
} // Core

View File

@@ -2758,7 +2758,7 @@ void DebuggerPluginPrivate::dumpLog()
/*! Activates the previous mode when the current mode is the debug mode. */
void DebuggerPluginPrivate::activatePreviousMode()
{
if (ModeManager::currentMode() == MODE_DEBUG && m_previousMode.isValid()) {
if (ModeManager::currentModeId() == MODE_DEBUG && m_previousMode.isValid()) {
// If stopping the application also makes Qt Creator active (as the
// "previously active application"), doing the switch synchronously
// leads to funny effects with floating dock widgets
@@ -3390,7 +3390,7 @@ void DebuggerPluginPrivate::onModeChanged(Id mode)
void saveModeToRestore()
{
dd->m_previousMode = ModeManager::currentMode();
dd->m_previousMode = ModeManager::currentModeId();
}
} // namespace Internal
@@ -3522,7 +3522,7 @@ void setPerspectiveEnabled(const QByteArray &perspectiveId, bool enabled)
void selectPerspective(const QByteArray &perspectiveId)
{
if (ModeManager::currentMode() == MODE_DEBUG
if (ModeManager::currentModeId() == MODE_DEBUG
&& dd->m_mainWindow->currentPerspective() == perspectiveId) {
return;
}

View File

@@ -523,7 +523,7 @@ void HelpPluginPrivate::updateSideBarSource(const QUrl &newUrl)
void HelpPluginPrivate::setupHelpEngineIfNeeded()
{
LocalHelpManager::setEngineNeedsUpdate();
if (ModeManager::currentMode() == m_mode.id()
if (ModeManager::currentModeId() == m_mode.id()
|| LocalHelpManager::contextHelpOption() == HelpManager::ExternalHelpAlways)
LocalHelpManager::setupGuiHelpEngine();
}

View File

@@ -1689,7 +1689,7 @@ void ProjectExplorerPluginPrivate::showSessionManager()
updateActions();
if (ModeManager::currentMode() == Core::Constants::MODE_WELCOME)
if (ModeManager::currentModeId() == Core::Constants::MODE_WELCOME)
updateWelcomePage();
}

View File

@@ -93,7 +93,7 @@ QmlDesignerPlugin *QmlDesignerPlugin::m_instance = nullptr;
static bool isInDesignerMode()
{
return Core::ModeManager::currentMode() == Core::Constants::MODE_DESIGN;
return Core::ModeManager::currentModeId() == Core::Constants::MODE_DESIGN;
}
static bool checkIfEditorIsQtQuick(Core::IEditor *editor)
@@ -106,7 +106,7 @@ static bool checkIfEditorIsQtQuick(Core::IEditor *editor)
|| document->language() == QmlJS::Dialect::QmlQtQuick2Ui
|| document->language() == QmlJS::Dialect::Qml;
if (Core::ModeManager::currentMode() == Core::Constants::MODE_DESIGN) {
if (Core::ModeManager::currentModeId() == Core::Constants::MODE_DESIGN) {
Core::AsynchronousMessageBox::warning(QmlDesignerPlugin::tr("Cannot Open Design Mode"),
QmlDesignerPlugin::tr("The QML file is not currently opened in a QML Editor."));
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);

View File

@@ -1031,7 +1031,7 @@ bool QmlJSEditor::isDesignModePreferred() const
alwaysPreferDesignMode = true;
// stay in design mode if we are there
Id mode = ModeManager::currentMode();
Id mode = ModeManager::currentModeId();
return alwaysPreferDesignMode || mode == Core::Constants::MODE_DESIGN;
}