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