2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2009-01-27 15:12:32 +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).
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2009-01-27 15:12:32 +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.
|
2009-01-27 15:12:32 +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-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
#include "behaviorsettingspage.h"
|
2009-12-08 17:37:40 +01:00
|
|
|
|
|
|
|
|
#include "behaviorsettings.h"
|
2011-08-16 10:45:23 +02:00
|
|
|
#include "typingsettings.h"
|
2009-01-27 15:12:32 +01:00
|
|
|
#include "storagesettings.h"
|
|
|
|
|
#include "tabsettings.h"
|
2011-02-01 14:13:54 +01:00
|
|
|
#include "extraencodingsettings.h"
|
2009-01-27 15:12:32 +01:00
|
|
|
#include "ui_behaviorsettingspage.h"
|
2011-08-16 10:45:23 +02:00
|
|
|
#include "simplecodestylepreferences.h"
|
2011-06-20 16:23:40 +02:00
|
|
|
#include "texteditorconstants.h"
|
2011-08-16 10:45:23 +02:00
|
|
|
#include "codestylepool.h"
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-10-28 19:26:20 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-10-28 19:47:49 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QSettings>
|
2010-10-28 19:26:20 +02:00
|
|
|
#include <QtCore/QTextCodec>
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
|
|
|
|
|
{
|
|
|
|
|
explicit BehaviorSettingsPagePrivate(const BehaviorSettingsPageParameters &p);
|
|
|
|
|
|
|
|
|
|
const BehaviorSettingsPageParameters m_parameters;
|
2011-11-23 15:15:01 +00:00
|
|
|
Internal::Ui::BehaviorSettingsPage *m_page;
|
2009-12-08 17:37:40 +01:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
void init();
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
CodeStylePool *m_defaultCodeStylePool;
|
|
|
|
|
SimpleCodeStylePreferences *m_codeStyle;
|
|
|
|
|
SimpleCodeStylePreferences *m_pageCodeStyle;
|
|
|
|
|
TypingSettings m_typingSettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
StorageSettings m_storageSettings;
|
2009-12-08 17:37:40 +01:00
|
|
|
BehaviorSettings m_behaviorSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
ExtraEncodingSettings m_extraEncodingSettings;
|
2009-12-08 17:37:40 +01:00
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
QString m_searchKeywords;
|
2009-01-27 15:12:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate
|
|
|
|
|
(const BehaviorSettingsPageParameters &p)
|
2011-08-16 10:45:23 +02:00
|
|
|
: m_parameters(p), m_page(0), m_pageCodeStyle(0)
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BehaviorSettingsPage::BehaviorSettingsPagePrivate::init()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
|
|
|
|
if (const QSettings *s = Core::ICore::instance()->settings()) {
|
2011-08-16 10:45:23 +02:00
|
|
|
m_codeStyle->fromSettings(m_parameters.settingsPrefix, s);
|
|
|
|
|
m_typingSettings.fromSettings(m_parameters.settingsPrefix, s);
|
2009-01-27 15:12:32 +01:00
|
|
|
m_storageSettings.fromSettings(m_parameters.settingsPrefix, s);
|
2009-12-08 17:37:40 +01:00
|
|
|
m_behaviorSettings.fromSettings(m_parameters.settingsPrefix, s);
|
2011-02-01 14:13:54 +01:00
|
|
|
m_extraEncodingSettings.fromSettings(m_parameters.settingsPrefix, s);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters &p,
|
2009-12-08 17:37:40 +01:00
|
|
|
QObject *parent)
|
2010-04-12 15:53:17 +02:00
|
|
|
: TextEditorOptionsPage(parent),
|
2011-09-16 13:10:06 +02:00
|
|
|
d(new BehaviorSettingsPagePrivate(p))
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
// global tab preferences for all other languages
|
|
|
|
|
d->m_codeStyle = new SimpleCodeStylePreferences(this);
|
|
|
|
|
d->m_codeStyle->setDisplayName(tr("Global", "Settings"));
|
2012-01-05 11:05:28 +01:00
|
|
|
d->m_codeStyle->setId(QLatin1String(Constants::GLOBAL_SETTINGS_ID));
|
2011-08-16 10:45:23 +02:00
|
|
|
|
|
|
|
|
// default pool for all other languages
|
|
|
|
|
d->m_defaultCodeStylePool = new CodeStylePool(0, this); // Any language
|
|
|
|
|
d->m_defaultCodeStylePool->addCodeStyle(d->m_codeStyle);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->init();
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BehaviorSettingsPage::~BehaviorSettingsPage()
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
delete d;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
QString BehaviorSettingsPage::id() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_parameters.id;
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString BehaviorSettingsPage::displayName() const
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_parameters.displayName;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
QWidget *w = new QWidget(parent);
|
2011-11-23 15:15:01 +00:00
|
|
|
d->m_page = new Internal::Ui::BehaviorSettingsPage;
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_page->setupUi(w);
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_pageCodeStyle = new SimpleCodeStylePreferences(w);
|
|
|
|
|
d->m_pageCodeStyle->setDelegatingPool(d->m_codeStyle->delegatingPool());
|
|
|
|
|
d->m_pageCodeStyle->setTabSettings(d->m_codeStyle->tabSettings());
|
|
|
|
|
d->m_pageCodeStyle->setCurrentDelegate(d->m_codeStyle->currentDelegate());
|
|
|
|
|
d->m_page->behaviorWidget->setCodeStyle(d->m_pageCodeStyle);
|
2010-10-28 19:26:20 +02:00
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
settingsToUI();
|
2010-10-28 19:26:20 +02:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
if (d->m_searchKeywords.isEmpty())
|
|
|
|
|
d->m_searchKeywords = d->m_page->behaviorWidget->collectUiKeywords();
|
2010-10-28 19:47:49 +02:00
|
|
|
|
2009-01-27 15:12:32 +01:00
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BehaviorSettingsPage::apply()
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!d->m_page) // page was never shown
|
2010-12-02 18:28:16 +01:00
|
|
|
return;
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
TypingSettings newTypingSettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
StorageSettings newStorageSettings;
|
2009-12-08 17:37:40 +01:00
|
|
|
BehaviorSettings newBehaviorSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
ExtraEncodingSettings newExtraEncodingSettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
settingsFromUI(&newTypingSettings, &newStorageSettings,
|
|
|
|
|
&newBehaviorSettings, &newExtraEncodingSettings);
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
QSettings *s = Core::ICore::instance()->settings();
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
if (d->m_codeStyle->tabSettings() != d->m_pageCodeStyle->tabSettings()) {
|
|
|
|
|
d->m_codeStyle->setTabSettings(d->m_pageCodeStyle->tabSettings());
|
2011-06-20 16:23:40 +02:00
|
|
|
if (s)
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_codeStyle->toSettings(d->m_parameters.settingsPrefix, s);
|
2011-06-20 16:23:40 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
if (d->m_codeStyle->currentDelegate() != d->m_pageCodeStyle->currentDelegate()) {
|
|
|
|
|
d->m_codeStyle->setCurrentDelegate(d->m_pageCodeStyle->currentDelegate());
|
2009-01-27 15:12:32 +01:00
|
|
|
if (s)
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_codeStyle->toSettings(d->m_parameters.settingsPrefix, s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newTypingSettings != d->m_typingSettings) {
|
|
|
|
|
d->m_typingSettings = newTypingSettings;
|
|
|
|
|
if (s)
|
|
|
|
|
d->m_typingSettings.toSettings(d->m_parameters.settingsPrefix, s);
|
|
|
|
|
|
|
|
|
|
emit typingSettingsChanged(newTypingSettings);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
if (newStorageSettings != d->m_storageSettings) {
|
|
|
|
|
d->m_storageSettings = newStorageSettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
if (s)
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_storageSettings.toSettings(d->m_parameters.settingsPrefix, s);
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
emit storageSettingsChanged(newStorageSettings);
|
|
|
|
|
}
|
2009-12-08 17:37:40 +01:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
if (newBehaviorSettings != d->m_behaviorSettings) {
|
|
|
|
|
d->m_behaviorSettings = newBehaviorSettings;
|
2009-12-08 17:37:40 +01:00
|
|
|
if (s)
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_behaviorSettings.toSettings(d->m_parameters.settingsPrefix, s);
|
2009-12-08 17:37:40 +01:00
|
|
|
|
|
|
|
|
emit behaviorSettingsChanged(newBehaviorSettings);
|
|
|
|
|
}
|
2010-10-28 19:26:20 +02:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
if (newExtraEncodingSettings != d->m_extraEncodingSettings) {
|
|
|
|
|
d->m_extraEncodingSettings = newExtraEncodingSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
if (s)
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_extraEncodingSettings.toSettings(d->m_parameters.settingsPrefix, s);
|
2011-02-01 14:13:54 +01:00
|
|
|
|
|
|
|
|
emit extraEncodingSettingsChanged(newExtraEncodingSettings);
|
|
|
|
|
}
|
2010-10-28 19:26:20 +02:00
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
if (s) {
|
|
|
|
|
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_page->behaviorWidget->assignedCodec()->name());
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
void BehaviorSettingsPage::settingsFromUI(TypingSettings *typingSettings,
|
|
|
|
|
StorageSettings *storageSettings,
|
2011-02-01 14:13:54 +01:00
|
|
|
BehaviorSettings *behaviorSettings,
|
|
|
|
|
ExtraEncodingSettings *extraEncodingSettings) const
|
2010-12-02 18:28:16 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_page->behaviorWidget->assignedTypingSettings(typingSettings);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_page->behaviorWidget->assignedStorageSettings(storageSettings);
|
|
|
|
|
d->m_page->behaviorWidget->assignedBehaviorSettings(behaviorSettings);
|
|
|
|
|
d->m_page->behaviorWidget->assignedExtraEncodingSettings(extraEncodingSettings);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void BehaviorSettingsPage::settingsToUI()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
d->m_page->behaviorWidget->setAssignedTypingSettings(d->m_typingSettings);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_page->behaviorWidget->setAssignedStorageSettings(d->m_storageSettings);
|
|
|
|
|
d->m_page->behaviorWidget->setAssignedBehaviorSettings(d->m_behaviorSettings);
|
|
|
|
|
d->m_page->behaviorWidget->setAssignedExtraEncodingSettings(d->m_extraEncodingSettings);
|
|
|
|
|
d->m_page->behaviorWidget->setAssignedCodec(
|
2011-02-01 14:13:54 +01:00
|
|
|
Core::EditorManager::instance()->defaultTextCodec());
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void BehaviorSettingsPage::finish()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!d->m_page) // page was never shown
|
2011-02-01 14:13:54 +01:00
|
|
|
return;
|
2011-09-16 13:10:06 +02:00
|
|
|
delete d->m_page;
|
|
|
|
|
d->m_page = 0;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
ICodeStylePreferences *BehaviorSettingsPage::codeStyle() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_codeStyle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CodeStylePool *BehaviorSettingsPage::codeStylePool() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_defaultCodeStylePool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TypingSettings &BehaviorSettingsPage::typingSettings() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_typingSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const StorageSettings &BehaviorSettingsPage::storageSettings() const
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_storageSettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
2009-11-24 15:05:02 +01:00
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const BehaviorSettings &BehaviorSettingsPage::behaviorSettings() const
|
2009-12-08 17:37:40 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_behaviorSettings;
|
2009-12-08 17:37:40 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
const ExtraEncodingSettings &BehaviorSettingsPage::extraEncodingSettings() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_extraEncodingSettings;
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
bool BehaviorSettingsPage::matches(const QString &s) const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
2009-11-24 15:05:02 +01:00
|
|
|
}
|