forked from qt-creator/qt-creator
Core: Use Id in Context instead of plain int.
Change-Id: Iaa8e48459fb19b7d3b8821d0374925d0c6a7e0cc Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -466,12 +466,12 @@ ActionManagerPrivate::~ActionManagerPrivate()
|
||||
qDeleteAll(m_idCmdMap.values());
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug in, const Context &context)
|
||||
QDebug operator<<(QDebug d, const Context &context)
|
||||
{
|
||||
in << "CONTEXT: ";
|
||||
foreach (int c, context)
|
||||
in << " " << c << Id::fromUniqueIdentifier(c).toString();
|
||||
return in;
|
||||
d << "CONTEXT: ";
|
||||
foreach (Id id, context)
|
||||
d << " " << id.uniqueIdentifier() << " " << id.toString();
|
||||
return d;
|
||||
}
|
||||
|
||||
void ActionManagerPrivate::setContext(const Context &context)
|
||||
|
||||
@@ -333,8 +333,8 @@ QKeySequence Shortcut::keySequence() const
|
||||
|
||||
void Shortcut::setCurrentContext(const Core::Context &context)
|
||||
{
|
||||
foreach (int ctxt, m_context) {
|
||||
if (context.contains(ctxt)) {
|
||||
foreach (Id id, m_context) {
|
||||
if (context.contains(id)) {
|
||||
if (!m_shortcut->isEnabled()) {
|
||||
m_shortcut->setEnabled(true);
|
||||
emit activeStateChanged();
|
||||
@@ -423,7 +423,7 @@ void Action::updateActiveState()
|
||||
setActive(m_action->isEnabled() && m_action->isVisible() && !m_action->isSeparator());
|
||||
}
|
||||
|
||||
static QString msgActionWarning(QAction *newAction, int k, QAction *oldAction)
|
||||
static QString msgActionWarning(QAction *newAction, Id id, QAction *oldAction)
|
||||
{
|
||||
QString msg;
|
||||
QTextStream str(&msg);
|
||||
@@ -431,9 +431,8 @@ static QString msgActionWarning(QAction *newAction, int k, QAction *oldAction)
|
||||
<< ": Action ";
|
||||
if (oldAction)
|
||||
str << oldAction->objectName() << '/' << oldAction->text();
|
||||
str << " is already registered for context " << k << ' '
|
||||
<< Core::Id::fromUniqueIdentifier(k).toString()
|
||||
<< '.';
|
||||
str << " is already registered for context " << id.uniqueIdentifier() << ' '
|
||||
<< id.toString() << '.';
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -447,10 +446,10 @@ void Action::addOverrideAction(QAction *action, const Core::Context &context, bo
|
||||
m_contextActionMap.insert(0, action);
|
||||
} else {
|
||||
for (int i = 0; i < context.size(); ++i) {
|
||||
int k = context.at(i);
|
||||
if (m_contextActionMap.contains(k))
|
||||
qWarning("%s", qPrintable(msgActionWarning(action, k, m_contextActionMap.value(k, 0))));
|
||||
m_contextActionMap.insert(k, action);
|
||||
Id id = context.at(i);
|
||||
if (m_contextActionMap.contains(id))
|
||||
qWarning("%s", qPrintable(msgActionWarning(action, id, m_contextActionMap.value(id, 0))));
|
||||
m_contextActionMap.insert(id, action);
|
||||
}
|
||||
}
|
||||
m_scriptableMap[action] = scriptable;
|
||||
@@ -459,7 +458,7 @@ void Action::addOverrideAction(QAction *action, const Core::Context &context, bo
|
||||
|
||||
void Action::removeOverrideAction(QAction *action)
|
||||
{
|
||||
QMutableMapIterator<int, QPointer<QAction> > it(m_contextActionMap);
|
||||
QMutableMapIterator<Id, QPointer<QAction> > it(m_contextActionMap);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value() == 0)
|
||||
|
||||
@@ -145,7 +145,7 @@ private:
|
||||
Utils::ProxyAction *m_action;
|
||||
QString m_toolTip;
|
||||
|
||||
QMap<int, QPointer<QAction> > m_contextActionMap;
|
||||
QMap<Id, QPointer<QAction> > m_contextActionMap;
|
||||
QMap<QAction*, bool> m_scriptableMap;
|
||||
bool m_active;
|
||||
bool m_contextInitialized;
|
||||
|
||||
@@ -362,7 +362,7 @@ void ShortcutSettings::markPossibleCollisions(ShortcutItem *item)
|
||||
if (item->m_key.isEmpty())
|
||||
return;
|
||||
|
||||
int globalId = Context(Constants::C_GLOBAL).at(0);
|
||||
Id globalId = Context(Constants::C_GLOBAL).at(0);
|
||||
|
||||
foreach (ShortcutItem *currentItem, m_scitems) {
|
||||
|
||||
@@ -371,11 +371,10 @@ void ShortcutSettings::markPossibleCollisions(ShortcutItem *item)
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (int context, currentItem->m_cmd->context()) {
|
||||
|
||||
foreach (Id id, currentItem->m_cmd->context()) {
|
||||
// conflict if context is identical, OR if one
|
||||
// of the contexts is the global context
|
||||
if (item->m_cmd->context().contains(context) ||
|
||||
if (item->m_cmd->context().contains(id) ||
|
||||
(item->m_cmd->context().contains(globalId) &&
|
||||
!currentItem->m_cmd->context().isEmpty()) ||
|
||||
(currentItem->m_cmd->context().contains(globalId) &&
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
#include "icontext.h"
|
||||
|
||||
#include "id.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Core {
|
||||
@@ -40,14 +38,4 @@ Context::Context(const char *id, int offset)
|
||||
d.append(Id(QLatin1String(id) + QString::number(offset)).uniqueIdentifier());
|
||||
}
|
||||
|
||||
void Context::add(const char *id)
|
||||
{
|
||||
d.append(Id(QByteArray(id)).uniqueIdentifier());
|
||||
}
|
||||
|
||||
bool Context::contains(const char *id) const
|
||||
{
|
||||
return d.contains(Id(QByteArray(id)).uniqueIdentifier());
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define ICONTEXT_H
|
||||
|
||||
#include <coreplugin/core_global.h>
|
||||
#include <coreplugin/id.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
@@ -44,30 +45,28 @@ class CORE_EXPORT Context
|
||||
public:
|
||||
Context() {}
|
||||
|
||||
explicit Context(const char *c1) { add(c1); }
|
||||
Context(const char *c1, const char *c2) { add(c1); add(c2); }
|
||||
Context(const char *c1, const char *c2, const char *c3) { add(c1); add(c2); add(c3); }
|
||||
explicit Context(Id c1) { add(c1); }
|
||||
Context(Id c1, Id c2) { add(c1); add(c2); }
|
||||
Context(Id c1, Id c2, Id c3) { add(c1); add(c2); add(c3); }
|
||||
Context(const char *base, int offset);
|
||||
void add(const char *c);
|
||||
bool contains(const char *c) const;
|
||||
bool contains(int c) const { return d.contains(c); }
|
||||
bool contains(Id c) const { return d.contains(c); }
|
||||
int size() const { return d.size(); }
|
||||
bool isEmpty() const { return d.isEmpty(); }
|
||||
int at(int i) const { return d.at(i); }
|
||||
Id at(int i) const { return d.at(i); }
|
||||
|
||||
// FIXME: Make interface slimmer.
|
||||
typedef QList<int>::const_iterator const_iterator;
|
||||
typedef QList<Id>::const_iterator const_iterator;
|
||||
const_iterator begin() const { return d.begin(); }
|
||||
const_iterator end() const { return d.end(); }
|
||||
int indexOf(int c) const { return d.indexOf(c); }
|
||||
int indexOf(Id c) const { return d.indexOf(c); }
|
||||
void removeAt(int i) { d.removeAt(i); }
|
||||
void prepend(int c) { d.prepend(c); }
|
||||
void prepend(Id c) { d.prepend(c); }
|
||||
void add(const Context &c) { d += c.d; }
|
||||
void add(int c) { d.append(c); }
|
||||
void add(Id c) { d.append(c); }
|
||||
bool operator==(const Context &c) const { return d == c.d; }
|
||||
|
||||
private:
|
||||
QList<int> d;
|
||||
QList<Id> d;
|
||||
};
|
||||
|
||||
class CORE_EXPORT IContext : public QObject
|
||||
|
||||
@@ -1206,21 +1206,21 @@ void MainWindow::writeSettings()
|
||||
|
||||
void MainWindow::updateAdditionalContexts(const Context &remove, const Context &add)
|
||||
{
|
||||
foreach (const int context, remove) {
|
||||
if (context == 0)
|
||||
foreach (const Id id, remove) {
|
||||
if (!id.isValid())
|
||||
continue;
|
||||
|
||||
int index = m_additionalContexts.indexOf(context);
|
||||
int index = m_additionalContexts.indexOf(id);
|
||||
if (index != -1)
|
||||
m_additionalContexts.removeAt(index);
|
||||
}
|
||||
|
||||
foreach (const int context, add) {
|
||||
if (context == 0)
|
||||
foreach (const Id id, add) {
|
||||
if (!id.isValid())
|
||||
continue;
|
||||
|
||||
if (!m_additionalContexts.contains(context))
|
||||
m_additionalContexts.prepend(context);
|
||||
if (!m_additionalContexts.contains(id))
|
||||
m_additionalContexts.prepend(id);
|
||||
}
|
||||
|
||||
updateContext();
|
||||
@@ -1237,9 +1237,9 @@ void MainWindow::updateContext()
|
||||
|
||||
Context uniquecontexts;
|
||||
for (int i = 0; i < contexts.size(); ++i) {
|
||||
const int c = contexts.at(i);
|
||||
if (!uniquecontexts.contains(c))
|
||||
uniquecontexts.add(c);
|
||||
const Id id = contexts.at(i);
|
||||
if (!uniquecontexts.contains(id))
|
||||
uniquecontexts.add(id);
|
||||
}
|
||||
|
||||
m_actionManager->d->setContext(uniquecontexts);
|
||||
|
||||
@@ -285,8 +285,8 @@ void BauhausPlugin::contextChanged(Core::IContext *context, const Core::Context
|
||||
{
|
||||
Q_UNUSED(context)
|
||||
|
||||
foreach (int additionalContext, additionalContexts) {
|
||||
if (m_context->context().contains(additionalContext)) {
|
||||
foreach (Core::Id id, additionalContexts) {
|
||||
if (m_context->context().contains(id)) {
|
||||
m_isActive = true;
|
||||
m_mainWidget->showEditor(Core::EditorManager::currentEditor());
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user