diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp index 6af46548a6a3ff285fd39d2e38a7d78aaa4a81ce..5ffc9b864a07b8b30cb640dfb707a6f0b64b80e7 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> @@ -88,21 +89,31 @@ 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.name() + "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("Project"); - d->m_defaultCodeStyle->setCurrentDelegate(d->m_useGlobal ? TextEditorSettings::codeStyle() : 0); + // if setCurrentDelegate is 0 values are read from *this prefs + d->m_defaultCodeStyle->setCurrentDelegate(d->m_useGlobal + ? TextEditorSettings::codeStyle() : 0); + + connect(SessionManager::instance(), SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)), + this, SLOT(slotAboutToRemoveProject(ProjectExplorer::Project*))); } EditorConfiguration::~EditorConfiguration() @@ -237,6 +248,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::codeStyle(baseTextEditor->languageSettingsId())); + + // TODO: what about text codec and switching settings? +} + void EditorConfiguration::setUseGlobalSettings(bool use) { d->m_useGlobal = use; @@ -321,7 +341,27 @@ void EditorConfiguration::setTextCodec(QTextCodec *textCodec) d->m_textCodec = textCodec; } -TabSettings actualTabSettings(const QString &fileName, const BaseTextEditorWidget *baseTextEditor) +void EditorConfiguration::slotAboutToRemoveProject(ProjectExplorer::Project *project) +{ + if (project->editorConfiguration() != this) + return; + + Core::DocumentModel *model = Core::EditorManager::documentModel(); + QList<Core::IEditor *> editors = model->editorsForDocuments(model->openedDocuments()); + foreach (Core::IEditor *editor, editors) { + 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); + } + } + } +} + +TabSettings actualTabSettings(const QString &fileName, + const BaseTextEditorWidget *baseTextEditor) { if (baseTextEditor) return baseTextEditor->tabSettings(); diff --git a/src/plugins/projectexplorer/editorconfiguration.h b/src/plugins/projectexplorer/editorconfiguration.h index af419c8c6cb102c64ae8a995d2c36cb6dcdb7f6a..d5a50d6c06813cfc49d464548027eb800a361577 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; diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 83394bf1caff89d53090c888e6a1299fc30d4f9d..9ba6c45b12e02bdf25b8b027072c8abe612c473f 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -4537,8 +4537,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) { @@ -4546,25 +4544,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::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 3db73fb48267cdc12f9525e80491b6f3dc4ddb28..06121362e958b39991115a8adfbc5ecd2f8e9cd5 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -377,7 +377,6 @@ private slots: bool inFindScope(const QTextCursor &cursor); bool inFindScope(int selectionStart, int selectionEnd); void inSnippetMode(bool *active); - void onCodeStylePreferencesDestroyed(); private: Internal::BaseTextEditorWidgetPrivate *d;