Commit efcb8022 authored by Daniel Teske's avatar Daniel Teske

EditorConfiguration: Fix crash on unloading projects

Task-number: QTCREATORBUG-12814
Change-Id: I84d2ae60b8362b6fef45283c36aef1b8a20dbd95
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent ceedde87
......@@ -32,8 +32,11 @@
#include "projectexplorer.h"
#include "project.h"
#include <utils/algorithm.h>
#include <coreplugin/id.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/simplecodestylepreferences.h>
......@@ -82,6 +85,7 @@ struct EditorConfigurationPrivate
QTextCodec *m_textCodec;
QMap<Core::Id, ICodeStylePreferences *> m_languageCodeStylePreferences;
QList<ITextEditor *> m_editors;
};
EditorConfiguration::EditorConfiguration() : d(new EditorConfigurationPrivate)
......@@ -116,6 +120,8 @@ EditorConfiguration::EditorConfiguration() : d(new EditorConfigurationPrivate)
connect(SessionManager::instance(), SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
this, SLOT(slotAboutToRemoveProject(ProjectExplorer::Project*)));
connect(Core::EditorManager::instance(), SIGNAL(editorsClosed(QList<Core::IEditor*>)),
this, SLOT(editorsClosed(QList<Core::IEditor*>)));
}
EditorConfiguration::~EditorConfiguration()
......@@ -256,6 +262,7 @@ void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
if (baseTextEditor)
switchSettings(baseTextEditor);
}
d->m_editors.append(textEditor);
}
void EditorConfiguration::deconfigureEditor(ITextEditor *textEditor) const
......@@ -264,6 +271,8 @@ void EditorConfiguration::deconfigureEditor(ITextEditor *textEditor) const
if (baseTextEditor)
baseTextEditor->setCodeStyle(TextEditorSettings::codeStyle(baseTextEditor->languageSettingsId()));
d->m_editors.removeOne(textEditor);
// TODO: what about text codec and switching settings?
}
......@@ -384,16 +393,15 @@ void EditorConfiguration::slotAboutToRemoveProject(ProjectExplorer::Project *pro
if (project->editorConfiguration() != this)
return;
foreach (Core::IEditor *editor, Core::DocumentModel::editorsForOpenedDocuments()) {
if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) {
Core::IDocument *document = editor->document();
if (document) {
Project *editorProject = SessionManager::projectForFile(document->filePath());
if (project == editorProject)
deconfigureEditor(textEditor);
}
}
}
foreach (TextEditor::ITextEditor *editor, d->m_editors)
deconfigureEditor(editor);
}
void EditorConfiguration::editorsClosed(const QList<Core::IEditor*> &closedEditors)
{
Utils::erase(d->m_editors, [&closedEditors](Core::IEditor *editor) {
return closedEditors.contains(editor);
});
}
TabSettings actualTabSettings(const QString &fileName,
......
......@@ -35,7 +35,10 @@
#include <QObject>
#include <QVariantMap>
namespace Core { class Id; }
namespace Core {
class IEditor;
class Id;
}
namespace TextEditor {
class ITextEditor;
......@@ -107,6 +110,7 @@ private slots:
void setTextCodec(QTextCodec *textCodec);
void slotAboutToRemoveProject(ProjectExplorer::Project *project);
void editorsClosed(const QList<Core::IEditor*> &closedEditors);
private:
void switchSettings(TextEditor::BaseTextEditorWidget *baseTextEditor) const;
......
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