forked from qt-creator/qt-creator
Avoid multiple currentEditorChanged signals and stream line switching to
preferred mode. Switching to preferred mode is solely done by the editor manager.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include <coreplugin/icorelistener.h>
|
#include <coreplugin/icorelistener.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtCore/QPair>
|
#include <QtCore/QPair>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
@@ -87,7 +88,6 @@ struct DesignEditorInfo {
|
|||||||
int widgetIndex;
|
int widgetIndex;
|
||||||
QStringList mimeTypes;
|
QStringList mimeTypes;
|
||||||
QList<int> context;
|
QList<int> context;
|
||||||
bool preferredMode;
|
|
||||||
QWidget *widget;
|
QWidget *widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -181,13 +181,11 @@ QStringList DesignMode::registeredMimeTypes() const
|
|||||||
*/
|
*/
|
||||||
void DesignMode::registerDesignWidget(QWidget *widget,
|
void DesignMode::registerDesignWidget(QWidget *widget,
|
||||||
const QStringList &mimeTypes,
|
const QStringList &mimeTypes,
|
||||||
const QList<int> &context,
|
const QList<int> &context)
|
||||||
bool preferDesignMode)
|
|
||||||
{
|
{
|
||||||
int index = d->m_stackWidget->addWidget(widget);
|
int index = d->m_stackWidget->addWidget(widget);
|
||||||
|
|
||||||
DesignEditorInfo *info = new DesignEditorInfo;
|
DesignEditorInfo *info = new DesignEditorInfo;
|
||||||
info->preferredMode = preferDesignMode;
|
|
||||||
info->mimeTypes = mimeTypes;
|
info->mimeTypes = mimeTypes;
|
||||||
info->context = context;
|
info->context = context;
|
||||||
info->widgetIndex = index;
|
info->widgetIndex = index;
|
||||||
@@ -209,8 +207,10 @@ void DesignMode::unregisterDesignWidget(QWidget *widget)
|
|||||||
// if editor changes, check if we have valid mimetype registered.
|
// if editor changes, check if we have valid mimetype registered.
|
||||||
void DesignMode::currentEditorChanged(Core::IEditor *editor)
|
void DesignMode::currentEditorChanged(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
|
if (d->m_currentEditor.data() == editor)
|
||||||
|
return;
|
||||||
|
|
||||||
bool mimeEditorAvailable = false;
|
bool mimeEditorAvailable = false;
|
||||||
bool modeActivated = false;
|
|
||||||
Core::ICore *core = Core::ICore::instance();
|
Core::ICore *core = Core::ICore::instance();
|
||||||
|
|
||||||
if (editor && editor->file()) {
|
if (editor && editor->file()) {
|
||||||
@@ -227,10 +227,6 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
|
|||||||
setActiveContext(editorInfo->context);
|
setActiveContext(editorInfo->context);
|
||||||
mimeEditorAvailable = true;
|
mimeEditorAvailable = true;
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
if (editorInfo->preferredMode && core->modeManager()->currentMode() != this) {
|
|
||||||
core->modeManager()->activateMode(Constants::MODE_DESIGN);
|
|
||||||
modeActivated = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,29 +234,24 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!mimeEditorAvailable) {
|
|
||||||
setActiveContext(QList<int>());
|
|
||||||
setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mimeEditorAvailable && core->modeManager()->currentMode() == this)
|
|
||||||
{
|
|
||||||
// switch back to edit mode - we don't want to be here
|
|
||||||
core->modeManager()->activateMode(Constants::MODE_EDIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d->m_currentEditor.data() == editor)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (d->m_currentEditor)
|
if (d->m_currentEditor)
|
||||||
disconnect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
|
disconnect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
|
||||||
|
|
||||||
d->m_currentEditor = QWeakPointer<Core::IEditor>(editor);
|
if (!mimeEditorAvailable) {
|
||||||
|
setActiveContext(QList<int>());
|
||||||
|
setEnabled(false);
|
||||||
|
d->m_currentEditor = QWeakPointer<Core::IEditor>();
|
||||||
|
emit actionsUpdated(d->m_currentEditor.data());
|
||||||
|
|
||||||
if (d->m_currentEditor)
|
QTC_ASSERT(core->modeManager()->currentMode() != this, core->modeManager()->activateMode(Constants::MODE_EDIT));
|
||||||
connect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
|
} else {
|
||||||
|
d->m_currentEditor = QWeakPointer<Core::IEditor>(editor);
|
||||||
|
|
||||||
emit actionsUpdated(d->m_currentEditor.data());
|
if (d->m_currentEditor)
|
||||||
|
connect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
|
||||||
|
|
||||||
|
emit actionsUpdated(d->m_currentEditor.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignMode::updateActions()
|
void DesignMode::updateActions()
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ public:
|
|||||||
|
|
||||||
void registerDesignWidget(QWidget *widget,
|
void registerDesignWidget(QWidget *widget,
|
||||||
const QStringList &mimeTypes,
|
const QStringList &mimeTypes,
|
||||||
const QList<int> &context,
|
const QList<int> &context);
|
||||||
bool preferDesignMode = false);
|
|
||||||
void unregisterDesignWidget(QWidget *widget);
|
void unregisterDesignWidget(QWidget *widget);
|
||||||
|
|
||||||
QStringList registeredMimeTypes() const;
|
QStringList registeredMimeTypes() const;
|
||||||
|
|||||||
@@ -979,7 +979,6 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
|
|||||||
if (isVisible())
|
if (isVisible())
|
||||||
editor->widget()->setFocus();
|
editor->widget()->setFocus();
|
||||||
}
|
}
|
||||||
emit currentEditorChanged(editor);
|
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user