Commit c7e8b51d authored by hjk's avatar hjk
Browse files

core: use a class derived from QList<int> instead of a QList<int> for Core::Context

A mostly mechanical change.

Reviewed-By: con
parent a54fc1f6
...@@ -319,7 +319,7 @@ public: ...@@ -319,7 +319,7 @@ public:
QWidget *widget() { return m_editor; } QWidget *widget() { return m_editor; }
QList<int> context() const { return m_context; } Core::Context context() const { return m_context; }
bool createNew(const QString & /* contents */ = QString()) { bool createNew(const QString & /* contents */ = QString()) {
m_editor->setData(QByteArray()); m_editor->setData(QByteArray());
...@@ -354,7 +354,7 @@ private: ...@@ -354,7 +354,7 @@ private:
BinEditor *m_editor; BinEditor *m_editor;
QString m_displayName; QString m_displayName;
BinEditorFile *m_file; BinEditorFile *m_file;
QList<int> m_context; Core::Context m_context;
QToolBar *m_toolBar; QToolBar *m_toolBar;
Utils::LineColumnLabel *m_cursorPositionLabel; Utils::LineColumnLabel *m_cursorPositionLabel;
}; };
......
...@@ -69,7 +69,7 @@ private slots: ...@@ -69,7 +69,7 @@ private slots:
void updateCurrentEditor(Core::IContext *object); void updateCurrentEditor(Core::IContext *object);
private: private:
QList<int> m_context; Core::Context m_context;
QAction *registerNewAction(const QString &id, const QString &title = QString()); QAction *registerNewAction(const QString &id, const QString &title = QString());
QAction *registerNewAction(const QString &id, QObject *receiver, const char *slot, QAction *registerNewAction(const QString &id, QObject *receiver, const char *slot,
const QString &title = QString()); const QString &title = QString());
......
...@@ -303,7 +303,7 @@ BookmarkContext::BookmarkContext(BookmarkView *widget) ...@@ -303,7 +303,7 @@ BookmarkContext::BookmarkContext(BookmarkView *widget)
m_context << UniqueIDManager::instance()->uniqueIdentifier(Constants::BOOKMARKS_CONTEXT); m_context << UniqueIDManager::instance()->uniqueIdentifier(Constants::BOOKMARKS_CONTEXT);
} }
QList<int> BookmarkContext::context() const Context BookmarkContext::context() const
{ {
return m_context; return m_context;
} }
...@@ -321,7 +321,7 @@ BookmarkManager::BookmarkManager() : ...@@ -321,7 +321,7 @@ BookmarkManager::BookmarkManager() :
m_bookmarkIcon(QLatin1String(":/bookmarks/images/bookmark.png")), m_bookmarkIcon(QLatin1String(":/bookmarks/images/bookmark.png")),
m_selectionModel(new QItemSelectionModel(this, this)) m_selectionModel(new QItemSelectionModel(this, this))
{ {
connect(Core::ICore::instance(), SIGNAL(contextChanged(Core::IContext*,QList<int>)), connect(Core::ICore::instance(), SIGNAL(contextChanged(Core::IContext*,Core::Context)),
this, SLOT(updateActionStatus())); this, SLOT(updateActionStatus()));
connect(ProjectExplorerPlugin::instance()->session(), SIGNAL(sessionLoaded()), connect(ProjectExplorerPlugin::instance()->session(), SIGNAL(sessionLoaded()),
......
...@@ -161,11 +161,11 @@ class BookmarkContext : public Core::IContext ...@@ -161,11 +161,11 @@ class BookmarkContext : public Core::IContext
{ {
public: public:
BookmarkContext(BookmarkView *widget); BookmarkContext(BookmarkView *widget);
virtual QList<int> context() const; virtual Core::Context context() const;
virtual QWidget *widget(); virtual QWidget *widget();
private: private:
BookmarkView *m_bookmarkView; BookmarkView *m_bookmarkView;
QList<int> m_context; Core::Context m_context;
}; };
class BookmarkViewFactory : public Core::INavigationWidgetFactory class BookmarkViewFactory : public Core::INavigationWidgetFactory
......
...@@ -69,13 +69,9 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *) ...@@ -69,13 +69,9 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *)
{ {
Core::ICore *core = Core::ICore::instance(); Core::ICore *core = Core::ICore::instance();
Core::ActionManager *am = core->actionManager(); Core::ActionManager *am = core->actionManager();
Core::UniqueIDManager *uidm = core->uniqueIDManager();
QList<int> context = QList<int>() << core->uniqueIDManager()-> Core::Context textcontext(uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR));
uniqueIdentifier(Constants::BOOKMARKS_CONTEXT); Core::Context globalcontext(Core::Constants::C_GLOBAL_ID);
QList<int> textcontext, globalcontext;
textcontext << core->uniqueIDManager()->
uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
globalcontext << Core::Constants::C_GLOBAL_ID;
Core::ActionContainer *mtools = Core::ActionContainer *mtools =
am->actionContainer(Core::Constants::M_TOOLS); am->actionContainer(Core::Constants::M_TOOLS);
......
...@@ -56,7 +56,7 @@ CMakeEditorEditable::CMakeEditorEditable(CMakeEditor *editor) ...@@ -56,7 +56,7 @@ CMakeEditorEditable::CMakeEditorEditable(CMakeEditor *editor)
m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR); m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
} }
QList<int> CMakeEditorEditable::context() const Core::Context CMakeEditorEditable::context() const
{ {
return m_context; return m_context;
} }
......
...@@ -53,14 +53,14 @@ class CMakeEditorEditable : public TextEditor::BaseTextEditorEditable ...@@ -53,14 +53,14 @@ class CMakeEditorEditable : public TextEditor::BaseTextEditorEditable
{ {
public: public:
CMakeEditorEditable(CMakeEditor *); CMakeEditorEditable(CMakeEditor *);
QList<int> context() const; Core::Context context() const;
bool duplicateSupported() const { return true; } bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent); Core::IEditor *duplicate(QWidget *parent);
QString id() const; QString id() const;
bool isTemporary() const { return false; } bool isTemporary() const { return false; }
private: private:
QList<int> m_context; Core::Context m_context;
}; };
class CMakeEditor : public TextEditor::BaseTextEditor class CMakeEditor : public TextEditor::BaseTextEditor
......
...@@ -265,7 +265,7 @@ bool ActionManagerPrivate::hasContext(int context) const ...@@ -265,7 +265,7 @@ bool ActionManagerPrivate::hasContext(int context) const
return m_context.contains(context); return m_context.contains(context);
} }
void ActionManagerPrivate::setContext(const QList<int> &context) void ActionManagerPrivate::setContext(const Context &context)
{ {
// here are possibilities for speed optimization if necessary: // here are possibilities for speed optimization if necessary:
// let commands (de-)register themselves for contexts // let commands (de-)register themselves for contexts
...@@ -276,9 +276,9 @@ void ActionManagerPrivate::setContext(const QList<int> &context) ...@@ -276,9 +276,9 @@ void ActionManagerPrivate::setContext(const QList<int> &context)
it.value()->setCurrentContext(m_context); it.value()->setCurrentContext(m_context);
} }
bool ActionManagerPrivate::hasContext(QList<int> context) const bool ActionManagerPrivate::hasContext(const Context &context) const
{ {
for (int i=0; i<m_context.count(); ++i) { for (int i = 0; i < m_context.count(); ++i) {
if (context.contains(m_context.at(i))) if (context.contains(m_context.at(i)))
return true; return true;
} }
...@@ -321,7 +321,7 @@ ActionContainer *ActionManagerPrivate::createMenuBar(const QString &id) ...@@ -321,7 +321,7 @@ ActionContainer *ActionManagerPrivate::createMenuBar(const QString &id)
return mbc; return mbc;
} }
Command *ActionManagerPrivate::registerAction(QAction *action, const QString &id, const QList<int> &context) Command *ActionManagerPrivate::registerAction(QAction *action, const QString &id, const Context &context)
{ {
Action *a = 0; Action *a = 0;
Command *c = registerOverridableAction(action, id, false); Command *c = registerOverridableAction(action, id, false);
...@@ -377,7 +377,7 @@ Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const ...@@ -377,7 +377,7 @@ Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const
return a; return a;
} }
Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QString &id, const QList<int> &context) Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QString &id, const Context &context)
{ {
Shortcut *sc = 0; Shortcut *sc = 0;
int uid = UniqueIDManager::instance()->uniqueIdentifier(id); int uid = UniqueIDManager::instance()->uniqueIdentifier(id);
...@@ -404,7 +404,7 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QStri ...@@ -404,7 +404,7 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QStri
sc->setShortcut(shortcut); sc->setShortcut(shortcut);
if (context.isEmpty()) if (context.isEmpty())
sc->setContext(QList<int>() << 0); sc->setContext(Context(0));
else else
sc->setContext(context); sc->setContext(context);
......
...@@ -45,6 +45,7 @@ namespace Core { ...@@ -45,6 +45,7 @@ namespace Core {
class ActionContainer; class ActionContainer;
class Command; class Command;
class Context;
class CORE_EXPORT ActionManager : public QObject class CORE_EXPORT ActionManager : public QObject
{ {
...@@ -56,8 +57,8 @@ public: ...@@ -56,8 +57,8 @@ public:
virtual ActionContainer *createMenu(const QString &id) = 0; virtual ActionContainer *createMenu(const QString &id) = 0;
virtual ActionContainer *createMenuBar(const QString &id) = 0; virtual ActionContainer *createMenuBar(const QString &id) = 0;
virtual Command *registerAction(QAction *action, const QString &id, const QList<int> &context) = 0; virtual Command *registerAction(QAction *action, const QString &id, const Context &context) = 0;
virtual Command *registerShortcut(QShortcut *shortcut, const QString &id, const QList<int> &context) = 0; virtual Command *registerShortcut(QShortcut *shortcut, const QString &id, const Context &context) = 0;
virtual Command *command(const QString &id) const = 0; virtual Command *command(const QString &id) const = 0;
virtual ActionContainer *actionContainer(const QString &id) const = 0; virtual ActionContainer *actionContainer(const QString &id) const = 0;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define ACTIONMANAGERPRIVATE_H #define ACTIONMANAGERPRIVATE_H
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icontext.h>
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QHash> #include <QtCore/QHash>
...@@ -64,7 +65,7 @@ public: ...@@ -64,7 +65,7 @@ public:
explicit ActionManagerPrivate(MainWindow *mainWnd); explicit ActionManagerPrivate(MainWindow *mainWnd);
~ActionManagerPrivate(); ~ActionManagerPrivate();
void setContext(const QList<int> &context); void setContext(const Context &context);
static ActionManagerPrivate *instance(); static ActionManagerPrivate *instance();
void saveSettings(QSettings *settings); void saveSettings(QSettings *settings);
...@@ -85,19 +86,19 @@ public: ...@@ -85,19 +86,19 @@ public:
ActionContainer *createMenuBar(const QString &id); ActionContainer *createMenuBar(const QString &id);
Command *registerAction(QAction *action, const QString &id, Command *registerAction(QAction *action, const QString &id,
const QList<int> &context); const Context &context);
Command *registerShortcut(QShortcut *shortcut, const QString &id, Command *registerShortcut(QShortcut *shortcut, const QString &id,
const QList<int> &context); const Context &context);
Core::Command *command(const QString &id) const; Core::Command *command(const QString &id) const;
Core::ActionContainer *actionContainer(const QString &id) const; Core::ActionContainer *actionContainer(const QString &id) const;
private: private:
bool hasContext(QList<int> context) const; bool hasContext(const Context &context) const;
Command *registerOverridableAction(QAction *action, const QString &id, Command *registerOverridableAction(QAction *action, const QString &id,
bool checkUnique); bool checkUnique);
static ActionManagerPrivate* m_instance; static ActionManagerPrivate *m_instance;
QList<int> m_defaultGroups; QList<int> m_defaultGroups;
typedef QHash<int, CommandPrivate *> IdCmdMap; typedef QHash<int, CommandPrivate *> IdCmdMap;
...@@ -109,7 +110,7 @@ private: ...@@ -109,7 +110,7 @@ private:
// typedef QMap<int, int> GlobalGroupMap; // typedef QMap<int, int> GlobalGroupMap;
// GlobalGroupMap m_globalgroups; // GlobalGroupMap m_globalgroups;
// //
QList<int> m_context; Context m_context;
MainWindow *m_mainWnd; MainWindow *m_mainWnd;
}; };
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "command_p.h" #include "command_p.h"
#include "icore.h" #include "icore.h"
#include "icontext.h"
#include "uniqueidmanager.h" #include "uniqueidmanager.h"
#include <QtCore/QDebug> #include <QtCore/QDebug>
...@@ -238,7 +239,7 @@ QShortcut *CommandPrivate::shortcut() const ...@@ -238,7 +239,7 @@ QShortcut *CommandPrivate::shortcut() const
return 0; return 0;
} }
QList<int> CommandPrivate::context() const Core::Context CommandPrivate::context() const
{ {
return m_context; return m_context;
} }
...@@ -295,12 +296,12 @@ QShortcut *Shortcut::shortcut() const ...@@ -295,12 +296,12 @@ QShortcut *Shortcut::shortcut() const
return m_shortcut; return m_shortcut;
} }
void Shortcut::setContext(const QList<int> &context) void Shortcut::setContext(const Core::Context &context)
{ {
m_context = context; m_context = context;
} }
QList<int> Shortcut::context() const Core::Context Shortcut::context() const
{ {
return m_context; return m_context;
} }
...@@ -333,7 +334,7 @@ QString Shortcut::defaultText() const ...@@ -333,7 +334,7 @@ QString Shortcut::defaultText() const
return m_defaultText; return m_defaultText;
} }
bool Shortcut::setCurrentContext(const QList<int> &context) bool Shortcut::setCurrentContext(const Context &context)
{ {
foreach (int ctxt, m_context) { foreach (int ctxt, m_context) {
if (context.contains(ctxt)) { if (context.contains(ctxt)) {
...@@ -431,7 +432,7 @@ QKeySequence Action::keySequence() const ...@@ -431,7 +432,7 @@ QKeySequence Action::keySequence() const
return m_action->shortcut(); return m_action->shortcut();
} }
bool Action::setCurrentContext(const QList<int> &context) bool Action::setCurrentContext(const Core::Context &context)
{ {
m_context = context; m_context = context;
...@@ -484,7 +485,7 @@ static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAc ...@@ -484,7 +485,7 @@ static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAc
return msg; return msg;
} }
void Action::addOverrideAction(QAction *action, const QList<int> &context) void Action::addOverrideAction(QAction *action, const Core::Context &context)
{ {
if (context.isEmpty()) { if (context.isEmpty()) {
m_contextActionMap.insert(0, action); m_contextActionMap.insert(0, action);
......
...@@ -43,6 +43,8 @@ QT_END_NAMESPACE ...@@ -43,6 +43,8 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
class Context;
class CORE_EXPORT Command : public QObject class CORE_EXPORT Command : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -65,7 +67,7 @@ public: ...@@ -65,7 +67,7 @@ public:
virtual QAction *action() const = 0; virtual QAction *action() const = 0;
virtual QShortcut *shortcut() const = 0; virtual QShortcut *shortcut() const = 0;
virtual QList<int> context() const = 0; virtual Context context() const = 0;
virtual void setAttribute(CommandAttribute attr) = 0; virtual void setAttribute(CommandAttribute attr) = 0;
virtual void removeAttribute(CommandAttribute attr) = 0; virtual void removeAttribute(CommandAttribute attr) = 0;
......
...@@ -60,19 +60,19 @@ public: ...@@ -60,19 +60,19 @@ public:
QAction *action() const; QAction *action() const;
QShortcut *shortcut() const; QShortcut *shortcut() const;
QList<int> context() const; Context context() const;
void setAttribute(CommandAttribute attr); void setAttribute(CommandAttribute attr);
void removeAttribute(CommandAttribute attr); void removeAttribute(CommandAttribute attr);
bool hasAttribute(CommandAttribute attr) const; bool hasAttribute(CommandAttribute attr) const;
virtual bool setCurrentContext(const QList<int> &context) = 0; virtual bool setCurrentContext(const Context &context) = 0;
QString stringWithAppendedShortcut(const QString &str) const; QString stringWithAppendedShortcut(const QString &str) const;
protected: protected:
QList<int> m_context; Context m_context;
QString m_category; QString m_category;
int m_attributes; int m_attributes;
int m_id; int m_id;
...@@ -98,9 +98,9 @@ public: ...@@ -98,9 +98,9 @@ public:
void setShortcut(QShortcut *shortcut); void setShortcut(QShortcut *shortcut);
QShortcut *shortcut() const; QShortcut *shortcut() const;
void setContext(const QList<int> &context); void setContext(const Context &context);
QList<int> context() const; Context context() const;
bool setCurrentContext(const QList<int> &context); bool setCurrentContext(const Context &context);
bool isActive() const; bool isActive() const;
private: private:
...@@ -126,9 +126,9 @@ public: ...@@ -126,9 +126,9 @@ public:
void setLocations(const QList<CommandLocation> &locations); void setLocations(const QList<CommandLocation> &locations);
QList<CommandLocation> locations() const; QList<CommandLocation> locations() const;
bool setCurrentContext(const QList<int> &context); bool setCurrentContext(const Context &context);
bool isActive() const; bool isActive() const;
void addOverrideAction(QAction *action, const QList<int> &context); void addOverrideAction(QAction *action, const Context &context);
protected: protected:
void updateToolTipWithKeySequence(); void updateToolTipWithKeySequence();
......
...@@ -58,7 +58,7 @@ public: ...@@ -58,7 +58,7 @@ public:
int priority() const { return m_priority; } int priority() const { return m_priority; }
QWidget *widget() { return m_widget; } QWidget *widget() { return m_widget; }
QString id() const { return m_id; } QString id() const { return m_id; }
QList<int> context() const { return m_context; } Context context() const { return m_context; }
QString contextHelpId() const { return m_helpId; } QString contextHelpId() const { return m_helpId; }
void setDisplayName(const QString &name) { m_displayName = name; } void setDisplayName(const QString &name) { m_displayName = name; }
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
void setWidget(QWidget *widget) { m_widget = widget; } void setWidget(QWidget *widget) { m_widget = widget; }
void setId(const QString &id) { m_id = id; } void setId(const QString &id) { m_id = id; }
void setContextHelpId(const QString &helpId) { m_helpId = helpId; } void setContextHelpId(const QString &helpId) { m_helpId = helpId; }
void setContext(const QList<int> &context) { m_context = context; } void setContext(const Context &context) { m_context = context; }
private: private:
QString m_displayName; QString m_displayName;
...@@ -76,7 +76,7 @@ private: ...@@ -76,7 +76,7 @@ private:
QWidget *m_widget; QWidget *m_widget;
QString m_id; QString m_id;
QString m_helpId; QString m_helpId;
QList<int> m_context; Context m_context;
}; };
} // namespace Core } // namespace Core
......
...@@ -191,7 +191,7 @@ QStatusBar *CoreImpl::statusBar() const ...@@ -191,7 +191,7 @@ QStatusBar *CoreImpl::statusBar() const
return m_mainwindow->statusBar(); return m_mainwindow->statusBar();
} }
void CoreImpl::updateAdditionalContexts(const QList<int> &remove, const QList<int> &add) void CoreImpl::updateAdditionalContexts(const Context &remove, const Context &add)
{ {
m_mainwindow->updateAdditionalContexts(remove, add); m_mainwindow->updateAdditionalContexts(remove, add);
} }
......
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
// Adds and removes additional active contexts, these contexts are appended // Adds and removes additional active contexts, these contexts are appended
// to the currently active contexts. // to the currently active contexts.
void updateAdditionalContexts(const QList<int> &remove, const QList<int> &add); void updateAdditionalContexts(const Context &remove, const Context &add);
bool hasContext(int context) const;