Commit 08ccda58 authored by dt's avatar dt
Browse files

EditorManager: Change openEditor/activateEditor to not do mode switching

Also introduce a indirection, modes have now types, edit and debug have
the same type, and editors do have a prefered type of modes instead of a
prefered mode.

That fixes the bug that if the prefered qml editing mode was set to
design, then in switching between qml editors would
- in Edit Mode: stay in edit mode
- in Debug Mode: switch to debug mode
parent f068e115
......@@ -58,6 +58,7 @@ public:
int priority() const { return m_priority; }
QWidget *widget() { return m_widget; }
QString id() const { return m_id; }
QString type() const { return m_type; }
Context context() const { return m_context; }
QString contextHelpId() const { return m_helpId; }
......@@ -66,6 +67,7 @@ public:
void setPriority(int priority) { m_priority = priority; }
void setWidget(QWidget *widget) { m_widget = widget; }
void setId(const QString &id) { m_id = id; }
void setType(const QString &type) { m_type = type; }
void setContextHelpId(const QString &helpId) { m_helpId = helpId; }
void setContext(const Context &context) { m_context = context; }
......@@ -75,6 +77,7 @@ private:
int m_priority;
QWidget *m_widget;
QString m_id;
QString m_type;
QString m_helpId;
Context m_context;
};
......
......@@ -68,8 +68,11 @@ const char * const IDE_REVISION_STR = "";
//modes
const char * const MODE_WELCOME = "Welcome";
const char * const MODE_WELCOME_TYPE = "Type.Welcome";
const char * const MODE_EDIT = "Edit";
const char * const MODE_EDIT_TYPE = "Type.Edit";
const char * const MODE_DESIGN = "Design";
const char * const MODE_DESIGN_TYPE = "Type.Design";
const int P_MODE_WELCOME = 100;
const int P_MODE_EDIT = 90;
const int P_MODE_DESIGN = 89;
......
......@@ -164,6 +164,11 @@ QString DesignMode::id() const
return QLatin1String(Constants::MODE_DESIGN);
}
QString DesignMode::type() const
{
return QLatin1String(Constants::MODE_DESIGN_TYPE);
}
QStringList DesignMode::registeredMimeTypes() const
{
QStringList rc;
......
......@@ -73,6 +73,7 @@ public:
QIcon icon() const;
int priority() const;
QString id() const;
QString type() const;
signals:
void actionsUpdated(Core::IEditor *editor);
......
......@@ -114,6 +114,11 @@ QString EditMode::id() const
return QLatin1String(Constants::MODE_EDIT);
}
QString EditMode::type() const
{
return QLatin1String(Constants::MODE_EDIT_TYPE);
}
Context EditMode::context() const
{
static Context contexts(Constants::C_EDIT_MODE,
......
......@@ -58,6 +58,7 @@ public:
int priority() const;
QWidget* widget();
QString id() const;
QString type() const;
Context context() const;
private slots:
......
......@@ -970,7 +970,7 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
if (!(flags & NoActivate)) {
setCurrentEditor(editor, (flags & IgnoreNavigationHistory));
if (!(flags & NoModeSwitch)) {
if (flags & ModeSwitch) {
switchToPreferedMode();
}
if (isVisible())
......@@ -1254,13 +1254,14 @@ void EditorManager::switchToPreferedMode()
QString preferedMode;
// Figure out prefered mode for editor
if (m_d->m_currentEditor)
preferedMode = m_d->m_currentEditor->preferredMode();
preferedMode = m_d->m_currentEditor->preferredModeType();
if (preferedMode.isEmpty())
preferedMode = Constants::MODE_EDIT;
preferedMode = Constants::MODE_EDIT_TYPE;
if (m_d->m_core->modeManager()->currentMode()->id() != preferedMode)
m_d->m_core->modeManager()->activateMode(preferedMode);
if (m_d->m_core->modeManager()->currentMode()->type() != preferedMode) {
m_d->m_core->modeManager()->activateModeType(preferedMode);
}
}
IEditor *EditorManager::openEditorWithContents(const QString &editorId,
......
......@@ -109,7 +109,7 @@ public:
enum OpenEditorFlag {
NoActivate = 1,
IgnoreNavigationHistory = 2,
NoModeSwitch = 4
ModeSwitch = 4
};
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
......
......@@ -276,9 +276,9 @@ void EditorView::listSelectionActivated(int index)
EditorManager *em = CoreImpl::instance()->editorManager();
QAbstractItemModel *model = EditorManager::instance()->openedEditorsModel();
if (IEditor *editor = model->data(model->index(index, 0), Qt::UserRole).value<IEditor*>()) {
em->activateEditor(this, editor);
em->activateEditor(this, editor, Core::EditorManager::ModeSwitch);
} else {
em->activateEditor(model->index(index, 0), this);
em->activateEditor(model->index(index, 0), this, Core::EditorManager::ModeSwitch);
}
}
......@@ -445,9 +445,11 @@ void EditorView::goBackInNavigationHistory()
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor;
if (location.file) {
editor = em->activateEditor(this, location.file, EditorManager::IgnoreNavigationHistory);
editor = em->activateEditor(this, location.file,
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
} else {
editor = em->openEditor(this, location.fileName, location.id, EditorManager::IgnoreNavigationHistory);
editor = em->openEditor(this, location.fileName, location.id,
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
if (!editor) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
continue;
......@@ -469,7 +471,8 @@ void EditorView::goForwardInNavigationHistory()
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor;
if (location.file) {
editor = em->activateEditor(this, location.file, EditorManager::IgnoreNavigationHistory);
editor = em->activateEditor(this, location.file,
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
} else {
editor = em->openEditor(this, location.fileName, location.id, EditorManager::IgnoreNavigationHistory);
if (!editor) {
......
......@@ -65,7 +65,7 @@ public:
virtual QWidget *toolBar() = 0;
virtual QString preferredMode() const { return QString(); }
virtual QString preferredModeType() const { return QString(); }
signals:
void changed();
......
......@@ -190,7 +190,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
void OpenEditorsWidget::activateEditor(const QModelIndex &index)
{
m_ui.editorList->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
EditorManager::instance()->activateEditor(index);
EditorManager::instance()->activateEditor(index, 0, EditorManager::ModeSwitch);
}
void OpenEditorsWidget::closeEditor(const QModelIndex &index)
......
......@@ -277,9 +277,10 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
return;
if (IFile *file = item->data(0, Qt::UserRole).value<IFile*>()) {
EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>();
EditorManager::instance()->activateEditor(view, file);
EditorManager::instance()->activateEditor(view, file, Core::EditorManager::ModeSwitch);
} else {
EditorManager::instance()->openEditor(item->toolTip(0), item->data(0, Qt::UserRole+2).toByteArray());
EditorManager::instance()->openEditor(item->toolTip(0), item->data(0, Qt::UserRole+2).toByteArray(),
Core::EditorManager::ModeSwitch);
}
}
......
......@@ -256,12 +256,12 @@ void EditorToolBar::changeActiveEditor(int row)
if (editor) {
if (editor != em->currentEditor())
em->activateEditor(editor, EditorManager::NoModeSwitch);
em->activateEditor(editor);
} else {
//em->activateEditor(model->index(index, 0), this);
QString fileName = model->data(modelIndex, Qt::UserRole + 1).toString();
QByteArray kind = model->data(modelIndex, Qt::UserRole + 2).toByteArray();
editor = em->openEditor(fileName, kind, EditorManager::NoModeSwitch);
editor = em->openEditor(fileName, kind);
}
if (editor) {
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row());
......
......@@ -52,6 +52,7 @@ public:
virtual QIcon icon() const = 0;
virtual int priority() const = 0;
virtual QString id() const = 0;
virtual QString type() const = 0;
void setEnabled(bool enabled);
bool isEnabled() const;
......
......@@ -964,7 +964,7 @@ void MainWindow::openFileWith()
if (isExternal) {
editorManager()->openExternalEditor(fileName, editorId);
} else {
editorManager()->openEditor(fileName, editorId);
editorManager()->openEditor(fileName, editorId, Core::EditorManager::ModeSwitch);
}
}
}
......@@ -1272,7 +1272,7 @@ void MainWindow::openRecentFile()
if (const QAction *action = qobject_cast<const QAction*>(sender())) {
const QString fileName = action->data().toString();
if (!fileName.isEmpty())
editorManager()->openEditor(fileName);
editorManager()->openEditor(fileName, QString(), Core::EditorManager::ModeSwitch);
}
}
......
......@@ -149,6 +149,19 @@ IMode *ModeManager::mode(const QString &id) const
return 0;
}
void ModeManager::activateModeType(const QString &type)
{
int index = -1;
for (int i = 0; i < d->m_modes.count(); ++i) {
if (d->m_modes.at(i)->type() == type) {
index = i;
break;
}
}
if (index != -1)
d->m_modeStack->setCurrentIndex(index);
}
void ModeManager::activateMode(const QString &id)
{
const int index = indexOf(id);
......
......@@ -66,6 +66,8 @@ public:
void addProjectSelector(QAction *action);
void addWidget(QWidget *widget);
void activateModeType(const QString &type);
signals:
void currentModeAboutToChange(Core::IMode *mode);
......
......@@ -342,7 +342,7 @@ void CodepasterPlugin::finishFetch(const QString &titleDescription,
Core::IEditor* editor = EditorManager::instance()->openEditor(fileName);
QTC_ASSERT(editor, return)
editor->setDisplayName(titleDescription);
EditorManager::instance()->activateEditor(editor);
EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
}
Q_EXPORT_PLUGIN(CodepasterPlugin)
......@@ -285,7 +285,8 @@ void CppFileSettingsWidget::slotEdit()
QString path = licenseTemplatePath();
// Edit existing file with C++
if (!path.isEmpty()) {
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID));
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID),
Core::EditorManager::ModeSwitch);
return;
}
// Pick a file name and write new template, edit with C++
......@@ -301,7 +302,8 @@ void CppFileSettingsWidget::slotEdit()
file.write(tr(licenseTemplateTemplate).toUtf8());
file.close();
setLicenseTemplatePath(path);
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID));
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID),
Core::EditorManager::ModeSwitch);
}
// --------------- CppFileSettingsPage
......
......@@ -304,9 +304,11 @@ void CppFindReferences::searchFinished()
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{
if (item.path.size() > 0) {
TextEditor::BaseTextEditor::openEditorAt(item.path.first(), item.lineNumber, item.textMarkPos);
TextEditor::BaseTextEditor::openEditorAt(item.path.first(), item.lineNumber, item.textMarkPos,
QString(),
Core::EditorManager::ModeSwitch);
} else {
Core::EditorManager::instance()->openEditor(item.text);
Core::EditorManager::instance()->openEditor(item.text, QString(), Core::EditorManager::ModeSwitch);
}
}
......
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