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

@@ -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