2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-06 11:58:06 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-07-06 11:58:06 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-06 11:58:06 +02: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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-07-06 11:58:06 +02:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-07-06 11:58:06 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-06 11:58:06 +02:00
|
|
|
|
2011-05-25 08:50:01 +02:00
|
|
|
#include "qmljstoolssettings.h"
|
|
|
|
#include "qmljstoolsconstants.h"
|
2011-08-16 10:45:23 +02:00
|
|
|
#include "qmljscodestylepreferencesfactory.h"
|
2011-05-25 08:50:01 +02:00
|
|
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/simplecodestylepreferences.h>
|
|
|
|
#include <texteditor/tabsettings.h>
|
|
|
|
#include <texteditor/codestylepool.h>
|
2011-05-25 08:50:01 +02:00
|
|
|
|
2011-11-24 11:48:00 +01:00
|
|
|
#include <utils/settingsutils.h>
|
2011-05-25 08:50:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
#include <coreplugin/icore.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2011-05-25 08:50:01 +02:00
|
|
|
|
2012-09-24 12:06:49 +02:00
|
|
|
using namespace TextEditor;
|
2011-05-25 08:50:01 +02:00
|
|
|
|
|
|
|
namespace QmlJSTools {
|
|
|
|
|
2012-09-24 12:06:49 +02:00
|
|
|
const char idKey[] = "QmlJSGlobal";
|
2011-05-25 08:50:01 +02:00
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
static SimpleCodeStylePreferences *m_globalCodeStyle = 0;
|
2011-05-25 08:50:01 +02:00
|
|
|
|
|
|
|
QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
2012-09-24 12:06:49 +02:00
|
|
|
QTC_ASSERT(!m_globalCodeStyle, return);
|
2011-05-25 08:50:01 +02:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
// code style factory
|
2012-09-24 12:06:49 +02:00
|
|
|
ICodeStylePreferencesFactory *factory = new QmlJSCodeStylePreferencesFactory();
|
2013-09-19 17:59:27 +02:00
|
|
|
TextEditorSettings::registerCodeStyleFactory(factory);
|
2011-08-16 10:45:23 +02:00
|
|
|
|
|
|
|
// code style pool
|
2012-09-24 12:06:49 +02:00
|
|
|
CodeStylePool *pool = new CodeStylePool(factory, this);
|
2013-09-19 17:59:27 +02:00
|
|
|
TextEditorSettings::registerCodeStylePool(Constants::QML_JS_SETTINGS_ID, pool);
|
2011-08-16 10:45:23 +02:00
|
|
|
|
|
|
|
// global code style settings
|
2012-09-24 12:06:49 +02:00
|
|
|
m_globalCodeStyle = new SimpleCodeStylePreferences(this);
|
|
|
|
m_globalCodeStyle->setDelegatingPool(pool);
|
|
|
|
m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
|
2013-09-20 10:35:16 +02:00
|
|
|
m_globalCodeStyle->setId(idKey);
|
2012-09-24 12:06:49 +02:00
|
|
|
pool->addCodeStyle(m_globalCodeStyle);
|
2013-09-19 17:59:27 +02:00
|
|
|
TextEditorSettings::registerCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID, m_globalCodeStyle);
|
2011-08-16 10:45:23 +02:00
|
|
|
|
|
|
|
// built-in settings
|
|
|
|
// Qt style
|
2012-09-24 12:06:49 +02:00
|
|
|
SimpleCodeStylePreferences *qtCodeStyle = new SimpleCodeStylePreferences();
|
2013-09-20 10:35:16 +02:00
|
|
|
qtCodeStyle->setId("qt");
|
2011-08-16 10:45:23 +02:00
|
|
|
qtCodeStyle->setDisplayName(tr("Qt"));
|
|
|
|
qtCodeStyle->setReadOnly(true);
|
|
|
|
TabSettings qtTabSettings;
|
|
|
|
qtTabSettings.m_tabPolicy = TabSettings::SpacesOnlyTabPolicy;
|
|
|
|
qtTabSettings.m_tabSize = 4;
|
|
|
|
qtTabSettings.m_indentSize = 4;
|
|
|
|
qtTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent;
|
|
|
|
qtCodeStyle->setTabSettings(qtTabSettings);
|
|
|
|
pool->addCodeStyle(qtCodeStyle);
|
|
|
|
|
|
|
|
// default delegate for global preferences
|
2012-09-24 12:06:49 +02:00
|
|
|
m_globalCodeStyle->setCurrentDelegate(qtCodeStyle);
|
2011-08-16 10:45:23 +02:00
|
|
|
|
|
|
|
pool->loadCustomCodeStyles();
|
|
|
|
|
|
|
|
// load global settings (after built-in settings are added to the pool)
|
2012-08-09 12:58:51 +03:00
|
|
|
QSettings *s = Core::ICore::settings();
|
2012-11-21 22:43:22 +02:00
|
|
|
m_globalCodeStyle->fromSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
2012-08-09 12:58:51 +03:00
|
|
|
|
|
|
|
// legacy handling start (Qt Creator Version < 2.4)
|
|
|
|
const bool legacyTransformed =
|
|
|
|
s->value(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), false).toBool();
|
|
|
|
|
|
|
|
if (!legacyTransformed) {
|
|
|
|
// creator 2.4 didn't mark yet the transformation (first run of creator 2.4)
|
|
|
|
|
|
|
|
// we need to transform the settings only if at least one from
|
|
|
|
// below settings was already written - otherwise we use
|
|
|
|
// defaults like it would be the first run of creator 2.4 without stored settings
|
|
|
|
const QStringList groups = s->childGroups();
|
|
|
|
const bool needTransform = groups.contains(QLatin1String("textTabPreferences")) ||
|
|
|
|
groups.contains(QLatin1String("QmlJSTabPreferences"));
|
|
|
|
|
|
|
|
if (needTransform) {
|
|
|
|
const QString currentFallback = s->value(QLatin1String("QmlJSTabPreferences/CurrentFallback")).toString();
|
|
|
|
TabSettings legacyTabSettings;
|
|
|
|
if (currentFallback == QLatin1String("QmlJSGlobal")) {
|
|
|
|
// no delegate, global overwritten
|
|
|
|
Utils::fromSettings(QLatin1String("QmlJSTabPreferences"),
|
|
|
|
QString(), s, &legacyTabSettings);
|
|
|
|
} else {
|
|
|
|
// delegating to global
|
2013-09-19 17:59:27 +02:00
|
|
|
legacyTabSettings = TextEditorSettings::codeStyle()->currentTabSettings();
|
2011-11-24 11:48:00 +01:00
|
|
|
}
|
2012-08-09 12:58:51 +03:00
|
|
|
|
|
|
|
// create custom code style out of old settings
|
2012-09-24 12:06:49 +02:00
|
|
|
ICodeStylePreferences *oldCreator = pool->createCodeStyle(
|
2013-09-20 10:35:16 +02:00
|
|
|
"legacy", legacyTabSettings, QVariant(), tr("Old Creator"));
|
2012-08-09 12:58:51 +03:00
|
|
|
|
|
|
|
// change the current delegate and save
|
2012-09-24 12:06:49 +02:00
|
|
|
m_globalCodeStyle->setCurrentDelegate(oldCreator);
|
2012-11-21 22:43:22 +02:00
|
|
|
m_globalCodeStyle->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
2011-11-24 11:48:00 +01:00
|
|
|
}
|
2012-08-09 12:58:51 +03:00
|
|
|
// mark old settings as transformed
|
|
|
|
s->setValue(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), true);
|
2011-11-24 11:48:00 +01:00
|
|
|
// legacy handling stop
|
2011-05-25 08:50:01 +02:00
|
|
|
}
|
2011-08-16 10:45:23 +02:00
|
|
|
|
|
|
|
// mimetypes to be handled
|
2013-09-19 18:43:48 +02:00
|
|
|
TextEditorSettings::registerMimeTypeForLanguageId(Constants::QML_MIMETYPE, Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::registerMimeTypeForLanguageId(Constants::QBS_MIMETYPE, Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::registerMimeTypeForLanguageId(Constants::QMLPROJECT_MIMETYPE, Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::registerMimeTypeForLanguageId(Constants::QMLTYPES_MIMETYPE, Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::registerMimeTypeForLanguageId(Constants::JS_MIMETYPE, Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::registerMimeTypeForLanguageId(Constants::JSON_MIMETYPE, Constants::QML_JS_SETTINGS_ID);
|
2011-05-25 08:50:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlJSToolsSettings::~QmlJSToolsSettings()
|
|
|
|
{
|
2013-09-19 17:59:27 +02:00
|
|
|
TextEditorSettings::unregisterCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::unregisterCodeStylePool(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
|
|
|
TextEditorSettings::unregisterCodeStyleFactory(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
2013-03-11 13:21:57 +01:00
|
|
|
|
2012-09-24 12:06:49 +02:00
|
|
|
delete m_globalCodeStyle;
|
|
|
|
m_globalCodeStyle = 0;
|
2011-05-25 08:50:01 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 12:06:49 +02:00
|
|
|
SimpleCodeStylePreferences *QmlJSToolsSettings::globalCodeStyle()
|
2011-05-25 08:50:01 +02:00
|
|
|
{
|
2012-09-24 12:06:49 +02:00
|
|
|
return m_globalCodeStyle;
|
2011-05-25 08:50:01 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 12:06:49 +02:00
|
|
|
} // namespace QmlJSTools
|