Files
qt-creator/src/plugins/qmljseditor/qmljseditingsettingspage.cpp

172 lines
5.7 KiB
C++
Raw Normal View History

/****************************************************************************
**
** 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>
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";
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)
{
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();
settings->endGroup();
}
void QmlJsEditingSettings::toSettings(QSettings *settings) const
{
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);
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;
}
class QmlJsEditingSettingsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(QmlDesigner::Internal::QmlJsEditingSettingsPage)
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;
};
QmlJsEditingSettings QmlJsEditingSettings::get()
{
QmlJsEditingSettings settings;
settings.fromSettings(Core::ICore::settings());
return settings;
}
QmlJsEditingSettingsPage::QmlJsEditingSettingsPage()
{
setId("C.QmlJsEditing");
setDisplayName(QmlJsEditingSettingsPageWidget::tr("QML/JS Editing"));
setCategory(Constants::SETTINGS_CATEGORY_QML);
setWidgetCreator([] { return new QmlJsEditingSettingsPageWidget; });
}