2016-06-18 14:15:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmljseditingsettingspage.h"
|
|
|
|
|
#include "qmljseditorconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
|
2019-07-18 14:17:25 +02:00
|
|
|
const char AUTO_FORMAT_ON_SAVE[] = "QmlJSEditor.AutoFormatOnSave";
|
|
|
|
|
const char AUTO_FORMAT_ONLY_CURRENT_PROJECT[] = "QmlJSEditor.AutoFormatOnlyCurrentProject";
|
|
|
|
|
const char QML_CONTEXTPANE_KEY[] = "QmlJSEditor.ContextPaneEnabled";
|
|
|
|
|
const char QML_CONTEXTPANEPIN_KEY[] = "QmlJSEditor.ContextPanePinned";
|
2016-06-18 14:15:02 +02:00
|
|
|
|
|
|
|
|
using namespace QmlJSEditor;
|
|
|
|
|
using namespace QmlJSEditor::Internal;
|
|
|
|
|
|
|
|
|
|
QmlJsEditingSettings::QmlJsEditingSettings()
|
|
|
|
|
: m_enableContextPane(false),
|
|
|
|
|
m_pinContextPane(false),
|
|
|
|
|
m_autoFormatOnSave(false),
|
|
|
|
|
m_autoFormatOnlyCurrentProject(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::set()
|
|
|
|
|
{
|
|
|
|
|
if (get() != *this)
|
|
|
|
|
toSettings(Core::ICore::settings());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::fromSettings(QSettings *settings)
|
|
|
|
|
{
|
2019-07-18 14:17:25 +02:00
|
|
|
settings->beginGroup(QmlJSEditor::Constants::SETTINGS_CATEGORY_QML);
|
|
|
|
|
m_enableContextPane = settings->value(QML_CONTEXTPANE_KEY, QVariant(false)).toBool();
|
|
|
|
|
m_pinContextPane = settings->value(QML_CONTEXTPANEPIN_KEY, QVariant(false)).toBool();
|
|
|
|
|
m_autoFormatOnSave = settings->value(AUTO_FORMAT_ON_SAVE, QVariant(false)).toBool();
|
|
|
|
|
m_autoFormatOnlyCurrentProject
|
|
|
|
|
= settings->value(AUTO_FORMAT_ONLY_CURRENT_PROJECT, QVariant(false)).toBool();
|
2016-06-18 14:15:02 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::toSettings(QSettings *settings) const
|
|
|
|
|
{
|
2019-07-18 14:17:25 +02:00
|
|
|
settings->beginGroup(QmlJSEditor::Constants::SETTINGS_CATEGORY_QML);
|
|
|
|
|
settings->setValue(QML_CONTEXTPANE_KEY, m_enableContextPane);
|
|
|
|
|
settings->setValue(QML_CONTEXTPANEPIN_KEY, m_pinContextPane);
|
|
|
|
|
settings->setValue(AUTO_FORMAT_ON_SAVE, m_autoFormatOnSave);
|
|
|
|
|
settings->setValue(AUTO_FORMAT_ONLY_CURRENT_PROJECT, m_autoFormatOnlyCurrentProject);
|
2016-06-18 14:15:02 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJsEditingSettings::equals(const QmlJsEditingSettings &other) const
|
|
|
|
|
{
|
|
|
|
|
return m_enableContextPane == other.m_enableContextPane
|
|
|
|
|
&& m_pinContextPane == other.m_pinContextPane
|
|
|
|
|
&& m_autoFormatOnSave == other.m_autoFormatOnSave
|
|
|
|
|
&& m_autoFormatOnlyCurrentProject == other.m_autoFormatOnlyCurrentProject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJsEditingSettings::enableContextPane() const
|
|
|
|
|
{
|
|
|
|
|
return m_enableContextPane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::setEnableContextPane(const bool enableContextPane)
|
|
|
|
|
{
|
|
|
|
|
m_enableContextPane = enableContextPane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJsEditingSettings::pinContextPane() const
|
|
|
|
|
{
|
|
|
|
|
return m_pinContextPane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::setPinContextPane(const bool pinContextPane)
|
|
|
|
|
{
|
|
|
|
|
m_pinContextPane = pinContextPane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJsEditingSettings::autoFormatOnSave() const
|
|
|
|
|
{
|
|
|
|
|
return m_autoFormatOnSave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::setAutoFormatOnSave(const bool autoFormatOnSave)
|
|
|
|
|
{
|
|
|
|
|
m_autoFormatOnSave = autoFormatOnSave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJsEditingSettings::autoFormatOnlyCurrentProject() const
|
|
|
|
|
{
|
|
|
|
|
return m_autoFormatOnlyCurrentProject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsEditingSettings::setAutoFormatOnlyCurrentProject(const bool autoFormatOnlyCurrentProject)
|
|
|
|
|
{
|
|
|
|
|
m_autoFormatOnlyCurrentProject = autoFormatOnlyCurrentProject;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 16:11:51 +01:00
|
|
|
class QmlJsEditingSettingsPageWidget final : public Core::IOptionsPageWidget
|
2016-06-18 14:15:02 +02:00
|
|
|
{
|
2020-01-28 16:11:51 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(QmlDesigner::Internal::QmlJsEditingSettingsPage)
|
2016-06-18 14:15:02 +02:00
|
|
|
|
2020-01-28 16:11:51 +01:00
|
|
|
public:
|
|
|
|
|
QmlJsEditingSettingsPageWidget()
|
|
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
auto s = QmlJsEditingSettings::get();
|
|
|
|
|
m_ui.textEditHelperCheckBox->setChecked(s.enableContextPane());
|
|
|
|
|
m_ui.textEditHelperCheckBoxPin->setChecked(s.pinContextPane());
|
|
|
|
|
m_ui.autoFormatOnSave->setChecked(s.autoFormatOnSave());
|
|
|
|
|
m_ui.autoFormatOnlyCurrentProject->setChecked(s.autoFormatOnlyCurrentProject());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void apply() final
|
|
|
|
|
{
|
|
|
|
|
QmlJsEditingSettings s;
|
|
|
|
|
s.setEnableContextPane(m_ui.textEditHelperCheckBox->isChecked());
|
|
|
|
|
s.setPinContextPane(m_ui.textEditHelperCheckBoxPin->isChecked());
|
|
|
|
|
s.setAutoFormatOnSave(m_ui.autoFormatOnSave->isChecked());
|
|
|
|
|
s.setAutoFormatOnlyCurrentProject(m_ui.autoFormatOnlyCurrentProject->isChecked());
|
|
|
|
|
s.set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Ui::QmlJsEditingSettingsPage m_ui;
|
|
|
|
|
};
|
2016-06-18 14:15:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
QmlJsEditingSettings QmlJsEditingSettings::get()
|
|
|
|
|
{
|
|
|
|
|
QmlJsEditingSettings settings;
|
|
|
|
|
settings.fromSettings(Core::ICore::settings());
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 02:45:30 +01:00
|
|
|
QmlJsEditingSettingsPage::QmlJsEditingSettingsPage()
|
2016-06-18 14:15:02 +02:00
|
|
|
{
|
|
|
|
|
setId("C.QmlJsEditing");
|
2020-01-28 16:11:51 +01:00
|
|
|
setDisplayName(QmlJsEditingSettingsPageWidget::tr("QML/JS Editing"));
|
2016-06-18 14:15:02 +02:00
|
|
|
setCategory(Constants::SETTINGS_CATEGORY_QML);
|
2020-01-28 16:11:51 +01:00
|
|
|
setWidgetCreator([] { return new QmlJsEditingSettingsPageWidget; });
|
2016-06-18 14:15:02 +02:00
|
|
|
}
|
|
|
|
|
|