2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-01-27 15:12:32 +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.
|
2009-01-27 15:12:32 +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
|
|
|
****************************************************************************/
|
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"
|
2020-02-03 08:54:44 +01:00
|
|
|
#include "texteditorsettings.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>
|
2021-12-06 12:41:09 +01:00
|
|
|
|
2013-02-25 21:34:47 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2021-12-06 12:41:09 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2013-04-04 11:17:13 +02:00
|
|
|
// for opening the respective coding style preferences
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
2013-04-04 11:17:13 +02:00
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
|
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-01-21 15:44:41 +01:00
|
|
|
namespace TextEditor {
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-01-21 15:44:41 +01:00
|
|
|
struct BehaviorSettingsPage::BehaviorSettingsPagePrivate : public QObject
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-01-21 15:44:41 +01:00
|
|
|
BehaviorSettingsPagePrivate();
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-01-21 15:44:41 +01:00
|
|
|
const QString m_settingsPrefix{"text"};
|
2013-12-03 14:17:03 +01:00
|
|
|
QPointer<QWidget> m_widget;
|
2017-07-18 23:15:52 +02:00
|
|
|
Internal::Ui::BehaviorSettingsPage *m_page = nullptr;
|
2009-12-08 17:37:40 +01:00
|
|
|
|
2017-07-18 23:15:52 +02:00
|
|
|
CodeStylePool *m_defaultCodeStylePool = nullptr;
|
|
|
|
|
SimpleCodeStylePreferences *m_codeStyle = nullptr;
|
|
|
|
|
SimpleCodeStylePreferences *m_pageCodeStyle = nullptr;
|
2011-08-16 10:45:23 +02:00
|
|
|
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-01-27 15:12:32 +01:00
|
|
|
};
|
|
|
|
|
|
2020-01-21 15:44:41 +01:00
|
|
|
BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate()
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2020-01-21 15:44:41 +01:00
|
|
|
// global tab preferences for all other languages
|
|
|
|
|
m_codeStyle = new SimpleCodeStylePreferences(this);
|
|
|
|
|
m_codeStyle->setDisplayName(tr("Global", "Settings"));
|
|
|
|
|
m_codeStyle->setId(Constants::GLOBAL_SETTINGS_ID);
|
|
|
|
|
|
|
|
|
|
// default pool for all other languages
|
|
|
|
|
m_defaultCodeStylePool = new CodeStylePool(nullptr, this); // Any language
|
|
|
|
|
m_defaultCodeStylePool->addCodeStyle(m_codeStyle);
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2021-12-01 15:41:12 +02:00
|
|
|
QSettings * const s = Core::ICore::settings();
|
2020-01-21 15:44:41 +01:00
|
|
|
m_codeStyle->fromSettings(m_settingsPrefix, s);
|
|
|
|
|
m_typingSettings.fromSettings(m_settingsPrefix, s);
|
|
|
|
|
m_storageSettings.fromSettings(m_settingsPrefix, s);
|
|
|
|
|
m_behaviorSettings.fromSettings(m_settingsPrefix, s);
|
|
|
|
|
m_extraEncodingSettings.fromSettings(m_settingsPrefix, s);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-21 15:44:41 +01:00
|
|
|
BehaviorSettingsPage::BehaviorSettingsPage()
|
|
|
|
|
: d(new BehaviorSettingsPagePrivate)
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-01-21 15:44:41 +01:00
|
|
|
// Add the GUI used to configure the tab, storage and interaction settings
|
|
|
|
|
setId(Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS);
|
|
|
|
|
setDisplayName(tr("Behavior"));
|
|
|
|
|
|
2020-01-15 15:00:57 +01:00
|
|
|
setCategory(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("TextEditor", "Text Editor"));
|
|
|
|
|
setCategoryIconPath(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON_PATH);
|
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
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *BehaviorSettingsPage::widget()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!d->m_widget) {
|
|
|
|
|
d->m_widget = new QWidget;
|
|
|
|
|
d->m_page = new Internal::Ui::BehaviorSettingsPage;
|
|
|
|
|
d->m_page->setupUi(d->m_widget);
|
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
|
d->m_page->gridLayout->setContentsMargins(-1, 0, -1, 0); // don't ask.
|
|
|
|
|
d->m_pageCodeStyle = new SimpleCodeStylePreferences(d->m_widget);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
TabSettingsWidget *tabSettingsWidget = d->m_page->behaviorWidget->tabSettingsWidget();
|
|
|
|
|
tabSettingsWidget->setCodingStyleWarningVisible(true);
|
2015-12-13 01:18:33 +02:00
|
|
|
connect(tabSettingsWidget, &TabSettingsWidget::codingStyleLinkClicked,
|
|
|
|
|
this, &BehaviorSettingsPage::openCodingStylePreferences);
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
settingsToUI();
|
|
|
|
|
}
|
|
|
|
|
return d->m_widget;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *s = Core::ICore::settings();
|
2021-12-06 12:41:09 +01:00
|
|
|
QTC_ASSERT(s, return);
|
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());
|
2021-12-06 12:41:09 +01:00
|
|
|
d->m_codeStyle->toSettings(d->m_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());
|
2021-12-06 12:41:09 +01:00
|
|
|
d->m_codeStyle->toSettings(d->m_settingsPrefix, s);
|
2011-08-16 10:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newTypingSettings != d->m_typingSettings) {
|
|
|
|
|
d->m_typingSettings = newTypingSettings;
|
2021-12-06 12:41:09 +01:00
|
|
|
d->m_typingSettings.toSettings(d->m_settingsPrefix, s);
|
2011-08-16 10:45:23 +02:00
|
|
|
|
2020-02-03 08:54:44 +01:00
|
|
|
emit TextEditorSettings::instance()->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;
|
2021-12-06 12:41:09 +01:00
|
|
|
d->m_storageSettings.toSettings(d->m_settingsPrefix, s);
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-02-03 08:54:44 +01:00
|
|
|
emit TextEditorSettings::instance()->storageSettingsChanged(newStorageSettings);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
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;
|
2021-12-06 12:41:09 +01:00
|
|
|
d->m_behaviorSettings.toSettings(d->m_settingsPrefix, s);
|
2009-12-08 17:37:40 +01:00
|
|
|
|
2020-02-03 08:54:44 +01:00
|
|
|
emit TextEditorSettings::instance()->behaviorSettingsChanged(newBehaviorSettings);
|
2009-12-08 17:37:40 +01:00
|
|
|
}
|
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;
|
2021-12-06 12:41:09 +01:00
|
|
|
d->m_extraEncodingSettings.toSettings(d->m_settingsPrefix, s);
|
2011-02-01 14:13:54 +01:00
|
|
|
|
2020-02-03 08:54:44 +01:00
|
|
|
emit TextEditorSettings::instance()->extraEncodingSettingsChanged(newExtraEncodingSettings);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
2010-10-28 19:26:20 +02:00
|
|
|
|
2021-12-06 12:41:09 +01:00
|
|
|
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
|
|
|
|
|
d->m_page->behaviorWidget->assignedCodecName());
|
|
|
|
|
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULT_LINE_TERMINATOR),
|
|
|
|
|
d->m_page->behaviorWidget->assignedLineEnding());
|
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);
|
2013-08-29 15:46:04 +02:00
|
|
|
d->m_page->behaviorWidget->setAssignedCodec(Core::EditorManager::defaultTextCodec());
|
2019-09-03 22:37:25 +02:00
|
|
|
d->m_page->behaviorWidget->setAssignedLineEnding(Core::EditorManager::defaultLineEnding());
|
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
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete d->m_widget;
|
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;
|
2018-09-20 01:16:01 +03:00
|
|
|
d->m_page = nullptr;
|
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
|
|
|
}
|
|
|
|
|
|
2013-04-04 11:17:13 +02:00
|
|
|
|
|
|
|
|
void BehaviorSettingsPage::openCodingStylePreferences(TabSettingsWidget::CodingStyleLink link)
|
|
|
|
|
{
|
|
|
|
|
switch (link) {
|
2015-02-03 23:46:35 +02:00
|
|
|
case TabSettingsWidget::CppLink:
|
2021-08-30 10:58:08 +02:00
|
|
|
Core::ICore::showOptionsDialog(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID);
|
2013-04-04 11:17:13 +02:00
|
|
|
break;
|
2015-02-03 23:46:35 +02:00
|
|
|
case TabSettingsWidget::QtQuickLink:
|
2015-02-23 11:07:38 +01:00
|
|
|
Core::ICore::showOptionsDialog(QmlJSTools::Constants::QML_JS_CODE_STYLE_SETTINGS_ID);
|
2013-04-04 11:17:13 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-21 15:44:41 +01:00
|
|
|
|
|
|
|
|
} // namespace TextEditor
|