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