summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkobus <jaroslaw.kobus@digia.com>2013-09-27 12:46:08 +0200
committerJarek Kobus <jaroslaw.kobus@digia.com>2013-10-07 11:12:34 +0200
commit3584ce8955548323778545f9ba62ece2f31f503d (patch)
tree44c19beb11c8cefd593f81a62a8d442019b8ade6
parent2ad6ba2ad8e7c4584c2611c0b4a5d72eb9ec828d (diff)
downloadqt-creator-3584ce8955548323778545f9ba62ece2f31f503d.tar.gz
Fix a crash on codestylesettings
Task-number: QTCREATORBUG-10235 Instead of rely on ICodeStylePreferences::destroyed() signal, when all other objects might be in destruction phase, clear project code style settings explicitly, when project closes. Change-Id: I0dd6675d54c5495d4006acbc9ad12c95f1d0a00c Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
-rw-r--r--src/plugins/projectexplorer/editorconfiguration.cpp41
-rw-r--r--src/plugins/projectexplorer/editorconfiguration.h3
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp16
-rw-r--r--src/plugins/texteditor/basetexteditor.h1
4 files changed, 44 insertions, 17 deletions
diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp
index 6273d97149..dbe0b0acad 100644
--- a/src/plugins/projectexplorer/editorconfiguration.cpp
+++ b/src/plugins/projectexplorer/editorconfiguration.cpp
@@ -33,6 +33,7 @@
#include "project.h"
#include <coreplugin/id.h>
+#include <coreplugin/icore.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/simplecodestylepreferences.h>
@@ -91,22 +92,32 @@ EditorConfiguration::EditorConfiguration() : d(new EditorConfigurationPrivate)
while (itCodeStyle.hasNext()) {
itCodeStyle.next();
Core::Id languageId = itCodeStyle.key();
+ // global prefs for language
ICodeStylePreferences *originalPreferences = itCodeStyle.value();
ICodeStylePreferencesFactory *factory = textEditorSettings->codeStyleFactory(languageId);
+ // clone of global prefs for language - it will became project prefs for language
ICodeStylePreferences *preferences = factory->createCodeStyle();
+ // project prefs can point to the global language pool, which contains also the global language prefs
preferences->setDelegatingPool(textEditorSettings->codeStylePool(languageId));
preferences->setId(languageId.toString() + QLatin1String("Project"));
preferences->setDisplayName(tr("Project %1", "Settings, %1 is a language (C++ or QML)").arg(factory->displayName()));
+ // project prefs by default point to global prefs (which in turn can delegate to anything else or not)
preferences->setCurrentDelegate(originalPreferences);
d->m_languageCodeStylePreferences.insert(languageId, preferences);
}
+ // clone of global prefs (not language specific), for project scope
d->m_defaultCodeStyle = new SimpleCodeStylePreferences(this);
d->m_defaultCodeStyle->setDelegatingPool(textEditorSettings->codeStylePool());
d->m_defaultCodeStyle->setDisplayName(tr("Project", "Settings"));
d->m_defaultCodeStyle->setId(kId);
+ // if setCurrentDelegate is 0 values are read from *this prefs
d->m_defaultCodeStyle->setCurrentDelegate(d->m_useGlobal
? TextEditorSettings::instance()->codeStyle() : 0);
+
+ const SessionManager *session = ProjectExplorerPlugin::instance()->session();
+ connect(session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
+ this, SLOT(slotAboutToRemoveProject(ProjectExplorer::Project*)));
}
EditorConfiguration::~EditorConfiguration()
@@ -243,6 +254,15 @@ void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
}
}
+void EditorConfiguration::deconfigureEditor(ITextEditor *textEditor) const
+{
+ BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(textEditor->widget());
+ if (baseTextEditor)
+ baseTextEditor->setCodeStyle(TextEditorSettings::instance()->codeStyle(baseTextEditor->languageSettingsId()));
+
+ // TODO: what about text codec and switching settings?
+}
+
void EditorConfiguration::setUseGlobalSettings(bool use)
{
d->m_useGlobal = use;
@@ -325,6 +345,27 @@ void EditorConfiguration::setTextCodec(QTextCodec *textCodec)
d->m_textCodec = textCodec;
}
+void EditorConfiguration::slotAboutToRemoveProject(ProjectExplorer::Project *project)
+{
+ if (project->editorConfiguration() != this)
+ return;
+
+ Core::EditorManager *em = Core::ICore::editorManager();
+ const SessionManager *session = ProjectExplorerPlugin::instance()->session();
+ QList<Core::IEditor*> editors = em->openedEditors();
+ for (int i = 0; i < editors.count(); i++) {
+ Core::IEditor *editor = editors.at(i);
+ if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) {
+ Core::IDocument *document = editor->document();
+ if (document) {
+ Project *editorProject = session->projectForFile(document->fileName());
+ if (project == editorProject)
+ deconfigureEditor(textEditor);
+ }
+ }
+ }
+}
+
TabSettings actualTabSettings(const QString &fileName,
const BaseTextEditorWidget *baseTextEditor)
{
diff --git a/src/plugins/projectexplorer/editorconfiguration.h b/src/plugins/projectexplorer/editorconfiguration.h
index 0caaf2f58c..b8e4d9f22e 100644
--- a/src/plugins/projectexplorer/editorconfiguration.h
+++ b/src/plugins/projectexplorer/editorconfiguration.h
@@ -50,6 +50,7 @@ class ExtraEncodingSettings;
namespace ProjectExplorer {
+class Project;
struct EditorConfigurationPrivate;
class PROJECTEXPLORER_EXPORT EditorConfiguration : public QObject
@@ -77,6 +78,7 @@ public:
QMap<Core::Id, TextEditor::ICodeStylePreferences *> codeStyles() const;
void configureEditor(TextEditor::ITextEditor *textEditor) const;
+ void deconfigureEditor(TextEditor::ITextEditor *textEditor) const;
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
@@ -96,6 +98,7 @@ private slots:
void setTextCodec(QTextCodec *textCodec);
+ void slotAboutToRemoveProject(ProjectExplorer::Project *project);
private:
void switchSettings(TextEditor::BaseTextEditorWidget *baseTextEditor) const;
template <class NewSenderT, class OldSenderT>
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 7fdb2c9534..96ec4c868d 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -4623,8 +4623,6 @@ void BaseTextEditorWidget::setCodeStyle(ICodeStylePreferences *preferences)
this, SLOT(setTabSettings(TextEditor::TabSettings)));
disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
- disconnect(d->m_codeStylePreferences, SIGNAL(destroyed()),
- this, SLOT(onCodeStylePreferencesDestroyed()));
}
d->m_codeStylePreferences = preferences;
if (d->m_codeStylePreferences) {
@@ -4632,25 +4630,11 @@ void BaseTextEditorWidget::setCodeStyle(ICodeStylePreferences *preferences)
this, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
- connect(d->m_codeStylePreferences, SIGNAL(destroyed()),
- this, SLOT(onCodeStylePreferencesDestroyed()));
setTabSettings(d->m_codeStylePreferences->currentTabSettings());
slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue());
}
}
-void BaseTextEditorWidget::onCodeStylePreferencesDestroyed()
-{
- if (sender() != d->m_codeStylePreferences)
- return;
- ICodeStylePreferences *prefs = TextEditorSettings::instance()->codeStyle(languageSettingsId());
- if (prefs == d->m_codeStylePreferences)
- prefs = 0;
- // avoid failing disconnects, m_codeStylePreferences has already been reduced to QObject
- d->m_codeStylePreferences = 0;
- setCodeStyle(prefs);
-}
-
void BaseTextEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
{
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index ce99441e20..2b9e831df3 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -381,7 +381,6 @@ private slots:
bool inFindScope(const QTextCursor &cursor);
bool inFindScope(int selectionStart, int selectionEnd);
void inSnippetMode(bool *active);
- void onCodeStylePreferencesDestroyed();
private:
Internal::BaseTextEditorWidgetPrivate *d;