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:
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()) {
m_editor->setData(QByteArray());
......@@ -354,7 +354,7 @@ private:
BinEditor *m_editor;
QString m_displayName;
BinEditorFile *m_file;
QList<int> m_context;
Core::Context m_context;
QToolBar *m_toolBar;
Utils::LineColumnLabel *m_cursorPositionLabel;
};
......
......@@ -69,7 +69,7 @@ private slots:
void updateCurrentEditor(Core::IContext *object);
private:
QList<int> m_context;
Core::Context m_context;
QAction *registerNewAction(const QString &id, const QString &title = QString());
QAction *registerNewAction(const QString &id, QObject *receiver, const char *slot,
const QString &title = QString());
......
......@@ -303,7 +303,7 @@ BookmarkContext::BookmarkContext(BookmarkView *widget)
m_context << UniqueIDManager::instance()->uniqueIdentifier(Constants::BOOKMARKS_CONTEXT);
}
QList<int> BookmarkContext::context() const
Context BookmarkContext::context() const
{
return m_context;
}
......@@ -321,7 +321,7 @@ BookmarkManager::BookmarkManager() :
m_bookmarkIcon(QLatin1String(":/bookmarks/images/bookmark.png")),
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()));
connect(ProjectExplorerPlugin::instance()->session(), SIGNAL(sessionLoaded()),
......
......@@ -161,11 +161,11 @@ class BookmarkContext : public Core::IContext
{
public:
BookmarkContext(BookmarkView *widget);
virtual QList<int> context() const;
virtual Core::Context context() const;
virtual QWidget *widget();
private:
BookmarkView *m_bookmarkView;
QList<int> m_context;
Core::Context m_context;
};
class BookmarkViewFactory : public Core::INavigationWidgetFactory
......
......@@ -69,13 +69,9 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *)
{
Core::ICore *core = Core::ICore::instance();
Core::ActionManager *am = core->actionManager();
QList<int> context = QList<int>() << core->uniqueIDManager()->
uniqueIdentifier(Constants::BOOKMARKS_CONTEXT);
QList<int> textcontext, globalcontext;
textcontext << core->uniqueIDManager()->
uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
globalcontext << Core::Constants::C_GLOBAL_ID;
Core::UniqueIDManager *uidm = core->uniqueIDManager();
Core::Context textcontext(uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR));
Core::Context globalcontext(Core::Constants::C_GLOBAL_ID);
Core::ActionContainer *mtools =
am->actionContainer(Core::Constants::M_TOOLS);
......
......@@ -56,7 +56,7 @@ CMakeEditorEditable::CMakeEditorEditable(CMakeEditor *editor)
m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
}
QList<int> CMakeEditorEditable::context() const
Core::Context CMakeEditorEditable::context() const
{
return m_context;
}
......
......@@ -53,14 +53,14 @@ class CMakeEditorEditable : public TextEditor::BaseTextEditorEditable
{
public:
CMakeEditorEditable(CMakeEditor *);
QList<int> context() const;
Core::Context context() const;
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
QString id() const;
bool isTemporary() const { return false; }
private:
QList<int> m_context;
Core::Context m_context;
};
class CMakeEditor : public TextEditor::BaseTextEditor
......
......@@ -265,7 +265,7 @@ bool ActionManagerPrivate::hasContext(int context) const
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:
// let commands (de-)register themselves for contexts
......@@ -276,9 +276,9 @@ void ActionManagerPrivate::setContext(const QList<int> &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)))
return true;
}
......@@ -321,7 +321,7 @@ ActionContainer *ActionManagerPrivate::createMenuBar(const QString &id)
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;
Command *c = registerOverridableAction(action, id, false);
......@@ -377,7 +377,7 @@ Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const
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;
int uid = UniqueIDManager::instance()->uniqueIdentifier(id);
......@@ -404,7 +404,7 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QStri
sc->setShortcut(shortcut);
if (context.isEmpty())
sc->setContext(QList<int>() << 0);
sc->setContext(Context(0));
else
sc->setContext(context);
......
......@@ -45,6 +45,7 @@ namespace Core {
class ActionContainer;
class Command;
class Context;
class CORE_EXPORT ActionManager : public QObject
{
......@@ -56,8 +57,8 @@ public:
virtual ActionContainer *createMenu(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 *registerShortcut(QShortcut *shortcut, 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 Context &context) = 0;
virtual Command *command(const QString &id) const = 0;
virtual ActionContainer *actionContainer(const QString &id) const = 0;
......
......@@ -31,6 +31,7 @@
#define ACTIONMANAGERPRIVATE_H
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icontext.h>
#include <QtCore/QMap>
#include <QtCore/QHash>
......@@ -64,7 +65,7 @@ public:
explicit ActionManagerPrivate(MainWindow *mainWnd);
~ActionManagerPrivate();
void setContext(const QList<int> &context);
void setContext(const Context &context);
static ActionManagerPrivate *instance();
void saveSettings(QSettings *settings);
......@@ -85,19 +86,19 @@ public:
ActionContainer *createMenuBar(const QString &id);
Command *registerAction(QAction *action, const QString &id,
const QList<int> &context);
const Context &context);
Command *registerShortcut(QShortcut *shortcut, const QString &id,
const QList<int> &context);
const Context &context);
Core::Command *command(const QString &id) const;
Core::ActionContainer *actionContainer(const QString &id) const;
private:
bool hasContext(QList<int> context) const;
bool hasContext(const Context &context) const;
Command *registerOverridableAction(QAction *action, const QString &id,
bool checkUnique);
static ActionManagerPrivate* m_instance;
static ActionManagerPrivate *m_instance;
QList<int> m_defaultGroups;
typedef QHash<int, CommandPrivate *> IdCmdMap;
......@@ -109,7 +110,7 @@ private:
// typedef QMap<int, int> GlobalGroupMap;
// GlobalGroupMap m_globalgroups;
//
QList<int> m_context;
Context m_context;
MainWindow *m_mainWnd;
};
......
......@@ -30,6 +30,7 @@
#include "command_p.h"
#include "icore.h"
#include "icontext.h"
#include "uniqueidmanager.h"
#include <QtCore/QDebug>
......@@ -238,7 +239,7 @@ QShortcut *CommandPrivate::shortcut() const
return 0;
}
QList<int> CommandPrivate::context() const
Core::Context CommandPrivate::context() const
{
return m_context;
}
......@@ -295,12 +296,12 @@ QShortcut *Shortcut::shortcut() const
return m_shortcut;
}
void Shortcut::setContext(const QList<int> &context)
void Shortcut::setContext(const Core::Context &context)
{
m_context = context;
}
QList<int> Shortcut::context() const
Core::Context Shortcut::context() const
{
return m_context;
}
......@@ -333,7 +334,7 @@ QString Shortcut::defaultText() const
return m_defaultText;
}
bool Shortcut::setCurrentContext(const QList<int> &context)
bool Shortcut::setCurrentContext(const Context &context)
{
foreach (int ctxt, m_context) {
if (context.contains(ctxt)) {
......@@ -431,7 +432,7 @@ QKeySequence Action::keySequence() const
return m_action->shortcut();
}
bool Action::setCurrentContext(const QList<int> &context)
bool Action::setCurrentContext(const Core::Context &context)
{
m_context = context;
......@@ -484,7 +485,7 @@ static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAc
return msg;
}
void Action::addOverrideAction(QAction *action, const QList<int> &context)
void Action::addOverrideAction(QAction *action, const Core::Context &context)
{
if (context.isEmpty()) {
m_contextActionMap.insert(0, action);
......
......@@ -43,6 +43,8 @@ QT_END_NAMESPACE
namespace Core {
class Context;
class CORE_EXPORT Command : public QObject
{
Q_OBJECT
......@@ -65,7 +67,7 @@ public:
virtual QAction *action() 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 removeAttribute(CommandAttribute attr) = 0;
......
......@@ -60,19 +60,19 @@ public:
QAction *action() const;
QShortcut *shortcut() const;
QList<int> context() const;
Context context() const;
void setAttribute(CommandAttribute attr);
void removeAttribute(CommandAttribute attr);
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;
protected:
QList<int> m_context;
Context m_context;
QString m_category;
int m_attributes;
int m_id;
......@@ -98,9 +98,9 @@ public:
void setShortcut(QShortcut *shortcut);
QShortcut *shortcut() const;
void setContext(const QList<int> &context);
QList<int> context() const;
bool setCurrentContext(const QList<int> &context);
void setContext(const Context &context);
Context context() const;
bool setCurrentContext(const Context &context);
bool isActive() const;
private:
......@@ -126,9 +126,9 @@ public:
void setLocations(const QList<CommandLocation> &locations);
QList<CommandLocation> locations() const;
bool setCurrentContext(const QList<int> &context);
bool setCurrentContext(const Context &context);
bool isActive() const;
void addOverrideAction(QAction *action, const QList<int> &context);
void addOverrideAction(QAction *action, const Context &context);
protected:
void updateToolTipWithKeySequence();
......
......@@ -58,7 +58,7 @@ public:
int priority() const { return m_priority; }
QWidget *widget() { return m_widget; }
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; }
void setDisplayName(const QString &name) { m_displayName = name; }
......@@ -67,7 +67,7 @@ public:
void setWidget(QWidget *widget) { m_widget = widget; }
void setId(const QString &id) { m_id = id; }
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:
QString m_displayName;
......@@ -76,7 +76,7 @@ private:
QWidget *m_widget;
QString m_id;
QString m_helpId;
QList<int> m_context;
Context m_context;
};
} // namespace Core
......
......@@ -191,7 +191,7 @@ QStatusBar *CoreImpl::statusBar() const
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);
}
......
......@@ -82,7 +82,7 @@ public:
// Adds and removes additional active contexts, these contexts are appended
// 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;
void addContextObject(IContext *context);
void removeContextObject(IContext *context);
......
......@@ -87,7 +87,7 @@ bool DesignModeCoreListener::coreAboutToClose()
struct DesignEditorInfo {
int widgetIndex;
QStringList mimeTypes;
QList<int> context;
Context context;
QWidget *widget;
};
......@@ -101,7 +101,7 @@ struct DesignModePrivate {
EditorManager *m_editorManager;
QStackedWidget *m_stackWidget;
QList<int> m_activeContext;
Context m_activeContext;
};
DesignModePrivate::DesignModePrivate(DesignMode *q, EditorManager *editorManager) :
......@@ -134,10 +134,10 @@ DesignMode::~DesignMode()
delete d;
}
QList<int> DesignMode::context() const
Context DesignMode::context() const
{
static QList<int> contexts = QList<int>() <<
Core::UniqueIDManager::instance()->uniqueIdentifier(Constants::C_DESIGN_MODE);
static Context contexts(
Core::UniqueIDManager::instance()->uniqueIdentifier(Constants::C_DESIGN_MODE));
return contexts;
}
......@@ -181,7 +181,7 @@ QStringList DesignMode::registeredMimeTypes() const
*/
void DesignMode::registerDesignWidget(QWidget *widget,
const QStringList &mimeTypes,
const QList<int> &context)
const Context &context)
{
int index = d->m_stackWidget->addWidget(widget);
......@@ -235,7 +235,7 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
disconnect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
if (!mimeEditorAvailable) {
setActiveContext(QList<int>());
setActiveContext(Context());
if (core->modeManager()->currentMode() == this)
core->modeManager()->activateMode(Core::Constants::MODE_EDIT);
setEnabled(false);
......@@ -260,14 +260,14 @@ void DesignMode::updateContext(Core::IMode *newMode, Core::IMode *oldMode)
{
if (newMode == this) {
// Apply active context
Core::ICore::instance()->updateAdditionalContexts(QList<int>(), d->m_activeContext);
Core::ICore::instance()->updateAdditionalContexts(Context(), d->m_activeContext);
} else if (oldMode == this) {
// Remove active context
Core::ICore::instance()->updateAdditionalContexts(d->m_activeContext, QList<int>());
Core::ICore::instance()->updateAdditionalContexts(d->m_activeContext, Context());
}
}
void DesignMode::setActiveContext(const QList<int> &context)
void DesignMode::setActiveContext(const Context &context)
{
if (d->m_activeContext == context)
return;
......
......@@ -59,13 +59,13 @@ public:
void registerDesignWidget(QWidget *widget,
const QStringList &mimeTypes,
const QList<int> &context);
const Context &context);
void unregisterDesignWidget(QWidget *widget);
QStringList registeredMimeTypes() const;
// IContext
QList<int> context() const;
Context context() const;
QWidget *widget();
// IMode
......@@ -83,7 +83,7 @@ private slots:
void updateContext(Core::IMode *newMode, Core::IMode *oldMode);
private:
void setActiveContext(const QList<int> &context);
void setActiveContext(const Context &context);
DesignModePrivate *d;
friend class Internal::DesignModeCoreListener;
......
......@@ -115,12 +115,12 @@ QString EditMode::id() const
return QLatin1String(Constants::MODE_EDIT);
}
QList<int> EditMode::context() const
Context EditMode::context() const
{
static QList<int> contexts = QList<int>() <<
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_EDIT_MODE) <<
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_EDITORMANAGER) <<
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_NAVIGATION_PANE);
static Context contexts(
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_EDIT_MODE),
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_EDITORMANAGER) ,
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_NAVIGATION_PANE));
return contexts;
}
......
......@@ -58,7 +58,7 @@ public:
int priority() const;
QWidget* widget();
QString id() const;
QList<int> context() const;
Context context() const;
private slots:
void grabEditorManager(Core::IMode *mode);
......
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