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-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.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
|
|
|
|
|
** 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"
|
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"
|
|
|
|
|
|
|
|
|
|
#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;
|
2010-12-02 18:28:16 +01:00
|
|
|
Ui::BehaviorSettingsPage *m_page;
|
2009-12-08 17:37:40 +01:00
|
|
|
|
2009-01-27 15:12:32 +01:00
|
|
|
TabSettings m_tabSettings;
|
|
|
|
|
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)
|
2010-12-02 18:28:16 +01:00
|
|
|
: m_parameters(p), m_page(0)
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
|
|
|
|
if (const QSettings *s = Core::ICore::instance()->settings()) {
|
|
|
|
|
m_tabSettings.fromSettings(m_parameters.settingsPrefix, s);
|
|
|
|
|
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),
|
2009-01-27 15:12:32 +01:00
|
|
|
m_d(new BehaviorSettingsPagePrivate(p))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BehaviorSettingsPage::~BehaviorSettingsPage()
|
|
|
|
|
{
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
QString BehaviorSettingsPage::id() const
|
|
|
|
|
{
|
2009-11-27 16:12:12 +01:00
|
|
|
return m_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
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
return m_d->m_parameters.displayName;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
QWidget *w = new QWidget(parent);
|
2010-12-02 18:28:16 +01:00
|
|
|
m_d->m_page = new Ui::BehaviorSettingsPage;
|
|
|
|
|
m_d->m_page->setupUi(w);
|
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-02-01 14:13:54 +01:00
|
|
|
if (m_d->m_searchKeywords.isEmpty())
|
|
|
|
|
m_d->m_searchKeywords = m_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()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_d->m_page) // page was never shown
|
|
|
|
|
return;
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2009-01-27 15:12:32 +01:00
|
|
|
TabSettings newTabSettings;
|
|
|
|
|
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-02-01 14:13:54 +01:00
|
|
|
settingsFromUI(&newTabSettings, &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
|
|
|
|
|
|
|
|
if (newTabSettings != m_d->m_tabSettings) {
|
|
|
|
|
m_d->m_tabSettings = newTabSettings;
|
|
|
|
|
if (s)
|
|
|
|
|
m_d->m_tabSettings.toSettings(m_d->m_parameters.settingsPrefix, s);
|
|
|
|
|
|
|
|
|
|
emit tabSettingsChanged(newTabSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newStorageSettings != m_d->m_storageSettings) {
|
|
|
|
|
m_d->m_storageSettings = newStorageSettings;
|
|
|
|
|
if (s)
|
|
|
|
|
m_d->m_storageSettings.toSettings(m_d->m_parameters.settingsPrefix, s);
|
|
|
|
|
|
|
|
|
|
emit storageSettingsChanged(newStorageSettings);
|
|
|
|
|
}
|
2009-12-08 17:37:40 +01:00
|
|
|
|
|
|
|
|
if (newBehaviorSettings != m_d->m_behaviorSettings) {
|
|
|
|
|
m_d->m_behaviorSettings = newBehaviorSettings;
|
|
|
|
|
if (s)
|
|
|
|
|
m_d->m_behaviorSettings.toSettings(m_d->m_parameters.settingsPrefix, s);
|
|
|
|
|
|
|
|
|
|
emit behaviorSettingsChanged(newBehaviorSettings);
|
|
|
|
|
}
|
2010-10-28 19:26:20 +02:00
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
if (newExtraEncodingSettings != m_d->m_extraEncodingSettings) {
|
|
|
|
|
m_d->m_extraEncodingSettings = newExtraEncodingSettings;
|
|
|
|
|
if (s)
|
|
|
|
|
m_d->m_extraEncodingSettings.toSettings(m_d->m_parameters.settingsPrefix, s);
|
|
|
|
|
|
|
|
|
|
emit extraEncodingSettingsChanged(newExtraEncodingSettings);
|
|
|
|
|
}
|
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),
|
|
|
|
|
m_d->m_page->behaviorWidget->assignedCodec()->name());
|
|
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings,
|
|
|
|
|
StorageSettings *storageSettings,
|
|
|
|
|
BehaviorSettings *behaviorSettings,
|
|
|
|
|
ExtraEncodingSettings *extraEncodingSettings) const
|
2010-12-02 18:28:16 +01:00
|
|
|
{
|
2011-02-01 14:13:54 +01:00
|
|
|
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);
|
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-02-01 14:13:54 +01:00
|
|
|
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());
|
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-02-01 14:13:54 +01:00
|
|
|
if (!m_d->m_page) // page was never shown
|
|
|
|
|
return;
|
|
|
|
|
delete m_d->m_page;
|
|
|
|
|
m_d->m_page = 0;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const TabSettings &BehaviorSettingsPage::tabSettings() const
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
|
|
|
|
return m_d->m_tabSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const StorageSettings &BehaviorSettingsPage::storageSettings() const
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
|
|
|
|
return m_d->m_storageSettings;
|
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
|
return m_d->m_behaviorSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
const ExtraEncodingSettings &BehaviorSettingsPage::extraEncodingSettings() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_extraEncodingSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
bool BehaviorSettingsPage::matches(const QString &s) const
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
return m_d->m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
2009-11-24 15:05:02 +01:00
|
|
|
}
|