diff --git a/src/libs/utils/settingsutils.h b/src/libs/utils/settingsutils.h new file mode 100644 index 00000000000..4c01a0d9603 --- /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 +#include +#include +#include + +namespace Utils { + +template +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 +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 f6711bee361..00041b78186 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 9428209a9aa..897d25b7c23 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 2185a1e4538..0b53bba595b 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 720110d8456..e208ce88efa 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 638a3f3cbbf..e7e8b2c2293 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -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 ee2ef4ae970..d59cd9ef5ce 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 e76448c87ca..c819b723dbc 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(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 422f6085239..f2e74cffda5 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 750f447797e..0cc7cc8138f 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include #include -using namespace ProjectExplorer; +static const QLatin1String kPrefix("EditorConfiguration."); +static const QLatin1String kUseGlobal("EditorConfiguration.UseGlobal"); +static const QLatin1String kCodec("EditorConfiguration.Codec"); -namespace { -const char * const CODEC("EditorConfiguration.Codec"); -} +using namespace TextEditor; -EditorConfiguration::EditorConfiguration() - : m_defaultTextCodec(0) +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; +}; + +EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate) { } -QTextCodec *EditorConfiguration::defaultTextCodec() const +EditorConfiguration::~EditorConfiguration() { - return m_defaultTextCodec; } -void EditorConfiguration::setDefaultTextCodec(QTextCodec *codec) +bool EditorConfiguration::useGlobalSettings() const { - m_defaultTextCodec = codec; + return m_d->m_useGlobal; +} + +void EditorConfiguration::cloneGlobalSettings() +{ + 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(textEditor->widget())) + switchSettings(baseTextEditor); + } +} + +void EditorConfiguration::setUseGlobalSettings(bool use) +{ + m_d->m_useGlobal = use; + const SessionManager *session = ProjectExplorerPlugin::instance()->session(); + QList opened = Core::EditorManager::instance()->openedEditors(); + foreach (Core::IEditor *editor, opened) { + if (BaseTextEditor *baseTextEditor = qobject_cast(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 +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 98e70a29636..d6e5bdbce8d 100644 --- a/src/plugins/projectexplorer/editorconfiguration.h +++ b/src/plugins/projectexplorer/editorconfiguration.h @@ -36,30 +36,99 @@ #include "projectexplorer_export.h" +#include #include +#include -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(); - // defaultTextCodec can be 0, in that case the editor settings default encoding shall be used - QTextCodec *defaultTextCodec() const; - void setDefaultTextCodec(QTextCodec *codec); + bool useGlobalSettings() const; + void cloneGlobalSettings(); + + // The default codec is returned in the case the project doesn't override it. + QTextCodec *textCodec() const; + + 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 + void switchSettings_helper(const NewSenderT *newSender, + const OldSenderT *oldSender, + TextEditor::BaseTextEditor *baseTextEditor) const; + + void emitTabSettingsChanged(); + void emitStorageSettingsChanged(); + void emitBehaviorSettingsChanged(); + void emitExtraEncodingSettingsChanged(); + + QScopedPointer 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 f98bd8f7b0b..6d8a4194e46 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp @@ -36,7 +36,6 @@ #include "project.h" #include -#include 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(); + const EditorConfiguration *config = m_project->editorConfiguration(); + settingsToUi(config); - QList mibs = QTextCodec::availableMibs(); - qSort(mibs); - QList 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++; - } + setGlobalSettingsEnabled(config->useGlobalSettings()); - connect(m_ui.encodingComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentEncodingChanged(int))); + 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 6b9b586db3a..3742811e2e7 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 m_codecs; }; } // namespace Internal diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.ui b/src/plugins/projectexplorer/editorsettingspropertiespage.ui index da7c45c2627..ce010787849 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.ui +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.ui @@ -6,29 +6,64 @@ 0 0 - 275 - 44 + 368 + 98 - - - 0 - - - 0 - - - + + + - Default file encoding: + Use global settings - - + + + + + + + Qt::Horizontal + + + + 224 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 12 + + + + + + + + Restore Global Values + + + + + TextEditor::BehaviorSettingsWidget + QWidget +
texteditor/behaviorsettingswidget.h
+ 1 +
+
diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index f8d8390d4b8..993142fdb49 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(editor)) - if (Project *project = projectForFile(fileName)) { - if (QTextCodec *codec = project->editorConfiguration()->defaultTextCodec()) - textEditor->setTextCodec(codec, TextEditor::ITextEditor::TextCodecFromProjectSetting); + if (TextEditor::ITextEditor *textEditor = qobject_cast(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 d30836bb974..53eee3cae13 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 3a5be7597b4..0b8704ab637 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp @@ -38,6 +38,7 @@ #include #include #include +#include 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 5167a3a950e..f8650ce869d 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 e51a74939b2..e5cddc71c13 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 b4da82fd8f6..0b2bb4b3db6 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 5fa4ac164b7..e74d890a9d0 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 a47d0f2b83e..37b43407d6f 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 874aa2b5680..348970d700f 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 385eaa9478a..45b1eb5004f 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 22b6c53ad81..b3d6a96d49f 100644 --- a/src/plugins/texteditor/behaviorsettings.cpp +++ b/src/plugins/texteditor/behaviorsettings.cpp @@ -33,6 +33,8 @@ #include "behaviorsettings.h" +#include + #include #include @@ -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 d10a7c1f335..0f45e0ac0b8 100644 --- a/src/plugins/texteditor/behaviorsettings.h +++ b/src/plugins/texteditor/behaviorsettings.h @@ -36,6 +36,8 @@ #include "texteditor_global.h" +#include + 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 059c1ed6991..8e45cd88474 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 @@ -44,7 +45,6 @@ #include #include -#include 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 mibs = QTextCodec::availableMibs(); - qSort(mibs); - QList 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); - } - - 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,12 +150,39 @@ 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); - Core::EditorManager::instance()->setUtf8BomSetting( - Core::IFile::Utf8BomSetting(m_d->m_page->utf8BomBox->currentIndex())); + emit extraEncodingSettingsChanged(newExtraEncodingSettings); + } + + if (s) { + s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING), + m_d->m_page->behaviorWidget->assignedCodec()->name()); + } +} + +void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings, + StorageSettings *storageSettings, + BehaviorSettings *behaviorSettings, + ExtraEncodingSettings *extraEncodingSettings) const +{ + 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::settingsToUI() +{ + 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::finish() @@ -211,57 +193,6 @@ void BehaviorSettingsPage::finish() m_d->m_page = 0; } -void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings, - StorageSettings &storageSettings, - BehaviorSettings &behaviorSettings) const -{ - 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(); -} - -void BehaviorSettingsPage::settingsToUI() -{ - 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); -} - const TabSettings &BehaviorSettingsPage::tabSettings() const { return m_d->m_tabSettings; @@ -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 3df5456b5ee..4d118b065ce 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 m_codecs; diff --git a/src/plugins/texteditor/behaviorsettingspage.ui b/src/plugins/texteditor/behaviorsettingspage.ui index e14f95dfe78..b5b3316bde3 100644 --- a/src/plugins/texteditor/behaviorsettingspage.ui +++ b/src/plugins/texteditor/behaviorsettingspage.ui @@ -1,429 +1,23 @@ - TextEditor::BehaviorSettingsPage - + BehaviorSettingsPage + 0 0 - 662 - 538 + 432 + 50 - - - - - Tabs and Indentation - - - - - - Insert &spaces instead of tabs - - - - - - - - 0 - 0 - - - - Ta&b size: - - - tabSize - - - - - - - - 0 - 0 - - - - 1 - - - 20 - - - - - - - Qt::Horizontal - - - - 0 - 22 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 30 - 20 - - - - - - - - false - - - Automatically determine based on the nearest indented line (previous line preferred over next line) - - - Based on the surrounding lines - - - - - - - - - - 0 - 0 - - - - &Indent size: - - - indentSize - - - - - - - - 0 - 0 - - - - 1 - - - 20 - - - - - - - Enable automatic &indentation - - - - - - - Backspace will go back one indentation level instead of one space. - - - &Backspace follows indentation - - - - - - - - - Block indentation style: - - - - - - - <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> - - - - Exclude Braces - - - - - Include Braces - - - - - GNU Style - - - - - - - - Tab key performs auto-indent: - - - - - - - - Never - - - - - Always - - - - - In Leading White Space - - - - - - - - Align continuation lines: - - - - - - - <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> - - - - Not At All - - - - - With Spaces - - - - - With Regular Indent - - - - - - - - + + Form + + + + - - - Cleanup actions which are automatically performed right before the file is saved to disk. - - - Cleanups Upon Saving - - - - - - Removes trailing whitespace upon saving. - - - &Clean whitespace - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 30 - 20 - - - - - - - - false - - - Clean whitespace in entire document instead of only for changed parts. - - - In entire &document - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 30 - 20 - - - - - - - - false - - - Correct leading whitespace according to tab settings. - - - Clean indentation - - - - - - - - - &Ensure newline at end of file - - - - - - - - - - Mouse - - - - - - Enable &mouse navigation - - - - - - - Enable scroll &wheel zooming - - - - - - - Qt::Vertical @@ -431,187 +25,21 @@ Influences the indentation of continuation lines. 20 - 8 + 13 - - - - File Encodings - - - - - - Default encoding: - - - - - - - - - - 0 - 0 - - - - QComboBox::AdjustToMinimumContentsLengthWithIcon - - - 20 - - - - - - - Qt::Horizontal - - - - 285 - 20 - - - - - - - - - - UTF-8 BOM: - - - - - - - - - <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> - - - - Add If Encoding Is UTF-8 - - - - - Keep If Already Present - - - - - Always Delete - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - insertSpaces - tabSize - autoIndent - smartBackspace - tabKeyBehavior - cleanWhitespace - inEntireDocument - cleanIndentation - addFinalNewLine - + + + TextEditor::BehaviorSettingsWidget + QWidget +
texteditor/behaviorsettingswidget.h
+ 1 +
+
- - - cleanWhitespace - toggled(bool) - inEntireDocument - setEnabled(bool) - - - 87 - 323 - - - 205 - 353 - - - - - cleanWhitespace - toggled(bool) - cleanIndentation - setEnabled(bool) - - - 60 - 323 - - - 134 - 384 - - - - - insertSpaces - toggled(bool) - autoInsertSpaces - setEnabled(bool) - - - 105 - 49 - - - 105 - 78 - - - - +
diff --git a/src/plugins/texteditor/behaviorsettingswidget.cpp b/src/plugins/texteditor/behaviorsettingswidget.cpp new file mode 100644 index 00000000000..de9c8e75502 --- /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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace TextEditor { + +struct BehaviorSettingsWidgetPrivate +{ + Ui::BehaviorSettingsWidget m_ui; + QList m_codecs; +}; + +BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent) + : QWidget(parent) + , m_d(new BehaviorSettingsWidgetPrivate) +{ + m_d->m_ui.setupUi(this); + + QList mibs = QTextCodec::availableMibs(); + qSort(mibs); + QList::iterator firstNonNegative = + std::find_if(mibs.begin(), mibs.end(), std::bind2nd(std::greater_equal(), 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 00000000000..53776768328 --- /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 + +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 00000000000..3c1ee24b3a2 --- /dev/null +++ b/src/plugins/texteditor/behaviorsettingswidget.ui @@ -0,0 +1,607 @@ + + + BehaviorSettingsWidget + + + + 0 + 0 + 762 + 463 + + + + + 0 + + + + + Tabs and Indentation + + + + + + Insert &spaces instead of tabs + + + + + + + + 0 + 0 + + + + Ta&b size: + + + tabSize + + + + + + + + 0 + 0 + + + + 1 + + + 20 + + + + + + + Qt::Horizontal + + + + 0 + 22 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 30 + 20 + + + + + + + + false + + + Automatically determine based on the nearest indented line (previous line preferred over next line) + + + Based on the surrounding lines + + + + + + + + + + 0 + 0 + + + + &Indent size: + + + indentSize + + + + + + + + 0 + 0 + + + + 1 + + + 20 + + + + + + + Enable automatic &indentation + + + + + + + Backspace will go back one indentation level instead of one space. + + + &Backspace follows indentation + + + + + + + + + Block indentation style: + + + + + + + <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> + + + + Exclude Braces + + + + + Include Braces + + + + + GNU Style + + + + + + + + Tab key performs auto-indent: + + + + + + + + Never + + + + + Always + + + + + In Leading White Space + + + + + + + + Align continuation lines: + + + + + + + <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> + + + + Not At All + + + + + With Spaces + + + + + With Regular Indent + + + + + + + + + + + + + Cleanup actions which are automatically performed right before the file is saved to disk. + + + Cleanups Upon Saving + + + + + + Removes trailing whitespace upon saving. + + + &Clean whitespace + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 30 + 20 + + + + + + + + false + + + Clean whitespace in entire document instead of only for changed parts. + + + In entire &document + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 30 + 20 + + + + + + + + false + + + Correct leading whitespace according to tab settings. + + + Clean indentation + + + + + + + + + &Ensure newline at end of file + + + + + + + + + + File Encodings + + + + + + Default encoding: + + + + + + + + + + 0 + 0 + + + + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 20 + + + + + + + Qt::Horizontal + + + + 285 + 20 + + + + + + + + + + UTF-8 BOM: + + + + + + + + + <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> + + + + Add If Encoding Is UTF-8 + + + + + Keep If Already Present + + + + + Always Delete + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Mouse + + + + + + Enable &mouse navigation + + + + + + + Enable scroll &wheel zooming + + + + + + + + + + insertSpaces + tabSize + autoIndent + smartBackspace + tabKeyBehavior + cleanWhitespace + inEntireDocument + cleanIndentation + addFinalNewLine + + + + + cleanWhitespace + toggled(bool) + inEntireDocument + setEnabled(bool) + + + 87 + 323 + + + 205 + 353 + + + + + cleanWhitespace + toggled(bool) + cleanIndentation + setEnabled(bool) + + + 60 + 323 + + + 134 + 384 + + + + + insertSpaces + toggled(bool) + autoInsertSpaces + setEnabled(bool) + + + 105 + 49 + + + 105 + 78 + + + + + diff --git a/src/plugins/texteditor/extraencodingsettings.cpp b/src/plugins/texteditor/extraencodingsettings.cpp new file mode 100644 index 00000000000..505f1e36e69 --- /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 + +#include +#include + +// 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 00000000000..57e5bffb991 --- /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 + +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 59f0c3430cb..5e4d5937a07 100644 --- a/src/plugins/texteditor/findincurrentfile.cpp +++ b/src/plugins/texteditor/findincurrentfile.cpp @@ -75,7 +75,7 @@ Utils::FileIterator *FindInCurrentFile::files() const QMap 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() << codec); } diff --git a/src/plugins/texteditor/findinfiles.cpp b/src/plugins/texteditor/findinfiles.cpp index 7eac2697f40..6f275243de3 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 66900174c46..2d2c420f471 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 87e8a355dce..2a53c91dbfa 100644 --- a/src/plugins/texteditor/refactoringchanges.h +++ b/src/plugins/texteditor/refactoringchanges.h @@ -122,7 +122,9 @@ private: bool openIfClosed = false); static QList rangesToSelections(QTextDocument *document, const QList &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 841ab8bf64b..0af4675f829 100644 --- a/src/plugins/texteditor/storagesettings.cpp +++ b/src/plugins/texteditor/storagesettings.cpp @@ -33,6 +33,8 @@ #include "storagesettings.h" +#include + #include #include @@ -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 def8df30b61..b5bf472ff97 100644 --- a/src/plugins/texteditor/storagesettings.h +++ b/src/plugins/texteditor/storagesettings.h @@ -36,6 +36,8 @@ #include "texteditor_global.h" +#include + 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 008c715fc03..716a747cbfe 100644 --- a/src/plugins/texteditor/tabsettings.cpp +++ b/src/plugins/texteditor/tabsettings.cpp @@ -33,6 +33,8 @@ #include "tabsettings.h" +#include + #include #include #include @@ -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 - - 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(); + Utils::fromSettings(QLatin1String(groupPostfix), category, s, this); } +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 664a90a2fea..3d8a92d8e80 100644 --- a/src/plugins/texteditor/tabsettings.h +++ b/src/plugins/texteditor/tabsettings.h @@ -36,6 +36,7 @@ #include "texteditor_global.h" +#include #include 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 70b93fc195a..d94850da974 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 a7365d5eee9..2ceb12bf3a7 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 ee73589f1dc..c48ddddc075 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 2f8fa77cbba..371c71c8e0c 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;