forked from qt-creator/qt-creator
Break IMode's inheritance from IContext
IContext has the purpose of matching the current focus widget hierarchy to active context and context help. We do have actions that are enabled by mode context and we do have some modes that specify context help, and modes do have associated widgets. But the inheritance of IMode from IContext also forces IModes to create their widgets early which is undesirable. We already manually add the active mode's context via updateAdditionalContexts, so we already do not rely on the focus and do not need the IContext for that. Instead add a context property to IMode directly. Also, modes can just create an IContext for their widget if they need it _when_ the widget is created. Change-Id: I1178b73ffa7b6e4c25221dca0419c7def78f7bdc Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -25,6 +25,8 @@ public:
|
|||||||
Utils::FancyMainWindow *m_mainWindow = nullptr;
|
Utils::FancyMainWindow *m_mainWindow = nullptr;
|
||||||
int m_priority = -1;
|
int m_priority = -1;
|
||||||
Utils::Id m_id;
|
Utils::Id m_id;
|
||||||
|
Context m_context;
|
||||||
|
QPointer<QWidget> m_widget;
|
||||||
bool m_isEnabled = true;
|
bool m_isEnabled = true;
|
||||||
BoolAspect m_isVisible;
|
BoolAspect m_isVisible;
|
||||||
};
|
};
|
||||||
@@ -123,7 +125,7 @@ public:
|
|||||||
Registers the mode in \QC.
|
Registers the mode in \QC.
|
||||||
*/
|
*/
|
||||||
IMode::IMode(QObject *parent)
|
IMode::IMode(QObject *parent)
|
||||||
: IContext(parent)
|
: QObject(parent)
|
||||||
, m_d(new Internal::IModePrivate)
|
, m_d(new Internal::IModePrivate)
|
||||||
{
|
{
|
||||||
m_d->m_isVisible.setDefaultValue(true);
|
m_d->m_isVisible.setDefaultValue(true);
|
||||||
@@ -197,6 +199,16 @@ void IMode::setMenu(QMenu *menu)
|
|||||||
m_d->m_menu = menu;
|
m_d->m_menu = menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IMode::setContext(const Context &context)
|
||||||
|
{
|
||||||
|
m_d->m_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMode::setWidget(QWidget *widget)
|
||||||
|
{
|
||||||
|
m_d->m_widget = widget;
|
||||||
|
}
|
||||||
|
|
||||||
Utils::FancyMainWindow *IMode::mainWindow()
|
Utils::FancyMainWindow *IMode::mainWindow()
|
||||||
{
|
{
|
||||||
if (m_d->m_mainWindow)
|
if (m_d->m_mainWindow)
|
||||||
@@ -225,4 +237,14 @@ QMenu *IMode::menu() const
|
|||||||
return m_d->m_menu;
|
return m_d->m_menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context IMode::context() const
|
||||||
|
{
|
||||||
|
return m_d->m_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *IMode::widget() const
|
||||||
|
{
|
||||||
|
return m_d->m_widget;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace Internal {
|
|||||||
class IModePrivate;
|
class IModePrivate;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CORE_EXPORT IMode : public IContext
|
class CORE_EXPORT IMode : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName)
|
Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName)
|
||||||
@@ -43,6 +43,8 @@ public:
|
|||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
bool isVisible() const;
|
bool isVisible() const;
|
||||||
QMenu *menu() const;
|
QMenu *menu() const;
|
||||||
|
Context context() const;
|
||||||
|
QWidget *widget() const;
|
||||||
|
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
void setVisible(bool visible);
|
void setVisible(bool visible);
|
||||||
@@ -51,6 +53,8 @@ public:
|
|||||||
void setPriority(int priority);
|
void setPriority(int priority);
|
||||||
void setId(Utils::Id id);
|
void setId(Utils::Id id);
|
||||||
void setMenu(QMenu *menu);
|
void setMenu(QMenu *menu);
|
||||||
|
void setContext(const Context &context);
|
||||||
|
void setWidget(QWidget *widget);
|
||||||
|
|
||||||
Utils::FancyMainWindow *mainWindow();
|
Utils::FancyMainWindow *mainWindow();
|
||||||
void setMainWindow(Utils::FancyMainWindow *mw);
|
void setMainWindow(Utils::FancyMainWindow *mw);
|
||||||
|
|||||||
@@ -209,8 +209,6 @@ void ModeManagerPrivate::appendMode(IMode *mode)
|
|||||||
{
|
{
|
||||||
const int index = m_modeCommands.count();
|
const int index = m_modeCommands.count();
|
||||||
|
|
||||||
ICore::addContextObject(mode);
|
|
||||||
|
|
||||||
m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName(),
|
m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName(),
|
||||||
mode->menu() != nullptr);
|
mode->menu() != nullptr);
|
||||||
m_modeStack->setTabEnabled(index, mode->isEnabled());
|
m_modeStack->setTabEnabled(index, mode->isEnabled());
|
||||||
@@ -266,8 +264,6 @@ void ModeManager::removeMode(IMode *mode)
|
|||||||
|
|
||||||
d->m_modeCommands.remove(index);
|
d->m_modeCommands.remove(index);
|
||||||
d->m_modeStack->removeTab(index);
|
d->m_modeStack->removeTab(index);
|
||||||
|
|
||||||
ICore::removeContextObject(mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModeManagerPrivate::ensureVisibleEnabledMode()
|
void ModeManagerPrivate::ensureVisibleEnabledMode()
|
||||||
|
|||||||
@@ -366,7 +366,6 @@ public:
|
|||||||
Icons::MODE_PROJECT_FLAT, Icons::MODE_PROJECT_FLAT_ACTIVE));
|
Icons::MODE_PROJECT_FLAT, Icons::MODE_PROJECT_FLAT_ACTIVE));
|
||||||
setPriority(Constants::P_MODE_SESSION);
|
setPriority(Constants::P_MODE_SESSION);
|
||||||
setId(Constants::MODE_SESSION);
|
setId(Constants::MODE_SESSION);
|
||||||
setContextHelp("Managing Projects");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -913,6 +912,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
auto splitter = new MiniSplitter(Qt::Vertical);
|
auto splitter = new MiniSplitter(Qt::Vertical);
|
||||||
splitter->addWidget(dd->m_proWindow);
|
splitter->addWidget(dd->m_proWindow);
|
||||||
splitter->addWidget(new OutputPanePlaceHolder(Constants::MODE_SESSION, splitter));
|
splitter->addWidget(new OutputPanePlaceHolder(Constants::MODE_SESSION, splitter));
|
||||||
|
auto context = new IContext(splitter);
|
||||||
|
context->setWidget(splitter);
|
||||||
|
context->setContextHelp("Managing Projects");
|
||||||
|
ICore::addContextObject(context);
|
||||||
dd->m_projectsMode.setWidget(splitter);
|
dd->m_projectsMode.setWidget(splitter);
|
||||||
dd->m_projectsMode.setEnabled(false);
|
dd->m_projectsMode.setEnabled(false);
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -764,7 +765,6 @@ WelcomeMode::WelcomeMode()
|
|||||||
|
|
||||||
setPriority(Core::Constants::P_MODE_WELCOME);
|
setPriority(Core::Constants::P_MODE_WELCOME);
|
||||||
setId(Core::Constants::MODE_WELCOME);
|
setId(Core::Constants::MODE_WELCOME);
|
||||||
setContextHelp("Qt Design Studio Manual");
|
|
||||||
setContext(Core::Context(Core::Constants::C_WELCOME_MODE));
|
setContext(Core::Context(Core::Constants::C_WELCOME_MODE));
|
||||||
|
|
||||||
QFontDatabase::addApplicationFont(":/studiofonts/TitilliumWeb-Regular.ttf");
|
QFontDatabase::addApplicationFont(":/studiofonts/TitilliumWeb-Regular.ttf");
|
||||||
@@ -809,6 +809,10 @@ WelcomeMode::WelcomeMode()
|
|||||||
m_modeWidget = new QWidget;
|
m_modeWidget = new QWidget;
|
||||||
m_modeWidget->setLayout(boxLayout);
|
m_modeWidget->setLayout(boxLayout);
|
||||||
boxLayout->addWidget(m_quickWidget);
|
boxLayout->addWidget(m_quickWidget);
|
||||||
|
auto context = new IContext(m_modeWidget);
|
||||||
|
context->setWidget(m_modeWidget);
|
||||||
|
context->setContextHelp("Qt Design Studio Manual");
|
||||||
|
ICore::addContextObject(context);
|
||||||
setWidget(m_modeWidget);
|
setWidget(m_modeWidget);
|
||||||
|
|
||||||
QStringList designStudioQchPathes
|
QStringList designStudioQchPathes
|
||||||
|
|||||||
@@ -299,7 +299,6 @@ WelcomeMode::WelcomeMode()
|
|||||||
|
|
||||||
setPriority(Constants::P_MODE_WELCOME);
|
setPriority(Constants::P_MODE_WELCOME);
|
||||||
setId(Constants::MODE_WELCOME);
|
setId(Constants::MODE_WELCOME);
|
||||||
setContextHelp("Qt Creator Manual");
|
|
||||||
setContext(Context(Constants::C_WELCOME_MODE));
|
setContext(Context(Constants::C_WELCOME_MODE));
|
||||||
|
|
||||||
m_modeWidget = new ResizeSignallingWidget;
|
m_modeWidget = new ResizeSignallingWidget;
|
||||||
@@ -346,6 +345,10 @@ WelcomeMode::WelcomeMode()
|
|||||||
spacing(0),
|
spacing(0),
|
||||||
}.attachTo(m_modeWidget);
|
}.attachTo(m_modeWidget);
|
||||||
|
|
||||||
|
auto context = new IContext(m_modeWidget);
|
||||||
|
context->setWidget(m_modeWidget);
|
||||||
|
context->setContextHelp("Qt Creator Manual");
|
||||||
|
ICore::addContextObject(context);
|
||||||
setWidget(m_modeWidget);
|
setWidget(m_modeWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user