Commit 2df4cb21 authored by hjk's avatar hjk Committed by Eike Ziller
Browse files

Core::ModeManager: make some functions static



Change-Id: I5c1275ba3f596d8911fd2e4404181bf57b58f494
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 81ca5298
......@@ -871,7 +871,7 @@ QString AnalyzerManager::msgToolFinished(const QString &name, int issuesFound)
void AnalyzerManager::showMode()
{
if (m_instance->d->m_mode)
ModeManager::instance()->activateMode(m_instance->d->m_mode->id());
ModeManager::activateMode(m_instance->d->m_mode->id());
}
void AnalyzerManager::stopTool()
......
......@@ -236,8 +236,8 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
if (!mimeEditorAvailable) {
setActiveContext(Context());
if (ModeManager::instance()->currentMode() == this)
ModeManager::instance()->activateMode(QLatin1String(Core::Constants::MODE_EDIT));
if (ModeManager::currentMode() == this)
ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
setEnabled(false);
d->m_currentEditor = QWeakPointer<Core::IEditor>();
emit actionsUpdated(d->m_currentEditor.data());
......@@ -272,7 +272,7 @@ void DesignMode::setActiveContext(const Context &context)
if (d->m_activeContext == context)
return;
if (ModeManager::instance()->currentMode() == this)
if (ModeManager::currentMode() == this)
Core::ICore::updateAdditionalContexts(d->m_activeContext, context);
d->m_activeContext = context;
......
......@@ -89,8 +89,7 @@ EditMode::EditMode() :
m_splitter->setStretchFactor(0, 0);
m_splitter->setStretchFactor(1, 1);
ModeManager *modeManager = ModeManager::instance();
connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)),
connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(grabEditorManager(Core::IMode*)));
m_splitter->setFocusProxy(m_editorManager);
......
......@@ -151,7 +151,7 @@ EditorManagerPlaceHolder::EditorManagerPlaceHolder(Core::IMode *mode, QWidget *p
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
this, SLOT(currentModeChanged(Core::IMode *)));
currentModeChanged(Core::ModeManager::instance()->currentMode());
currentModeChanged(ModeManager::currentMode());
}
EditorManagerPlaceHolder::~EditorManagerPlaceHolder()
......@@ -1382,7 +1382,7 @@ void EditorManager::switchToPreferedMode()
if (preferedMode.isEmpty())
preferedMode = QLatin1String(Constants::MODE_EDIT_TYPE);
ModeManager::instance()->activateModeType(preferedMode);
ModeManager::activateModeType(preferedMode);
}
IEditor *EditorManager::openEditorWithContents(const Id &editorId,
......
......@@ -101,7 +101,7 @@ public:
static ScriptManager *scriptManager();
static VariableManager *variableManager();
static VcsManager *vcsManager();
static ModeManager *modeManager();
static QT_DEPRECATED ModeManager *modeManager(); // Use ModeManager::... directly.
static MimeDatabase *mimeDatabase();
static HelpManager *helpManager();
......
......@@ -875,7 +875,7 @@ void MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesFlags f
if (!file && (flags & ICore::StopOnLoadFail))
return;
if (file && (flags & ICore::SwitchMode))
Core::ModeManager::instance()->activateMode(QLatin1String(Core::Constants::MODE_EDIT));
ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
} else {
QFlags<EditorManager::OpenEditorFlag> emFlags;
if (flags & ICore::SwitchMode)
......@@ -932,7 +932,7 @@ void MainWindow::setFocusToEditor()
}
// switch to edit mode if necessary
m_coreImpl->modeManager()->activateMode(QLatin1String(Constants::MODE_EDIT));
ModeManager::activateMode(QLatin1String(Constants::MODE_EDIT));
}
void MainWindow::showNewItemDialog(const QString &title,
......
......@@ -71,11 +71,6 @@ namespace Core {
struct ModeManagerPrivate
{
explicit ModeManagerPrivate(Internal::MainWindow *mainWindow,
Internal::FancyTabWidget *modeStack,
ModeManager *q);
static ModeManager *m_instance;
Internal::MainWindow *m_mainWindow;
Internal::FancyTabWidget *m_modeStack;
Internal::FancyActionBar *m_actionBar;
......@@ -87,44 +82,49 @@ struct ModeManagerPrivate
int m_oldCurrent;
};
ModeManager *ModeManagerPrivate::m_instance = 0;
static ModeManagerPrivate *d;
static ModeManager *m_instance = 0;
ModeManagerPrivate::ModeManagerPrivate(Internal::MainWindow *mainWindow,
Internal::FancyTabWidget *modeStack,
ModeManager *q) :
m_mainWindow(mainWindow),
m_modeStack(modeStack),
m_signalMapper(new QSignalMapper(q)),
m_oldCurrent(-1)
static int indexOf(const QString &id)
{
for (int i = 0; i < d->m_modes.count(); ++i) {
if (d->m_modes.at(i)->id() == id)
return i;
}
qDebug() << "Warning, no such mode:" << id;
return -1;
}
ModeManager::ModeManager(Internal::MainWindow *mainWindow,
Internal::FancyTabWidget *modeStack) :
d(new ModeManagerPrivate(mainWindow, modeStack, this))
Internal::FancyTabWidget *modeStack)
{
ModeManagerPrivate::m_instance = this;
m_instance = this;
d = new ModeManagerPrivate();
d->m_mainWindow = mainWindow;
d->m_modeStack = modeStack;
d->m_signalMapper = new QSignalMapper(this);
d->m_oldCurrent = -1;
d->m_actionBar = new Internal::FancyActionBar(modeStack);
d->m_modeStack->addCornerWidget(d->m_actionBar);
connect(d->m_modeStack, SIGNAL(currentAboutToShow(int)), SLOT(currentTabAboutToChange(int)));
connect(d->m_modeStack, SIGNAL(currentChanged(int)), SLOT(currentTabChanged(int)));
connect(d->m_signalMapper, SIGNAL(mapped(QString)), this, SLOT(activateMode(QString)));
connect(d->m_signalMapper, SIGNAL(mapped(QString)), this, SLOT(slotActivateMode(QString)));
}
void ModeManager::init()
{
QObject::connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject*)),
this, SLOT(objectAdded(QObject*)));
m_instance, SLOT(objectAdded(QObject*)));
QObject::connect(ExtensionSystem::PluginManager::instance(), SIGNAL(aboutToRemoveObject(QObject*)),
this, SLOT(aboutToRemoveObject(QObject*)));
m_instance, SLOT(aboutToRemoveObject(QObject*)));
}
ModeManager::~ModeManager()
{
delete d;
ModeManagerPrivate::m_instance = 0;
d = 0;
m_instance = 0;
}
void ModeManager::addWidget(QWidget *widget)
......@@ -135,7 +135,7 @@ void ModeManager::addWidget(QWidget *widget)
d->m_modeStack->insertCornerWidget(d->m_modeStack->cornerWidgetCount() -1, widget);
}
IMode *ModeManager::currentMode() const
IMode *ModeManager::currentMode()
{
int currentIndex = d->m_modeStack->currentIndex();
if (currentIndex < 0)
......@@ -143,17 +143,7 @@ IMode *ModeManager::currentMode() const
return d->m_modes.at(currentIndex);
}
int ModeManager::indexOf(const QString &id) const
{
for (int i = 0; i < d->m_modes.count(); ++i) {
if (d->m_modes.at(i)->id() == id)
return i;
}
qDebug() << "Warning, no such mode:" << id;
return -1;
}
IMode *ModeManager::mode(const QString &id) const
IMode *ModeManager::mode(const QString &id)
{
const int index = indexOf(id);
if (index >= 0)
......@@ -176,6 +166,11 @@ void ModeManager::activateModeType(const QString &type)
d->m_modeStack->setCurrentIndex(index);
}
void ModeManager::slotActivateMode(const QString &id)
{
m_instance->activateMode(id);
}
void ModeManager::activateMode(const QString &id)
{
const int index = indexOf(id);
......@@ -347,7 +342,7 @@ void ModeManager::setModeBarHidden(bool hidden)
ModeManager *ModeManager::instance()
{
return ModeManagerPrivate::m_instance;
return m_instance;
}
} // namespace Core
......@@ -49,8 +49,6 @@ namespace Internal {
class FancyTabWidget;
}
struct ModeManagerPrivate;
class CORE_EXPORT ModeManager : public QObject
{
Q_OBJECT
......@@ -59,18 +57,20 @@ public:
explicit ModeManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack);
virtual ~ModeManager();
void init();
static void init();
static ModeManager *instance();
IMode *currentMode() const;
IMode *mode(const QString &id) const;
static IMode *currentMode();
static IMode *mode(const QString &id);
void addAction(QAction *action, int priority);
void addProjectSelector(QAction *action);
void addWidget(QWidget *widget);
static void addAction(QAction *action, int priority);
static void addProjectSelector(QAction *action);
static void addWidget(QWidget *widget);
void activateModeType(const QString &type);
void setModeBarHidden(bool hidden);
static void activateModeType(const QString &type);
static void setModeBarHidden(bool hidden);
static void activateMode(const QString &id);
static void setFocusToCurrentMode();
signals:
void currentModeAboutToChange(Core::IMode *mode);
......@@ -78,22 +78,14 @@ signals:
// the default argument '=0' is important for connects without the oldMode argument.
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode = 0);
public slots:
void activateMode(const QString &id);
void setFocusToCurrentMode();
private slots:
void slotActivateMode(const QString &id);
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
void currentTabAboutToChange(int index);
void currentTabChanged(int index);
void updateModeToolTip();
void enabledStateChanged();
private:
int indexOf(const QString &id) const;
ModeManagerPrivate *d;
};
} // namespace Core
......
......@@ -450,7 +450,7 @@ void OutputPaneManager::showPage(int idx, bool focus)
if (!OutputPanePlaceHolder::getCurrent()) {
// In this mode we don't have a placeholder
// switch to the output mode and switch the page
ModeManager::instance()->activateMode(QLatin1String(Constants::MODE_EDIT));
ModeManager::activateMode(QLatin1String(Constants::MODE_EDIT));
}
if (OutputPanePlaceHolder::getCurrent()) {
// make the page visible
......
......@@ -2462,7 +2462,7 @@ void DebuggerPluginPrivate::updateDebugActions()
void DebuggerPluginPrivate::onCoreAboutToOpen()
{
m_mainWindow->onModeChanged(ModeManager::instance()->currentMode());
m_mainWindow->onModeChanged(ModeManager::currentMode());
}
void DebuggerPluginPrivate::onModeChanged(IMode *mode)
......@@ -2517,10 +2517,9 @@ void DebuggerPluginPrivate::dumpLog()
/*! Activates the previous mode when the current mode is the debug mode. */
void DebuggerPluginPrivate::activatePreviousMode()
{
ModeManager *modeManager = ModeManager::instance();
if (modeManager->currentMode() == modeManager->mode(QLatin1String(MODE_DEBUG))
if (ModeManager::currentMode() == ModeManager::mode(QLatin1String(MODE_DEBUG))
&& !m_previousMode.isEmpty()) {
modeManager->activateMode(m_previousMode);
ModeManager::activateMode(m_previousMode);
m_previousMode.clear();
}
}
......@@ -2529,9 +2528,8 @@ void DebuggerPluginPrivate::activateDebugMode()
{
m_reverseDirectionAction->setChecked(false);
m_reverseDirectionAction->setEnabled(false);
ModeManager *modeManager = ModeManager::instance();
m_previousMode = modeManager->currentMode()->id();
modeManager->activateMode(_(MODE_DEBUG));
m_previousMode = ModeManager::currentMode()->id();
ModeManager::activateMode(_(MODE_DEBUG));
}
void DebuggerPluginPrivate::sessionLoaded()
......@@ -3178,8 +3176,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
m_visibleStartAction->setAttribute(Utils::ProxyAction::UpdateIcon);
m_visibleStartAction->setAction(cmd->action());
ModeManager *modeManager = ModeManager::instance();
modeManager->addAction(m_visibleStartAction, Constants::P_ACTION_DEBUG);
ModeManager::addAction(m_visibleStartAction, Constants::P_ACTION_DEBUG);
cmd = am->registerAction(m_debugWithoutDeployAction,
"Debugger.DebugWithoutDeploy", globalcontext);
......
......@@ -98,7 +98,7 @@ QStringList FormEditorFactory::mimeTypes() const
void FormEditorFactory::designerModeClicked()
{
Core::ModeManager::instance()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
Core::ModeManager::activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
}
} // namespace Internal
......
......@@ -663,7 +663,7 @@ void HelpPlugin::resetRightPaneScale()
void HelpPlugin::activateHelpMode()
{
if (contextHelpOption() != Help::Constants::ExternalHelpAlways)
Core::ModeManager::instance()->activateMode(QLatin1String(Constants::ID_MODE_HELP));
Core::ModeManager::activateMode(QLatin1String(Constants::ID_MODE_HELP));
else
showExternalWindow();
}
......@@ -785,8 +785,8 @@ void HelpPlugin::contextHelpOptionChanged()
m_externalWindow->show();
connectExternalHelpWindow();
if (m_oldMode && m_mode == ModeManager::instance()->currentMode())
ModeManager::instance()->activateMode(m_oldMode->id());
if (m_oldMode && m_mode == ModeManager::currentMode())
ModeManager::activateMode(m_oldMode->id());
}
}
} else if (modeWidget != m_splitter
......@@ -815,15 +815,15 @@ void HelpPlugin::contextHelpOptionChanged()
void HelpPlugin::setupHelpEngineIfNeeded()
{
m_helpManager->setEngineNeedsUpdate();
if (Core::ModeManager::instance()->currentMode() == m_mode
if (Core::ModeManager::currentMode() == m_mode
|| contextHelpOption() == Help::Constants::ExternalHelpAlways)
m_helpManager->setupGuiHelpEngine();
}
HelpViewer *HelpPlugin::viewerForContextMode()
{
if (ModeManager::instance()->currentMode()->id() == Core::Constants::MODE_WELCOME)
ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
if (ModeManager::currentMode()->id() == Core::Constants::MODE_WELCOME)
ModeManager::activateMode(Core::Constants::MODE_EDIT);
bool showSideBySide = false;
RightPanePlaceHolder *placeHolder = RightPanePlaceHolder::current();
......@@ -873,7 +873,7 @@ void HelpPlugin::activateContext()
switchToHelpMode();
return;
}
if (ModeManager::instance()->currentMode() == m_mode)
if (ModeManager::currentMode() == m_mode)
return;
// Find out what to show
......
......@@ -243,8 +243,7 @@ void OpenPagesManager::closeCurrentPage()
false).toBool();
if (m_model->rowCount() == 1 && closeOnReturn) {
Core::ModeManager *modeManager = Core::ModeManager::instance();
modeManager->activateMode(Core::Constants::MODE_EDIT);
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
} else {
Q_ASSERT(indexes.count() == 1);
removePage(indexes.first().row());
......
......@@ -469,7 +469,7 @@ bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
case Qt::Key_Escape:
if (!ke->modifiers()) {
event->accept();
QTimer::singleShot(0, Core::ModeManager::instance(), SLOT(setFocusToCurrentMode()));
QTimer::singleShot(0, this, SLOT(setFocusToCurrentMode()));
return true;
}
case Qt::Key_Alt:
......@@ -485,6 +485,11 @@ bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
return QWidget::eventFilter(obj, event);
}
void LocatorWidget::setFocusToCurrentMode()
{
Core::ModeManager::setFocusToCurrentMode();
}
void LocatorWidget::showCompletionList()
{
const int border = m_completionList->frameWidth();
......
......@@ -77,6 +77,7 @@ private slots:
void showConfigureDialog();
void updateEntries();
void scheduleAcceptCurrentEntry();
void setFocusToCurrentMode();
private:
bool eventFilter(QObject *obj, QEvent *event);
......
......@@ -103,7 +103,7 @@ MaemoQemuManager::MaemoQemuManager(QObject *parent)
qemuCommand->setAttribute(Core::Command::CA_UpdateText);
qemuCommand->setAttribute(Core::Command::CA_UpdateIcon);
Core::ModeManager::instance()->addAction(qemuCommand->action(), 1);
Core::ModeManager::addAction(qemuCommand->action(), 1);
m_qemuAction->setEnabled(false);
m_qemuAction->setVisible(false);
......
......@@ -690,7 +690,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
// Add to mode bar
Core::ModeManager::instance()->addAction(cmd->action(), Constants::P_ACTION_BUILDPROJECT);
Core::ModeManager::addAction(cmd->action(), Constants::P_ACTION_BUILDPROJECT);
// rebuild action
d->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
......@@ -780,7 +780,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R")));
mbuild->addAction(cmd, Constants::G_BUILD_RUN);
Core::ModeManager::instance()->addAction(cmd->action(), Constants::P_ACTION_RUN);
Core::ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN);
d->m_runActionContextMenu = new QAction(runIcon, tr("Run"), this);
cmd = am->registerAction(d->m_runActionContextMenu, Constants::RUNCONTEXTMENU, projecTreeContext);
......@@ -886,7 +886,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
QWidget *mainWindow = Core::ICore::mainWindow();
d->m_targetSelector = new Internal::MiniProjectTargetSelector(d->m_projectSelectorAction, d->m_session, mainWindow);
connect(d->m_projectSelectorAction, SIGNAL(triggered()), d->m_targetSelector, SLOT(show()));
Core::ModeManager::instance()->addProjectSelector(d->m_projectSelectorAction);
Core::ModeManager::addProjectSelector(d->m_projectSelectorAction);
d->m_projectSelectorActionMenu = new QAction(this);
d->m_projectSelectorActionMenu->setEnabled(false);
......@@ -1197,9 +1197,8 @@ void ProjectExplorerPlugin::showSessionManager()
updateActions();
Core::ModeManager *modeManager = Core::ModeManager::instance();
Core::IMode *welcomeMode = modeManager->mode(QLatin1String(Core::Constants::MODE_WELCOME));
if (modeManager->currentMode() == welcomeMode)
Core::IMode *welcomeMode = Core::ModeManager::mode(QLatin1String(Core::Constants::MODE_WELCOME));
if (Core::ModeManager::currentMode() == welcomeMode)
updateWelcomePage();
}
......@@ -1342,7 +1341,7 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
updateActions();
if (!openedPro.isEmpty())
Core::ModeManager::instance()->activateMode(QLatin1String(Core::Constants::MODE_EDIT));
Core::ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
return openedPro;
}
......@@ -1435,7 +1434,7 @@ void ProjectExplorerPlugin::determineSessionToRestoreAtStartup()
d->m_sessionToRestoreAtStartup = d->m_session->lastSession();
if (!d->m_sessionToRestoreAtStartup.isNull())
Core::ModeManager::instance()->activateMode(QLatin1String(Core::Constants::MODE_EDIT));
Core::ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
}
/*!
......
......@@ -560,8 +560,8 @@ bool SessionManager::createImpl(const QString &fileName)
setStartupProject(0);
if (!isDefaultVirgin()) {
ModeManager::instance()->activateMode(QLatin1String(Core::Constants::MODE_EDIT));
ModeManager::instance()->setFocusToCurrentMode();
ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
ModeManager::setFocusToCurrentMode();
}
emit sessionLoaded();
......@@ -636,8 +636,8 @@ bool SessionManager::loadImpl(const QString &fileName)
if (modeIdentifier.isEmpty())
modeIdentifier = QLatin1String(Core::Constants::MODE_EDIT);
ModeManager::instance()->activateMode(modeIdentifier);
ModeManager::instance()->setFocusToCurrentMode();
ModeManager::activateMode(modeIdentifier);
ModeManager::setFocusToCurrentMode();
emit sessionLoaded();
}
......
......@@ -182,7 +182,7 @@ QList<QToolButton *> NavigatorSideBarItem::createToolBarWidgets()
void DocumentWarningWidget::goToError()
{
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
}
// ---------- DesignModeWidget
......
......@@ -288,7 +288,7 @@ void BauhausPlugin::createDesignModeWidget()
void BauhausPlugin::updateEditor(Core::IEditor *editor)
{
if (editor && editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID
&& Core::ModeManager::instance()->currentMode() == m_designMode)
&& Core::ModeManager::currentMode() == m_designMode)
{
m_mainWidget->showEditor(editor);
}
......@@ -371,18 +371,16 @@ BauhausPlugin *BauhausPlugin::pluginInstance()
void BauhausPlugin::switchTextDesign()
{
Core::ModeManager *modeManager = Core::ModeManager::instance();
Core::EditorManager *editorManager = Core::EditorManager::instance();
Core::IEditor *editor = editorManager->currentEditor();
if (modeManager->currentMode()->id() == Core::Constants::MODE_EDIT) {
if (Core::ModeManager::currentMode()->id() == Core::Constants::MODE_EDIT) {
if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) {
modeManager->activateMode(Core::Constants::MODE_DESIGN);
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
m_mainWidget->setFocus();
}
} else if (modeManager->currentMode()->id() == Core::Constants::MODE_DESIGN) {
modeManager->activateMode(Core::Constants::MODE_EDIT);
} else if (Core::ModeManager::currentMode()->id() == Core::Constants::MODE_DESIGN) {
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment