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

use Core::Id for IMode::id and IMode::type



Change-Id: Ic7ce5b883e054c6eeba078327042e99e1c556345
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 2d612a25
......@@ -125,8 +125,8 @@ public:
setDisplayName(tr("Analyze"));
setIcon(QIcon(QLatin1String(":/images/analyzer_mode.png")));
setPriority(P_MODE_ANALYZE);
setId(QLatin1String(MODE_ANALYZE));
setType(QLatin1String(MODE_EDIT_TYPE));
setId(MODE_ANALYZE);
setType(MODE_EDIT_TYPE);
}
~AnalyzerMode()
......
......@@ -92,7 +92,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
if (success) {
m_editMode = new EditMode;
addObject(m_editMode);
m_mainWindow->modeManager()->activateMode(m_editMode->id());
ModeManager::activateMode(m_editMode->id());
m_designMode = new DesignMode;
}
return success;
......
......@@ -130,8 +130,8 @@ DesignMode::DesignMode()
setDisplayName(tr("Design"));
setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Design.png")));
setPriority(Constants::P_MODE_DESIGN);
setId(QLatin1String(Constants::MODE_DESIGN));
setType(QLatin1String(Constants::MODE_DESIGN_TYPE));
setId(Constants::MODE_DESIGN);
setType(Constants::MODE_DESIGN_TYPE);
ExtensionSystem::PluginManager::instance()->addObject(d->m_coreListener);
......@@ -237,7 +237,7 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
if (!mimeEditorAvailable) {
setActiveContext(Context());
if (ModeManager::currentMode() == this)
ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
ModeManager::activateMode(Core::Constants::MODE_EDIT);
setEnabled(false);
d->m_currentEditor = QWeakPointer<Core::IEditor>();
emit actionsUpdated(d->m_currentEditor.data());
......
......@@ -60,8 +60,8 @@ EditMode::EditMode() :
setDisplayName(tr("Edit"));
setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Edit.png")));
setPriority(Constants::P_MODE_EDIT);
setId(QLatin1String(Constants::MODE_EDIT));
setType(QLatin1String(Constants::MODE_EDIT_TYPE));
setId(Constants::MODE_EDIT);
setType(Constants::MODE_EDIT_TYPE);
m_rightSplitWidgetLayout->setSpacing(0);
m_rightSplitWidgetLayout->setMargin(0);
......
......@@ -1374,13 +1374,13 @@ QStringList EditorManager::getOpenFileNames() const
/// forcePrefered = false, only switch if it is not visible
void EditorManager::switchToPreferedMode()
{
QString preferedMode;
Id preferedMode;
// Figure out preferred mode for editor
if (d->m_currentEditor)
preferedMode = d->m_currentEditor->preferredModeType();
if (preferedMode.isEmpty())
preferedMode = QLatin1String(Constants::MODE_EDIT_TYPE);
if (!preferedMode.isValid())
preferedMode = Id(Constants::MODE_EDIT_TYPE);
ModeManager::activateModeType(preferedMode);
}
......
......@@ -72,7 +72,7 @@ public:
virtual QWidget *toolBar() = 0;
virtual QString preferredModeType() const { return QString(); }
virtual Id preferredModeType() const { return Id(); }
signals:
void changed();
......
......@@ -51,10 +51,10 @@ public:
QByteArray name() const;
QString toString() const;
bool isValid() const { return m_id; }
bool operator==(const Id &id) const { return m_id == id.m_id; }
bool operator!=(const Id &id) const { return m_id != id.m_id; }
bool operator<(const Id &id) const { return m_id < id.m_id; }
bool operator>(const Id &id) const { return m_id > id.m_id; }
bool operator==(Id id) const { return m_id == id.m_id; }
bool operator!=(Id id) const { return m_id != id.m_id; }
bool operator<(Id id) const { return m_id < id.m_id; }
bool operator>(Id id) const { return m_id > id.m_id; }
int uniqueIdentifier() const { return m_id; }
static Id fromUniqueIdentifier(int uid) { return Id(uid, uid); }
......
......@@ -34,6 +34,7 @@
#define IMODE_H
#include "icontext.h"
#include "id.h"
#include <QIcon>
......@@ -50,16 +51,16 @@ public:
QString displayName() const { return m_displayName; }
QIcon icon() const { return m_icon; }
int priority() const { return m_priority; }
QString id() const { return m_id; }
QString type() const { return m_type; }
Id id() const { return m_id; }
Id type() const { return m_type; }
bool isEnabled() const;
void setEnabled(bool enabled);
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
void setIcon(const QIcon &icon) { m_icon = icon; }
void setPriority(int priority) { m_priority = priority; }
void setId(const QString &id) { m_id = id; }
void setType(const QString &type) { m_type = type; }
void setId(Id id) { m_id = id; }
void setType(Id type) { m_type = type; }
signals:
void enabledStateChanged(bool enabled);
......@@ -68,8 +69,8 @@ private:
QString m_displayName;
QIcon m_icon;
int m_priority;
QString m_id;
QString m_type;
Id m_id;
Id m_type;
bool m_isEnabled;
};
......
......@@ -912,7 +912,7 @@ void MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesFlags f
if (!document && (flags & ICore::StopOnLoadFail))
return;
if (document && (flags & ICore::SwitchMode))
ModeManager::activateMode(QLatin1String(Core::Constants::MODE_EDIT));
ModeManager::activateMode(Id(Core::Constants::MODE_EDIT));
} else {
QFlags<EditorManager::OpenEditorFlag> emFlags;
if (flags & ICore::SwitchMode)
......@@ -969,7 +969,7 @@ void MainWindow::setFocusToEditor()
}
// switch to edit mode if necessary
ModeManager::activateMode(QLatin1String(Constants::MODE_EDIT));
ModeManager::activateMode(Id(Constants::MODE_EDIT));
}
void MainWindow::showNewItemDialog(const QString &title,
......
......@@ -85,13 +85,13 @@ struct ModeManagerPrivate
static ModeManagerPrivate *d;
static ModeManager *m_instance = 0;
static int indexOf(const QString &id)
static int indexOf(Id 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;
qDebug() << "Warning, no such mode:" << id.toString();
return -1;
}
......@@ -109,7 +109,7 @@ ModeManager::ModeManager(Internal::MainWindow *mainWindow,
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(slotActivateMode(QString)));
connect(d->m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotActivateMode(int)));
}
void ModeManager::init()
......@@ -143,7 +143,7 @@ IMode *ModeManager::currentMode()
return d->m_modes.at(currentIndex);
}
IMode *ModeManager::mode(const QString &id)
IMode *ModeManager::mode(Id id)
{
const int index = indexOf(id);
if (index >= 0)
......@@ -151,7 +151,7 @@ IMode *ModeManager::mode(const QString &id)
return 0;
}
void ModeManager::activateModeType(const QString &type)
void ModeManager::activateModeType(Id type)
{
if (currentMode() && currentMode()->type() == type)
return;
......@@ -166,12 +166,12 @@ void ModeManager::activateModeType(const QString &type)
d->m_modeStack->setCurrentIndex(index);
}
void ModeManager::slotActivateMode(const QString &id)
void ModeManager::slotActivateMode(int id)
{
m_instance->activateMode(id);
m_instance->activateMode(Id::fromUniqueIdentifier(id));
}
void ModeManager::activateMode(const QString &id)
void ModeManager::activateMode(Id id)
{
const int index = indexOf(id);
if (index >= 0)
......@@ -198,7 +198,7 @@ void ModeManager::objectAdded(QObject *obj)
// Register mode shortcut
ActionManager *am = d->m_mainWindow->actionManager();
const Id shortcutId(QLatin1String("QtCreator.Mode.") + mode->id());
const Id shortcutId(QLatin1String("QtCreator.Mode.") + mode->id().toString());
QShortcut *shortcut = new QShortcut(d->m_mainWindow);
shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName()));
Command *cmd = am->registerShortcut(shortcut, shortcutId, Context(Constants::C_GLOBAL));
......@@ -221,7 +221,7 @@ void ModeManager::objectAdded(QObject *obj)
currentCmd->setKeySequence(currentCmd->defaultKeySequence());
}
d->m_signalMapper->setMapping(shortcut, mode->id());
d->m_signalMapper->setMapping(shortcut, mode->id().uniqueIdentifier());
connect(shortcut, SIGNAL(activated()), d->m_signalMapper, SLOT(map()));
connect(mode, SIGNAL(enabledStateChanged(bool)),
this, SLOT(enabledStateChanged()));
......
......@@ -33,8 +33,9 @@
#ifndef MODEMANAGER_H
#define MODEMANAGER_H
#include <QObject>
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QObject>
QT_BEGIN_NAMESPACE
class QAction;
......@@ -61,15 +62,15 @@ public:
static ModeManager *instance();
static IMode *currentMode();
static IMode *mode(const QString &id);
static IMode *mode(Id id);
static void addAction(QAction *action, int priority);
static void addProjectSelector(QAction *action);
static void addWidget(QWidget *widget);
static void activateModeType(const QString &type);
static void activateModeType(Id type);
static void setModeBarHidden(bool hidden);
static void activateMode(const QString &id);
static void activateMode(Id id);
static void setFocusToCurrentMode();
signals:
......@@ -79,7 +80,7 @@ signals:
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode = 0);
private slots:
void slotActivateMode(const QString &id);
void slotActivateMode(int id);
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
void currentTabAboutToChange(int index);
......
......@@ -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::activateMode(QLatin1String(Constants::MODE_EDIT));
ModeManager::activateMode(Id(Constants::MODE_EDIT));
}
if (OutputPanePlaceHolder::getCurrent()) {
// make the page visible
......
......@@ -306,7 +306,7 @@ void DebuggerMainWindow::setEngineDebugLanguages(DebuggerLanguages languages)
void DebuggerMainWindow::onModeChanged(IMode *mode)
{
d->m_inDebugMode = (mode && mode->id() == QLatin1String(Constants::MODE_DEBUG));
d->m_inDebugMode = (mode && mode->id() == Constants::MODE_DEBUG);
setDockActionsVisible(d->m_inDebugMode);
// Hide all the debugger windows if mode is different.
......
......@@ -552,8 +552,8 @@ public:
setDisplayName(DebuggerPlugin::tr("Debug"));
setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Debug.png")));
setPriority(85);
setId(QLatin1String(MODE_DEBUG));
setType(QLatin1String(CC::MODE_EDIT_TYPE));
setId(MODE_DEBUG);
setType(CC::MODE_EDIT_TYPE);
}
~DebugMode()
......@@ -1123,7 +1123,7 @@ public:
DebuggerMainWindow *m_mainWindow;
DebuggerRunControlFactory *m_debuggerRunControlFactory;
QString m_previousMode;
Id m_previousMode;
QList<DebuggerStartParameters> m_scheduledStarts;
Utils::ProxyAction *m_visibleStartAction;
......@@ -2453,7 +2453,7 @@ void DebuggerPluginPrivate::onModeChanged(IMode *mode)
m_mainWindow->onModeChanged(mode);
if (mode->id() != QLatin1String(Constants::MODE_DEBUG)) {
if (mode->id() != Constants::MODE_DEBUG) {
m_toolTipManager->leavingDebugMode();
return;
}
......@@ -2497,10 +2497,10 @@ void DebuggerPluginPrivate::dumpLog()
/*! Activates the previous mode when the current mode is the debug mode. */
void DebuggerPluginPrivate::activatePreviousMode()
{
if (ModeManager::currentMode() == ModeManager::mode(QLatin1String(MODE_DEBUG))
&& !m_previousMode.isEmpty()) {
if (ModeManager::currentMode() == ModeManager::mode(MODE_DEBUG)
&& m_previousMode.isValid()) {
ModeManager::activateMode(m_previousMode);
m_previousMode.clear();
m_previousMode = Id();
}
}
......@@ -2509,7 +2509,7 @@ void DebuggerPluginPrivate::activateDebugMode()
m_reverseDirectionAction->setChecked(false);
m_reverseDirectionAction->setEnabled(false);
m_previousMode = ModeManager::currentMode()->id();
ModeManager::activateMode(_(MODE_DEBUG));
ModeManager::activateMode(MODE_DEBUG);
}
void DebuggerPluginPrivate::sessionLoaded()
......
......@@ -99,7 +99,7 @@ QStringList FormEditorFactory::mimeTypes() const
void FormEditorFactory::designerModeClicked()
{
Core::ModeManager::activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
}
} // namespace Internal
......
......@@ -188,10 +188,10 @@ SharedTools::WidgetHost *FormEditorStack::formWindowEditorForXmlEditor(const Cor
void FormEditorStack::modeAboutToChange(Core::IMode *m)
{
if (Designer::Constants::Internal::debug && m)
qDebug() << "FormEditorStack::modeAboutToChange" << m->id();
qDebug() << "FormEditorStack::modeAboutToChange" << m->id().toString();
// Sync the editor when entering edit mode
if (m && m->id() == QLatin1String(Core::Constants::MODE_EDIT))
if (m && m->id() == Core::Constants::MODE_EDIT)
foreach(const EditorData &data, m_formEditors)
data.formWindowEditor->syncXmlEditor();
}
......
......@@ -279,9 +279,9 @@ TextEditor::PlainTextEditor *FormWindowEditor::textEditor()
return &d->m_textEditor;
}
QString FormWindowEditor::preferredModeType() const
Core::Id FormWindowEditor::preferredModeType() const
{
return QLatin1String(Core::Constants::MODE_DESIGN_TYPE);
return Core::Constants::MODE_DESIGN_TYPE;
}
} // namespace Designer
......
......@@ -87,7 +87,7 @@ public:
virtual QWidget *toolBar();
virtual QString preferredModeType() const;
virtual Core::Id preferredModeType() const;
// For uic code model support
QString contents() const;
......
......@@ -53,9 +53,9 @@ GLSLEditorEditable::GLSLEditorEditable(GLSLTextEditorWidget *editor)
TextEditor::Constants::C_TEXTEDITOR));
}
QString GLSLEditorEditable::preferredModeType() const
Core::Id GLSLEditorEditable::preferredModeType() const
{
return QString();
return Core::Id();
}
} // namespace Internal
......
......@@ -52,7 +52,7 @@ public:
Core::Id id() const;
bool isTemporary() const { return false; }
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QString preferredModeType() const;
Core::Id preferredModeType() const;
};
} // namespace Internal
......
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