2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "editorconfiguration.h"
|
2011-02-01 14:13:54 +01:00
|
|
|
#include "session.h"
|
|
|
|
|
#include "projectexplorer.h"
|
|
|
|
|
#include "project.h"
|
2010-11-02 16:14:00 +01:00
|
|
|
|
2014-08-12 15:19:25 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <coreplugin/id.h>
|
2013-09-27 12:46:08 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2014-08-12 15:19:25 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <texteditor/textdocument.h>
|
2011-02-01 14:13:54 +01:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/simplecodestylepreferences.h>
|
|
|
|
|
#include <texteditor/typingsettings.h>
|
2011-02-01 14:13:54 +01:00
|
|
|
#include <texteditor/storagesettings.h>
|
|
|
|
|
#include <texteditor/behaviorsettings.h>
|
|
|
|
|
#include <texteditor/extraencodingsettings.h>
|
2013-03-26 15:56:33 +01:00
|
|
|
#include <texteditor/tabsettings.h>
|
2014-01-09 14:44:25 +01:00
|
|
|
#include <texteditor/marginsettings.h>
|
2011-02-03 15:48:14 +01:00
|
|
|
#include <texteditor/icodestylepreferencesfactory.h>
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLatin1String>
|
|
|
|
|
#include <QByteArray>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
static const QLatin1String kPrefix("EditorConfiguration.");
|
|
|
|
|
static const QLatin1String kUseGlobal("EditorConfiguration.UseGlobal");
|
|
|
|
|
static const QLatin1String kCodec("EditorConfiguration.Codec");
|
2011-02-03 15:48:14 +01:00
|
|
|
static const QLatin1String kCodeStylePrefix("EditorConfiguration.CodeStyle.");
|
|
|
|
|
static const QLatin1String kCodeStyleCount("EditorConfiguration.CodeStyle.Count");
|
2011-02-01 14:13:54 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
struct EditorConfigurationPrivate
|
|
|
|
|
{
|
2016-04-13 15:52:14 +02:00
|
|
|
EditorConfigurationPrivate() :
|
|
|
|
|
m_typingSettings(TextEditorSettings::typingSettings()),
|
|
|
|
|
m_storageSettings(TextEditorSettings::storageSettings()),
|
|
|
|
|
m_behaviorSettings(TextEditorSettings::behaviorSettings()),
|
|
|
|
|
m_extraEncodingSettings(TextEditorSettings::extraEncodingSettings()),
|
|
|
|
|
m_textCodec(Core::EditorManager::defaultTextCodec())
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
ICodeStylePreferences *m_defaultCodeStyle = nullptr;
|
2011-08-16 10:45:23 +02:00
|
|
|
TypingSettings m_typingSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
StorageSettings m_storageSettings;
|
|
|
|
|
BehaviorSettings m_behaviorSettings;
|
2016-04-13 15:52:14 +02:00
|
|
|
bool m_useGlobal = true;
|
2011-02-01 14:13:54 +01:00
|
|
|
ExtraEncodingSettings m_extraEncodingSettings;
|
2014-01-09 14:44:25 +01:00
|
|
|
MarginSettings m_marginSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
QTextCodec *m_textCodec;
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
QMap<Core::Id, ICodeStylePreferences *> m_languageCodeStylePreferences;
|
2014-08-15 14:42:30 +02:00
|
|
|
QList<BaseTextEditor *> m_editors;
|
2011-02-01 14:13:54 +01:00
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
EditorConfiguration::EditorConfiguration() : d(new EditorConfigurationPrivate)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2013-09-19 17:59:27 +02:00
|
|
|
const QMap<Core::Id, ICodeStylePreferences *> languageCodeStylePreferences = TextEditorSettings::codeStyles();
|
2012-11-21 21:47:17 +02:00
|
|
|
QMapIterator<Core::Id, ICodeStylePreferences *> itCodeStyle(languageCodeStylePreferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
while (itCodeStyle.hasNext()) {
|
|
|
|
|
itCodeStyle.next();
|
2012-11-21 21:47:17 +02:00
|
|
|
Core::Id languageId = itCodeStyle.key();
|
2013-09-27 12:46:08 +02:00
|
|
|
// global prefs for language
|
2011-08-16 10:45:23 +02:00
|
|
|
ICodeStylePreferences *originalPreferences = itCodeStyle.value();
|
2013-09-19 17:59:27 +02:00
|
|
|
ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId);
|
2013-09-27 12:46:08 +02:00
|
|
|
// clone of global prefs for language - it will became project prefs for language
|
2011-08-16 10:45:23 +02:00
|
|
|
ICodeStylePreferences *preferences = factory->createCodeStyle();
|
2013-09-27 12:46:08 +02:00
|
|
|
// project prefs can point to the global language pool, which contains also the global language prefs
|
2013-09-19 17:59:27 +02:00
|
|
|
preferences->setDelegatingPool(TextEditorSettings::codeStylePool(languageId));
|
2013-09-20 10:35:16 +02:00
|
|
|
preferences->setId(languageId.name() + "Project");
|
2011-06-08 10:45:26 +02:00
|
|
|
preferences->setDisplayName(tr("Project %1", "Settings, %1 is a language (C++ or QML)").arg(factory->displayName()));
|
2013-09-27 12:46:08 +02:00
|
|
|
// project prefs by default point to global prefs (which in turn can delegate to anything else or not)
|
2011-08-16 10:45:23 +02:00
|
|
|
preferences->setCurrentDelegate(originalPreferences);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_languageCodeStylePreferences.insert(languageId, preferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
2011-08-16 10:45:23 +02:00
|
|
|
|
2013-09-27 12:46:08 +02:00
|
|
|
// clone of global prefs (not language specific), for project scope
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_defaultCodeStyle = new SimpleCodeStylePreferences(this);
|
2013-09-19 17:59:27 +02:00
|
|
|
d->m_defaultCodeStyle->setDelegatingPool(TextEditorSettings::codeStylePool());
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_defaultCodeStyle->setDisplayName(tr("Project", "Settings"));
|
2013-09-20 10:35:16 +02:00
|
|
|
d->m_defaultCodeStyle->setId("Project");
|
2013-09-27 12:46:08 +02:00
|
|
|
// if setCurrentDelegate is 0 values are read from *this prefs
|
2014-10-28 22:39:02 +02:00
|
|
|
d->m_defaultCodeStyle->setCurrentDelegate(TextEditorSettings::codeStyle());
|
2013-09-27 12:46:08 +02:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(SessionManager::instance(), &SessionManager::aboutToRemoveProject,
|
|
|
|
|
this, &EditorConfiguration::slotAboutToRemoveProject);
|
2010-01-14 16:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
EditorConfiguration::~EditorConfiguration()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-03-14 14:14:48 +01:00
|
|
|
qDeleteAll(d->m_languageCodeStylePreferences);
|
2012-06-28 12:16:48 +02:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
bool EditorConfiguration::useGlobalSettings() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_useGlobal;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void EditorConfiguration::cloneGlobalSettings()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-09-19 17:59:27 +02:00
|
|
|
d->m_defaultCodeStyle->setTabSettings(TextEditorSettings::codeStyle()->tabSettings());
|
|
|
|
|
setTypingSettings(TextEditorSettings::typingSettings());
|
|
|
|
|
setStorageSettings(TextEditorSettings::storageSettings());
|
|
|
|
|
setBehaviorSettings(TextEditorSettings::behaviorSettings());
|
|
|
|
|
setExtraEncodingSettings(TextEditorSettings::extraEncodingSettings());
|
2014-01-09 14:44:25 +01:00
|
|
|
setMarginSettings(TextEditorSettings::marginSettings());
|
2013-08-29 15:46:04 +02:00
|
|
|
d->m_textCodec = Core::EditorManager::defaultTextCodec();
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextCodec *EditorConfiguration::textCodec() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_textCodec;
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
const TypingSettings &EditorConfiguration::typingSettings() const
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
return d->m_typingSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StorageSettings &EditorConfiguration::storageSettings() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_storageSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BehaviorSettings &EditorConfiguration::behaviorSettings() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_behaviorSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ExtraEncodingSettings &EditorConfiguration::extraEncodingSettings() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_extraEncodingSettings;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-09 14:44:25 +01:00
|
|
|
const MarginSettings &EditorConfiguration::marginSettings() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_marginSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
ICodeStylePreferences *EditorConfiguration::codeStyle() const
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
return d->m_defaultCodeStyle;
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
ICodeStylePreferences *EditorConfiguration::codeStyle(Core::Id languageId) const
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
return d->m_languageCodeStylePreferences.value(languageId, codeStyle());
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
QMap<Core::Id, ICodeStylePreferences *> EditorConfiguration::codeStyles() const
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_languageCodeStylePreferences;
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-14 16:24:21 +01:00
|
|
|
QVariantMap EditorConfiguration::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
2011-09-16 13:10:06 +02:00
|
|
|
map.insert(kUseGlobal, d->m_useGlobal);
|
|
|
|
|
map.insert(kCodec, d->m_textCodec->name());
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
map.insert(kCodeStyleCount, d->m_languageCodeStylePreferences.count());
|
2012-11-21 21:47:17 +02:00
|
|
|
QMapIterator<Core::Id, ICodeStylePreferences *> itCodeStyle(d->m_languageCodeStylePreferences);
|
2011-08-16 10:45:23 +02:00
|
|
|
int i = 0;
|
2011-02-03 15:48:14 +01:00
|
|
|
while (itCodeStyle.hasNext()) {
|
|
|
|
|
itCodeStyle.next();
|
|
|
|
|
QVariantMap settingsIdMap;
|
2013-03-19 18:27:04 +01:00
|
|
|
settingsIdMap.insert(QLatin1String("language"), itCodeStyle.key().toSetting());
|
2011-02-03 15:48:14 +01:00
|
|
|
QVariantMap value;
|
|
|
|
|
itCodeStyle.value()->toMap(QString(), &value);
|
|
|
|
|
settingsIdMap.insert(QLatin1String("value"), value);
|
|
|
|
|
map.insert(kCodeStylePrefix + QString::number(i), settingsIdMap);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_defaultCodeStyle->tabSettings().toMap(kPrefix, &map);
|
|
|
|
|
d->m_typingSettings.toMap(kPrefix, &map);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_storageSettings.toMap(kPrefix, &map);
|
|
|
|
|
d->m_behaviorSettings.toMap(kPrefix, &map);
|
|
|
|
|
d->m_extraEncodingSettings.toMap(kPrefix, &map);
|
2014-01-09 14:44:25 +01:00
|
|
|
d->m_marginSettings.toMap(kPrefix, &map);
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2010-01-14 16:24:21 +01:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-06 11:54:09 +02:00
|
|
|
void EditorConfiguration::fromMap(const QVariantMap &map)
|
2010-01-14 16:24:21 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
const QByteArray &codecName = map.value(kCodec, d->m_textCodec->name()).toByteArray();
|
|
|
|
|
d->m_textCodec = QTextCodec::codecForName(codecName);
|
|
|
|
|
if (!d->m_textCodec)
|
2013-08-29 15:46:04 +02:00
|
|
|
d->m_textCodec = Core::EditorManager::defaultTextCodec();
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
const int codeStyleCount = map.value(kCodeStyleCount, 0).toInt();
|
|
|
|
|
for (int i = 0; i < codeStyleCount; ++i) {
|
|
|
|
|
QVariantMap settingsIdMap = map.value(kCodeStylePrefix + QString::number(i)).toMap();
|
|
|
|
|
if (settingsIdMap.isEmpty()) {
|
|
|
|
|
qWarning() << "No data for code style settings list" << i << "found!";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-03-19 18:27:04 +01:00
|
|
|
Core::Id languageId = Core::Id::fromSetting(settingsIdMap.value(QLatin1String("language")));
|
2011-02-03 15:48:14 +01:00
|
|
|
QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
|
2011-08-16 10:45:23 +02:00
|
|
|
ICodeStylePreferences *preferences = d->m_languageCodeStylePreferences.value(languageId);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (preferences)
|
2011-02-03 15:48:14 +01:00
|
|
|
preferences->fromMap(QString(), value);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_defaultCodeStyle->fromMap(kPrefix, map);
|
|
|
|
|
d->m_typingSettings.fromMap(kPrefix, map);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_storageSettings.fromMap(kPrefix, map);
|
|
|
|
|
d->m_behaviorSettings.fromMap(kPrefix, map);
|
|
|
|
|
d->m_extraEncodingSettings.fromMap(kPrefix, map);
|
2014-01-09 14:44:25 +01:00
|
|
|
d->m_marginSettings.fromMap(kPrefix, map);
|
2014-10-28 22:39:02 +02:00
|
|
|
setUseGlobalSettings(map.value(kUseGlobal, d->m_useGlobal).toBool());
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 19:10:38 +02:00
|
|
|
void EditorConfiguration::configureEditor(BaseTextEditor *textEditor) const
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *widget = textEditor->editorWidget();
|
2014-07-23 19:10:38 +02:00
|
|
|
if (widget)
|
|
|
|
|
widget->setCodeStyle(codeStyle(widget->languageSettingsId()));
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!d->m_useGlobal) {
|
2013-07-16 17:10:16 +02:00
|
|
|
textEditor->textDocument()->setCodec(d->m_textCodec);
|
2014-07-23 19:10:38 +02:00
|
|
|
if (widget)
|
|
|
|
|
switchSettings(widget);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
2014-08-12 15:19:25 +02:00
|
|
|
d->m_editors.append(textEditor);
|
2015-05-26 13:57:37 +02:00
|
|
|
connect(textEditor, &BaseTextEditor::destroyed, this, [this, textEditor]() {
|
|
|
|
|
d->m_editors.removeOne(textEditor);
|
|
|
|
|
});
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 19:10:38 +02:00
|
|
|
void EditorConfiguration::deconfigureEditor(BaseTextEditor *textEditor) const
|
2013-09-27 12:46:08 +02:00
|
|
|
{
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *widget = textEditor->editorWidget();
|
2014-07-23 19:10:38 +02:00
|
|
|
if (widget)
|
|
|
|
|
widget->setCodeStyle(TextEditorSettings::codeStyle(widget->languageSettingsId()));
|
2013-09-27 12:46:08 +02:00
|
|
|
|
2014-08-12 15:19:25 +02:00
|
|
|
d->m_editors.removeOne(textEditor);
|
|
|
|
|
|
2013-09-27 12:46:08 +02:00
|
|
|
// TODO: what about text codec and switching settings?
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void EditorConfiguration::setUseGlobalSettings(bool use)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_useGlobal = use;
|
2014-10-28 22:39:02 +02:00
|
|
|
d->m_defaultCodeStyle->setCurrentDelegate(use ? TextEditorSettings::codeStyle() : 0);
|
2014-05-07 16:25:04 +02:00
|
|
|
foreach (Core::IEditor *editor, Core::DocumentModel::editorsForOpenedDocuments()) {
|
2016-04-13 15:52:14 +02:00
|
|
|
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
|
2015-02-02 00:37:38 +02:00
|
|
|
Project *project = SessionManager::projectForFile(editor->document()->filePath());
|
2011-02-01 14:13:54 +01:00
|
|
|
if (project && project->editorConfiguration() == this)
|
2014-07-23 19:10:38 +02:00
|
|
|
switchSettings(widget);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
template<typename New, typename Old>
|
|
|
|
|
static void switchSettings_helper(const New *newSender, const Old *oldSender,
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *widget)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2016-01-29 16:38:37 +02:00
|
|
|
QObject::disconnect(oldSender, &Old::marginSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setMarginSettings);
|
|
|
|
|
QObject::disconnect(oldSender, &Old::typingSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setTypingSettings);
|
|
|
|
|
QObject::disconnect(oldSender, &Old::storageSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setStorageSettings);
|
|
|
|
|
QObject::disconnect(oldSender, &Old::behaviorSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setBehaviorSettings);
|
|
|
|
|
QObject::disconnect(oldSender, &Old::extraEncodingSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setExtraEncodingSettings);
|
|
|
|
|
|
|
|
|
|
QObject::connect(newSender, &New::marginSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setMarginSettings);
|
|
|
|
|
QObject::connect(newSender, &New::typingSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setTypingSettings);
|
|
|
|
|
QObject::connect(newSender, &New::storageSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setStorageSettings);
|
|
|
|
|
QObject::connect(newSender, &New::behaviorSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setBehaviorSettings);
|
|
|
|
|
QObject::connect(newSender, &New::extraEncodingSettingsChanged,
|
|
|
|
|
widget, &TextEditorWidget::setExtraEncodingSettings);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
void EditorConfiguration::switchSettings(TextEditorWidget *widget) const
|
2013-09-19 17:59:27 +02:00
|
|
|
{
|
|
|
|
|
if (d->m_useGlobal) {
|
2014-07-23 19:10:38 +02:00
|
|
|
widget->setMarginSettings(TextEditorSettings::marginSettings());
|
|
|
|
|
widget->setTypingSettings(TextEditorSettings::typingSettings());
|
|
|
|
|
widget->setStorageSettings(TextEditorSettings::storageSettings());
|
|
|
|
|
widget->setBehaviorSettings(TextEditorSettings::behaviorSettings());
|
|
|
|
|
widget->setExtraEncodingSettings(TextEditorSettings::extraEncodingSettings());
|
|
|
|
|
switchSettings_helper(TextEditorSettings::instance(), this, widget);
|
2013-09-19 17:59:27 +02:00
|
|
|
} else {
|
2014-07-23 19:10:38 +02:00
|
|
|
widget->setMarginSettings(marginSettings());
|
|
|
|
|
widget->setTypingSettings(typingSettings());
|
|
|
|
|
widget->setStorageSettings(storageSettings());
|
|
|
|
|
widget->setBehaviorSettings(behaviorSettings());
|
|
|
|
|
widget->setExtraEncodingSettings(extraEncodingSettings());
|
|
|
|
|
switchSettings_helper(this, TextEditorSettings::instance(), widget);
|
2013-09-19 17:59:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
void EditorConfiguration::setTypingSettings(const TypingSettings &settings)
|
2011-08-16 10:45:23 +02:00
|
|
|
{
|
|
|
|
|
d->m_typingSettings = settings;
|
|
|
|
|
emit typingSettingsChanged(d->m_typingSettings);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
void EditorConfiguration::setStorageSettings(const StorageSettings &settings)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_storageSettings = settings;
|
|
|
|
|
emit storageSettingsChanged(d->m_storageSettings);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
void EditorConfiguration::setBehaviorSettings(const BehaviorSettings &settings)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_behaviorSettings = settings;
|
|
|
|
|
emit behaviorSettingsChanged(d->m_behaviorSettings);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
void EditorConfiguration::setExtraEncodingSettings(const ExtraEncodingSettings &settings)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_extraEncodingSettings = settings;
|
|
|
|
|
emit extraEncodingSettingsChanged(d->m_extraEncodingSettings);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-09 14:44:25 +01:00
|
|
|
void EditorConfiguration::setMarginSettings(const MarginSettings &settings)
|
|
|
|
|
{
|
|
|
|
|
if (d->m_marginSettings != settings) {
|
|
|
|
|
d->m_marginSettings = settings;
|
|
|
|
|
emit marginSettingsChanged(d->m_marginSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void EditorConfiguration::setTextCodec(QTextCodec *textCodec)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_textCodec = textCodec;
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-09 14:44:25 +01:00
|
|
|
void EditorConfiguration::setShowWrapColumn(bool onoff)
|
|
|
|
|
{
|
|
|
|
|
if (d->m_marginSettings.m_showMargin != onoff) {
|
|
|
|
|
d->m_marginSettings.m_showMargin = onoff;
|
|
|
|
|
emit marginSettingsChanged(d->m_marginSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorConfiguration::setWrapColumn(int column)
|
|
|
|
|
{
|
|
|
|
|
if (d->m_marginSettings.m_marginColumn != column) {
|
|
|
|
|
d->m_marginSettings.m_marginColumn = column;
|
|
|
|
|
emit marginSettingsChanged(d->m_marginSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 22:37:28 +03:00
|
|
|
void EditorConfiguration::slotAboutToRemoveProject(Project *project)
|
2013-09-27 12:46:08 +02:00
|
|
|
{
|
|
|
|
|
if (project->editorConfiguration() != this)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
foreach (BaseTextEditor *editor, d->m_editors)
|
2014-08-12 15:19:25 +02:00
|
|
|
deconfigureEditor(editor);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-27 12:46:08 +02:00
|
|
|
TabSettings actualTabSettings(const QString &fileName,
|
2014-09-22 18:43:31 +02:00
|
|
|
const TextDocument *baseTextdocument)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2014-01-17 14:59:20 +01:00
|
|
|
if (baseTextdocument)
|
|
|
|
|
return baseTextdocument->tabSettings();
|
2015-02-02 00:37:38 +02:00
|
|
|
if (Project *project = SessionManager::projectForFile(Utils::FileName::fromString(fileName)))
|
2013-09-05 11:46:07 +02:00
|
|
|
return project->editorConfiguration()->codeStyle()->tabSettings();
|
2013-09-19 17:59:27 +02:00
|
|
|
return TextEditorSettings::codeStyle()->tabSettings();
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // ProjectExplorer
|