diff options
| author | Leandro Melo <leandro.melo@nokia.com> | 2011-02-01 14:13:54 +0100 |
|---|---|---|
| committer | Leandro Melo <leandro.melo@nokia.com> | 2011-02-21 17:22:24 +0100 |
| commit | ea313f3ec84692c6112ad2a0f7d47909dafbb69c (patch) | |
| tree | e952cb85d0e9ca8d974d2c44f8dc4396a1cc0026 /src | |
| parent | cbafc50acc48d75a1fc993e72bcb6587f8bb9a4e (diff) | |
| download | qt-creator-ea313f3ec84692c6112ad2a0f7d47909dafbb69c.tar.gz | |
Text editor: Introduce per project settings
With some refactorings to make the code look better.
Reviewed-by: con
Diffstat (limited to 'src')
46 files changed, 1955 insertions, 912 deletions
diff --git a/src/libs/utils/settingsutils.h b/src/libs/utils/settingsutils.h new file mode 100644 index 0000000000..4c01a0d960 --- /dev/null +++ b/src/libs/utils/settingsutils.h @@ -0,0 +1,78 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef SETTINGSUTILS_H +#define SETTINGSUTILS_H + +#include <QtCore/QString> +#include <QtCore/QLatin1String> +#include <QtCore/QSettings> +#include <QtCore/QVariant> + +namespace Utils { + +template <class SettingsClassT> +void fromSettings(const QString &postFix, + const QString &category, + const QSettings *s, + SettingsClassT *obj) +{ + QVariantMap map; + const QStringList &keys = s->allKeys(); + foreach (const QString &key, keys) + map.insert(key, s->value(key)); + + QString group = postFix; + if (!category.isEmpty()) + group.insert(0, category); + group += QLatin1Char('/'); + obj->fromMap(group, map); +} + +template <class SettingsClassT> +void toSettings(const QString &postFix, + const QString &category, + QSettings *s, + const SettingsClassT *obj) +{ + QString group = postFix; + if (!category.isEmpty()) + group.insert(0, category); + group += QLatin1Char('/'); + + QVariantMap map; + obj->toMap(group, &map); + QVariantMap::const_iterator it = map.constBegin(); + for (; it != map.constEnd(); ++it) + s->setValue(it.key(), it.value()); +} + +} // Utils + +#endif // SETTINGSUTILS_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index f6711bee36..00041b7818 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -167,7 +167,8 @@ HEADERS += $$PWD/environment.h \ $$PWD/ssh/sftpdefs.h \ $$PWD/ssh/sftpchannel.h \ $$PWD/ssh/sftpchannel_p.h \ - $$PWD/ssh/sshremoteprocessrunner.h + $$PWD/ssh/sshremoteprocessrunner.h \ + $$PWD/settingsutils.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 9428209a9a..897d25b7c2 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -220,7 +220,6 @@ struct EditorManagerPrivate { OpenEditorsModel *m_editorModel; IFile::ReloadSetting m_reloadSetting; - IFile::Utf8BomSetting m_utf8BomSetting; QString m_titleAddition; }; @@ -242,8 +241,7 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) : m_goForwardAction(new QAction(QIcon(QLatin1String(Constants::ICON_NEXT)), EditorManager::tr("Go Forward"), parent)), m_windowPopup(0), m_coreListener(0), - m_reloadSetting(IFile::AlwaysAsk), - m_utf8BomSetting(IFile::OnlyKeep) + m_reloadSetting(IFile::AlwaysAsk) { m_editorModel = new OpenEditorsModel(parent); } @@ -1803,14 +1801,12 @@ bool EditorManager::restoreState(const QByteArray &state) static const char * const documentStatesKey = "EditorManager/DocumentStates"; static const char * const reloadBehaviorKey = "EditorManager/ReloadBehavior"; -static const char * const utf8BomBehaviorKey = "EditorManager/Utf8BomBehavior"; void EditorManager::saveSettings() { SettingsDatabase *settings = m_d->m_core->settingsDatabase(); settings->setValue(QLatin1String(documentStatesKey), m_d->m_editorStates); settings->setValue(QLatin1String(reloadBehaviorKey), m_d->m_reloadSetting); - settings->setValue(QLatin1String(utf8BomBehaviorKey), m_d->m_utf8BomSetting); } void EditorManager::readSettings() @@ -1830,9 +1826,6 @@ void EditorManager::readSettings() if (settings->contains(QLatin1String(reloadBehaviorKey))) m_d->m_reloadSetting = (IFile::ReloadSetting)settings->value(QLatin1String(reloadBehaviorKey)).toInt(); - - if (settings->contains(QLatin1String(utf8BomBehaviorKey))) - m_d->m_utf8BomSetting = (IFile::Utf8BomSetting)settings->value(QLatin1String(utf8BomBehaviorKey)).toInt(); } @@ -1900,17 +1893,7 @@ IFile::ReloadSetting EditorManager::reloadSetting() const return m_d->m_reloadSetting; } -void EditorManager::setUtf8BomSetting(IFile::Utf8BomSetting behavior) -{ - m_d->m_utf8BomSetting = behavior; -} - -IFile::Utf8BomSetting EditorManager::utf8BomSetting() const -{ - return m_d->m_utf8BomSetting; -} - -QTextCodec *EditorManager::defaultTextEncoding() const +QTextCodec *EditorManager::defaultTextCodec() const { QSettings *settings = Core::ICore::instance()->settings(); if (QTextCodec *candidate = QTextCodec::codecForName( diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 2185a1e453..0b53bba595 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -187,10 +187,7 @@ public: void setReloadSetting(IFile::ReloadSetting behavior); IFile::ReloadSetting reloadSetting() const; - void setUtf8BomSetting(IFile::Utf8BomSetting behavior); - IFile::Utf8BomSetting utf8BomSetting() const; - - QTextCodec *defaultTextEncoding() const; + QTextCodec *defaultTextCodec() const; static qint64 maxTextFileSize(); diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp index 720110d845..e208ce88ef 100644 --- a/src/plugins/cpptools/cppfilesettingspage.cpp +++ b/src/plugins/cpptools/cppfilesettingspage.cpp @@ -214,7 +214,7 @@ QString CppFileSettings::licenseTemplate(const QString &fileName, const QString return QString(); } - QTextCodec *codec = Core::EditorManager::instance()->defaultTextEncoding(); + QTextCodec *codec = Core::EditorManager::instance()->defaultTextCodec(); QTextStream licenseStream(&file); licenseStream.setCodec(codec); licenseStream.setAutoDetectUnicode(true); diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index 638a3f3cbb..e7e8b2c229 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -39,6 +39,7 @@ #include <cpptools/cppmodelmanager.h> #include <texteditor/texteditorsettings.h> #include <texteditor/tabsettings.h> +#include <projectexplorer/editorconfiguration.h> #include <QtGui/QTextBlock> @@ -64,7 +65,9 @@ CppRefactoringFile CppRefactoringChanges::file(const QString &fileName) return CppRefactoringFile(fileName, this); } -void CppRefactoringChanges::indentSelection(const QTextCursor &selection) const +void CppRefactoringChanges::indentSelection(const QTextCursor &selection, + const QString &fileName, + const TextEditor::BaseTextEditor *textEditor) const { // ### shares code with CPPEditor::indent() QTextDocument *doc = selection.document(); @@ -72,7 +75,8 @@ void CppRefactoringChanges::indentSelection(const QTextCursor &selection) const QTextBlock block = doc->findBlock(selection.selectionStart()); const QTextBlock end = doc->findBlock(selection.selectionEnd()).next(); - const TextEditor::TabSettings &tabSettings(TextEditor::TextEditorSettings::instance()->tabSettings()); + const TextEditor::TabSettings &tabSettings = + ProjectExplorer::actualTabSettings(fileName, textEditor); CppTools::QtStyleCodeFormatter codeFormatter(tabSettings); codeFormatter.updateStateUntil(block); diff --git a/src/plugins/cpptools/cpprefactoringchanges.h b/src/plugins/cpptools/cpprefactoringchanges.h index ee2ef4ae97..d59cd9ef5c 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.h +++ b/src/plugins/cpptools/cpprefactoringchanges.h @@ -92,7 +92,9 @@ public: CppRefactoringFile file(const QString &fileName); private: - virtual void indentSelection(const QTextCursor &selection) const; + virtual void indentSelection(const QTextCursor &selection, + const QString &fileName, + const TextEditor::BaseTextEditor *textEditor) const; virtual void fileChanged(const QString &fileName); private: diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index e76448c87c..c819b723db 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -1169,9 +1169,12 @@ void FakeVimPluginPrivate::setUseFakeVim(const QVariant &value) //core->updateAdditionalContexts(Core::Context(), // Core::Context(FAKEVIM_CONTEXT)); showCommandBuffer(QString()); - TabSettings ts = TextEditorSettings::instance()->tabSettings(); - foreach (Core::IEditor *editor, m_editorToHandler.keys()) - m_editorToHandler[editor]->restoreWidget(ts.m_tabSize); + foreach (Core::IEditor *editor, m_editorToHandler.keys()) { + if (TextEditor::BaseTextEditor *textEditor = + qobject_cast<TextEditor::BaseTextEditor *>(editor->widget())) { + m_editorToHandler[editor]->restoreWidget(textEditor->tabSettings().m_tabSize); + } + } } } diff --git a/src/plugins/projectexplorer/allprojectsfind.cpp b/src/plugins/projectexplorer/allprojectsfind.cpp index 422f608523..f2e74cffda 100644 --- a/src/plugins/projectexplorer/allprojectsfind.cpp +++ b/src/plugins/projectexplorer/allprojectsfind.cpp @@ -111,9 +111,7 @@ Utils::FileIterator *AllProjectsFind::files() const foreach (const QString &fileName, filteredFiles) { QTextCodec *codec = openEditorEncodings.value(fileName); if (!codec) - codec = project->editorConfiguration()->defaultTextCodec(); - if (!codec) - codec = Core::EditorManager::instance()->defaultTextEncoding(); + codec = project->editorConfiguration()->textCodec(); encodings.insert(fileName, codec); } } diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp index 750f447797..0cc7cc8138 100644 --- a/src/plugins/projectexplorer/editorconfiguration.cpp +++ b/src/plugins/projectexplorer/editorconfiguration.cpp @@ -32,43 +32,324 @@ **************************************************************************/ #include "editorconfiguration.h" +#include "session.h" +#include "projectexplorer.h" +#include "project.h" +#include <coreplugin/editormanager/editormanager.h> + +#include <texteditor/itexteditor.h> +#include <texteditor/basetexteditor.h> +#include <texteditor/texteditorsettings.h> +#include <texteditor/tabsettings.h> +#include <texteditor/storagesettings.h> +#include <texteditor/behaviorsettings.h> +#include <texteditor/extraencodingsettings.h> + +#include <QtCore/QLatin1String> +#include <QtCore/QByteArray> #include <QtCore/QTextCodec> -using namespace ProjectExplorer; +static const QLatin1String kPrefix("EditorConfiguration."); +static const QLatin1String kUseGlobal("EditorConfiguration.UseGlobal"); +static const QLatin1String kCodec("EditorConfiguration.Codec"); + +using namespace TextEditor; + +namespace ProjectExplorer { + +struct EditorConfigurationPrivate +{ + EditorConfigurationPrivate() + : m_useGlobal(true) + , m_tabSettings(TextEditorSettings::instance()->tabSettings()) + , m_storageSettings(TextEditorSettings::instance()->storageSettings()) + , m_behaviorSettings(TextEditorSettings::instance()->behaviorSettings()) + , m_extraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings()) + , m_textCodec(Core::EditorManager::instance()->defaultTextCodec()) + {} + + bool m_useGlobal; + TabSettings m_tabSettings; + StorageSettings m_storageSettings; + BehaviorSettings m_behaviorSettings; + ExtraEncodingSettings m_extraEncodingSettings; + QTextCodec *m_textCodec; +}; -namespace { -const char * const CODEC("EditorConfiguration.Codec"); +EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate) +{ } -EditorConfiguration::EditorConfiguration() - : m_defaultTextCodec(0) +EditorConfiguration::~EditorConfiguration() { } -QTextCodec *EditorConfiguration::defaultTextCodec() const +bool EditorConfiguration::useGlobalSettings() const { - return m_defaultTextCodec; + return m_d->m_useGlobal; } -void EditorConfiguration::setDefaultTextCodec(QTextCodec *codec) +void EditorConfiguration::cloneGlobalSettings() { - m_defaultTextCodec = codec; + m_d->m_tabSettings = TextEditorSettings::instance()->tabSettings(); + m_d->m_storageSettings = TextEditorSettings::instance()->storageSettings(); + m_d->m_behaviorSettings = TextEditorSettings::instance()->behaviorSettings(); + m_d->m_extraEncodingSettings = TextEditorSettings::instance()->extraEncodingSettings(); + m_d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec(); + + emitTabSettingsChanged(); + emitStorageSettingsChanged(); + emitBehaviorSettingsChanged(); + emitExtraEncodingSettingsChanged(); +} + +QTextCodec *EditorConfiguration::textCodec() const +{ + return m_d->m_textCodec; +} + +const TabSettings &EditorConfiguration::tabSettings() const +{ + return m_d->m_tabSettings; +} + +const StorageSettings &EditorConfiguration::storageSettings() const +{ + return m_d->m_storageSettings; +} + +const BehaviorSettings &EditorConfiguration::behaviorSettings() const +{ + return m_d->m_behaviorSettings; +} + +const ExtraEncodingSettings &EditorConfiguration::extraEncodingSettings() const +{ + return m_d->m_extraEncodingSettings; } QVariantMap EditorConfiguration::toMap() const { QVariantMap map; - QByteArray name = "Default"; - if (m_defaultTextCodec) - name = m_defaultTextCodec->name(); - map.insert(QLatin1String(CODEC), name); + map.insert(kUseGlobal, m_d->m_useGlobal); + map.insert(kCodec, m_d->m_textCodec->name()); + m_d->m_tabSettings.toMap(kPrefix, &map); + m_d->m_storageSettings.toMap(kPrefix, &map); + m_d->m_behaviorSettings.toMap(kPrefix, &map); + m_d->m_extraEncodingSettings.toMap(kPrefix, &map); + return map; } void EditorConfiguration::fromMap(const QVariantMap &map) { - QByteArray name = map.value(QLatin1String(CODEC)).toString().toLocal8Bit(); - QTextCodec *codec = QTextCodec::codecForName(name); - m_defaultTextCodec = codec; + m_d->m_useGlobal = map.value(kUseGlobal, m_d->m_useGlobal).toBool(); + + const QByteArray &codecName = map.value(kCodec, m_d->m_textCodec->name()).toByteArray(); + m_d->m_textCodec = QTextCodec::codecForName(codecName); + if (!m_d->m_textCodec) + m_d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec(); + + m_d->m_tabSettings.fromMap(kPrefix, map); + m_d->m_storageSettings.fromMap(kPrefix, map); + m_d->m_behaviorSettings.fromMap(kPrefix, map); + m_d->m_extraEncodingSettings.fromMap(kPrefix, map); +} + +void EditorConfiguration::apply(ITextEditor *textEditor) const +{ + if (!m_d->m_useGlobal) { + textEditor->setTextCodec(m_d->m_textCodec, ITextEditor::TextCodecFromProjectSetting); + if (BaseTextEditor *baseTextEditor = qobject_cast<BaseTextEditor *>(textEditor->widget())) + switchSettings(baseTextEditor); + } +} + +void EditorConfiguration::setUseGlobalSettings(bool use) +{ + m_d->m_useGlobal = use; + const SessionManager *session = ProjectExplorerPlugin::instance()->session(); + QList<Core::IEditor *> opened = Core::EditorManager::instance()->openedEditors(); + foreach (Core::IEditor *editor, opened) { + if (BaseTextEditor *baseTextEditor = qobject_cast<BaseTextEditor *>(editor->widget())) { + Project *project = session->projectForFile(editor->file()->fileName()); + if (project && project->editorConfiguration() == this) + switchSettings(baseTextEditor); + } + } +} + +void EditorConfiguration::switchSettings(BaseTextEditor *baseTextEditor) const +{ + if (m_d->m_useGlobal) + switchSettings_helper(TextEditorSettings::instance(), this, baseTextEditor); + else + switchSettings_helper(this, TextEditorSettings::instance(), baseTextEditor); +} + +template <class NewSenderT, class OldSenderT> +void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender, + const OldSenderT *oldSender, + BaseTextEditor *baseTextEditor) const +{ + baseTextEditor->setTabSettings(newSender->tabSettings()); + baseTextEditor->setStorageSettings(newSender->storageSettings()); + baseTextEditor->setBehaviorSettings(newSender->behaviorSettings()); + baseTextEditor->setExtraEncodingSettings(newSender->extraEncodingSettings()); + + disconnect(oldSender, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), + baseTextEditor, SLOT(setTabSettings(TextEditor::TabSettings))); + disconnect(oldSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), + baseTextEditor, SLOT(setStorageSettings(TextEditor::StorageSettings))); + disconnect(oldSender, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)), + baseTextEditor, SLOT(setBehaviorSettings(TextEditor::BehaviorSettings))); + disconnect(oldSender, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)), + baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings))); + + connect(newSender, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), + baseTextEditor, SLOT(setTabSettings(TextEditor::TabSettings))); + connect(newSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), + baseTextEditor, SLOT(setStorageSettings(TextEditor::StorageSettings))); + connect(newSender, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)), + baseTextEditor, SLOT(setBehaviorSettings(TextEditor::BehaviorSettings))); + connect(newSender, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)), + baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings))); +} + +void EditorConfiguration::setInsertSpaces(bool spaces) +{ + m_d->m_tabSettings.m_spacesForTabs = spaces; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setAutoInsertSpaces(bool autoSpaces) +{ + m_d->m_tabSettings.m_autoSpacesForTabs = autoSpaces; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setAutoIndent(bool autoIndent) +{ + m_d->m_tabSettings.m_autoIndent = autoIndent; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setSmartBackSpace(bool smartBackSpace) +{ + m_d->m_tabSettings.m_smartBackspace = smartBackSpace; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setTabSize(int size) +{ + m_d->m_tabSettings.m_tabSize = size; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setIndentSize(int size) +{ + m_d->m_tabSettings.m_indentSize = size; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setIndentBlocksBehavior(int index) +{ + m_d->m_tabSettings.m_indentBraces = index >= 1; + m_d->m_tabSettings.m_doubleIndentBlocks = index >= 2; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setTabKeyBehavior(int index) +{ + m_d->m_tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)index; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setContinuationAlignBehavior(int index) +{ + m_d->m_tabSettings.m_continuationAlignBehavior = (TabSettings::ContinuationAlignBehavior)index; + emitTabSettingsChanged(); +} + +void EditorConfiguration::setCleanWhiteSpace(bool cleanWhiteSpace) +{ + m_d->m_storageSettings.m_cleanWhitespace = cleanWhiteSpace; + emitStorageSettingsChanged(); +} + +void EditorConfiguration::setInEntireDocument(bool entireDocument) +{ + m_d->m_storageSettings.m_inEntireDocument = entireDocument; + emitStorageSettingsChanged(); +} + +void EditorConfiguration::setAddFinalNewLine(bool newLine) +{ + m_d->m_storageSettings.m_addFinalNewLine = newLine; + emitStorageSettingsChanged(); +} + +void EditorConfiguration::setCleanIndentation(bool cleanIndentation) +{ + m_d->m_storageSettings.m_cleanIndentation = cleanIndentation; + emitStorageSettingsChanged(); +} + +void EditorConfiguration::setMouseNavigation(bool mouseNavigation) +{ + m_d->m_behaviorSettings.m_mouseNavigation = mouseNavigation; + emitBehaviorSettingsChanged(); +} + +void EditorConfiguration::setScrollWheelZooming(bool scrollZooming) +{ + m_d->m_behaviorSettings.m_scrollWheelZooming = scrollZooming; + emitBehaviorSettingsChanged(); +} + +void EditorConfiguration::setUtf8BomSettings(int index) +{ + m_d->m_extraEncodingSettings.m_utf8BomSetting = (ExtraEncodingSettings::Utf8BomSetting)index; + emitExtraEncodingSettingsChanged(); +} + +void EditorConfiguration::setTextCodec(QTextCodec *textCodec) +{ + m_d->m_textCodec = textCodec; +} + +void EditorConfiguration::emitTabSettingsChanged() +{ + emit tabSettingsChanged(m_d->m_tabSettings); } + +void EditorConfiguration::emitStorageSettingsChanged() +{ + emit storageSettingsChanged(m_d->m_storageSettings); +} + +void EditorConfiguration::emitBehaviorSettingsChanged() +{ + emit behaviorSettingsChanged(m_d->m_behaviorSettings); +} + +void EditorConfiguration::emitExtraEncodingSettingsChanged() +{ + emit extraEncodingSettingsChanged(m_d->m_extraEncodingSettings); +} + +const TabSettings &actualTabSettings(const QString &fileName, const BaseTextEditor *baseTextEditor) +{ + if (baseTextEditor) { + return baseTextEditor->tabSettings(); + } else { + const SessionManager *session = ProjectExplorerPlugin::instance()->session(); + if (Project *project = session->projectForFile(fileName)) + return project->editorConfiguration()->tabSettings(); + else + return TextEditorSettings::instance()->tabSettings(); + } +} + +} // ProjectExplorer diff --git a/src/plugins/projectexplorer/editorconfiguration.h b/src/plugins/projectexplorer/editorconfiguration.h index 98e70a2963..d6e5bdbce8 100644 --- a/src/plugins/projectexplorer/editorconfiguration.h +++ b/src/plugins/projectexplorer/editorconfiguration.h @@ -36,30 +36,99 @@ #include "projectexplorer_export.h" +#include <QtCore/QObject> #include <QtCore/QVariantMap> +#include <QtCore/QScopedPointer> -QT_BEGIN_NAMESPACE -class QTextCodec; -QT_END_NAMESPACE +namespace TextEditor { +class ITextEditor; +class BaseTextEditor; +class TabSettings; +class StorageSettings; +class BehaviorSettings; +class ExtraEncodingSettings; +} namespace ProjectExplorer { -class PROJECTEXPLORER_EXPORT EditorConfiguration +struct EditorConfigurationPrivate; + +class PROJECTEXPLORER_EXPORT EditorConfiguration : public QObject { + Q_OBJECT + public: EditorConfiguration(); + ~EditorConfiguration(); + + bool useGlobalSettings() const; + void cloneGlobalSettings(); + + // The default codec is returned in the case the project doesn't override it. + QTextCodec *textCodec() const; - // defaultTextCodec can be 0, in that case the editor settings default encoding shall be used - QTextCodec *defaultTextCodec() const; - void setDefaultTextCodec(QTextCodec *codec); + const TextEditor::TabSettings &tabSettings() const; + const TextEditor::StorageSettings &storageSettings() const; + const TextEditor::BehaviorSettings &behaviorSettings() const; + const TextEditor::ExtraEncodingSettings &extraEncodingSettings() const; + + void apply(TextEditor::ITextEditor *textEditor) const; QVariantMap toMap() const; void fromMap(const QVariantMap &map); +signals: + void tabSettingsChanged(const TextEditor::TabSettings &); + void storageSettingsChanged(const TextEditor::StorageSettings &); + void behaviorSettingsChanged(const TextEditor::BehaviorSettings &); + void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &); + +private slots: + void setUseGlobalSettings(bool use); + + void setInsertSpaces(bool spaces); + void setAutoInsertSpaces(bool autoSpaces); + void setAutoIndent(bool autoIndent); + void setSmartBackSpace(bool smartBackSpace); + void setTabSize(int size); + void setIndentSize(int size); + void setIndentBlocksBehavior(int index); + void setTabKeyBehavior(int index); + void setContinuationAlignBehavior(int index); + + void setCleanWhiteSpace(bool cleanWhiteSpace); + void setInEntireDocument(bool entireDocument); + void setAddFinalNewLine(bool newLine); + void setCleanIndentation(bool cleanIndentation); + + void setMouseNavigation(bool mouseNavigation); + void setScrollWheelZooming(bool scrollZooming); + + void setUtf8BomSettings(int index); + + void setTextCodec(QTextCodec *textCodec); + private: - QTextCodec *m_defaultTextCodec; + void switchSettings(TextEditor::BaseTextEditor *baseTextEditor) const; + template <class NewSenderT, class OldSenderT> + void switchSettings_helper(const NewSenderT *newSender, + const OldSenderT *oldSender, + TextEditor::BaseTextEditor *baseTextEditor) const; + + void emitTabSettingsChanged(); + void emitStorageSettingsChanged(); + void emitBehaviorSettingsChanged(); + void emitExtraEncodingSettingsChanged(); + + QScopedPointer<EditorConfigurationPrivate> m_d; }; +// Return the editor settings in the case it's not null. Otherwise, try to find the project +// the file belongs to and return the project settings. If the file doesn't belong to any +// project return the global settings. +PROJECTEXPLORER_EXPORT const TextEditor::TabSettings &actualTabSettings( + const QString &fileName, const TextEditor::BaseTextEditor *baseTextEditor); + } // ProjectExplorer #endif // EDITORCONFIGURATION_H diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp index f98bd8f7b0..6d8a4194e4 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp @@ -36,7 +36,6 @@ #include "project.h" #include <QtCore/QTextCodec> -#include <QtCore/QDebug> using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; @@ -88,48 +87,75 @@ QIcon EditorSettingsPanel::icon() const return m_icon; } -EditorSettingsWidget::EditorSettingsWidget(Project *project) - : QWidget(), - m_project(project) +EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_project(project) { m_ui.setupUi(this); - QTextCodec *defaultTextCodec = 0; - m_codecs += defaultTextCodec; - m_ui.encodingComboBox->addItem(tr("Default")); - - defaultTextCodec = m_project->editorConfiguration()->defaultTextCodec(); - - QList<int> mibs = QTextCodec::availableMibs(); - qSort(mibs); - QList<int> sortedMibs; - foreach (int mib, mibs) - if (mib >= 0) - sortedMibs += mib; - foreach (int mib, mibs) - if (mib < 0) - sortedMibs += mib; - int i = 1; // 0 is the default - foreach (int mib, sortedMibs) { - QTextCodec *codec = QTextCodec::codecForMib(mib); - m_codecs += codec; - QString name = codec->name(); - foreach (const QByteArray &alias, codec->aliases()) { - name += QLatin1String(" / "); - name += QString::fromLatin1(alias); - } - m_ui.encodingComboBox->addItem(name); - if (defaultTextCodec == codec) - m_ui.encodingComboBox->setCurrentIndex(i); - i++; - } - - connect(m_ui.encodingComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentEncodingChanged(int))); + + const EditorConfiguration *config = m_project->editorConfiguration(); + settingsToUi(config); + + setGlobalSettingsEnabled(config->useGlobalSettings()); + + connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)), + this, SLOT(setGlobalSettingsEnabled(bool))); + connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)), + config, SLOT(setUseGlobalSettings(bool))); + connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues())); + connect(m_ui.behaviorSettingsWidget, SIGNAL(insertSpacesChanged(bool)), + config, SLOT(setInsertSpaces(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(autoInsertSpacesChanged(bool)), + config, SLOT(setAutoInsertSpaces(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(autoIndentChanged(bool)), + config, SLOT(setAutoIndent(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(smartBackSpaceChanged(bool)), + config, SLOT(setSmartBackSpace(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(tabSizeChanged(int)), + config, SLOT(setTabSize(int))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(indentSizeChanged(int)), + config, SLOT(setIndentSize(int))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(indentBlocksBehaviorChanged(int)), + config, SLOT(setIndentBlocksBehavior(int))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(tabKeyBehaviorChanged(int)), + config, SLOT(setTabKeyBehavior(int))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(continuationAlignBehaviorChanged(int)), + config, SLOT(setContinuationAlignBehavior(int))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(cleanWhiteSpaceChanged(bool)), + config, SLOT(setCleanWhiteSpace(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(inEntireDocumentChanged(bool)), + config, SLOT(setInEntireDocument(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(addFinalNewLineChanged(bool)), + config, SLOT(setAddFinalNewLine(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(cleanIndentationChanged(bool)), + config, SLOT(setCleanIndentation(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(mouseNavigationChanged(bool)), + config, SLOT(setMouseNavigation(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(scrollWheelZoomingChanged(bool)), + config, SLOT(setScrollWheelZooming(bool))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(utf8BomSettingsChanged(int)), + config, SLOT(setUtf8BomSettings(int))); + connect(m_ui.behaviorSettingsWidget, SIGNAL(textCodecChanged(QTextCodec*)), + config, SLOT(setTextCodec(QTextCodec*))); } -void EditorSettingsWidget::currentEncodingChanged(int index) +void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config) { - m_project->editorConfiguration()->setDefaultTextCodec(m_codecs.at(index)); + m_ui.useGlobalCheckBox->setChecked(config->useGlobalSettings()); + m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec()); + m_ui.behaviorSettingsWidget->setAssignedTabSettings(config->tabSettings()); + m_ui.behaviorSettingsWidget->setAssignedStorageSettings(config->storageSettings()); + m_ui.behaviorSettingsWidget->setAssignedBehaviorSettings(config->behaviorSettings()); + m_ui.behaviorSettingsWidget->setAssignedExtraEncodingSettings(config->extraEncodingSettings()); } +void EditorSettingsWidget::setGlobalSettingsEnabled(bool enabled) +{ + m_ui.behaviorSettingsWidget->setActive(!enabled); + m_ui.restoreButton->setEnabled(!enabled); +} +void EditorSettingsWidget::restoreDefaultValues() +{ + EditorConfiguration *config = m_project->editorConfiguration(); + config->cloneGlobalSettings(); + settingsToUi(config); +} diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.h b/src/plugins/projectexplorer/editorsettingspropertiespage.h index 6b9b586db3..3742811e2e 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.h +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.h @@ -39,6 +39,8 @@ namespace ProjectExplorer { +class EditorConfiguration; + namespace Internal { const char * const EDITORSETTINGS_PANEL_ID("ProjectExplorer.EditorSettingsPanel"); @@ -75,12 +77,14 @@ public: EditorSettingsWidget(Project *project); private slots: - void currentEncodingChanged(int index); + void setGlobalSettingsEnabled(bool enabled); + void restoreDefaultValues(); private: + void settingsToUi(const EditorConfiguration *config); + Ui::EditorSettingsPropertiesPage m_ui; Project *m_project; - QList<QTextCodec *> m_codecs; }; } // namespace Internal diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.ui b/src/plugins/projectexplorer/editorsettingspropertiespage.ui index da7c45c262..ce01078784 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.ui +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.ui @@ -6,29 +6,64 @@ <rect> <x>0</x> <y>0</y> - <width>275</width> - <height>44</height> + <width>368</width> + <height>98</height> </rect> </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="encodingLabel"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <widget class="QCheckBox" name="useGlobalCheckBox"> <property name="text"> - <string>Default file encoding:</string> + <string>Use global settings</string> </property> </widget> </item> - <item> - <widget class="QComboBox" name="encodingComboBox"/> + <item row="1" column="0" colspan="3"> + <widget class="TextEditor::BehaviorSettingsWidget" name="behaviorSettingsWidget" native="true"/> + </item> + <item row="2" column="0" colspan="2"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>224</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="3" column="1"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>12</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="2"> + <widget class="QPushButton" name="restoreButton"> + <property name="text"> + <string>Restore Global Values</string> + </property> + </widget> </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>TextEditor::BehaviorSettingsWidget</class> + <extends>QWidget</extends> + <header>texteditor/behaviorsettingswidget.h</header> + <container>1</container> + </customwidget> + </customwidgets> <resources/> <connections/> </ui> diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index f8d8390d4b..993142fdb4 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -321,7 +321,7 @@ SessionManager::SessionManager(QObject *parent) Core::EditorManager *em = m_core->editorManager(); connect(em, SIGNAL(editorCreated(Core::IEditor *, QString)), - this, SLOT(setEditorCodec(Core::IEditor *, QString))); + this, SLOT(configureEditor(Core::IEditor *, QString))); connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project *)), this, SLOT(updateWindowTitle())); connect(em, SIGNAL(editorOpened(Core::IEditor*)), @@ -823,13 +823,15 @@ bool SessionManager::projectContainsFile(Project *p, const QString &fileName) co return m_projectFileCache.value(p).contains(fileName); } -void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileName) +void SessionManager::configureEditor(Core::IEditor *editor, const QString &fileName) { - if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) - if (Project *project = projectForFile(fileName)) { - if (QTextCodec *codec = project->editorConfiguration()->defaultTextCodec()) - textEditor->setTextCodec(codec, TextEditor::ITextEditor::TextCodecFromProjectSetting); + if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) { + Project *project = projectForFile(fileName); + // Global settings are the default. + if (project && !project->editorConfiguration()->useGlobalSettings()) { + project->editorConfiguration()->apply(textEditor); } + } } QString SessionManager::currentSession() const diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h index d30836bb97..53eee3cae1 100644 --- a/src/plugins/projectexplorer/session.h +++ b/src/plugins/projectexplorer/session.h @@ -158,7 +158,7 @@ signals: private slots: void saveActiveMode(Core::IMode *mode); void clearProjectFileCache(); - void setEditorCodec(Core::IEditor *editor, const QString &fileName); + void configureEditor(Core::IEditor *editor, const QString &fileName); void updateWindowTitle(); void markSessionFileDirty(bool makeDefaultVirginDirty = true); diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp index 3a5be7597b..0b8704ab63 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp @@ -38,6 +38,7 @@ #include <qmljs/qmljsmodelmanagerinterface.h> #include <texteditor/texteditorsettings.h> #include <texteditor/tabsettings.h> +#include <projectexplorer/editorconfiguration.h> using namespace QmlJS; using namespace QmlJSTools; @@ -60,7 +61,9 @@ QmlJSRefactoringFile QmlJSRefactoringChanges::file(const QString &fileName) return QmlJSRefactoringFile(fileName, this); } -void QmlJSRefactoringChanges::indentSelection(const QTextCursor &selection) const +void QmlJSRefactoringChanges::indentSelection(const QTextCursor &selection, + const QString &fileName, + const TextEditor::BaseTextEditor *textEditor) const { // ### shares code with QmlJSTextEditor::indent QTextDocument *doc = selection.document(); @@ -68,7 +71,8 @@ void QmlJSRefactoringChanges::indentSelection(const QTextCursor &selection) cons QTextBlock block = doc->findBlock(selection.selectionStart()); const QTextBlock end = doc->findBlock(selection.selectionEnd()).next(); - const TextEditor::TabSettings &tabSettings(TextEditor::TextEditorSettings::instance()->tabSettings()); + const TextEditor::TabSettings &tabSettings = + ProjectExplorer::actualTabSettings(fileName, textEditor); QtStyleCodeFormatter codeFormatter(tabSettings); codeFormatter.updateStateUntil(block); diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.h b/src/plugins/qmljstools/qmljsrefactoringchanges.h index 5167a3a950..f8650ce869 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.h +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.h @@ -84,7 +84,9 @@ public: QmlJSRefactoringFile file(const QString &fileName); private: - virtual void indentSelection(const QTextCursor &selection) const; + virtual void indentSelection(const QTextCursor &selection, + const QString &fileName, + const TextEditor::BaseTextEditor *textEditor) const; virtual void fileChanged(const QString &fileName); private: diff --git a/src/plugins/texteditor/autocompleter.cpp b/src/plugins/texteditor/autocompleter.cpp index e51a74939b..e5cddc71c1 100644 --- a/src/plugins/texteditor/autocompleter.cpp +++ b/src/plugins/texteditor/autocompleter.cpp @@ -263,7 +263,8 @@ bool AutoCompleter::autoBackspace(QTextCursor &cursor) return false; } -int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor) +int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, + const TabSettings &tabSettings) { if (!m_autoParenthesesEnabled) return 0; @@ -289,17 +290,16 @@ int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor) if (condition) {| statement; */ - const TabSettings &ts = TextEditorSettings::instance()->tabSettings(); QTextBlock block = cursor.block(); - int indentation = ts.indentationColumn(block.text()); + int indentation = tabSettings.indentationColumn(block.text()); if (block.next().isValid()) { // not the last block block = block.next(); //skip all empty blocks - while (block.isValid() && ts.onlySpace(block.text())) + while (block.isValid() && tabSettings.onlySpace(block.text())) block = block.next(); if (block.isValid() - && ts.indentationColumn(block.text()) > indentation) + && tabSettings.indentationColumn(block.text()) > indentation) return 0; } diff --git a/src/plugins/texteditor/autocompleter.h b/src/plugins/texteditor/autocompleter.h index b4da82fd8f..0b2bb4b3db 100644 --- a/src/plugins/texteditor/autocompleter.h +++ b/src/plugins/texteditor/autocompleter.h @@ -45,6 +45,8 @@ QT_END_NAMESPACE namespace TextEditor { +class TabSettings; + class TEXTEDITOR_EXPORT AutoCompleter { public: @@ -64,7 +66,8 @@ public: virtual bool autoBackspace(QTextCursor &cursor); // Hook to insert special characters on enter. Returns the number of extra blocks inserted. - virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor); + virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, + const TabSettings &tabSettings); virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const; diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index 5fa4ac164b..e74d890a9d 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -37,6 +37,7 @@ #include "basetexteditor.h" #include "storagesettings.h" #include "tabsettings.h" +#include "extraencodingsettings.h" #include "syntaxhighlighter.h" #include "texteditorconstants.h" @@ -180,6 +181,7 @@ public: QString m_mimeType; StorageSettings m_storageSettings; TabSettings m_tabSettings; + ExtraEncodingSettings m_extraEncodingSettings; QTextDocument *m_document; Internal::DocumentMarker *m_documentMarker; SyntaxHighlighter *m_highlighter; @@ -211,7 +213,7 @@ BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) : m_documentMarker(new Internal::DocumentMarker(m_document)), m_highlighter(0), m_lineTerminatorMode(NativeLineTerminator), - m_codec(Core::EditorManager::instance()->defaultTextEncoding()), + m_codec(Core::EditorManager::instance()->defaultTextCodec()), m_fileHasUtf8Bom(false), m_fileIsReadOnly(false), m_hasDecodingError(false) @@ -260,6 +262,16 @@ const TabSettings &BaseTextDocument::tabSettings() const return d->m_tabSettings; } +void BaseTextDocument::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings) +{ + d->m_extraEncodingSettings = extraEncodingSettings; +} + +const ExtraEncodingSettings &BaseTextDocument::extraEncodingSettings() const +{ + return d->m_extraEncodingSettings; +} + QString BaseTextDocument::fileName() const { return d->m_fileName; @@ -358,9 +370,10 @@ bool BaseTextDocument::save(const QString &fileName) if (d->m_lineTerminatorMode == BaseTextDocumentPrivate::CRLFLineTerminator) plainText.replace(QLatin1Char('\n'), QLatin1String("\r\n")); - Core::IFile::Utf8BomSetting utf8bomSetting = Core::EditorManager::instance()->utf8BomSetting(); - if (d->m_codec->name() == "UTF-8" && - (utf8bomSetting == Core::IFile::AlwaysAdd || (utf8bomSetting == Core::IFile::OnlyKeep && d->m_fileHasUtf8Bom))) { + if (d->m_codec->name() == "UTF-8" + && (d->m_extraEncodingSettings.m_utf8BomSetting == ExtraEncodingSettings::AlwaysAdd + || (d->m_extraEncodingSettings.m_utf8BomSetting == ExtraEncodingSettings::OnlyKeep + && d->m_fileHasUtf8Bom))) { file.write("\xef\xbb\xbf", 3); } diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index a47d0f2b83..37b43407d6 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -51,6 +51,7 @@ class DocumentMarker; class ITextMarkable; class StorageSettings; class TabSettings; +class ExtraEncodingSettings; class SyntaxHighlighter; class BaseTextDocumentPrivate; @@ -64,9 +65,11 @@ public: void setStorageSettings(const StorageSettings &storageSettings); void setTabSettings(const TabSettings &tabSettings); + void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings); const StorageSettings &storageSettings() const; const TabSettings &tabSettings() const; + const ExtraEncodingSettings &extraEncodingSettings() const; ITextMarkable *documentMarker() const; diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 874aa2b568..348970d700 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1555,7 +1555,8 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) const TabSettings &ts = d->m_document->tabSettings(); cursor.beginEditBlock(); - int extraBlocks = d->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor); + int extraBlocks = + d->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor, tabSettings()); QString previousIndentationString; if (ts.m_autoIndent) { @@ -5424,6 +5425,11 @@ void BaseTextEditor::setCompletionSettings(const TextEditor::CompletionSettings d->m_autoCompleter->setSurroundWithEnabled(completionSettings.m_autoInsertBrackets); } +void BaseTextEditor::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings) +{ + d->m_document->setExtraEncodingSettings(extraEncodingSettings); +} + void BaseTextEditor::fold() { QTextDocument *doc = document(); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 385eaa9478..45b1eb5004 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -75,6 +75,7 @@ class DisplaySettings; class StorageSettings; class Indenter; class AutoCompleter; +class ExtraEncodingSettings; class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject { @@ -412,6 +413,7 @@ public slots: virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &); virtual void setStorageSettings(const TextEditor::StorageSettings &); virtual void setCompletionSettings(const TextEditor::CompletionSettings &); + virtual void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &); protected: bool viewportEvent(QEvent *event); diff --git a/src/plugins/texteditor/behaviorsettings.cpp b/src/plugins/texteditor/behaviorsettings.cpp index 22b6c53ad8..b3d6a96d49 100644 --- a/src/plugins/texteditor/behaviorsettings.cpp +++ b/src/plugins/texteditor/behaviorsettings.cpp @@ -33,6 +33,8 @@ #include "behaviorsettings.h" +#include <utils/settingsutils.h> + #include <QtCore/QSettings> #include <QtCore/QString> @@ -50,26 +52,27 @@ BehaviorSettings::BehaviorSettings() : void BehaviorSettings::toSettings(const QString &category, QSettings *s) const { - QString group = QLatin1String(groupPostfix); - if (!category.isEmpty()) - group.insert(0, category); - s->beginGroup(group); - s->setValue(QLatin1String(mouseNavigationKey), m_mouseNavigation); - s->setValue(QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming); - s->endGroup(); + Utils::toSettings(QLatin1String(groupPostfix), category, s, this); } void BehaviorSettings::fromSettings(const QString &category, const QSettings *s) { - QString group = QLatin1String(groupPostfix); - if (!category.isEmpty()) - group.insert(0, category); - group += QLatin1Char('/'); + *this = BehaviorSettings(); + Utils::fromSettings(QLatin1String(groupPostfix), category, s, this); +} - *this = BehaviorSettings(); // Assign defaults +void BehaviorSettings::toMap(const QString &prefix, QVariantMap *map) const +{ + map->insert(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation); + map->insert(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming); +} - m_mouseNavigation = s->value(group + QLatin1String(mouseNavigationKey), m_mouseNavigation).toBool(); - m_scrollWheelZooming = s->value(group + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming).toBool(); +void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map) +{ + m_mouseNavigation = + map.value(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation).toBool(); + m_scrollWheelZooming = + map.value(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming).toBool(); } bool BehaviorSettings::equals(const BehaviorSettings &ds) const diff --git a/src/plugins/texteditor/behaviorsettings.h b/src/plugins/texteditor/behaviorsettings.h index d10a7c1f33..0f45e0ac0b 100644 --- a/src/plugins/texteditor/behaviorsettings.h +++ b/src/plugins/texteditor/behaviorsettings.h @@ -36,6 +36,8 @@ #include "texteditor_global.h" +#include <QtCore/QVariant> + QT_BEGIN_NAMESPACE class QSettings; QT_END_NAMESPACE @@ -54,6 +56,9 @@ public: void toSettings(const QString &category, QSettings *s) const; void fromSettings(const QString &category, const QSettings *s); + void toMap(const QString &prefix, QVariantMap *map) const; + void fromMap(const QString &prefix, const QVariantMap &map); + bool equals(const BehaviorSettings &bs) const; bool m_mouseNavigation; diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp index 059c1ed699..8e45cd8847 100644 --- a/src/plugins/texteditor/behaviorsettingspage.cpp +++ b/src/plugins/texteditor/behaviorsettingspage.cpp @@ -36,6 +36,7 @@ #include "behaviorsettings.h" #include "storagesettings.h" #include "tabsettings.h" +#include "extraencodingsettings.h" #include "ui_behaviorsettingspage.h" #include <coreplugin/icore.h> @@ -44,7 +45,6 @@ #include <QtCore/QSettings> #include <QtCore/QTextCodec> -#include <QtCore/QTextStream> using namespace TextEditor; @@ -58,6 +58,7 @@ struct BehaviorSettingsPage::BehaviorSettingsPagePrivate TabSettings m_tabSettings; StorageSettings m_storageSettings; BehaviorSettings m_behaviorSettings; + ExtraEncodingSettings m_extraEncodingSettings; QString m_searchKeywords; }; @@ -70,6 +71,7 @@ BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate m_tabSettings.fromSettings(m_parameters.settingsPrefix, s); m_storageSettings.fromSettings(m_parameters.settingsPrefix, s); m_behaviorSettings.fromSettings(m_parameters.settingsPrefix, s); + m_extraEncodingSettings.fromSettings(m_parameters.settingsPrefix, s); } } @@ -100,60 +102,11 @@ QWidget *BehaviorSettingsPage::createPage(QWidget *parent) QWidget *w = new QWidget(parent); m_d->m_page = new Ui::BehaviorSettingsPage; m_d->m_page->setupUi(w); - settingsToUI(); - if (m_d->m_searchKeywords.isEmpty()) { - QLatin1Char sep(' '); - QTextStream(&m_d->m_searchKeywords) - << m_d->m_page->insertSpaces->text() - << sep << m_d->m_page->autoInsertSpaces->text() - << sep << m_d->m_page->autoIndent->text() - << sep << m_d->m_page->smartBackspace->text() - << sep << m_d->m_page->indentBlocksLabel->text() - << sep << m_d->m_page->continuationAlignLabel->text() - << sep << m_d->m_page->tabKeyIndentLabel->text() - << sep << m_d->m_page->cleanWhitespace->text() - << sep << m_d->m_page->inEntireDocument->text() - << sep << m_d->m_page->cleanIndentation->text() - << sep << m_d->m_page->addFinalNewLine->text() - << sep << m_d->m_page->encodingLabel->text() - << sep << m_d->m_page->utf8BomLabel->text() - << sep << m_d->m_page->mouseNavigation->text() - << sep << m_d->m_page->scrollWheelZooming->text() - << sep << m_d->m_page->groupBoxTabAndIndentSettings->title() - << sep << m_d->m_page->groupBoxStorageSettings->title() - << sep << m_d->m_page->groupBoxEncodings->title() - << sep << m_d->m_page->groupBoxMouse->title(); - m_d->m_searchKeywords.remove(QLatin1Char('&')); - } - QSettings *settings = Core::ICore::instance()->settings(); - QTextCodec *defaultTextCodec = QTextCodec::codecForLocale(); - if (QTextCodec *candidate = QTextCodec::codecForName( - settings->value(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING)).toByteArray())) - defaultTextCodec = candidate; - QList<int> mibs = QTextCodec::availableMibs(); - qSort(mibs); - QList<int> sortedMibs; - foreach (int mib, mibs) - if (mib >= 0) - sortedMibs += mib; - foreach (int mib, mibs) - if (mib < 0) - sortedMibs += mib; - for (int i = 0; i < sortedMibs.count(); i++) { - QTextCodec *codec = QTextCodec::codecForMib(sortedMibs.at(i)); - m_codecs += codec; - QString name = codec->name(); - foreach (const QByteArray &alias, codec->aliases()) { - name += QLatin1String(" / "); - name += QString::fromLatin1(alias); - } - m_d->m_page->encodingBox->addItem(name); - if (defaultTextCodec == codec) - m_d->m_page->encodingBox->setCurrentIndex(i); - } + settingsToUI(); - m_d->m_page->utf8BomBox->setCurrentIndex(Core::EditorManager::instance()->utf8BomSetting()); + if (m_d->m_searchKeywords.isEmpty()) + m_d->m_searchKeywords = m_d->m_page->behaviorWidget->collectUiKeywords(); return w; } @@ -162,14 +115,16 @@ void BehaviorSettingsPage::apply() { if (!m_d->m_page) // page was never shown return; + TabSettings newTabSettings; StorageSettings newStorageSettings; BehaviorSettings newBehaviorSettings; + ExtraEncodingSettings newExtraEncodingSettings; - settingsFromUI(newTabSettings, newStorageSettings, newBehaviorSettings); + settingsFromUI(&newTabSettings, &newStorageSettings, &newBehaviorSettings, + &newExtraEncodingSettings); - Core::ICore *core = Core::ICore::instance(); - QSettings *s = core->settings(); + QSettings *s = Core::ICore::instance()->settings(); if (newTabSettings != m_d->m_tabSettings) { m_d->m_tabSettings = newTabSettings; @@ -195,71 +150,47 @@ void BehaviorSettingsPage::apply() emit behaviorSettingsChanged(newBehaviorSettings); } - QSettings* settings = Core::ICore::instance()->settings(); - settings->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING), - m_codecs.at(m_d->m_page->encodingBox->currentIndex())->name()); + if (newExtraEncodingSettings != m_d->m_extraEncodingSettings) { + m_d->m_extraEncodingSettings = newExtraEncodingSettings; + if (s) + m_d->m_extraEncodingSettings.toSettings(m_d->m_parameters.settingsPrefix, s); + + emit extraEncodingSettingsChanged(newExtraEncodingSettings); + } - Core::EditorManager::instance()->setUtf8BomSetting( - Core::IFile::Utf8BomSetting(m_d->m_page->utf8BomBox->currentIndex())); + if (s) { + s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING), + m_d->m_page->behaviorWidget->assignedCodec()->name()); + } } -void BehaviorSettingsPage::finish() +void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings, + StorageSettings *storageSettings, + BehaviorSettings *behaviorSettings, + ExtraEncodingSettings *extraEncodingSettings) const { - if (!m_d->m_page) // page was never shown - return; - delete m_d->m_page; - m_d->m_page = 0; + m_d->m_page->behaviorWidget->assignedTabSettings(tabSettings); + m_d->m_page->behaviorWidget->assignedStorageSettings(storageSettings); + m_d->m_page->behaviorWidget->assignedBehaviorSettings(behaviorSettings); + m_d->m_page->behaviorWidget->assignedExtraEncodingSettings(extraEncodingSettings); } -void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings, - StorageSettings &storageSettings, - BehaviorSettings &behaviorSettings) const +void BehaviorSettingsPage::settingsToUI() { - tabSettings.m_spacesForTabs = m_d->m_page->insertSpaces->isChecked(); - tabSettings.m_autoSpacesForTabs = m_d->m_page->autoInsertSpaces->isChecked(); - tabSettings.m_autoIndent = m_d->m_page->autoIndent->isChecked(); - tabSettings.m_smartBackspace = m_d->m_page->smartBackspace->isChecked(); - tabSettings.m_tabSize = m_d->m_page->tabSize->value(); - tabSettings.m_indentSize = m_d->m_page->indentSize->value(); - tabSettings.m_indentBraces = m_d->m_page->indentBlocksBehavior->currentIndex() >= 1; - tabSettings.m_doubleIndentBlocks = m_d->m_page->indentBlocksBehavior->currentIndex() >= 2; - - tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)m_d->m_page->tabKeyBehavior->currentIndex(); - tabSettings.m_continuationAlignBehavior = (TabSettings::ContinuationAlignBehavior)m_d->m_page->continuationAlignBehavior->currentIndex(); - - storageSettings.m_cleanWhitespace = m_d->m_page->cleanWhitespace->isChecked(); - storageSettings.m_inEntireDocument = m_d->m_page->inEntireDocument->isChecked(); - storageSettings.m_cleanIndentation = m_d->m_page->cleanIndentation->isChecked(); - storageSettings.m_addFinalNewLine = m_d->m_page->addFinalNewLine->isChecked(); - - behaviorSettings.m_mouseNavigation = m_d->m_page->mouseNavigation->isChecked(); - behaviorSettings.m_scrollWheelZooming = m_d->m_page->scrollWheelZooming->isChecked(); + m_d->m_page->behaviorWidget->setAssignedTabSettings(m_d->m_tabSettings); + m_d->m_page->behaviorWidget->setAssignedStorageSettings(m_d->m_storageSettings); + m_d->m_page->behaviorWidget->setAssignedBehaviorSettings(m_d->m_behaviorSettings); + m_d->m_page->behaviorWidget->setAssignedExtraEncodingSettings(m_d->m_extraEncodingSettings); + m_d->m_page->behaviorWidget->setAssignedCodec( + Core::EditorManager::instance()->defaultTextCodec()); } -void BehaviorSettingsPage::settingsToUI() +void BehaviorSettingsPage::finish() { - const TabSettings &tabSettings = m_d->m_tabSettings; - m_d->m_page->insertSpaces->setChecked(tabSettings.m_spacesForTabs); - m_d->m_page->autoInsertSpaces->setChecked(tabSettings.m_autoSpacesForTabs); - m_d->m_page->autoIndent->setChecked(tabSettings.m_autoIndent); - m_d->m_page->smartBackspace->setChecked(tabSettings.m_smartBackspace); - m_d->m_page->tabSize->setValue(tabSettings.m_tabSize); - m_d->m_page->indentSize->setValue(tabSettings.m_indentSize); - m_d->m_page->indentBlocksBehavior->setCurrentIndex(tabSettings.m_indentBraces ? - (tabSettings.m_doubleIndentBlocks ? 2 : 1) - : 0); - m_d->m_page->tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior); - m_d->m_page->continuationAlignBehavior->setCurrentIndex(tabSettings.m_continuationAlignBehavior); - - const StorageSettings &storageSettings = m_d->m_storageSettings; - m_d->m_page->cleanWhitespace->setChecked(storageSettings.m_cleanWhitespace); - m_d->m_page->inEntireDocument->setChecked(storageSettings.m_inEntireDocument); - m_d->m_page->cleanIndentation->setChecked(storageSettings.m_cleanIndentation); - m_d->m_page->addFinalNewLine->setChecked(storageSettings.m_addFinalNewLine); - - const BehaviorSettings &behaviorSettings = m_d->m_behaviorSettings; - m_d->m_page->mouseNavigation->setChecked(behaviorSettings.m_mouseNavigation); - m_d->m_page->scrollWheelZooming->setChecked(behaviorSettings.m_scrollWheelZooming); + if (!m_d->m_page) // page was never shown + return; + delete m_d->m_page; + m_d->m_page = 0; } const TabSettings &BehaviorSettingsPage::tabSettings() const @@ -277,6 +208,11 @@ const BehaviorSettings &BehaviorSettingsPage::behaviorSettings() const return m_d->m_behaviorSettings; } +const ExtraEncodingSettings &BehaviorSettingsPage::extraEncodingSettings() const +{ + return m_d->m_extraEncodingSettings; +} + bool BehaviorSettingsPage::matches(const QString &s) const { return m_d->m_searchKeywords.contains(s, Qt::CaseInsensitive); diff --git a/src/plugins/texteditor/behaviorsettingspage.h b/src/plugins/texteditor/behaviorsettingspage.h index 3df5456b5e..4d118b065c 100644 --- a/src/plugins/texteditor/behaviorsettingspage.h +++ b/src/plugins/texteditor/behaviorsettingspage.h @@ -43,6 +43,7 @@ namespace TextEditor { class TabSettings; class StorageSettings; class BehaviorSettings; +class ExtraEncodingSettings; class BehaviorSettingsPageParameters { @@ -72,16 +73,19 @@ public: const TabSettings &tabSettings() const; const StorageSettings &storageSettings() const; const BehaviorSettings &behaviorSettings() const; + const ExtraEncodingSettings &extraEncodingSettings() const; signals: void tabSettingsChanged(const TextEditor::TabSettings &); void storageSettingsChanged(const TextEditor::StorageSettings &); void behaviorSettingsChanged(const TextEditor::BehaviorSettings &); + void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &); private: - void settingsFromUI(TabSettings &rc, - StorageSettings &storageSettings, - BehaviorSettings &behaviorSettings) const; + void settingsFromUI(TabSettings *tabSettings, + StorageSettings *storageSettings, + BehaviorSettings *behaviorSettings, + ExtraEncodingSettings *extraEncodingSettings) const; void settingsToUI(); QList<QTextCodec *> m_codecs; diff --git a/src/plugins/texteditor/behaviorsettingspage.ui b/src/plugins/texteditor/behaviorsettingspage.ui index e14f95dfe7..b5b3316bde 100644 --- a/src/plugins/texteditor/behaviorsettingspage.ui +++ b/src/plugins/texteditor/behaviorsettingspage.ui @@ -1,429 +1,23 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>TextEditor::BehaviorSettingsPage</class> - <widget class="QWidget" name="TextEditor::BehaviorSettingsPage"> + <class>BehaviorSettingsPage</class> + <widget class="QWidget" name="BehaviorSettingsPage"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>662</width> - <height>538</height> + <width>432</width> + <height>50</height> </rect> </property> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="0" column="0" colspan="2"> - <widget class="QGroupBox" name="groupBoxTabAndIndentSettings"> - <property name="title"> - <string>Tabs and Indentation</string> - </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="0"> - <widget class="QCheckBox" name="insertSpaces"> - <property name="text"> - <string>Insert &spaces instead of tabs</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="labelTabSize"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Ta&b size:</string> - </property> - <property name="buddy"> - <cstring>tabSize</cstring> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QSpinBox" name="tabSize"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>20</number> - </property> - </widget> - </item> - <item row="0" column="3"> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - </spacer> - </item> - <item row="1" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <spacer name="horizontalSpacer_5"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>30</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QCheckBox" name="autoInsertSpaces"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>Automatically determine based on the nearest indented line (previous line preferred over next line)</string> - </property> - <property name="text"> - <string>Based on the surrounding lines</string> - </property> - </widget> - </item> - </layout> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="labelIndentSize"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>&Indent size:</string> - </property> - <property name="buddy"> - <cstring>indentSize</cstring> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QSpinBox" name="indentSize"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>20</number> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="autoIndent"> - <property name="text"> - <string>Enable automatic &indentation</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QCheckBox" name="smartBackspace"> - <property name="toolTip"> - <string>Backspace will go back one indentation level instead of one space.</string> - </property> - <property name="text"> - <string>&Backspace follows indentation</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="indentBlocksLabel"> - <property name="text"> - <string>Block indentation style:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QComboBox" name="indentBlocksBehavior"> - <property name="toolTip"> - <string><html><head/><body> -Controls the indentation style of curly brace blocks. - -<ul> -<li>Exclude Braces: The braces are not indented. -<pre> -void foo() -{ - if (a) - { - bar(); - } -} -</pre> -</li> - -<li>Include Braces: The braces are indented. The contents of the block are on the same level as the braces. -<pre> -void foo() - { - if (a) - { - bar(); - } - } -</pre> -</li> - -<li>GNU Style: Indent the braces for blocks in statements. The contents are indented twice. -<pre> -void foo() -{ - if (a) - { - bar(); - } -} -</pre> -</li> -</ul></body></html></string> - </property> - <item> - <property name="text"> - <string>Exclude Braces</string> - </property> - </item> - <item> - <property name="text"> - <string>Include Braces</string> - </property> - </item> - <item> - <property name="text"> - <string>GNU Style</string> - </property> - </item> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="tabKeyIndentLabel"> - <property name="text"> - <string>Tab key performs auto-indent:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QComboBox" name="tabKeyBehavior"> - <item> - <property name="text"> - <string>Never</string> - </property> - </item> - <item> - <property name="text"> - <string>Always</string> - </property> - </item> - <item> - <property name="text"> - <string>In Leading White Space</string> - </property> - </item> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="continuationAlignLabel"> - <property name="text"> - <string>Align continuation lines:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QComboBox" name="continuationAlignBehavior"> - <property name="toolTip"> - <string><html><head/><body> -Influences the indentation of continuation lines. - -<ul> -<li>Not At All: Do not align at all. Lines will only be indented to the current logical indentation depth. -<pre> -(tab)int i = foo(a, b -(tab)c, d); -</pre> -</li> - -<li>With Spaces: Always use spaces for alignment, regardless of the other indentation settings. -<pre> -(tab)int i = foo(a, b -(tab) c, d); -</pre> -</li> - -<li>With Regular Indent: Use tabs and/or spaces for alignment, as configured above. -<pre> -(tab)int i = foo(a, b -(tab)(tab)(tab) c, d); -</pre> -</li> -</ul></body></html></string> - </property> - <item> - <property name="text"> - <string>Not At All</string> - </property> - </item> - <item> - <property name="text"> - <string>With Spaces</string> - </property> - </item> - <item> - <property name="text"> - <string>With Regular Indent</string> - </property> - </item> - </widget> - </item> - </layout> - </item> - </layout> - </widget> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="TextEditor::BehaviorSettingsWidget" name="behaviorWidget" native="true"/> </item> <item row="1" column="0"> - <widget class="QGroupBox" name="groupBoxStorageSettings"> - <property name="toolTip"> - <string>Cleanup actions which are automatically performed right before the file is saved to disk.</string> - </property> - <property name="title"> - <string>Cleanups Upon Saving</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QCheckBox" name="cleanWhitespace"> - <property name="toolTip"> - <string>Removes trailing whitespace upon saving.</string> - </property> - <property name="text"> - <string>&Clean whitespace</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>30</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QCheckBox" name="inEntireDocument"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>Clean whitespace in entire document instead of only for changed parts.</string> - </property> - <property name="text"> - <string>In entire &document</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="cleanIndentationLayout"> - <item> - <spacer name="cleanIndentationSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>30</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QCheckBox" name="cleanIndentation"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>Correct leading whitespace according to tab settings.</string> - </property> - <property name="text"> - <string>Clean indentation</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QCheckBox" name="addFinalNewLine"> - <property name="text"> - <string>&Ensure newline at end of file</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="2" column="0" colspan="2"> - <widget class="QGroupBox" name="groupBoxMouse"> - <property name="title"> - <string>Mouse</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QCheckBox" name="mouseNavigation"> - <property name="text"> - <string>Enable &mouse navigation</string> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="scrollWheelZooming"> - <property name="text"> - <string>Enable scroll &wheel zooming</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="3" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -431,187 +25,21 @@ Influences the indentation of continuation lines. <property name="sizeHint" stdset="0"> <size> <width>20</width> - <height>8</height> + <height>13</height> </size> </property> </spacer> </item> - <item row="1" column="1"> - <widget class="QGroupBox" name="groupBoxEncodings"> - <property name="title"> - <string>File Encodings</string> - </property> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="0" column="0"> - <widget class="QLabel" name="encodingLabel"> - <property name="text"> - <string>Default encoding: </string> - </property> - </widget> - </item> - <item row="0" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_6"> - <item> - <widget class="QComboBox" name="encodingBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="sizeAdjustPolicy"> - <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum> - </property> - <property name="minimumContentsLength"> - <number>20</number> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_6"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>285</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="utf8BomLabel"> - <property name="text"> - <string>UTF-8 BOM:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QComboBox" name="utf8BomBox"> - <property name="toolTip"> - <string><html><head/><body> -<p>How text editors should deal with UTF-8 Byte Order Marks. The options are:</p> -<ul ><li><i>Add If Encoding Is UTF-8:</i> always add a BOM when saving a file in UTF-8 encoding. Note that this will not work if the encoding is <i>System</i>, as Qt Creator does not know what it actually is.</li> -<li><i>Keep If Already Present: </i>save the file with a BOM if it already had one when it was loaded.</li> -<li><i>Always Delete:</i> never write an UTF-8 BOM, possibly deleting a pre-existing one.</li></ul> -<p>Note that UTF-8 BOMs are uncommon and treated incorrectly by some editors, so it usually makes little sense to add any.</p> -<p>This setting does <b>not</b> influence the use of UTF-16 and UTF-32 BOMs.</p></body></html></string> - </property> - <item> - <property name="text"> - <string>Add If Encoding Is UTF-8</string> - </property> - </item> - <item> - <property name="text"> - <string>Keep If Already Present</string> - </property> - </item> - <item> - <property name="text"> - <string>Always Delete</string> - </property> - </item> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="2" column="0" colspan="2"> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> </layout> </widget> - <tabstops> - <tabstop>insertSpaces</tabstop> - <tabstop>tabSize</tabstop> - <tabstop>autoIndent</tabstop> - <tabstop>smartBackspace</tabstop> - <tabstop>tabKeyBehavior</tabstop> - <tabstop>cleanWhitespace</tabstop> - <tabstop>inEntireDocument</tabstop> - <tabstop>cleanIndentation</tabstop> - <tabstop>addFinalNewLine</tabstop> - </tabstops> + <customwidgets> + <customwidget> + <class>TextEditor::BehaviorSettingsWidget</class> + <extends>QWidget</extends> + <header>texteditor/behaviorsettingswidget.h</header> + <container>1</container> + </customwidget> + </customwidgets> <resources/> - <connections> - <connection> - <sender>cleanWhitespace</sender> - <signal>toggled(bool)</signal> - <receiver>inEntireDocument</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>87</x> - <y>323</y> - </hint> - <hint type="destinationlabel"> - <x>205</x> - <y>353</y> - </hint> - </hints> - </connection> - <connection> - <sender>cleanWhitespace</sender> - <signal>toggled(bool)</signal> - <receiver>cleanIndentation</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>60</x> - <y>323</y> - </hint> - <hint type="destinationlabel"> - <x>134</x> - <y>384</y> - </hint> - </hints> - </connection> - <connection> - <sender>insertSpaces</sender> - <signal>toggled(bool)</signal> - <receiver>autoInsertSpaces</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>105</x> - <y>49</y> - </hint> - <hint type="destinationlabel"> - <x>105</x> - <y>78</y> - </hint> - </hints> - </connection> - </connections> + <connections/> </ui> diff --git a/src/plugins/texteditor/behaviorsettingswidget.cpp b/src/plugins/texteditor/behaviorsettingswidget.cpp new file mode 100644 index 0000000000..de9c8e7550 --- /dev/null +++ b/src/plugins/texteditor/behaviorsettingswidget.cpp @@ -0,0 +1,244 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "behaviorsettingswidget.h" +#include "ui_behaviorsettingswidget.h" + +#include <texteditor/tabsettings.h> +#include <texteditor/storagesettings.h> +#include <texteditor/behaviorsettings.h> +#include <texteditor/extraencodingsettings.h> + +#include <QtCore/QList> +#include <QtCore/QString> +#include <QtCore/QByteArray> +#include <QtCore/QTextCodec> +#include <QtCore/QTextStream> + +#include <algorithm> +#include <functional> + +namespace TextEditor { + +struct BehaviorSettingsWidgetPrivate +{ + Ui::BehaviorSettingsWidget m_ui; + QList<QTextCodec *> m_codecs; +}; + +BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent) + : QWidget(parent) + , m_d(new BehaviorSettingsWidgetPrivate) +{ + m_d->m_ui.setupUi(this); + + QList<int> mibs = QTextCodec::availableMibs(); + qSort(mibs); + QList<int>::iterator firstNonNegative = + std::find_if(mibs.begin(), mibs.end(), std::bind2nd(std::greater_equal<int>(), 0)); + if (firstNonNegative != mibs.end()) + std::rotate(mibs.begin(), firstNonNegative, mibs.end()); + foreach (int mib, mibs) { + QTextCodec *codec = QTextCodec::codecForMib(mib); + QString compoundName = codec->name(); + foreach (const QByteArray &alias, codec->aliases()) { + compoundName += QLatin1String(" / "); + compoundName += QString::fromLatin1(alias); + } + m_d->m_ui.encodingBox->addItem(compoundName); + m_d->m_codecs.append(codec); + } + + connect(m_d->m_ui.insertSpaces, SIGNAL(clicked(bool)), this, SIGNAL(insertSpacesChanged(bool))); + connect(m_d->m_ui.autoInsertSpaces, SIGNAL(clicked(bool)), + this, SIGNAL(autoInsertSpacesChanged(bool))); + connect(m_d->m_ui.autoIndent, SIGNAL(clicked(bool)), this, SIGNAL(autoIndentChanged(bool))); + connect(m_d->m_ui.smartBackspace, SIGNAL(clicked(bool)), + this, SIGNAL(smartBackSpaceChanged(bool))); + connect(m_d->m_ui.tabSize, SIGNAL(valueChanged(int)), this, SIGNAL(tabSizeChanged(int))); + connect(m_d->m_ui.indentSize, SIGNAL(valueChanged(int)), this, SIGNAL(indentSizeChanged(int))); + connect(m_d->m_ui.indentBlocksBehavior, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(indentBlocksBehaviorChanged(int))); + connect(m_d->m_ui.tabKeyBehavior, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(tabKeyBehaviorChanged(int))); + connect(m_d->m_ui.continuationAlignBehavior, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(continuationAlignBehaviorChanged(int))); + connect(m_d->m_ui.cleanWhitespace, SIGNAL(clicked(bool)), + this, SIGNAL(cleanWhiteSpaceChanged(bool))); + connect(m_d->m_ui.inEntireDocument, SIGNAL(clicked(bool)), + this, SIGNAL(inEntireDocumentChanged(bool))); + connect(m_d->m_ui.addFinalNewLine, SIGNAL(clicked(bool)), + this, SIGNAL(addFinalNewLineChanged(bool))); + connect(m_d->m_ui.cleanIndentation, SIGNAL(clicked(bool)), + this, SIGNAL(cleanIndentationChanged(bool))); + connect(m_d->m_ui.mouseNavigation, SIGNAL(clicked(bool)), + this, SIGNAL(mouseNavigationChanged(bool))); + connect(m_d->m_ui.scrollWheelZooming, SIGNAL(clicked(bool)), + this, SIGNAL(scrollWheelZoomingChanged(bool))); + connect(m_d->m_ui.utf8BomBox, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(utf8BomSettingsChanged(int))); + connect(m_d->m_ui.encodingBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(handleEncodingBoxChange(int))); +} + +BehaviorSettingsWidget::~BehaviorSettingsWidget() +{ + delete m_d; +} + +void BehaviorSettingsWidget::setActive(bool active) +{ + m_d->m_ui.groupBoxEncodings->setEnabled(active); + m_d->m_ui.groupBoxMouse->setEnabled(active); + m_d->m_ui.groupBoxStorageSettings->setEnabled(active); + m_d->m_ui.groupBoxTabAndIndentSettings->setEnabled(active); +} + +void BehaviorSettingsWidget::setAssignedCodec(QTextCodec *codec) +{ + for (int i = 0; i < m_d->m_codecs.size(); ++i) { + if (codec == m_d->m_codecs.at(i)) { + m_d->m_ui.encodingBox->setCurrentIndex(i); + break; + } + } +} + +QTextCodec *BehaviorSettingsWidget::assignedCodec() const +{ + return m_d->m_codecs.at(m_d->m_ui.encodingBox->currentIndex()); +} + +void BehaviorSettingsWidget::setAssignedTabSettings(const TabSettings &tabSettings) +{ + m_d->m_ui.insertSpaces->setChecked(tabSettings.m_spacesForTabs); + m_d->m_ui.autoInsertSpaces->setChecked(tabSettings.m_autoSpacesForTabs); + m_d->m_ui.autoIndent->setChecked(tabSettings.m_autoIndent); + m_d->m_ui.smartBackspace->setChecked(tabSettings.m_smartBackspace); + m_d->m_ui.tabSize->setValue(tabSettings.m_tabSize); + m_d->m_ui.indentSize->setValue(tabSettings.m_indentSize); + m_d->m_ui.indentBlocksBehavior->setCurrentIndex(tabSettings.m_indentBraces ? + (tabSettings.m_doubleIndentBlocks ? 2 : 1) + : 0); + m_d->m_ui.tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior); + m_d->m_ui.continuationAlignBehavior->setCurrentIndex(tabSettings.m_continuationAlignBehavior); +} + +void BehaviorSettingsWidget::assignedTabSettings(TabSettings *tabSettings) const +{ + tabSettings->m_spacesForTabs = m_d->m_ui.insertSpaces->isChecked(); + tabSettings->m_autoSpacesForTabs = m_d->m_ui.autoInsertSpaces->isChecked(); + tabSettings->m_autoIndent = m_d->m_ui.autoIndent->isChecked(); + tabSettings->m_smartBackspace = m_d->m_ui.smartBackspace->isChecked(); + tabSettings->m_tabSize = m_d->m_ui.tabSize->value(); + tabSettings->m_indentSize = m_d->m_ui.indentSize->value(); + tabSettings->m_indentBraces = m_d->m_ui.indentBlocksBehavior->currentIndex() >= 1; + tabSettings->m_doubleIndentBlocks = m_d->m_ui.indentBlocksBehavior->currentIndex() >= 2; + + tabSettings->m_tabKeyBehavior = + (TabSettings::TabKeyBehavior)m_d->m_ui.tabKeyBehavior->currentIndex(); + tabSettings->m_continuationAlignBehavior = + (TabSettings::ContinuationAlignBehavior)m_d->m_ui.continuationAlignBehavior->currentIndex(); +} + +void BehaviorSettingsWidget::setAssignedStorageSettings(const StorageSettings &storageSettings) +{ + m_d->m_ui.cleanWhitespace->setChecked(storageSettings.m_cleanWhitespace); + m_d->m_ui.inEntireDocument->setChecked(storageSettings.m_inEntireDocument); + m_d->m_ui.cleanIndentation->setChecked(storageSettings.m_cleanIndentation); + m_d->m_ui.addFinalNewLine->setChecked(storageSettings.m_addFinalNewLine); +} + +void BehaviorSettingsWidget::assignedStorageSettings(StorageSettings *storageSettings) const +{ + storageSettings->m_cleanWhitespace = m_d->m_ui.cleanWhitespace->isChecked(); + storageSettings->m_inEntireDocument = m_d->m_ui.inEntireDocument->isChecked(); + storageSettings->m_cleanIndentation = m_d->m_ui.cleanIndentation->isChecked(); + storageSettings->m_addFinalNewLine = m_d->m_ui.addFinalNewLine->isChecked(); +} + +void BehaviorSettingsWidget::setAssignedBehaviorSettings(const BehaviorSettings &behaviorSettings) +{ + m_d->m_ui.mouseNavigation->setChecked(behaviorSettings.m_mouseNavigation); + m_d->m_ui.scrollWheelZooming->setChecked(behaviorSettings.m_scrollWheelZooming); +} + +void BehaviorSettingsWidget::assignedBehaviorSettings(BehaviorSettings *behaviorSettings) const +{ + behaviorSettings->m_mouseNavigation = m_d->m_ui.mouseNavigation->isChecked(); + behaviorSettings->m_scrollWheelZooming = m_d->m_ui.scrollWheelZooming->isChecked(); +} + +void BehaviorSettingsWidget::setAssignedExtraEncodingSettings( + const ExtraEncodingSettings &encodingSettings) +{ + m_d->m_ui.utf8BomBox->setCurrentIndex(encodingSettings.m_utf8BomSetting); +} + +void BehaviorSettingsWidget::assignedExtraEncodingSettings( + ExtraEncodingSettings *encodingSettings) const +{ + encodingSettings->m_utf8BomSetting = + (ExtraEncodingSettings::Utf8BomSetting)m_d->m_ui.utf8BomBox->currentIndex(); +} + +QString BehaviorSettingsWidget::collectUiKeywords() const +{ + static const QLatin1Char sep(' '); + QString keywords; + QTextStream(&keywords) + << m_d->m_ui.insertSpaces->text() + << sep << m_d->m_ui.autoInsertSpaces->text() + << sep << m_d->m_ui.autoIndent->text() + << sep << m_d->m_ui.smartBackspace->text() + << sep << m_d->m_ui.indentBlocksLabel->text() + << sep << m_d->m_ui.continuationAlignLabel->text() + << sep << m_d->m_ui.tabKeyIndentLabel->text() + << sep << m_d->m_ui.cleanWhitespace->text() + << sep << m_d->m_ui.inEntireDocument->text() + << sep << m_d->m_ui.cleanIndentation->text() + << sep << m_d->m_ui.addFinalNewLine->text() + << sep << m_d->m_ui.encodingLabel->text() + << sep << m_d->m_ui.utf8BomLabel->text() + << sep << m_d->m_ui.mouseNavigation->text() + << sep << m_d->m_ui.scrollWheelZooming->text() + << sep << m_d->m_ui.groupBoxTabAndIndentSettings->title() + << sep << m_d->m_ui.groupBoxStorageSettings->title() + << sep << m_d->m_ui.groupBoxEncodings->title() + << sep << m_d->m_ui.groupBoxMouse->title(); + keywords.remove(QLatin1Char('&')); + return keywords; +} + +void BehaviorSettingsWidget::handleEncodingBoxChange(int index) +{ + emit textCodecChanged(m_d->m_codecs.at(index)); +} + +} // TextEditor diff --git a/src/plugins/texteditor/behaviorsettingswidget.h b/src/plugins/texteditor/behaviorsettingswidget.h new file mode 100644 index 0000000000..5377676832 --- /dev/null +++ b/src/plugins/texteditor/behaviorsettingswidget.h @@ -0,0 +1,109 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef BEHAVIORSETTINGSWIDGET_H +#define BEHAVIORSETTINGSWIDGET_H + +#include "texteditor_global.h" + +#include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE +class QTextCodec; +QT_END_NAMESPACE + +namespace TextEditor { + +class TabSettings; +class StorageSettings; +class BehaviorSettings; +class ExtraEncodingSettings; + +struct BehaviorSettingsWidgetPrivate; + +class TEXTEDITOR_EXPORT BehaviorSettingsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit BehaviorSettingsWidget(QWidget *parent = 0); + virtual ~BehaviorSettingsWidget(); + + void setActive(bool active); + + void setAssignedCodec(QTextCodec *codec); + QTextCodec *assignedCodec() const; + + void setAssignedTabSettings(const TabSettings &tabSettings); + void assignedTabSettings(TabSettings *tabSettings) const; + + void setAssignedStorageSettings(const StorageSettings &storageSettings); + void assignedStorageSettings(StorageSettings *storageSettings) const; + + void setAssignedBehaviorSettings(const BehaviorSettings &behaviorSettings); + void assignedBehaviorSettings(BehaviorSettings *behaviorSettings) const; + + void setAssignedExtraEncodingSettings(const ExtraEncodingSettings &encodingSettings); + void assignedExtraEncodingSettings(ExtraEncodingSettings *encodingSettings) const; + + QString collectUiKeywords() const; + +signals: + void insertSpacesChanged(bool spaces); + void autoInsertSpacesChanged(bool autoSpaces); + void autoIndentChanged(bool autoIndent); + void smartBackSpaceChanged(bool smartBackSpace); + void tabSizeChanged(int size); + void indentSizeChanged(int size); + void indentBlocksBehaviorChanged(int index); + void tabKeyBehaviorChanged(int index); + void continuationAlignBehaviorChanged(int index); + + void cleanWhiteSpaceChanged(bool cleanWhiteSpace); + void inEntireDocumentChanged(bool entireDocument); + void addFinalNewLineChanged(bool newLine); + void cleanIndentationChanged(bool cleanIndentation); + + void mouseNavigationChanged(bool mouseNavigation); + void scrollWheelZoomingChanged(bool scrollZooming); + + void utf8BomSettingsChanged(int index); + + void textCodecChanged(QTextCodec *codec); + +private slots: + void handleEncodingBoxChange(int index); + +private: + BehaviorSettingsWidgetPrivate *m_d; +}; + +} // TextEditor + +#endif // BEHAVIORSETTINGSWIDGET_H diff --git a/src/plugins/texteditor/behaviorsettingswidget.ui b/src/plugins/texteditor/behaviorsettingswidget.ui new file mode 100644 index 0000000000..3c1ee24b3a --- /dev/null +++ b/src/plugins/texteditor/behaviorsettingswidget.ui @@ -0,0 +1,607 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BehaviorSettingsWidget</class> + <widget class="QWidget" name="BehaviorSettingsWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>762</width> + <height>463</height> + </rect> + </property> + <layout class="QGridLayout" name="gridLayout_3"> + <property name="margin"> + <number>0</number> + </property> + <item row="0" column="0" colspan="2"> + <widget class="QGroupBox" name="groupBoxTabAndIndentSettings"> + <property name="title"> + <string>Tabs and Indentation</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QCheckBox" name="insertSpaces"> + <property name="text"> + <string>Insert &spaces instead of tabs</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="labelTabSize"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Ta&b size:</string> + </property> + <property name="buddy"> + <cstring>tabSize</cstring> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QSpinBox" name="tabSize"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>20</number> + </property> + </widget> + </item> + <item row="0" column="3"> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>22</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <spacer name="horizontalSpacer_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>30</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="autoInsertSpaces"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Automatically determine based on the nearest indented line (previous line preferred over next line)</string> + </property> + <property name="text"> + <string>Based on the surrounding lines</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="labelIndentSize"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Indent size:</string> + </property> + <property name="buddy"> + <cstring>indentSize</cstring> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QSpinBox" name="indentSize"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>20</number> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QCheckBox" name="autoIndent"> + <property name="text"> + <string>Enable automatic &indentation</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QCheckBox" name="smartBackspace"> + <property name="toolTip"> + <string>Backspace will go back one indentation level instead of one space.</string> + </property> + <property name="text"> + <string>&Backspace follows indentation</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="indentBlocksLabel"> + <property name="text"> + <string>Block indentation style:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="indentBlocksBehavior"> + <property name="toolTip"> + <string><html><head/><body> +Controls the indentation style of curly brace blocks. + +<ul> +<li>Exclude Braces: The braces are not indented. +<pre> +void foo() +{ + if (a) + { + bar(); + } +} +</pre> +</li> + +<li>Include Braces: The braces are indented. The contents of the block are on the same level as the braces. +<pre> +void foo() + { + if (a) + { + bar(); + } + } +</pre> +</li> + +<li>GNU Style: Indent the braces for blocks in statements. The contents are indented twice. +<pre> +void foo() +{ + if (a) + { + bar(); + } +} +</pre> +</li> +</ul></body></html></string> + </property> + <item> + <property name="text"> + <string>Exclude Braces</string> + </property> + </item> + <item> + <property name="text"> + <string>Include Braces</string> + </property> + </item> + <item> + <property name="text"> + <string>GNU Style</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="tabKeyIndentLabel"> + <property name="text"> + <string>Tab key performs auto-indent:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QComboBox" name="tabKeyBehavior"> + <item> + <property name="text"> + <string>Never</string> + </property> + </item> + <item> + <property name="text"> + <string>Always</string> + </property> + </item> + <item> + <property name="text"> + <string>In Leading White Space</string> + </property> + </item> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="continuationAlignLabel"> + <property name="text"> + <string>Align continuation lines:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="continuationAlignBehavior"> + <property name="toolTip"> + <string><html><head/><body> +Influences the indentation of continuation lines. + +<ul> +<li>Not At All: Do not align at all. Lines will only be indented to the current logical indentation depth. +<pre> +(tab)int i = foo(a, b +(tab)c, d); +</pre> +</li> + +<li>With Spaces: Always use spaces for alignment, regardless of the other indentation settings. +<pre> +(tab)int i = foo(a, b +(tab) c, d); +</pre> +</li> + +<li>With Regular Indent: Use tabs and/or spaces for alignment, as configured above. +<pre> +(tab)int i = foo(a, b +(tab)(tab)(tab) c, d); +</pre> +</li> +</ul></body></html></string> + </property> + <item> + <property name="text"> + <string>Not At All</string> + </property> + </item> + <item> + <property name="text"> + <string>With Spaces</string> + </property> + </item> + <item> + <property name="text"> + <string>With Regular Indent</string> + </property> + </item> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QGroupBox" name="groupBoxStorageSettings"> + <property name="toolTip"> + <string>Cleanup actions which are automatically performed right before the file is saved to disk.</string> + </property> + <property name="title"> + <string>Cleanups Upon Saving</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QCheckBox" name="cleanWhitespace"> + <property name="toolTip"> + <string>Removes trailing whitespace upon saving.</string> + </property> + <property name="text"> + <string>&Clean whitespace</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>30</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="inEntireDocument"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Clean whitespace in entire document instead of only for changed parts.</string> + </property> + <property name="text"> + <string>In entire &document</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="cleanIndentationLayout"> + <item> + <spacer name="cleanIndentationSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>30</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="cleanIndentation"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Correct leading whitespace according to tab settings.</string> + </property> + <property name="text"> + <string>Clean indentation</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QCheckBox" name="addFinalNewLine"> + <property name="text"> + <string>&Ensure newline at end of file</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="1"> + <widget class="QGroupBox" name="groupBoxEncodings"> + <property name="title"> + <string>File Encodings</string> + </property> + <layout class="QGridLayout" name="gridLayout_4"> + <item row="0" column="0"> + <widget class="QLabel" name="encodingLabel"> + <property name="text"> + <string>Default encoding: </string> + </property> + </widget> + </item> + <item row="0" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QComboBox" name="encodingBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="sizeAdjustPolicy"> + <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum> + </property> + <property name="minimumContentsLength"> + <number>20</number> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_6"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>285</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="utf8BomLabel"> + <property name="text"> + <string>UTF-8 BOM:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QComboBox" name="utf8BomBox"> + <property name="toolTip"> + <string><html><head/><body> +<p>How text editors should deal with UTF-8 Byte Order Marks. The options are:</p> +<ul ><li><i>Add If Encoding Is UTF-8:</i> always add a BOM when saving a file in UTF-8 encoding. Note that this will not work if the encoding is <i>System</i>, as Qt Creator does not know what it actually is.</li> +<li><i>Keep If Already Present: </i>save the file with a BOM if it already had one when it was loaded.</li> +<li><i>Always Delete:</i> never write an UTF-8 BOM, possibly deleting a pre-existing one.</li></ul> +<p>Note that UTF-8 BOMs are uncommon and treated incorrectly by some editors, so it usually makes little sense to add any.</p> +<p>This setting does <b>not</b> influence the use of UTF-16 and UTF-32 BOMs.</p></body></html></string> + </property> + <item> + <property name="text"> + <string>Add If Encoding Is UTF-8</string> + </property> + </item> + <item> + <property name="text"> + <string>Keep If Already Present</string> + </property> + </item> + <item> + <property name="text"> + <string>Always Delete</string> + </property> + </item> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="2" column="0" colspan="2"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QGroupBox" name="groupBoxMouse"> + <property name="title"> + <string>Mouse</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QCheckBox" name="mouseNavigation"> + <property name="text"> + <string>Enable &mouse navigation</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="scrollWheelZooming"> + <property name="text"> + <string>Enable scroll &wheel zooming</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>insertSpaces</tabstop> + <tabstop>tabSize</tabstop> + <tabstop>autoIndent</tabstop> + <tabstop>smartBackspace</tabstop> + <tabstop>tabKeyBehavior</tabstop> + <tabstop>cleanWhitespace</tabstop> + <tabstop>inEntireDocument</tabstop> + <tabstop>cleanIndentation</tabstop> + <tabstop>addFinalNewLine</tabstop> + </tabstops> + <resources/> + <connections> + <connection> + <sender>cleanWhitespace</sender> + <signal>toggled(bool)</signal> + <receiver>inEntireDocument</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>87</x> + <y>323</y> + </hint> + <hint type="destinationlabel"> + <x>205</x> + <y>353</y> + </hint> + </hints> + </connection> + <connection> + <sender>cleanWhitespace</sender> + <signal>toggled(bool)</signal> + <receiver>cleanIndentation</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>60</x> + <y>323</y> + </hint> + <hint type="destinationlabel"> + <x>134</x> + <y>384</y> + </hint> + </hints> + </connection> + <connection> + <sender>insertSpaces</sender> + <signal>toggled(bool)</signal> + <receiver>autoInsertSpaces</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>105</x> + <y>49</y> + </hint> + <hint type="destinationlabel"> + <x>105</x> + <y>78</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/plugins/texteditor/extraencodingsettings.cpp b/src/plugins/texteditor/extraencodingsettings.cpp new file mode 100644 index 0000000000..505f1e36e6 --- /dev/null +++ b/src/plugins/texteditor/extraencodingsettings.cpp @@ -0,0 +1,78 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "extraencodingsettings.h" + +#include <utils/settingsutils.h> + +#include <QtCore/QLatin1String> +#include <QtCore/QSettings> + +// Keep this for compatibility reasons. +static const char * const kGroupPostfix = "EditorManager"; +static const char * const kUtf8BomBehaviorKey = "Utf8BomBehavior"; + +using namespace TextEditor; + +ExtraEncodingSettings::ExtraEncodingSettings() : m_utf8BomSetting(OnlyKeep) +{} + +ExtraEncodingSettings::~ExtraEncodingSettings() +{} + +void ExtraEncodingSettings::toSettings(const QString &category, QSettings *s) const +{ + Q_UNUSED(category) + + Utils::toSettings(QLatin1String(kGroupPostfix), QString(), s, this); +} + +void ExtraEncodingSettings::fromSettings(const QString &category, const QSettings *s) +{ + Q_UNUSED(category) + + *this = ExtraEncodingSettings(); + Utils::fromSettings(QLatin1String(kGroupPostfix), QString(), s, this); +} + +void ExtraEncodingSettings::toMap(const QString &prefix, QVariantMap *map) const +{ + map->insert(prefix + QLatin1String(kUtf8BomBehaviorKey), m_utf8BomSetting); +} + +void ExtraEncodingSettings::fromMap(const QString &prefix, const QVariantMap &map) +{ + m_utf8BomSetting = (Utf8BomSetting) + map.value(prefix + QLatin1String(kUtf8BomBehaviorKey), m_utf8BomSetting).toInt(); +} + +bool ExtraEncodingSettings::equals(const ExtraEncodingSettings &s) const +{ + return m_utf8BomSetting == s.m_utf8BomSetting; +} diff --git a/src/plugins/texteditor/extraencodingsettings.h b/src/plugins/texteditor/extraencodingsettings.h new file mode 100644 index 0000000000..57e5bffb99 --- /dev/null +++ b/src/plugins/texteditor/extraencodingsettings.h @@ -0,0 +1,73 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef ENCODINGSETTINGS_H +#define ENCODINGSETTINGS_H + +#include "texteditor_global.h" + +#include <QtCore/QVariant> + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace TextEditor { + +class TEXTEDITOR_EXPORT ExtraEncodingSettings +{ +public: + ExtraEncodingSettings(); + ~ExtraEncodingSettings(); + + void toSettings(const QString &category, QSettings *s) const; + void fromSettings(const QString &category, const QSettings *s); + + void toMap(const QString &prefix, QVariantMap *map) const; + void fromMap(const QString &prefix, const QVariantMap &map); + + bool equals(const ExtraEncodingSettings &s) const; + + enum Utf8BomSetting { + AlwaysAdd = 0, + OnlyKeep = 1, + AlwaysDelete = 2 + }; + Utf8BomSetting m_utf8BomSetting; +}; + +inline bool operator==(const ExtraEncodingSettings &a, const ExtraEncodingSettings &b) +{ return a.equals(b); } + +inline bool operator!=(const ExtraEncodingSettings &a, const ExtraEncodingSettings &b) +{ return !a.equals(b); } + +} // TextEditor + +#endif // ENCODINGSETTINGS_H diff --git a/src/plugins/texteditor/findincurrentfile.cpp b/src/plugins/texteditor/findincurrentfile.cpp index 59f0c3430c..5e4d5937a0 100644 --- a/src/plugins/texteditor/findincurrentfile.cpp +++ b/src/plugins/texteditor/findincurrentfile.cpp @@ -75,7 +75,7 @@ Utils::FileIterator *FindInCurrentFile::files() const QMap<QString, QTextCodec *> openEditorEncodings = ITextEditor::openedTextEditorsEncodings(); QTextCodec *codec = openEditorEncodings.value(fileName); if (!codec) - codec = Core::EditorManager::instance()->defaultTextEncoding(); + codec = Core::EditorManager::instance()->defaultTextCodec(); return new Utils::FileIterator(QStringList() << fileName, QList<QTextCodec *>() << codec); } diff --git a/src/plugins/texteditor/findinfiles.cpp b/src/plugins/texteditor/findinfiles.cpp index 7eac2697f4..6f275243de 100644 --- a/src/plugins/texteditor/findinfiles.cpp +++ b/src/plugins/texteditor/findinfiles.cpp @@ -73,7 +73,7 @@ Utils::FileIterator *FindInFiles::files() const { return new Utils::SubDirFileIterator(QStringList() << m_directory->currentText(), fileNameFilters(), - Core::EditorManager::instance()->defaultTextEncoding()); + Core::EditorManager::instance()->defaultTextCodec()); } QWidget *FindInFiles::createConfigWidget() diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 66900174c4..2d2c420f47 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -120,7 +120,7 @@ bool RefactoringChanges::createFile(const QString &fileName, const QString &cont if (reindent) { cursor.select(QTextCursor::Document); - indentSelection(cursor); + indentSelection(cursor, fileName, editor); } cursor.endEditBlock(); @@ -222,7 +222,7 @@ RefactoringFile::~RefactoringFile() // apply changes and reindent m_changes.apply(&c); foreach (const QTextCursor &selection, indentSelections) { - m_refactoringChanges->indentSelection(selection); + m_refactoringChanges->indentSelection(selection, m_fileName, m_editor); } c.endEditBlock(); diff --git a/src/plugins/texteditor/refactoringchanges.h b/src/plugins/texteditor/refactoringchanges.h index 87e8a355dc..2a53c91dbf 100644 --- a/src/plugins/texteditor/refactoringchanges.h +++ b/src/plugins/texteditor/refactoringchanges.h @@ -122,7 +122,9 @@ private: bool openIfClosed = false); static QList<QTextCursor> rangesToSelections(QTextDocument *document, const QList<Range> &ranges); - virtual void indentSelection(const QTextCursor &selection) const = 0; + virtual void indentSelection(const QTextCursor &selection, + const QString &fileName, + const BaseTextEditor *textEditor) const = 0; virtual void fileChanged(const QString &fileName) = 0; friend class RefactoringFile; diff --git a/src/plugins/texteditor/storagesettings.cpp b/src/plugins/texteditor/storagesettings.cpp index 841ab8bf64..0af4675f82 100644 --- a/src/plugins/texteditor/storagesettings.cpp +++ b/src/plugins/texteditor/storagesettings.cpp @@ -33,6 +33,8 @@ #include "storagesettings.h" +#include <utils/settingsutils.h> + #include <QtCore/QSettings> #include <QtCore/QString> @@ -54,27 +56,33 @@ StorageSettings::StorageSettings() void StorageSettings::toSettings(const QString &category, QSettings *s) const { - QString group = QLatin1String(groupPostfix); - if (!category.isEmpty()) - group.insert(0, category); - s->beginGroup(group); - s->setValue(QLatin1String(cleanWhitespaceKey), m_cleanWhitespace); - s->setValue(QLatin1String(inEntireDocumentKey), m_inEntireDocument); - s->setValue(QLatin1String(addFinalNewLineKey), m_addFinalNewLine); - s->setValue(QLatin1String(cleanIndentationKey), m_cleanIndentation); - s->endGroup(); + Utils::toSettings(QLatin1String(groupPostfix), category, s, this); } void StorageSettings::fromSettings(const QString &category, const QSettings *s) { - QString group = QLatin1String(groupPostfix); - if (!category.isEmpty()) - group.insert(0, category); - group += QLatin1Char('/'); - m_cleanWhitespace = s->value(group + QLatin1String(cleanWhitespaceKey), m_cleanWhitespace).toBool(); - m_inEntireDocument = s->value(group + QLatin1String(inEntireDocumentKey), m_inEntireDocument).toBool(); - m_addFinalNewLine = s->value(group + QLatin1String(addFinalNewLineKey), m_addFinalNewLine).toBool(); - m_cleanIndentation = s->value(group + QLatin1String(cleanIndentationKey), m_cleanIndentation).toBool(); + *this = StorageSettings(); + Utils::fromSettings(QLatin1String(groupPostfix), category, s, this); +} + +void StorageSettings::toMap(const QString &prefix, QVariantMap *map) const +{ + map->insert(prefix + QLatin1String(cleanWhitespaceKey), m_cleanWhitespace); + map->insert(prefix + QLatin1String(inEntireDocumentKey), m_inEntireDocument); + map->insert(prefix + QLatin1String(addFinalNewLineKey), m_addFinalNewLine); + map->insert(prefix + QLatin1String(cleanIndentationKey), m_cleanIndentation); +} + +void StorageSettings::fromMap(const QString &prefix, const QVariantMap &map) +{ + m_cleanWhitespace = + map.value(prefix + QLatin1String(cleanWhitespaceKey), m_cleanWhitespace).toBool(); + m_inEntireDocument = + map.value(prefix + QLatin1String(inEntireDocumentKey), m_inEntireDocument).toBool(); + m_addFinalNewLine = + map.value(prefix + QLatin1String(addFinalNewLineKey), m_addFinalNewLine).toBool(); + m_cleanIndentation = + map.value(prefix + QLatin1String(cleanIndentationKey), m_cleanIndentation).toBool(); } bool StorageSettings::equals(const StorageSettings &ts) const diff --git a/src/plugins/texteditor/storagesettings.h b/src/plugins/texteditor/storagesettings.h index def8df30b6..b5bf472ff9 100644 --- a/src/plugins/texteditor/storagesettings.h +++ b/src/plugins/texteditor/storagesettings.h @@ -36,6 +36,8 @@ #include "texteditor_global.h" +#include <QtCore/QVariant> + QT_BEGIN_NAMESPACE class QSettings; QT_END_NAMESPACE @@ -50,6 +52,9 @@ public: void toSettings(const QString &category, QSettings *s) const; void fromSettings(const QString &category, const QSettings *s); + void toMap(const QString &prefix, QVariantMap *map) const; + void fromMap(const QString &prefix, const QVariantMap &map); + bool equals(const StorageSettings &ts) const; bool m_cleanWhitespace; diff --git a/src/plugins/texteditor/tabsettings.cpp b/src/plugins/texteditor/tabsettings.cpp index 008c715fc0..716a747cbf 100644 --- a/src/plugins/texteditor/tabsettings.cpp +++ b/src/plugins/texteditor/tabsettings.cpp @@ -33,6 +33,8 @@ #include "tabsettings.h" +#include <utils/settingsutils.h> + #include <QtCore/QDebug> #include <QtCore/QSettings> #include <QtCore/QString> @@ -69,46 +71,48 @@ TabSettings::TabSettings() : void TabSettings::toSettings(const QString &category, QSettings *s) const { - QString group = QLatin1String(groupPostfix); - if (!category.isEmpty()) - group.insert(0, category); - s->beginGroup(group); - s->setValue(QLatin1String(spacesForTabsKey), m_spacesForTabs); - s->setValue(QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs); - s->setValue(QLatin1String(autoIndentKey), m_autoIndent); - s->setValue(QLatin1String(smartBackspaceKey), m_smartBackspace); - s->setValue(QLatin1String(tabSizeKey), m_tabSize); - s->setValue(QLatin1String(indentSizeKey), m_indentSize); - s->setValue(QLatin1String(indentBracesKey), m_indentBraces); - s->setValue(QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks); - s->setValue(QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior); - s->setValue(QLatin1String(paddingModeKey), m_continuationAlignBehavior); - s->endGroup(); + Utils::toSettings(QLatin1String(groupPostfix), category, s, this); } void TabSettings::fromSettings(const QString &category, const QSettings *s) { - QString group = QLatin1String(groupPostfix); - if (!category.isEmpty()) - group.insert(0, category); - group += QLatin1Char('/'); - *this = TabSettings(); // Assign defaults + Utils::fromSettings(QLatin1String(groupPostfix), category, s, this); +} - m_spacesForTabs = s->value(group + QLatin1String(spacesForTabsKey), m_spacesForTabs).toBool(); - m_autoSpacesForTabs = s->value(group + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs).toBool(); - m_autoIndent = s->value(group + QLatin1String(autoIndentKey), m_autoIndent).toBool(); - m_smartBackspace = s->value(group + QLatin1String(smartBackspaceKey), m_smartBackspace).toBool(); - m_tabSize = s->value(group + QLatin1String(tabSizeKey), m_tabSize).toInt(); - m_indentSize = s->value(group + QLatin1String(indentSizeKey), m_indentSize).toInt(); - m_indentBraces = s->value(group + QLatin1String(indentBracesKey), m_indentBraces).toBool(); - m_doubleIndentBlocks - = s->value(group + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks).toBool(); - - m_tabKeyBehavior = (TabKeyBehavior)s->value(group + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt(); - m_continuationAlignBehavior = (ContinuationAlignBehavior)s->value(group + QLatin1String(paddingModeKey), m_continuationAlignBehavior).toInt(); +void TabSettings::toMap(const QString &prefix, QVariantMap *map) const +{ + map->insert(prefix + QLatin1String(spacesForTabsKey), m_spacesForTabs); + map->insert(prefix + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs); + map->insert(prefix + QLatin1String(autoIndentKey), m_autoIndent); + map->insert(prefix + QLatin1String(smartBackspaceKey), m_smartBackspace); + map->insert(prefix + QLatin1String(tabSizeKey), m_tabSize); + map->insert(prefix + QLatin1String(indentSizeKey), m_indentSize); + map->insert(prefix + QLatin1String(indentBracesKey), m_indentBraces); + map->insert(prefix + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks); + map->insert(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior); + map->insert(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior); } +void TabSettings::fromMap(const QString &prefix, const QVariantMap &map) +{ + m_spacesForTabs = + map.value(prefix + QLatin1String(spacesForTabsKey), m_spacesForTabs).toBool(); + m_autoSpacesForTabs = + map.value(prefix + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs).toBool(); + m_autoIndent = map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool(); + m_smartBackspace = + map.value(prefix + QLatin1String(smartBackspaceKey), m_smartBackspace).toBool(); + m_tabSize = map.value(prefix + QLatin1String(tabSizeKey), m_tabSize).toInt(); + m_indentSize = map.value(prefix + QLatin1String(indentSizeKey), m_indentSize).toInt(); + m_indentBraces = map.value(prefix + QLatin1String(indentBracesKey), m_indentBraces).toBool(); + m_doubleIndentBlocks = + map.value(prefix + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks).toBool(); + m_tabKeyBehavior = (TabKeyBehavior) + map.value(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt(); + m_continuationAlignBehavior = (ContinuationAlignBehavior) + map.value(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior).toInt(); +} bool TabSettings::cursorIsAtBeginningOfLine(const QTextCursor &cursor) const { diff --git a/src/plugins/texteditor/tabsettings.h b/src/plugins/texteditor/tabsettings.h index 664a90a2fe..3d8a92d8e8 100644 --- a/src/plugins/texteditor/tabsettings.h +++ b/src/plugins/texteditor/tabsettings.h @@ -36,6 +36,7 @@ #include "texteditor_global.h" +#include <QtCore/QVariant> #include <QtGui/QTextBlock> QT_BEGIN_NAMESPACE @@ -68,6 +69,8 @@ public: void toSettings(const QString &category, QSettings *s) const; void fromSettings(const QString &category, const QSettings *s); + void toMap(const QString &prefix, QVariantMap *map) const; + void fromMap(const QString &prefix, const QVariantMap &map); int lineIndentPosition(const QString &text) const; int firstNonSpace(const QString &text) const; diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index 70b93fc195..d94850da97 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -80,7 +80,9 @@ SOURCES += texteditorplugin.cpp \ snippets/snippetssettings.cpp \ snippets/isnippetprovider.cpp \ snippets/snippetcollector.cpp \ - snippets/plaintextsnippetprovider.cpp + snippets/plaintextsnippetprovider.cpp \ + behaviorsettingswidget.cpp \ + extraencodingsettings.cpp HEADERS += texteditorplugin.h \ textfilewizard.h \ @@ -163,14 +165,18 @@ HEADERS += texteditorplugin.h \ snippets/snippetssettings.h \ snippets/isnippetprovider.h \ snippets/snippetcollector.h \ - snippets/plaintextsnippetprovider.h + snippets/plaintextsnippetprovider.h \ + behaviorsettingswidget.h \ + extraencodingsettings.h -FORMS += behaviorsettingspage.ui \ +FORMS += \ displaysettingspage.ui \ fontsettingspage.ui \ colorschemeedit.ui \ generichighlighter/highlightersettingspage.ui \ generichighlighter/managedefinitionsdialog.ui \ - snippets/snippetssettingspage.ui + snippets/snippetssettingspage.ui \ + behaviorsettingswidget.ui \ + behaviorsettingspage.ui RESOURCES += texteditor.qrc OTHER_FILES += TextEditor.mimetypes.xml diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index a7365d5eee..2ceb12bf3a 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -43,6 +43,7 @@ #include "fontsettingspage.h" #include "storagesettings.h" #include "tabsettings.h" +#include "extraencodingsettings.h" #include "texteditorplugin.h" #include "highlightersettingspage.h" #include "snippetssettingspage.h" @@ -238,6 +239,8 @@ void TextEditorSettings::initializeEditor(BaseTextEditor *editor) editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings))); connect(this, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)), editor, SLOT(setCompletionSettings(TextEditor::CompletionSettings))); + connect(this, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)), + editor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings))); connect(editor, SIGNAL(requestFontZoom(int)), this, SLOT(fontZoomRequested(int))); @@ -251,6 +254,7 @@ void TextEditorSettings::initializeEditor(BaseTextEditor *editor) editor->setBehaviorSettings(behaviorSettings()); editor->setDisplaySettings(displaySettings()); editor->setCompletionSettings(completionSettings()); + editor->setExtraEncodingSettings(extraEncodingSettings()); } @@ -289,6 +293,11 @@ const HighlighterSettings &TextEditorSettings::highlighterSettings() const return m_d->m_highlighterSettingsPage->highlighterSettings(); } +const ExtraEncodingSettings &TextEditorSettings::extraEncodingSettings() const +{ + return m_d->m_behaviorSettingsPage->extraEncodingSettings(); +} + void TextEditorSettings::setCompletionSettings(const TextEditor::CompletionSettings &settings) { if (m_d->m_completionSettings == settings) diff --git a/src/plugins/texteditor/texteditorsettings.h b/src/plugins/texteditor/texteditorsettings.h index ee73589f1d..c48ddddc07 100644 --- a/src/plugins/texteditor/texteditorsettings.h +++ b/src/plugins/texteditor/texteditorsettings.h @@ -48,6 +48,7 @@ class BehaviorSettings; class DisplaySettings; class CompletionSettings; class HighlighterSettings; +class ExtraEncodingSettings; namespace Internal { class TextEditorSettingsPrivate; @@ -77,6 +78,7 @@ public: const DisplaySettings &displaySettings() const; const CompletionSettings &completionSettings() const; const HighlighterSettings &highlighterSettings() const; + const ExtraEncodingSettings &extraEncodingSettings() const; void setCompletionSettings(const TextEditor::CompletionSettings &); @@ -87,6 +89,7 @@ signals: void behaviorSettingsChanged(const TextEditor::BehaviorSettings &); void displaySettingsChanged(const TextEditor::DisplaySettings &); void completionSettingsChanged(const TextEditor::CompletionSettings &); + void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &); private: Internal::TextEditorSettingsPrivate *m_d; diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 2f8fa77cbb..371c71c8e0 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -722,7 +722,7 @@ static QTextCodec *findProjectCodec(const QString &dir) for (ProjectList::const_iterator it = projects.constBegin(); it != pcend; ++it) if (const Core::IFile *file = (*it)->file()) if (file->fileName().startsWith(dir)) { - QTextCodec *codec = (*it)->editorConfiguration()->defaultTextCodec(); + QTextCodec *codec = (*it)->editorConfiguration()->textCodec(); if (VCSBase::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << dir << (*it)->displayName() << codec->name(); return codec; |
