Commit 5e47d35f authored by hjk's avatar hjk

Use Core::Id in ModeManager interface

Makes it more uniform to use and allows placeholder widget
creation to be independent of mode creations.

Change-Id: I4021bc9db7f8c78f0374c0cc3b3331506959afe4
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent ed7d5e0d
...@@ -197,7 +197,7 @@ void DesignMode::currentEditorChanged(IEditor *editor) ...@@ -197,7 +197,7 @@ void DesignMode::currentEditorChanged(IEditor *editor)
if (!mimeEditorAvailable) { if (!mimeEditorAvailable) {
setActiveContext(Context()); setActiveContext(Context());
if (ModeManager::currentMode() == this) if (ModeManager::currentMode() == id())
ModeManager::activateMode(Constants::MODE_EDIT); ModeManager::activateMode(Constants::MODE_EDIT);
setEnabled(false); setEnabled(false);
d->m_currentEditor = 0; d->m_currentEditor = 0;
...@@ -217,11 +217,11 @@ void DesignMode::updateActions() ...@@ -217,11 +217,11 @@ void DesignMode::updateActions()
emit actionsUpdated(d->m_currentEditor.data()); emit actionsUpdated(d->m_currentEditor.data());
} }
void DesignMode::updateContext(IMode *newMode, IMode *oldMode) void DesignMode::updateContext(Id newMode, Id oldMode)
{ {
if (newMode == this) if (newMode == id())
ICore::addAdditionalContext(d->m_activeContext); ICore::addAdditionalContext(d->m_activeContext);
else if (oldMode == this) else if (oldMode == id())
ICore::removeAdditionalContext(d->m_activeContext); ICore::removeAdditionalContext(d->m_activeContext);
} }
...@@ -230,7 +230,7 @@ void DesignMode::setActiveContext(const Context &context) ...@@ -230,7 +230,7 @@ void DesignMode::setActiveContext(const Context &context)
if (d->m_activeContext == context) if (d->m_activeContext == context)
return; return;
if (ModeManager::currentMode() == this) if (ModeManager::currentMode() == id())
ICore::updateAdditionalContexts(d->m_activeContext, context); ICore::updateAdditionalContexts(d->m_activeContext, context);
d->m_activeContext = context; d->m_activeContext = context;
......
...@@ -68,7 +68,7 @@ private: ...@@ -68,7 +68,7 @@ private:
void updateActions(); void updateActions();
void currentEditorChanged(IEditor *editor); void currentEditorChanged(IEditor *editor);
void updateContext(IMode *newMode, IMode *oldMode); void updateContext(Id newMode, Id oldMode);
void setActiveContext(const Context &context); void setActiveContext(const Context &context);
DesignModePrivate *d; DesignModePrivate *d;
......
...@@ -58,25 +58,25 @@ EditMode::EditMode() : ...@@ -58,25 +58,25 @@ EditMode::EditMode() :
m_rightSplitWidgetLayout->setMargin(0); m_rightSplitWidgetLayout->setMargin(0);
QWidget *rightSplitWidget = new QWidget; QWidget *rightSplitWidget = new QWidget;
rightSplitWidget->setLayout(m_rightSplitWidgetLayout); rightSplitWidget->setLayout(m_rightSplitWidgetLayout);
auto editorPlaceHolder = new EditorManagerPlaceHolder(this); auto editorPlaceHolder = new EditorManagerPlaceHolder(Constants::MODE_EDIT);
m_rightSplitWidgetLayout->insertWidget(0, editorPlaceHolder); m_rightSplitWidgetLayout->insertWidget(0, editorPlaceHolder);
MiniSplitter *rightPaneSplitter = new MiniSplitter; MiniSplitter *rightPaneSplitter = new MiniSplitter;
rightPaneSplitter->insertWidget(0, rightSplitWidget); rightPaneSplitter->insertWidget(0, rightSplitWidget);
rightPaneSplitter->insertWidget(1, new RightPanePlaceHolder(this)); rightPaneSplitter->insertWidget(1, new RightPanePlaceHolder(Constants::MODE_EDIT));
rightPaneSplitter->setStretchFactor(0, 1); rightPaneSplitter->setStretchFactor(0, 1);
rightPaneSplitter->setStretchFactor(1, 0); rightPaneSplitter->setStretchFactor(1, 0);
MiniSplitter *splitter = new MiniSplitter; MiniSplitter *splitter = new MiniSplitter;
splitter->setOrientation(Qt::Vertical); splitter->setOrientation(Qt::Vertical);
splitter->insertWidget(0, rightPaneSplitter); splitter->insertWidget(0, rightPaneSplitter);
QWidget *outputPane = new OutputPanePlaceHolder(this, splitter); QWidget *outputPane = new OutputPanePlaceHolder(Constants::MODE_EDIT, splitter);
outputPane->setObjectName(QLatin1String("EditModeOutputPanePlaceHolder")); outputPane->setObjectName(QLatin1String("EditModeOutputPanePlaceHolder"));
splitter->insertWidget(1, outputPane); splitter->insertWidget(1, outputPane);
splitter->setStretchFactor(0, 3); splitter->setStretchFactor(0, 3);
splitter->setStretchFactor(1, 0); splitter->setStretchFactor(1, 0);
m_splitter->insertWidget(0, new NavigationWidgetPlaceHolder(this)); m_splitter->insertWidget(0, new NavigationWidgetPlaceHolder(Constants::MODE_EDIT));
m_splitter->insertWidget(1, splitter); m_splitter->insertWidget(1, splitter);
m_splitter->setStretchFactor(0, 0); m_splitter->setStretchFactor(0, 0);
m_splitter->setStretchFactor(1, 1); m_splitter->setStretchFactor(1, 1);
...@@ -100,9 +100,9 @@ EditMode::~EditMode() ...@@ -100,9 +100,9 @@ EditMode::~EditMode()
delete m_splitter; delete m_splitter;
} }
void EditMode::grabEditorManager(IMode *mode) void EditMode::grabEditorManager(Id mode)
{ {
if (mode != this) if (mode != id())
return; return;
if (EditorManager::currentEditor()) if (EditorManager::currentEditor())
......
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
~EditMode(); ~EditMode();
private: private:
void grabEditorManager(IMode *mode); void grabEditorManager(Id mode);
QSplitter *m_splitter; QSplitter *m_splitter;
QVBoxLayout *m_rightSplitWidgetLayout; QVBoxLayout *m_rightSplitWidgetLayout;
......
...@@ -121,7 +121,7 @@ using namespace Utils; ...@@ -121,7 +121,7 @@ using namespace Utils;
//===================EditorManager===================== //===================EditorManager=====================
EditorManagerPlaceHolder::EditorManagerPlaceHolder(IMode *mode, QWidget *parent) EditorManagerPlaceHolder::EditorManagerPlaceHolder(Id mode, QWidget *parent)
: QWidget(parent), m_mode(mode) : QWidget(parent), m_mode(mode)
{ {
setLayout(new QVBoxLayout); setLayout(new QVBoxLayout);
...@@ -143,7 +143,7 @@ EditorManagerPlaceHolder::~EditorManagerPlaceHolder() ...@@ -143,7 +143,7 @@ EditorManagerPlaceHolder::~EditorManagerPlaceHolder()
} }
} }
void EditorManagerPlaceHolder::currentModeChanged(IMode *mode) void EditorManagerPlaceHolder::currentModeChanged(Id mode)
{ {
if (m_mode == mode) { if (m_mode == mode) {
QWidget *previousFocus = 0; QWidget *previousFocus = 0;
......
...@@ -72,13 +72,13 @@ class CORE_EXPORT EditorManagerPlaceHolder : public QWidget ...@@ -72,13 +72,13 @@ class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit EditorManagerPlaceHolder(IMode *mode, QWidget *parent = 0); explicit EditorManagerPlaceHolder(Id mode, QWidget *parent = 0);
~EditorManagerPlaceHolder(); ~EditorManagerPlaceHolder();
private: private:
void currentModeChanged(IMode *); void currentModeChanged(Id mode);
IMode *m_mode; Id m_mode;
}; };
class CORE_EXPORT EditorManager : public QObject class CORE_EXPORT EditorManager : public QObject
......
...@@ -115,15 +115,15 @@ ModeManager::~ModeManager() ...@@ -115,15 +115,15 @@ ModeManager::~ModeManager()
m_instance = 0; m_instance = 0;
} }
IMode *ModeManager::currentMode() Id ModeManager::currentMode()
{ {
int currentIndex = d->m_modeStack->currentIndex(); int currentIndex = d->m_modeStack->currentIndex();
if (currentIndex < 0) if (currentIndex < 0)
return 0; return 0;
return d->m_modes.at(currentIndex); return d->m_modes.at(currentIndex)->id();
} }
IMode *ModeManager::mode(Id id) static IMode *findMode(Id id)
{ {
const int index = indexOf(id); const int index = indexOf(id);
if (index >= 0) if (index >= 0)
...@@ -205,7 +205,7 @@ void ModeManager::enabledStateChanged() ...@@ -205,7 +205,7 @@ void ModeManager::enabledStateChanged()
d->m_modeStack->setTabEnabled(index, mode->isEnabled()); d->m_modeStack->setTabEnabled(index, mode->isEnabled());
// Make sure we leave any disabled mode to prevent possible crashes: // Make sure we leave any disabled mode to prevent possible crashes:
if (mode == currentMode() && !mode->isEnabled()) { if (mode->id() == currentMode() && !mode->isEnabled()) {
// This assumes that there is always at least one enabled mode. // This assumes that there is always at least one enabled mode.
for (int i = 0; i < d->m_modes.count(); ++i) { for (int i = 0; i < d->m_modes.count(); ++i) {
if (d->m_modes.at(i) != mode && if (d->m_modes.at(i) != mode &&
...@@ -256,7 +256,7 @@ void ModeManager::currentTabAboutToChange(int index) ...@@ -256,7 +256,7 @@ void ModeManager::currentTabAboutToChange(int index)
if (index >= 0) { if (index >= 0) {
IMode *mode = d->m_modes.at(index); IMode *mode = d->m_modes.at(index);
if (mode) if (mode)
emit currentModeAboutToChange(mode); emit currentModeAboutToChange(mode->id());
} }
} }
...@@ -276,13 +276,13 @@ void ModeManager::currentTabChanged(int index) ...@@ -276,13 +276,13 @@ void ModeManager::currentTabChanged(int index)
if (d->m_oldCurrent >= 0) if (d->m_oldCurrent >= 0)
oldMode = d->m_modes.at(d->m_oldCurrent); oldMode = d->m_modes.at(d->m_oldCurrent);
d->m_oldCurrent = index; d->m_oldCurrent = index;
emit currentModeChanged(mode, oldMode); emit currentModeChanged(mode ? mode->id() : Id(), oldMode ? oldMode->id() : Id());
} }
} }
void ModeManager::setFocusToCurrentMode() void ModeManager::setFocusToCurrentMode()
{ {
IMode *mode = currentMode(); IMode *mode = findMode(currentMode());
QTC_ASSERT(mode, return); QTC_ASSERT(mode, return);
QWidget *widget = mode->widget(); QWidget *widget = mode->widget();
if (widget) { if (widget) {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#pragma once #pragma once
#include <coreplugin/core_global.h> #include <coreplugin/id.h>
#include <QObject> #include <QObject>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
...@@ -34,9 +34,6 @@ QT_END_NAMESPACE ...@@ -34,9 +34,6 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
class Id;
class IMode;
namespace Internal { namespace Internal {
class MainWindow; class MainWindow;
class FancyTabWidget; class FancyTabWidget;
...@@ -49,8 +46,7 @@ class CORE_EXPORT ModeManager : public QObject ...@@ -49,8 +46,7 @@ class CORE_EXPORT ModeManager : public QObject
public: public:
static ModeManager *instance(); static ModeManager *instance();
static IMode *currentMode(); static Id currentMode();
static IMode *mode(Id id);
static void addAction(QAction *action, int priority); static void addAction(QAction *action, int priority);
static void addProjectSelector(QAction *action); static void addProjectSelector(QAction *action);
...@@ -63,10 +59,10 @@ public slots: ...@@ -63,10 +59,10 @@ public slots:
static void setModeSelectorVisible(bool visible); static void setModeSelectorVisible(bool visible);
signals: signals:
void currentModeAboutToChange(Core::IMode *mode); void currentModeAboutToChange(Core::Id mode);
// the default argument '=0' is important for connects without the oldMode argument. // the default argument '=0' is important for connects without the oldMode argument.
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode = 0); void currentModeChanged(Core::Id mode, Core::Id oldMode = Core::Id());
private: private:
explicit ModeManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack); explicit ModeManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack);
......
...@@ -55,7 +55,7 @@ NavigationWidgetPlaceHolder* NavigationWidgetPlaceHolder::current() ...@@ -55,7 +55,7 @@ NavigationWidgetPlaceHolder* NavigationWidgetPlaceHolder::current()
return m_current; return m_current;
} }
NavigationWidgetPlaceHolder::NavigationWidgetPlaceHolder(IMode *mode, QWidget *parent) NavigationWidgetPlaceHolder::NavigationWidgetPlaceHolder(Id mode, QWidget *parent)
:QWidget(parent), m_mode(mode) :QWidget(parent), m_mode(mode)
{ {
setLayout(new QVBoxLayout); setLayout(new QVBoxLayout);
...@@ -104,7 +104,7 @@ void NavigationWidgetPlaceHolder::applyStoredSize(int width) ...@@ -104,7 +104,7 @@ void NavigationWidgetPlaceHolder::applyStoredSize(int width)
// m_current points to the current PlaceHolder, or zero if there // m_current points to the current PlaceHolder, or zero if there
// is no PlaceHolder in this mode // is no PlaceHolder in this mode
// And that the parent of the NavigationWidget gets the correct parent // And that the parent of the NavigationWidget gets the correct parent
void NavigationWidgetPlaceHolder::currentModeAboutToChange(IMode *mode) void NavigationWidgetPlaceHolder::currentModeAboutToChange(Id mode)
{ {
NavigationWidget *navigationWidget = NavigationWidget::instance(); NavigationWidget *navigationWidget = NavigationWidget::instance();
......
...@@ -38,7 +38,6 @@ QT_END_NAMESPACE ...@@ -38,7 +38,6 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
class INavigationWidgetFactory; class INavigationWidgetFactory;
class IMode;
class Command; class Command;
class NavigationWidget; class NavigationWidget;
struct NavigationWidgetPrivate; struct NavigationWidgetPrivate;
...@@ -50,15 +49,15 @@ class CORE_EXPORT NavigationWidgetPlaceHolder : public QWidget ...@@ -50,15 +49,15 @@ class CORE_EXPORT NavigationWidgetPlaceHolder : public QWidget
friend class Core::NavigationWidget; friend class Core::NavigationWidget;
public: public:
explicit NavigationWidgetPlaceHolder(IMode *mode, QWidget *parent = 0); explicit NavigationWidgetPlaceHolder(Id mode, QWidget *parent = 0);
virtual ~NavigationWidgetPlaceHolder(); virtual ~NavigationWidgetPlaceHolder();
static NavigationWidgetPlaceHolder* current(); static NavigationWidgetPlaceHolder* current();
void applyStoredSize(int width); void applyStoredSize(int width);
private: private:
void currentModeAboutToChange(IMode *); void currentModeAboutToChange(Id mode);
IMode *m_mode; Id m_mode;
static NavigationWidgetPlaceHolder* m_current; static NavigationWidgetPlaceHolder* m_current;
}; };
......
...@@ -36,9 +36,9 @@ namespace Core { ...@@ -36,9 +36,9 @@ namespace Core {
class OutputPanePlaceHolderPrivate { class OutputPanePlaceHolderPrivate {
public: public:
explicit OutputPanePlaceHolderPrivate(IMode *mode, QSplitter *parent); explicit OutputPanePlaceHolderPrivate(Id mode, QSplitter *parent);
IMode *m_mode; Id m_mode;
QSplitter *m_splitter; QSplitter *m_splitter;
int m_nonMaximizedSize = 0; int m_nonMaximizedSize = 0;
bool m_isMaximized = false; bool m_isMaximized = false;
...@@ -46,14 +46,14 @@ public: ...@@ -46,14 +46,14 @@ public:
static OutputPanePlaceHolder* m_current; static OutputPanePlaceHolder* m_current;
}; };
OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(IMode *mode, QSplitter *parent) : OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Id mode, QSplitter *parent) :
m_mode(mode), m_splitter(parent) m_mode(mode), m_splitter(parent)
{ {
} }
OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0; OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0;
OutputPanePlaceHolder::OutputPanePlaceHolder(IMode *mode, QSplitter* parent) OutputPanePlaceHolder::OutputPanePlaceHolder(Id mode, QSplitter *parent)
: QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent)) : QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
{ {
setVisible(false); setVisible(false);
...@@ -83,7 +83,7 @@ OutputPanePlaceHolder::~OutputPanePlaceHolder() ...@@ -83,7 +83,7 @@ OutputPanePlaceHolder::~OutputPanePlaceHolder()
delete d; delete d;
} }
void OutputPanePlaceHolder::currentModeChanged(IMode *mode) void OutputPanePlaceHolder::currentModeChanged(Id mode)
{ {
if (d->m_current == this) { if (d->m_current == this) {
d->m_current = 0; d->m_current = 0;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#pragma once #pragma once
#include "core_global.h" #include "id.h"
#include <QWidget> #include <QWidget>
...@@ -35,9 +35,6 @@ QT_END_NAMESPACE ...@@ -35,9 +35,6 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
class IMode;
namespace Internal { class OutputPaneManager; }
class OutputPanePlaceHolderPrivate; class OutputPanePlaceHolderPrivate;
class CORE_EXPORT OutputPanePlaceHolder : public QWidget class CORE_EXPORT OutputPanePlaceHolder : public QWidget
...@@ -45,7 +42,7 @@ class CORE_EXPORT OutputPanePlaceHolder : public QWidget ...@@ -45,7 +42,7 @@ class CORE_EXPORT OutputPanePlaceHolder : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit OutputPanePlaceHolder(IMode *mode, QSplitter *parent = 0); explicit OutputPanePlaceHolder(Id mode, QSplitter *parent = 0);
~OutputPanePlaceHolder(); ~OutputPanePlaceHolder();
static OutputPanePlaceHolder *getCurrent(); static OutputPanePlaceHolder *getCurrent();
...@@ -62,7 +59,7 @@ protected: ...@@ -62,7 +59,7 @@ protected:
private: private:
void setHeight(int height); void setHeight(int height);
void currentModeChanged(IMode *); void currentModeChanged(Id mode);
OutputPanePlaceHolderPrivate *d; OutputPanePlaceHolderPrivate *d;
}; };
......
...@@ -45,7 +45,7 @@ RightPanePlaceHolder* RightPanePlaceHolder::current() ...@@ -45,7 +45,7 @@ RightPanePlaceHolder* RightPanePlaceHolder::current()
return m_current; return m_current;
} }
RightPanePlaceHolder::RightPanePlaceHolder(IMode *mode, QWidget *parent) RightPanePlaceHolder::RightPanePlaceHolder(Id mode, QWidget *parent)
:QWidget(parent), m_mode(mode) :QWidget(parent), m_mode(mode)
{ {
setLayout(new QVBoxLayout); setLayout(new QVBoxLayout);
...@@ -92,7 +92,7 @@ void RightPanePlaceHolder::applyStoredSize(int width) ...@@ -92,7 +92,7 @@ void RightPanePlaceHolder::applyStoredSize(int width)
// m_current points to the current PlaceHolder, or zero if there // m_current points to the current PlaceHolder, or zero if there
// is no PlaceHolder in this mode // is no PlaceHolder in this mode
// And that the parent of the RightPaneWidget gets the correct parent // And that the parent of the RightPaneWidget gets the correct parent
void RightPanePlaceHolder::currentModeChanged(IMode *mode) void RightPanePlaceHolder::currentModeChanged(Id mode)
{ {
if (m_current == this) { if (m_current == this) {
m_current = 0; m_current = 0;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#pragma once #pragma once
#include "core_global.h" #include "id.h"
#include <QWidget> #include <QWidget>
#include <QPointer> #include <QPointer>
...@@ -45,14 +45,14 @@ class CORE_EXPORT RightPanePlaceHolder : public QWidget ...@@ -45,14 +45,14 @@ class CORE_EXPORT RightPanePlaceHolder : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit RightPanePlaceHolder(IMode *mode, QWidget *parent = 0); explicit RightPanePlaceHolder(Id mode, QWidget *parent = 0);
~RightPanePlaceHolder(); ~RightPanePlaceHolder();
static RightPanePlaceHolder *current(); static RightPanePlaceHolder *current();
private: private:
void currentModeChanged(IMode *); void currentModeChanged(Id mode);
void applyStoredSize(int width); void applyStoredSize(int width);
IMode *m_mode; Id m_mode;
static RightPanePlaceHolder* m_current; static RightPanePlaceHolder* m_current;
}; };
......
...@@ -205,7 +205,7 @@ void DebuggerMainWindow::finalizeSetup() ...@@ -205,7 +205,7 @@ void DebuggerMainWindow::finalizeSetup()
addDockWidget(Qt::BottomDockWidgetArea, dock); addDockWidget(Qt::BottomDockWidgetArea, dock);
} }
QWidget *createModeWindow(Core::IMode *mode, DebuggerMainWindow *mainWindow, QWidget *central) QWidget *createModeWindow(const Core::Id &mode, DebuggerMainWindow *mainWindow, QWidget *central)
{ {
if (!central) if (!central)
central = new EditorManagerPlaceHolder(mode); central = new EditorManagerPlaceHolder(mode);
......
...@@ -40,7 +40,7 @@ class QComboBox; ...@@ -40,7 +40,7 @@ class QComboBox;
class QStackedWidget; class QStackedWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { class IMode; } namespace Core { class Id; }
namespace Utils { namespace Utils {
...@@ -135,6 +135,6 @@ private: ...@@ -135,6 +135,6 @@ private:
QHash<QByteArray, Perspective> m_perspectiveForPerspectiveId; QHash<QByteArray, Perspective> m_perspectiveForPerspectiveId;
}; };
QWidget *createModeWindow(Core::IMode *mode, DebuggerMainWindow *mainWindow, QWidget *central); QWidget *createModeWindow(const Core::Id &mode, DebuggerMainWindow *mainWindow, QWidget *central);