diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp index 6273d97149167a0f907d1cd78c2fc12a86370155..dbe0b0acad4e329243055f011c3dc7743671fe64 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 0caaf2f58cc8c55ca1537c649ae421cdd68ba2ac..b8e4d9f22e462edb480dd20cfcac4bafd34b85a9 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 7fdb2c9534e2fdae13d530bff365b1a4cedf21ca..96ec4c868dc015b9b13dae58a3d6d6ce0a945b46 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 ce99441e207215afe0303c39e5f2e2ea4902bcc2..2b9e831df338030c79bbd83775dc1249e5ef497c 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;