Commit 510971d2 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Introduced a single convenient function for updating additional contexts

While before you had to call add, then remove for each context id and
then call update, now you call updateAdditionalContexts with a list of
contexts to remove and add. It has the update step built in.

Reviewed-by: con
parent a3b7290f
......@@ -187,16 +187,9 @@ QStatusBar *CoreImpl::statusBar() const
return m_mainwindow->statusBar();
}
// adds and removes additional active contexts, this context is appended to the
// currently active contexts. call updateContext after changing
void CoreImpl::addAdditionalContext(int context)
void CoreImpl::updateAdditionalContexts(const QList<int> &remove, const QList<int> &add)
{
m_mainwindow->addAdditionalContext(context);
}
void CoreImpl::removeAdditionalContext(int context)
{
m_mainwindow->removeAdditionalContext(context);
m_mainwindow->updateAdditionalContexts(remove, add);
}
bool CoreImpl::hasContext(int context) const
......@@ -214,11 +207,6 @@ void CoreImpl::removeContextObject(IContext *context)
m_mainwindow->removeContextObject(context);
}
void CoreImpl::updateContext()
{
return m_mainwindow->updateContext();
}
void CoreImpl::openFiles(const QStringList &arguments)
{
m_mainwindow->openFiles(arguments);
......
......@@ -81,15 +81,12 @@ public:
QMainWindow *mainWindow() const;
QStatusBar *statusBar() const;
// adds and removes additional active contexts, this context is appended to the
// currently active contexts. call updateContext after changing
void addAdditionalContext(int context);
void removeAdditionalContext(int context);
// 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);
bool hasContext(int context) const;
void addContextObject(IContext *contex);
void removeContextObject(IContext *contex);
void updateContext();
void addContextObject(IContext *context);
void removeContextObject(IContext *context);
void openFiles(const QStringList &fileNames);
......
......@@ -267,16 +267,10 @@ void DesignMode::updateContext(Core::IMode *newMode, Core::IMode *oldMode)
{
if (newMode == this) {
// Apply active context
Core::ICore *core = Core::ICore::instance();
foreach (int contextId, d->m_activeContext)
core->addAdditionalContext(contextId);
core->updateContext();
Core::ICore::instance()->updateAdditionalContexts(QList<int>(), d->m_activeContext);
} else if (oldMode == this) {
// Remove active context
Core::ICore *core = Core::ICore::instance();
foreach (int contextId, d->m_activeContext)
core->removeAdditionalContext(contextId);
core->updateContext();
Core::ICore::instance()->updateAdditionalContexts(d->m_activeContext, QList<int>());
}
}
......@@ -285,15 +279,9 @@ void DesignMode::setActiveContext(const QList<int> &context)
if (d->m_activeContext == context)
return;
if (ModeManager::instance()->currentMode() == this) {
// Update active context
Core::ICore *core = Core::ICore::instance();
foreach (int contextId, d->m_activeContext)
core->removeAdditionalContext(contextId);
foreach (int contextId, context)
core->addAdditionalContext(contextId);
core->updateContext();
}
if (ModeManager::instance()->currentMode() == this)
Core::ICore::instance()->updateAdditionalContexts(d->m_activeContext, context);
d->m_activeContext = context;
}
......
......@@ -107,17 +107,14 @@ public:
virtual QMainWindow *mainWindow() const = 0;
virtual QStatusBar *statusBar() const = 0;
// adds and removes additional active contexts, this context is appended to the
// currently active contexts. call updateContext after changing
virtual IContext *currentContextObject() const = 0;
virtual void addAdditionalContext(int context) = 0;
virtual void removeAdditionalContext(int context) = 0;
// Adds and removes additional active contexts, these contexts are appended
// to the currently active contexts.
virtual void updateAdditionalContexts(const QList<int> &remove, const QList<int> &add) = 0;
virtual bool hasContext(int context) const = 0;
virtual void addContextObject(IContext *context) = 0;
virtual void removeContextObject(IContext *context) = 0;
virtual void updateContext() = 0;
virtual void openFiles(const QStringList &fileNames) = 0;
signals:
......
......@@ -1171,23 +1171,26 @@ void MainWindow::writeSettings()
m_navigationWidget->saveSettings(m_settings);
}
void MainWindow::addAdditionalContext(int context)
void MainWindow::updateAdditionalContexts(const QList<int> &remove, const QList<int> &add)
{
if (context == 0)
return;
foreach (const int context, remove) {
if (context == 0)
continue;
if (!m_additionalContexts.contains(context))
m_additionalContexts.prepend(context);
}
int index = m_additionalContexts.indexOf(context);
if (index != -1)
m_additionalContexts.removeAt(index);
}
void MainWindow::removeAdditionalContext(int context)
{
if (context == 0)
return;
foreach (const int context, add) {
if (context == 0)
continue;
int index = m_additionalContexts.indexOf(context);
if (index != -1)
m_additionalContexts.removeAt(index);
if (!m_additionalContexts.contains(context))
m_additionalContexts.prepend(context);
}
updateContext();
}
bool MainWindow::hasContext(int context) const
......
......@@ -114,11 +114,9 @@ public:
virtual QPrinter *printer() const;
IContext * currentContextObject() const;
QStatusBar *statusBar() const;
void addAdditionalContext(int context);
void removeAdditionalContext(int context);
bool hasContext(int context) const;
void updateContext();
void updateAdditionalContexts(const QList<int> &remove, const QList<int> &add);
bool hasContext(int context) const;
void setSuppressNavigationWidget(bool suppress);
......@@ -168,6 +166,8 @@ private slots:
private:
void updateContextObject(IContext *context);
void updateContext();
void registerDefaultContainers();
void registerDefaultActions();
......@@ -199,7 +199,7 @@ private:
Core::StatusBarWidget *m_outputView;
VersionDialog *m_versionDialog;
IContext * m_activeContext;
IContext *m_activeContext;
QMap<QWidget *, IContext *> m_contextWidgets;
......
......@@ -271,19 +271,14 @@ void ModeManager::currentTabChanged(int index)
// FIXME: This hardcoded context update is required for the Debug and Edit modes, since
// they use the editor widget, which is already a context widget so the main window won't
// go further up the parent tree to find the mode context.
ICore *core = ICore::instance();
foreach (const int context, d->m_addedContexts)
core->removeAdditionalContext(context);
ICore::instance()->updateAdditionalContexts(d->m_addedContexts, mode->context());
d->m_addedContexts = mode->context();
foreach (const int context, d->m_addedContexts)
core->addAdditionalContext(context);
IMode *oldMode = 0;
if (d->m_oldCurrent >= 0)
oldMode = d->m_modes.at(d->m_oldCurrent);
d->m_oldCurrent = index;
emit currentModeChanged(mode, oldMode);
core->updateContext();
}
}
......
......@@ -80,14 +80,9 @@ QSettings *CorePrototype::settings() const
return callee()->settings();
}
void CorePrototype::addAdditionalContext(int context)
void CorePrototype::updateAdditionalContexts(const QList<int> &remove, const QList<int> &add)
{
callee()->addAdditionalContext(context);
}
void CorePrototype::removeAdditionalContext(int context)
{
callee()->removeAdditionalContext(context);
callee()->updateAdditionalContexts(remove, add);
}
QString CorePrototype::toString() const
......
......@@ -66,8 +66,7 @@ public:
QSettings *settings() const;
public slots:
void addAdditionalContext(int context);
void removeAdditionalContext(int context);
void updateAdditionalContexts(const QList<int> &remove, const QList<int> &add);
QString toString() const;
private:
......
......@@ -1229,13 +1229,10 @@ void DebuggerPlugin::handleStateChanged(int state)
const bool startIsContinue = (state == InferiorStopped);
ICore *core = ICore::instance();
if (startIsContinue) {
core->addAdditionalContext(m_gdbRunningContext);
core->updateContext();
} else {
core->removeAdditionalContext(m_gdbRunningContext);
core->updateContext();
}
if (startIsContinue)
core->updateAdditionalContexts(QList<int>(), QList<int>() << m_gdbRunningContext);
else
core->updateAdditionalContexts(QList<int>() << m_gdbRunningContext, QList<int>());
const bool started = state == InferiorRunning
|| state == InferiorRunningRequested
......
......@@ -317,13 +317,7 @@ void DebuggerUISwitcher::changeDebuggerUI(const QString &langName)
Core::ICore *core = Core::ICore::instance();
const QList<int> &oldContexts = d->m_contextsForLanguage.value(d->m_activeLanguage);
const QList<int> &newContexts = d->m_contextsForLanguage.value(langId);
foreach(int ctx, oldContexts)
core->removeAdditionalContext(ctx);
foreach(int ctx, newContexts)
core->addAdditionalContext(ctx);
core->updateContext();
core->updateAdditionalContexts(oldContexts, newContexts);
d->m_activeLanguage = langId;
......
......@@ -1325,24 +1325,19 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
bool projectChanged = false;
if (d->m_currentProject != project) {
int oldContext = -1;
int newContext = -1;
int oldLanguageID = -1;
int newLanguageID = -1;
QList<int> oldContext;
QList<int> newContext;
if (d->m_currentProject) {
oldContext = d->m_currentProject->projectManager()->projectContext();
oldLanguageID = d->m_currentProject->projectManager()->projectLanguage();
oldContext.append(d->m_currentProject->projectManager()->projectContext());
oldContext.append(d->m_currentProject->projectManager()->projectLanguage());
}
if (project) {
newContext = project->projectManager()->projectContext();
newLanguageID = project->projectManager()->projectLanguage();
newContext.append(project->projectManager()->projectContext());
newContext.append(project->projectManager()->projectLanguage());
}
core->removeAdditionalContext(oldContext);
core->removeAdditionalContext(oldLanguageID);
core->addAdditionalContext(newContext);
core->addAdditionalContext(newLanguageID);
core->updateContext();
core->updateAdditionalContexts(oldContext, newContext);
d->m_currentProject = project;
......
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