forked from qt-creator/qt-creator
PE: apply project specific settings to nested text editors
Fixes: QTCREATORBUG-31875 Change-Id: I82749c43061d46c13d8ad06d4919343ee0074348 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -58,7 +58,7 @@ struct EditorConfigurationPrivate
|
|||||||
QTextCodec *m_textCodec;
|
QTextCodec *m_textCodec;
|
||||||
|
|
||||||
QMap<Utils::Id, ICodeStylePreferences *> m_languageCodeStylePreferences;
|
QMap<Utils::Id, ICodeStylePreferences *> m_languageCodeStylePreferences;
|
||||||
QList<BaseTextEditor *> m_editors;
|
QList<Core::IEditor *> m_editors;
|
||||||
};
|
};
|
||||||
|
|
||||||
EditorConfiguration::EditorConfiguration() : d(std::make_unique<EditorConfigurationPrivate>())
|
EditorConfiguration::EditorConfiguration() : d(std::make_unique<EditorConfigurationPrivate>())
|
||||||
@@ -230,29 +230,29 @@ void EditorConfiguration::fromMap(const Store &map)
|
|||||||
setUseGlobalSettings(map.value(kUseGlobal, d->m_useGlobal).toBool());
|
setUseGlobalSettings(map.value(kUseGlobal, d->m_useGlobal).toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorConfiguration::configureEditor(BaseTextEditor *textEditor) const
|
void EditorConfiguration::configureEditor(Core::IEditor *editor) const
|
||||||
{
|
{
|
||||||
TextEditorWidget *widget = textEditor->editorWidget();
|
TextEditorWidget *widget = TextEditorWidget::fromEditor(editor);
|
||||||
if (widget)
|
if (widget) {
|
||||||
widget->textDocument()->setCodeStyle(codeStyle(widget->languageSettingsId()));
|
widget->textDocument()->setCodeStyle(codeStyle(widget->languageSettingsId()));
|
||||||
if (!d->m_useGlobal) {
|
if (!d->m_useGlobal) {
|
||||||
textEditor->textDocument()->setCodec(d->m_textCodec);
|
widget->textDocument()->setCodec(d->m_textCodec);
|
||||||
if (widget)
|
|
||||||
switchSettings(widget);
|
switchSettings(widget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
d->m_editors.append(textEditor);
|
d->m_editors.append(editor);
|
||||||
connect(textEditor, &BaseTextEditor::destroyed, this, [this, textEditor]() {
|
connect(editor, &Core::IEditor::destroyed, this, [this, editor]() {
|
||||||
d->m_editors.removeOne(textEditor);
|
d->m_editors.removeOne(editor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorConfiguration::deconfigureEditor(BaseTextEditor *textEditor) const
|
void EditorConfiguration::deconfigureEditor(Core::IEditor *editor) const
|
||||||
{
|
{
|
||||||
TextEditorWidget *widget = textEditor->editorWidget();
|
TextEditorWidget *widget = TextEditorWidget::fromEditor(editor);
|
||||||
if (widget)
|
if (widget)
|
||||||
widget->textDocument()->setCodeStyle(TextEditorSettings::codeStyle(widget->languageSettingsId()));
|
widget->textDocument()->setCodeStyle(TextEditorSettings::codeStyle(widget->languageSettingsId()));
|
||||||
|
|
||||||
d->m_editors.removeOne(textEditor);
|
d->m_editors.removeOne(editor);
|
||||||
|
|
||||||
// TODO: what about text codec and switching settings?
|
// TODO: what about text codec and switching settings?
|
||||||
}
|
}
|
||||||
@@ -391,7 +391,7 @@ void EditorConfiguration::slotAboutToRemoveProject(Project *project)
|
|||||||
if (project->editorConfiguration() != this)
|
if (project->editorConfiguration() != this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (BaseTextEditor *editor : std::as_const(d->m_editors))
|
for (Core::IEditor *editor : std::as_const(d->m_editors))
|
||||||
deconfigureEditor(editor);
|
deconfigureEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ class ExtraEncodingSettings;
|
|||||||
class MarginSettings;
|
class MarginSettings;
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
namespace Core { class IEditor; }
|
||||||
namespace Utils { class FilePath; }
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
@@ -61,8 +62,8 @@ public:
|
|||||||
TextEditor::ICodeStylePreferences *codeStyle(Utils::Id languageId) const;
|
TextEditor::ICodeStylePreferences *codeStyle(Utils::Id languageId) const;
|
||||||
QMap<Utils::Id, TextEditor::ICodeStylePreferences *> codeStyles() const;
|
QMap<Utils::Id, TextEditor::ICodeStylePreferences *> codeStyles() const;
|
||||||
|
|
||||||
void configureEditor(TextEditor::BaseTextEditor *textEditor) const;
|
void configureEditor(Core::IEditor *editor) const;
|
||||||
void deconfigureEditor(TextEditor::BaseTextEditor *textEditor) const;
|
void deconfigureEditor(Core::IEditor *editor) const;
|
||||||
|
|
||||||
Utils::Store toMap() const;
|
Utils::Store toMap() const;
|
||||||
void fromMap(const Utils::Store &map);
|
void fromMap(const Utils::Store &map);
|
||||||
|
@@ -567,11 +567,9 @@ Project *ProjectManager::projectWithProjectFilePath(const FilePath &filePath)
|
|||||||
|
|
||||||
void ProjectManager::configureEditor(IEditor *editor, const FilePath &filePath)
|
void ProjectManager::configureEditor(IEditor *editor, const FilePath &filePath)
|
||||||
{
|
{
|
||||||
if (auto textEditor = qobject_cast<TextEditor::BaseTextEditor*>(editor)) {
|
// Global settings are the default.
|
||||||
// Global settings are the default.
|
if (Project *project = projectForFile(filePath))
|
||||||
if (Project *project = projectForFile(filePath))
|
project->editorConfiguration()->configureEditor(editor);
|
||||||
project->editorConfiguration()->configureEditor(textEditor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectManager::configureEditors(Project *project)
|
void ProjectManager::configureEditors(Project *project)
|
||||||
@@ -580,11 +578,8 @@ void ProjectManager::configureEditors(Project *project)
|
|||||||
for (IDocument *document : documents) {
|
for (IDocument *document : documents) {
|
||||||
if (project->isKnownFile(document->filePath())) {
|
if (project->isKnownFile(document->filePath())) {
|
||||||
const QList<IEditor *> editors = DocumentModel::editorsForDocument(document);
|
const QList<IEditor *> editors = DocumentModel::editorsForDocument(document);
|
||||||
for (IEditor *editor : editors) {
|
for (IEditor *editor : editors)
|
||||||
if (auto textEditor = qobject_cast<TextEditor::BaseTextEditor*>(editor)) {
|
project->editorConfiguration()->configureEditor(editor);
|
||||||
project->editorConfiguration()->configureEditor(textEditor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user