forked from qt-creator/qt-creator
TextEditor: Start moving settings pieces to standard patterns
Aspects would be nice in the long run. Change-Id: I6f44fdef6c3eedf6a480d550bdf2c7f4dc1c0c27 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "behaviorsettings.h"
|
||||
|
||||
#include "texteditorsettings.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
static const char mouseHidingKey[] = "MouseHiding";
|
||||
@@ -64,5 +66,29 @@ bool BehaviorSettings::equals(const BehaviorSettings &ds) const
|
||||
;
|
||||
}
|
||||
|
||||
BehaviorSettings &globalBehaviorSettings()
|
||||
{
|
||||
static BehaviorSettings theGlobalBehaviorSettings;
|
||||
return theGlobalBehaviorSettings;
|
||||
}
|
||||
|
||||
const char behaviorGroup[] = "textBehaviorSettings";
|
||||
|
||||
void updateGlobalBehaviorSettings(const BehaviorSettings &newBehaviorSettings)
|
||||
{
|
||||
if (newBehaviorSettings.equals(globalBehaviorSettings()))
|
||||
return;
|
||||
|
||||
globalBehaviorSettings() = newBehaviorSettings;
|
||||
storeToSettings(behaviorGroup, Core::ICore::settings(), globalBehaviorSettings().toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->behaviorSettingsChanged(newBehaviorSettings);
|
||||
}
|
||||
|
||||
void setupBehaviorSettings()
|
||||
{
|
||||
globalBehaviorSettings().fromMap(storeFromSettings(behaviorGroup, Core::ICore::settings()));
|
||||
}
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
|
@@ -23,9 +23,6 @@ public:
|
||||
|
||||
bool equals(const BehaviorSettings &bs) const;
|
||||
|
||||
friend bool operator==(const BehaviorSettings &t1, const BehaviorSettings &t2) { return t1.equals(t2); }
|
||||
friend bool operator!=(const BehaviorSettings &t1, const BehaviorSettings &t2) { return !t1.equals(t2); }
|
||||
|
||||
bool m_mouseHiding;
|
||||
bool m_mouseNavigation;
|
||||
bool m_scrollWheelZooming;
|
||||
@@ -35,4 +32,9 @@ public:
|
||||
bool m_smartSelectionChanging;
|
||||
};
|
||||
|
||||
TEXTEDITOR_EXPORT BehaviorSettings &globalBehaviorSettings();
|
||||
|
||||
void setupBehaviorSettings();
|
||||
void updateGlobalBehaviorSettings(const BehaviorSettings &newBehaviorSettings);
|
||||
|
||||
} // namespace TextEditor
|
||||
|
@@ -35,11 +35,6 @@ using namespace Utils;
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
const char behaviorGroup[] = "textBehaviorSettings";
|
||||
const char storageGroup[] = "textStorageSettings";
|
||||
const char typingGroup[] = "textTypingSettings";
|
||||
const char extraEncodingGroup[] = "textEditorManager";
|
||||
|
||||
class BehaviorSettingsPagePrivate : public QObject
|
||||
{
|
||||
public:
|
||||
@@ -51,10 +46,6 @@ public:
|
||||
CodeStylePool *m_defaultCodeStylePool = nullptr;
|
||||
SimpleCodeStylePreferences *m_codeStyle = nullptr;
|
||||
SimpleCodeStylePreferences *m_pageCodeStyle = nullptr;
|
||||
TypingSettings m_typingSettings;
|
||||
StorageSettings m_storageSettings;
|
||||
BehaviorSettings m_behaviorSettings;
|
||||
ExtraEncodingSettings m_extraEncodingSettings;
|
||||
};
|
||||
|
||||
BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate()
|
||||
@@ -68,12 +59,7 @@ BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate()
|
||||
m_defaultCodeStylePool = new CodeStylePool(nullptr, this); // Any language
|
||||
m_defaultCodeStylePool->addCodeStyle(m_codeStyle);
|
||||
|
||||
QtcSettings *s = Core::ICore::settings();
|
||||
m_codeStyle->fromSettings(m_settingsPrefix);
|
||||
m_typingSettings.fromMap(storeFromSettings(typingGroup, s));
|
||||
m_storageSettings.fromMap(storeFromSettings(storageGroup, s));
|
||||
m_behaviorSettings.fromMap(storeFromSettings(behaviorGroup, s));
|
||||
m_extraEncodingSettings.fromMap(storeFromSettings(extraEncodingGroup, s));
|
||||
}
|
||||
|
||||
class BehaviorSettingsWidgetImpl : public Core::IOptionsPageWidget
|
||||
@@ -111,10 +97,10 @@ public:
|
||||
}
|
||||
});
|
||||
|
||||
d->m_behaviorWidget->setAssignedTypingSettings(d->m_typingSettings);
|
||||
d->m_behaviorWidget->setAssignedStorageSettings(d->m_storageSettings);
|
||||
d->m_behaviorWidget->setAssignedBehaviorSettings(d->m_behaviorSettings);
|
||||
d->m_behaviorWidget->setAssignedExtraEncodingSettings(d->m_extraEncodingSettings);
|
||||
d->m_behaviorWidget->setAssignedTypingSettings(globalTypingSettings());
|
||||
d->m_behaviorWidget->setAssignedStorageSettings(globalStorageSettings());
|
||||
d->m_behaviorWidget->setAssignedBehaviorSettings(globalBehaviorSettings());
|
||||
d->m_behaviorWidget->setAssignedExtraEncodingSettings(globalExtraEncodingSettings());
|
||||
d->m_behaviorWidget->setAssignedCodec(Core::EditorManager::defaultTextCodec());
|
||||
d->m_behaviorWidget->setAssignedLineEnding(Core::EditorManager::defaultLineEnding());
|
||||
}
|
||||
@@ -147,8 +133,6 @@ void BehaviorSettingsWidgetImpl::apply()
|
||||
if (!d->m_behaviorWidget) // page was never shown
|
||||
return;
|
||||
|
||||
QtcSettings *s = Core::ICore::settings();
|
||||
|
||||
TypingSettings newTypingSettings;
|
||||
StorageSettings newStorageSettings;
|
||||
BehaviorSettings newBehaviorSettings;
|
||||
@@ -169,34 +153,12 @@ void BehaviorSettingsWidgetImpl::apply()
|
||||
d->m_codeStyle->toSettings(d->m_settingsPrefix);
|
||||
}
|
||||
|
||||
if (newTypingSettings != d->m_typingSettings) {
|
||||
d->m_typingSettings = newTypingSettings;
|
||||
storeToSettings(typingGroup, s, d->m_typingSettings.toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->typingSettingsChanged(newTypingSettings);
|
||||
}
|
||||
|
||||
if (newStorageSettings != d->m_storageSettings) {
|
||||
d->m_storageSettings = newStorageSettings;
|
||||
storeToSettings(storageGroup, s, d->m_storageSettings.toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->storageSettingsChanged(newStorageSettings);
|
||||
}
|
||||
|
||||
if (newBehaviorSettings != d->m_behaviorSettings) {
|
||||
d->m_behaviorSettings = newBehaviorSettings;
|
||||
storeToSettings(behaviorGroup, s, d->m_behaviorSettings.toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->behaviorSettingsChanged(newBehaviorSettings);
|
||||
}
|
||||
|
||||
if (newExtraEncodingSettings != d->m_extraEncodingSettings) {
|
||||
d->m_extraEncodingSettings = newExtraEncodingSettings;
|
||||
storeToSettings(extraEncodingGroup, s, d->m_extraEncodingSettings.toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->extraEncodingSettingsChanged(newExtraEncodingSettings);
|
||||
}
|
||||
updateGlobalTypingSettings(newTypingSettings);
|
||||
updateGlobalStorageSettings(newStorageSettings);
|
||||
updateGlobalBehaviorSettings(newBehaviorSettings);
|
||||
updateGlobalExtraEncodingSettings(newExtraEncodingSettings);
|
||||
|
||||
QtcSettings *s = Core::ICore::settings();
|
||||
s->setValue(Core::Constants::SETTINGS_DEFAULTTEXTENCODING,
|
||||
d->m_behaviorWidget->assignedCodecName());
|
||||
s->setValue(Core::Constants::SETTINGS_DEFAULT_LINE_TERMINATOR,
|
||||
@@ -215,22 +177,22 @@ CodeStylePool *BehaviorSettingsPage::codeStylePool() const
|
||||
|
||||
const TypingSettings &BehaviorSettingsPage::typingSettings() const
|
||||
{
|
||||
return d->m_typingSettings;
|
||||
return globalTypingSettings();
|
||||
}
|
||||
|
||||
const StorageSettings &BehaviorSettingsPage::storageSettings() const
|
||||
{
|
||||
return d->m_storageSettings;
|
||||
return globalStorageSettings();
|
||||
}
|
||||
|
||||
const BehaviorSettings &BehaviorSettingsPage::behaviorSettings() const
|
||||
{
|
||||
return d->m_behaviorSettings;
|
||||
return globalBehaviorSettings();
|
||||
}
|
||||
|
||||
const ExtraEncodingSettings &BehaviorSettingsPage::extraEncodingSettings() const
|
||||
{
|
||||
return d->m_extraEncodingSettings;
|
||||
return globalExtraEncodingSettings();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -4,6 +4,9 @@
|
||||
#include "extraencodingsettings.h"
|
||||
|
||||
#include "texteditortr.h"
|
||||
#include "texteditorsettings.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
// Keep this for compatibility reasons.
|
||||
static const char kUtf8BomBehaviorKey[] = "Utf8BomBehavior";
|
||||
@@ -39,4 +42,28 @@ QStringList ExtraEncodingSettings::lineTerminationModeNames()
|
||||
return {Tr::tr("Unix (LF)"), Tr::tr("Windows (CRLF)")};
|
||||
}
|
||||
|
||||
ExtraEncodingSettings &globalExtraEncodingSettings()
|
||||
{
|
||||
static ExtraEncodingSettings theGlobalExtraEncodingSettings;
|
||||
return theGlobalExtraEncodingSettings;
|
||||
}
|
||||
|
||||
const char extraEncodingGroup[] = "textEditorManager";
|
||||
|
||||
void updateGlobalExtraEncodingSettings(const ExtraEncodingSettings &newExtraEncodingSettings)
|
||||
{
|
||||
if (newExtraEncodingSettings.equals(globalExtraEncodingSettings()))
|
||||
return;
|
||||
|
||||
globalExtraEncodingSettings() = newExtraEncodingSettings;
|
||||
storeToSettings(extraEncodingGroup, Core::ICore::settings(), globalExtraEncodingSettings().toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->extraEncodingSettingsChanged(newExtraEncodingSettings);
|
||||
}
|
||||
|
||||
void setupExtraEncodingSettings()
|
||||
{
|
||||
globalExtraEncodingSettings().fromMap(storeFromSettings(extraEncodingGroup, Core::ICore::settings()));
|
||||
}
|
||||
|
||||
} // TextEditor
|
||||
|
@@ -20,12 +20,6 @@ public:
|
||||
|
||||
bool equals(const ExtraEncodingSettings &s) const;
|
||||
|
||||
friend bool operator==(const ExtraEncodingSettings &a, const ExtraEncodingSettings &b)
|
||||
{ return a.equals(b); }
|
||||
|
||||
friend bool operator!=(const ExtraEncodingSettings &a, const ExtraEncodingSettings &b)
|
||||
{ return !a.equals(b); }
|
||||
|
||||
static QStringList lineTerminationModeNames();
|
||||
|
||||
enum Utf8BomSetting {
|
||||
@@ -36,4 +30,9 @@ public:
|
||||
Utf8BomSetting m_utf8BomSetting;
|
||||
};
|
||||
|
||||
void setupExtraEncodingSettings();
|
||||
void updateGlobalExtraEncodingSettings(const ExtraEncodingSettings &newExtraEncodingSettings);
|
||||
|
||||
ExtraEncodingSettings &globalExtraEncodingSettings();
|
||||
|
||||
} // TextEditor
|
||||
|
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "storagesettings.h"
|
||||
|
||||
#include "texteditorsettings.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -94,4 +96,28 @@ bool StorageSettings::equals(const StorageSettings &ts) const
|
||||
&& m_ignoreFileTypes == ts.m_ignoreFileTypes;
|
||||
}
|
||||
|
||||
StorageSettings &globalStorageSettings()
|
||||
{
|
||||
static StorageSettings theGlobalStorageSettings;
|
||||
return theGlobalStorageSettings;
|
||||
}
|
||||
|
||||
const char storageGroup[] = "textStorageSettings";
|
||||
|
||||
void updateGlobalStorageSettings(const StorageSettings &newStorageSettings)
|
||||
{
|
||||
if (newStorageSettings.equals(globalStorageSettings()))
|
||||
return;
|
||||
|
||||
globalStorageSettings() = newStorageSettings;
|
||||
storeToSettings(storageGroup, Core::ICore::settings(), globalStorageSettings().toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->storageSettingsChanged(newStorageSettings);
|
||||
}
|
||||
|
||||
void setupStorageSettings()
|
||||
{
|
||||
globalStorageSettings().fromMap(storeFromSettings(storageGroup, Core::ICore::settings()));
|
||||
}
|
||||
|
||||
} // namespace TextEditor
|
||||
|
@@ -21,10 +21,6 @@ public:
|
||||
bool removeTrailingWhitespace(const QString &filePattern) const;
|
||||
|
||||
bool equals(const StorageSettings &ts) const;
|
||||
friend bool operator==(const StorageSettings &t1, const StorageSettings &t2)
|
||||
{ return t1.equals(t2); }
|
||||
friend bool operator!=(const StorageSettings &t1, const StorageSettings &t2)
|
||||
{ return !t1.equals(t2); }
|
||||
|
||||
QString m_ignoreFileTypes;
|
||||
bool m_cleanWhitespace;
|
||||
@@ -34,4 +30,9 @@ public:
|
||||
bool m_skipTrailingWhitespace;
|
||||
};
|
||||
|
||||
void setupStorageSettings();
|
||||
void updateGlobalStorageSettings(const StorageSettings &newStorageSettings);
|
||||
|
||||
StorageSettings &globalStorageSettings();
|
||||
|
||||
} // namespace TextEditor
|
||||
|
@@ -1,8 +1,10 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "behaviorsettings.h"
|
||||
#include "bookmarkfilter.h"
|
||||
#include "bookmarkmanager.h"
|
||||
#include "extraencodingsettings.h"
|
||||
#include "findincurrentfile.h"
|
||||
#include "findinfiles.h"
|
||||
#include "findinopenfiles.h"
|
||||
@@ -15,6 +17,7 @@
|
||||
#include "outlinefactory.h"
|
||||
#include "plaintexteditorfactory.h"
|
||||
#include "snippets/snippetprovider.h"
|
||||
#include "storagesettings.h"
|
||||
#include "tabsettings.h"
|
||||
#include "textdocument.h"
|
||||
#include "texteditor.h"
|
||||
@@ -23,6 +26,7 @@
|
||||
#include "texteditorsettings.h"
|
||||
#include "texteditortr.h"
|
||||
#include "textmark.h"
|
||||
#include "typingsettings.h"
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#include "codeassist/codeassist_test.h"
|
||||
@@ -92,6 +96,10 @@ void TextEditorPlugin::initialize()
|
||||
#endif
|
||||
|
||||
setupTextEditorSettings();
|
||||
setupBehaviorSettings();
|
||||
setupExtraEncodingSettings();
|
||||
setupStorageSettings();
|
||||
setupTypingSettings();
|
||||
|
||||
setupTextMarkRegistry(this);
|
||||
setupOutlineFactory();
|
||||
|
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "typingsettings.h"
|
||||
|
||||
#include "texteditorsettings.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
@@ -84,5 +86,28 @@ bool TypingSettings::tabShouldIndent(const QTextDocument *document,
|
||||
return (m_tabKeyBehavior == TabAlwaysIndents);
|
||||
}
|
||||
|
||||
TypingSettings &globalTypingSettings()
|
||||
{
|
||||
static TypingSettings theGlobalTypingSettings;
|
||||
return theGlobalTypingSettings;
|
||||
}
|
||||
|
||||
const char typingGroup[] = "textTypingSettings";
|
||||
|
||||
void updateGlobalTypingSettings(const TypingSettings &newTypingSettings)
|
||||
{
|
||||
if (newTypingSettings.equals(globalTypingSettings()))
|
||||
return;
|
||||
|
||||
globalTypingSettings() = newTypingSettings;
|
||||
storeToSettings(typingGroup, Core::ICore::settings(), globalTypingSettings().toMap());
|
||||
|
||||
emit TextEditorSettings::instance()->typingSettingsChanged(newTypingSettings);
|
||||
}
|
||||
|
||||
void setupTypingSettings()
|
||||
{
|
||||
globalTypingSettings().fromMap(storeFromSettings(typingGroup, Core::ICore::settings()));
|
||||
}
|
||||
|
||||
} // namespace TextEditor
|
||||
|
@@ -46,9 +46,6 @@ public:
|
||||
|
||||
bool equals(const TypingSettings &ts) const;
|
||||
|
||||
friend bool operator==(const TypingSettings &t1, const TypingSettings &t2) { return t1.equals(t2); }
|
||||
friend bool operator!=(const TypingSettings &t1, const TypingSettings &t2) { return !t1.equals(t2); }
|
||||
|
||||
bool m_autoIndent;
|
||||
TabKeyBehavior m_tabKeyBehavior;
|
||||
SmartBackspaceBehavior m_smartBackspaceBehavior;
|
||||
@@ -57,6 +54,11 @@ public:
|
||||
CommentPosition m_commentPosition = Automatic;
|
||||
};
|
||||
|
||||
void setupTypingSettings();
|
||||
void updateGlobalTypingSettings(const TypingSettings &newTypingSettings);
|
||||
|
||||
TypingSettings &globalTypingSettings();
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
Q_DECLARE_METATYPE(TextEditor::TypingSettings)
|
||||
|
Reference in New Issue
Block a user