2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
|
|
|
|
#include <texteditor/itexteditor.h>
|
|
|
|
|
#include <texteditor/basetexteditor.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/tabsettings.h>
|
2011-02-03 15:48:14 +01:00
|
|
|
#include <texteditor/tabpreferences.h>
|
2011-02-01 14:13:54 +01:00
|
|
|
#include <texteditor/storagesettings.h>
|
|
|
|
|
#include <texteditor/behaviorsettings.h>
|
|
|
|
|
#include <texteditor/extraencodingsettings.h>
|
2011-02-03 15:48:14 +01:00
|
|
|
#include <texteditor/codestylepreferencesmanager.h>
|
|
|
|
|
#include <texteditor/icodestylepreferencesfactory.h>
|
2011-02-01 14:13:54 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QLatin1String>
|
|
|
|
|
#include <QtCore/QByteArray>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QTextCodec>
|
2011-02-03 15:48:14 +01:00
|
|
|
#include <QtCore/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 kTabPrefix("EditorConfiguration.Tab.");
|
|
|
|
|
static const QLatin1String kTabCount("EditorConfiguration.Tab.Count");
|
|
|
|
|
static const QLatin1String kCodeStylePrefix("EditorConfiguration.CodeStyle.");
|
|
|
|
|
static const QLatin1String kCodeStyleCount("EditorConfiguration.CodeStyle.Count");
|
|
|
|
|
static const QLatin1String kId("Project");
|
2011-02-01 14:13:54 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
struct EditorConfigurationPrivate
|
|
|
|
|
{
|
|
|
|
|
EditorConfigurationPrivate()
|
|
|
|
|
: m_useGlobal(true)
|
2011-02-03 15:48:14 +01:00
|
|
|
, m_tabPreferences(0)
|
2011-02-01 14:13:54 +01:00
|
|
|
, m_storageSettings(TextEditorSettings::instance()->storageSettings())
|
|
|
|
|
, m_behaviorSettings(TextEditorSettings::instance()->behaviorSettings())
|
|
|
|
|
, m_extraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings())
|
|
|
|
|
, m_textCodec(Core::EditorManager::instance()->defaultTextCodec())
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
|
|
|
|
}
|
2011-02-01 14:13:54 +01:00
|
|
|
|
|
|
|
|
bool m_useGlobal;
|
2011-02-03 15:48:14 +01:00
|
|
|
TabPreferences *m_tabPreferences;
|
2011-02-01 14:13:54 +01:00
|
|
|
StorageSettings m_storageSettings;
|
|
|
|
|
BehaviorSettings m_behaviorSettings;
|
|
|
|
|
ExtraEncodingSettings m_extraEncodingSettings;
|
|
|
|
|
QTextCodec *m_textCodec;
|
2011-02-03 15:48:14 +01:00
|
|
|
|
|
|
|
|
QMap<QString, TabPreferences *> m_languageTabPreferences;
|
|
|
|
|
QMap<QString, IFallbackPreferences *> m_languageCodeStylePreferences;
|
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
|
|
|
{
|
2011-06-20 16:23:40 +02:00
|
|
|
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
|
|
|
|
|
QList<TabPreferences *> tabFallbacks;
|
|
|
|
|
tabFallbacks << textEditorSettings->tabPreferences();
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_tabPreferences = new TabPreferences(tabFallbacks, this);
|
|
|
|
|
d->m_tabPreferences->setFallbackEnabled(textEditorSettings->tabPreferences(), false);
|
|
|
|
|
d->m_tabPreferences->setDisplayName(tr("Project", "Settings"));
|
|
|
|
|
d->m_tabPreferences->setId(kId);
|
2011-02-03 15:48:14 +01:00
|
|
|
|
|
|
|
|
CodeStylePreferencesManager *manager =
|
|
|
|
|
CodeStylePreferencesManager::instance();
|
|
|
|
|
TextEditorSettings *settings = TextEditorSettings::instance();
|
|
|
|
|
|
|
|
|
|
const QMap<QString, TabPreferences *> languageTabPreferences = settings->languageTabPreferences();
|
|
|
|
|
QMapIterator<QString, TabPreferences *> itTab(languageTabPreferences);
|
|
|
|
|
while (itTab.hasNext()) {
|
|
|
|
|
itTab.next();
|
|
|
|
|
const QString languageId = itTab.key();
|
|
|
|
|
TabPreferences *originalPreferences = itTab.value();
|
2011-06-22 15:04:24 +02:00
|
|
|
QList<IFallbackPreferences *> fallbacks;
|
|
|
|
|
fallbacks << originalPreferences->fallbacks();
|
|
|
|
|
fallbacks << originalPreferences;
|
|
|
|
|
fallbacks << tabPreferences();
|
2011-02-03 15:48:14 +01:00
|
|
|
TabPreferences *preferences = new TabPreferences(
|
2011-06-22 15:04:24 +02:00
|
|
|
fallbacks, this);
|
|
|
|
|
for (int i = 0; i < fallbacks.count(); i++)
|
|
|
|
|
preferences->setFallbackEnabled(fallbacks.at(i), false);
|
2011-02-03 15:48:14 +01:00
|
|
|
preferences->setId(languageId + QLatin1String("Project"));
|
|
|
|
|
preferences->setCurrentFallback(originalPreferences);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_languageTabPreferences.insert(languageId, preferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QMap<QString, IFallbackPreferences *> languageCodeStylePreferences = settings->languageCodeStylePreferences();
|
|
|
|
|
QMapIterator<QString, IFallbackPreferences *> itCodeStyle(languageCodeStylePreferences);
|
|
|
|
|
while (itCodeStyle.hasNext()) {
|
|
|
|
|
itCodeStyle.next();
|
|
|
|
|
const QString languageId = itCodeStyle.key();
|
|
|
|
|
IFallbackPreferences *originalPreferences = itCodeStyle.value();
|
|
|
|
|
ICodeStylePreferencesFactory *factory = manager->factory(languageId);
|
|
|
|
|
IFallbackPreferences *preferences = factory->createPreferences(
|
|
|
|
|
QList<IFallbackPreferences *>() << originalPreferences);
|
2011-06-22 15:04:24 +02:00
|
|
|
preferences->setFallbackEnabled(originalPreferences, false);
|
2011-02-03 15:48:14 +01:00
|
|
|
preferences->setId(languageId + QLatin1String("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()));
|
2011-02-03 15:48:14 +01:00
|
|
|
preferences->setCurrentFallback(originalPreferences);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_languageCodeStylePreferences.insert(languageId, preferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
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
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
qDeleteAll(d->m_languageTabPreferences.values());
|
|
|
|
|
qDeleteAll(d->m_languageCodeStylePreferences.values());
|
|
|
|
|
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
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_tabPreferences->setSettings(TextEditorSettings::instance()->tabPreferences()->settings());
|
2011-02-03 15:48:14 +01:00
|
|
|
setStorageSettings(TextEditorSettings::instance()->storageSettings());
|
|
|
|
|
setBehaviorSettings(TextEditorSettings::instance()->behaviorSettings());
|
|
|
|
|
setExtraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings());
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_textCodec = Core::EditorManager::instance()->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-02-03 15:48:14 +01:00
|
|
|
TabPreferences *EditorConfiguration::tabPreferences() const
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_tabPreferences;
|
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
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
TabPreferences *EditorConfiguration::tabPreferences(const QString &languageId) const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
TabPreferences *prefs = d->m_languageTabPreferences.value(languageId);
|
2011-02-03 15:48:14 +01:00
|
|
|
if (!prefs)
|
2011-09-16 13:10:06 +02:00
|
|
|
prefs = d->m_tabPreferences;
|
2011-02-03 15:48:14 +01:00
|
|
|
return prefs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString, TabPreferences *> EditorConfiguration::languageTabPreferences() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_languageTabPreferences;
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IFallbackPreferences *EditorConfiguration::codeStylePreferences(const QString &languageId) const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_languageCodeStylePreferences.value(languageId);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString, IFallbackPreferences *> EditorConfiguration::languageCodeStylePreferences() const
|
|
|
|
|
{
|
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(kTabCount, d->m_languageTabPreferences.count());
|
|
|
|
|
QMapIterator<QString, TabPreferences *> itTab(d->m_languageTabPreferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
int i = 0;
|
|
|
|
|
while (itTab.hasNext()) {
|
|
|
|
|
itTab.next();
|
|
|
|
|
QVariantMap settingsIdMap;
|
|
|
|
|
settingsIdMap.insert(QLatin1String("language"), itTab.key());
|
|
|
|
|
QVariantMap value;
|
|
|
|
|
itTab.value()->toMap(QString(), &value);
|
|
|
|
|
settingsIdMap.insert(QLatin1String("value"), value);
|
|
|
|
|
map.insert(kTabPrefix + QString::number(i), settingsIdMap);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
map.insert(kCodeStyleCount, d->m_languageCodeStylePreferences.count());
|
|
|
|
|
QMapIterator<QString, IFallbackPreferences *> itCodeStyle(d->m_languageCodeStylePreferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
i = 0;
|
|
|
|
|
while (itCodeStyle.hasNext()) {
|
|
|
|
|
itCodeStyle.next();
|
|
|
|
|
QVariantMap settingsIdMap;
|
|
|
|
|
settingsIdMap.insert(QLatin1String("language"), itCodeStyle.key());
|
|
|
|
|
QVariantMap value;
|
|
|
|
|
itCodeStyle.value()->toMap(QString(), &value);
|
|
|
|
|
settingsIdMap.insert(QLatin1String("value"), value);
|
|
|
|
|
map.insert(kCodeStylePrefix + QString::number(i), settingsIdMap);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_tabPreferences->toMap(kPrefix, &map);
|
|
|
|
|
d->m_storageSettings.toMap(kPrefix, &map);
|
|
|
|
|
d->m_behaviorSettings.toMap(kPrefix, &map);
|
|
|
|
|
d->m_extraEncodingSettings.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
|
|
|
d->m_useGlobal = map.value(kUseGlobal, d->m_useGlobal).toBool();
|
2011-02-01 14:13:54 +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)
|
|
|
|
|
d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec();
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
const int tabCount = map.value(kTabCount, 0).toInt();
|
|
|
|
|
for (int i = 0; i < tabCount; ++i) {
|
|
|
|
|
QVariantMap settingsIdMap = map.value(kTabPrefix + QString::number(i)).toMap();
|
|
|
|
|
if (settingsIdMap.isEmpty()) {
|
|
|
|
|
qWarning() << "No data for tab settings list" << i << "found!";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QString languageId = settingsIdMap.value(QLatin1String("language")).toString();
|
|
|
|
|
QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
|
2011-09-16 13:10:06 +02:00
|
|
|
TabPreferences *preferences = d->m_languageTabPreferences.value(languageId);
|
2011-02-03 15:48:14 +01:00
|
|
|
if (preferences) {
|
|
|
|
|
preferences->fromMap(QString(), value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
QString languageId = settingsIdMap.value(QLatin1String("language")).toString();
|
|
|
|
|
QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
|
2011-09-16 13:10:06 +02:00
|
|
|
IFallbackPreferences *preferences = d->m_languageCodeStylePreferences.value(languageId);
|
2011-02-03 15:48:14 +01:00
|
|
|
if (preferences) {
|
|
|
|
|
preferences->fromMap(QString(), value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_tabPreferences->fromMap(kPrefix, map);
|
|
|
|
|
d->m_tabPreferences->setCurrentFallback(d->m_useGlobal
|
2011-02-03 15:48:14 +01:00
|
|
|
? TextEditorSettings::instance()->tabPreferences() : 0);
|
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);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-02-03 15:48:14 +01:00
|
|
|
BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(textEditor->widget());
|
|
|
|
|
baseTextEditor->setTabPreferences(tabPreferences(baseTextEditor->languageSettingsId()));
|
|
|
|
|
baseTextEditor->setCodeStylePreferences(codeStylePreferences(baseTextEditor->languageSettingsId()));
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!d->m_useGlobal) {
|
|
|
|
|
textEditor->setTextCodec(d->m_textCodec, ITextEditor::TextCodecFromProjectSetting);
|
2011-02-03 15:48:14 +01:00
|
|
|
if (baseTextEditor)
|
2011-02-01 14:13:54 +01:00
|
|
|
switchSettings(baseTextEditor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorConfiguration::setUseGlobalSettings(bool use)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_useGlobal = use;
|
|
|
|
|
d->m_tabPreferences->setCurrentFallback(d->m_useGlobal
|
2011-02-03 15:48:14 +01:00
|
|
|
? TextEditorSettings::instance()->tabPreferences() : 0);
|
2011-02-01 14:13:54 +01:00
|
|
|
const SessionManager *session = ProjectExplorerPlugin::instance()->session();
|
|
|
|
|
QList<Core::IEditor *> opened = Core::EditorManager::instance()->openedEditors();
|
|
|
|
|
foreach (Core::IEditor *editor, opened) {
|
2011-02-21 16:02:26 +01:00
|
|
|
if (BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(editor->widget())) {
|
2011-02-01 14:13:54 +01:00
|
|
|
Project *project = session->projectForFile(editor->file()->fileName());
|
|
|
|
|
if (project && project->editorConfiguration() == this)
|
|
|
|
|
switchSettings(baseTextEditor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void EditorConfiguration::switchSettings(BaseTextEditorWidget *baseTextEditor) const
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (d->m_useGlobal)
|
2011-02-01 14:13:54 +01:00
|
|
|
switchSettings_helper(TextEditorSettings::instance(), this, baseTextEditor);
|
|
|
|
|
else
|
|
|
|
|
switchSettings_helper(this, TextEditorSettings::instance(), baseTextEditor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class NewSenderT, class OldSenderT>
|
|
|
|
|
void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
|
|
|
|
|
const OldSenderT *oldSender,
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget *baseTextEditor) const
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
|
|
|
|
baseTextEditor->setStorageSettings(newSender->storageSettings());
|
|
|
|
|
baseTextEditor->setBehaviorSettings(newSender->behaviorSettings());
|
|
|
|
|
baseTextEditor->setExtraEncodingSettings(newSender->extraEncodingSettings());
|
|
|
|
|
|
|
|
|
|
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(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)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
void EditorConfiguration::setStorageSettings(const TextEditor::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
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
void EditorConfiguration::setBehaviorSettings(const TextEditor::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
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
void EditorConfiguration::setExtraEncodingSettings(const TextEditor::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
TabSettings actualTabSettings(const QString &fileName,
|
|
|
|
|
const BaseTextEditorWidget *baseTextEditor)
|
2011-02-01 14:13:54 +01:00
|
|
|
{
|
|
|
|
|
if (baseTextEditor) {
|
|
|
|
|
return baseTextEditor->tabSettings();
|
|
|
|
|
} else {
|
|
|
|
|
const SessionManager *session = ProjectExplorerPlugin::instance()->session();
|
|
|
|
|
if (Project *project = session->projectForFile(fileName))
|
2011-02-03 15:48:14 +01:00
|
|
|
return project->editorConfiguration()->tabPreferences()->settings();
|
2011-02-01 14:13:54 +01:00
|
|
|
else
|
2011-02-03 15:48:14 +01:00
|
|
|
return TextEditorSettings::instance()->tabPreferences()->settings();
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // ProjectExplorer
|