Commit 1181765a authored by hjk's avatar hjk
Browse files

cleanup interface of Core::Context

parent 46e55681
......@@ -250,7 +250,7 @@ QList<Command *> ActionManagerPrivate::commands() const
{
// transform list of CommandPrivate into list of Command
QList<Command *> result;
foreach(Command *cmd, m_idCmdMap.values())
foreach (Command *cmd, m_idCmdMap.values())
result << cmd;
return result;
}
......@@ -262,7 +262,7 @@ QList<ActionContainerPrivate *> ActionManagerPrivate::containers() const
bool ActionManagerPrivate::hasContext(int context) const
{
return m_context.d.contains(context);
return m_context.contains(context);
}
void ActionManagerPrivate::setContext(const Context &context)
......@@ -278,8 +278,8 @@ void ActionManagerPrivate::setContext(const Context &context)
bool ActionManagerPrivate::hasContext(const Context &context) const
{
for (int i = 0; i < m_context.d.count(); ++i) {
if (context.d.contains(m_context.d.at(i)))
for (int i = 0; i < m_context.size(); ++i) {
if (context.contains(m_context.at(i)))
return true;
}
return false;
......@@ -403,7 +403,7 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QStri
shortcut->setParent(m_mainWnd);
sc->setShortcut(shortcut);
if (context.d.isEmpty())
if (context.isEmpty())
sc->setContext(Context(0));
else
sc->setContext(context);
......
......@@ -336,8 +336,8 @@ QString Shortcut::defaultText() const
bool Shortcut::setCurrentContext(const Core::Context &context)
{
foreach (int ctxt, m_context.d) {
if (context.d.contains(ctxt)) {
foreach (int ctxt, m_context) {
if (context.contains(ctxt)) {
if (!m_shortcut->isEnabled()) {
m_shortcut->setEnabled(true);
emit activeStateChanged();
......@@ -487,7 +487,7 @@ static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAc
void Action::addOverrideAction(QAction *action, const Core::Context &context)
{
if (context.d.isEmpty()) {
if (context.isEmpty()) {
m_contextActionMap.insert(0, action);
} else {
for (int i = 0; i < context.size(); ++i) {
......
......@@ -267,7 +267,7 @@ void DesignMode::updateContext(Core::IMode *newMode, Core::IMode *oldMode)
void DesignMode::setActiveContext(const Context &context)
{
if (d->m_activeContext.d == context.d)
if (d->m_activeContext == context)
return;
if (ModeManager::instance()->currentMode() == this)
......
......@@ -393,7 +393,7 @@ void ShortcutSettings::markPossibleCollisions(ShortcutItem *item)
continue;
}
foreach (int context, currentItem->m_cmd->context().d) {
foreach (int context, currentItem->m_cmd->context()) {
// conflict if context is identical, OR if one
// of the contexts is the global context
......
......@@ -56,7 +56,19 @@ public:
int size() const { return d.size(); }
bool isEmpty() const { return d.isEmpty(); }
int at(int i) const { return d.at(i); }
public:
// FIXME: Make interface slimmer.
typedef QList<int>::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); }
void removeAt(int i) { d.removeAt(i); }
void prepend(int c) { d.prepend(c); }
void add(const Context &c) { d += c.d; }
void add(int c) { d.append(c); }
bool operator==(const Context &c) { return d == c.d; }
private:
QList<int> d;
};
......
......@@ -1198,21 +1198,21 @@ void MainWindow::writeSettings()
void MainWindow::updateAdditionalContexts(const Context &remove, const Context &add)
{
foreach (const int context, remove.d) {
foreach (const int context, remove) {
if (context == 0)
continue;
int index = m_additionalContexts.d.indexOf(context);
int index = m_additionalContexts.indexOf(context);
if (index != -1)
m_additionalContexts.d.removeAt(index);
m_additionalContexts.removeAt(index);
}
foreach (const int context, add.d) {
foreach (const int context, add) {
if (context == 0)
continue;
if (!m_additionalContexts.d.contains(context))
m_additionalContexts.d.prepend(context);
if (!m_additionalContexts.contains(context))
m_additionalContexts.prepend(context);
}
updateContext();
......@@ -1228,15 +1228,15 @@ void MainWindow::updateContext()
Context contexts;
if (m_activeContext)
contexts.d += m_activeContext->context().d;
contexts.add(m_activeContext->context());
contexts.d += m_additionalContexts.d;
contexts.add(m_additionalContexts);
Context uniquecontexts;
for (int i = 0; i < contexts.d.size(); ++i) {
const int c = contexts.d.at(i);
if (!uniquecontexts.d.contains(c))
uniquecontexts.d << c;
for (int i = 0; i < contexts.size(); ++i) {
const int c = contexts.at(i);
if (!uniquecontexts.contains(c))
uniquecontexts.add(c);
}
m_actionManager->setContext(uniquecontexts);
......
......@@ -1311,12 +1311,12 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
Core::Context newContext;
if (d->m_currentProject) {
oldContext.d.append(d->m_currentProject->projectManager()->projectContext());
oldContext.d.append(d->m_currentProject->projectManager()->projectLanguage());
oldContext.add(d->m_currentProject->projectManager()->projectContext());
oldContext.add(d->m_currentProject->projectManager()->projectLanguage());
}
if (project) {
newContext.d.append(project->projectManager()->projectContext());
newContext.d.append(project->projectManager()->projectLanguage());
newContext.add(project->projectManager()->projectContext());
newContext.add(project->projectManager()->projectLanguage());
}
core->updateAdditionalContexts(oldContext, newContext);
......
......@@ -275,8 +275,8 @@ void BauhausPlugin::contextChanged(Core::IContext *context, const Core::Context
{
Q_UNUSED(context)
foreach (int additionalContext, additionalContexts.d) {
if (m_context->context().d.contains(additionalContext)) {
foreach (int additionalContext, additionalContexts) {
if (m_context->context().contains(additionalContext)) {
m_isActive = true;
m_mainWidget->showEditor(m_editorManager->currentEditor());
return;
......
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