forked from qt-creator/qt-creator
Nim: Aspectify NimSettings
Change-Id: I3954bec762fb3f5d3426663108ff493f140f1b5e Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Filippo Cucchetto <filippocucchetto@gmail.com>
This commit is contained in:
@@ -28,8 +28,6 @@ add_qtc_plugin(Nim
|
||||
settings/nimcodestylepreferenceswidget.cpp settings/nimcodestylepreferenceswidget.h settings/nimcodestylepreferenceswidget.ui
|
||||
settings/nimcodestylesettingspage.cpp settings/nimcodestylesettingspage.h
|
||||
settings/nimsettings.cpp settings/nimsettings.h
|
||||
settings/nimtoolssettingspage.cpp settings/nimtoolssettingspage.h
|
||||
settings/nimtoolssettingswidget.ui
|
||||
suggest/client.cpp suggest/client.h
|
||||
suggest/clientrequests.cpp suggest/clientrequests.h
|
||||
suggest/nimsuggest.cpp suggest/nimsuggest.h
|
||||
|
||||
@@ -35,7 +35,6 @@ HEADERS += \
|
||||
settings/nimcodestylepreferencesfactory.h \
|
||||
settings/nimsettings.h \
|
||||
settings/nimcodestylepreferenceswidget.h \
|
||||
settings/nimtoolssettingspage.h \
|
||||
project/nimtoolchain.h \
|
||||
project/nimtoolchainfactory.h \
|
||||
suggest/client.h \
|
||||
@@ -71,7 +70,6 @@ SOURCES += \
|
||||
settings/nimcodestylepreferencesfactory.cpp \
|
||||
settings/nimsettings.cpp \
|
||||
settings/nimcodestylepreferenceswidget.cpp \
|
||||
settings/nimtoolssettingspage.cpp \
|
||||
project/nimtoolchain.cpp \
|
||||
project/nimtoolchainfactory.cpp \
|
||||
suggest/client.cpp \
|
||||
@@ -81,5 +79,4 @@ SOURCES += \
|
||||
suggest/server.cpp
|
||||
|
||||
FORMS += \
|
||||
settings/nimcodestylepreferenceswidget.ui \
|
||||
settings/nimtoolssettingswidget.ui
|
||||
settings/nimcodestylepreferenceswidget.ui
|
||||
|
||||
@@ -63,7 +63,6 @@ QtcPlugin {
|
||||
"nimcodestylepreferenceswidget.h", "nimcodestylepreferenceswidget.cpp", "nimcodestylepreferenceswidget.ui",
|
||||
"nimcodestylesettingspage.h", "nimcodestylesettingspage.cpp",
|
||||
"nimsettings.h", "nimsettings.cpp",
|
||||
"nimtoolssettingspage.h", "nimtoolssettingspage.cpp", "nimtoolssettingswidget.ui"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -106,9 +106,5 @@ const char C_NIM_SCRIPT_MIMETYPE[] = "text/x-nim-script";
|
||||
const char C_NIM_MIME_ICON[] = "text-x-nim";
|
||||
const char C_NIM_PROJECT_MIMETYPE[] = "text/x-nim-project";
|
||||
|
||||
const char C_NIM_SETTINGS_GROUP[] = "Nim";
|
||||
const char C_NIM_SETTINGS_NIMSUGGEST_GROUP[] = "NimSuggest";
|
||||
const char C_NIM_SETTINGS_COMMAND[] = "Command";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "project/nimbletaskstep.h"
|
||||
#include "settings/nimcodestylepreferencesfactory.h"
|
||||
#include "settings/nimcodestylesettingspage.h"
|
||||
#include "settings/nimtoolssettingspage.h"
|
||||
#include "settings/nimsettings.h"
|
||||
#include "suggest/nimsuggestcache.h"
|
||||
|
||||
@@ -61,10 +60,9 @@ class NimPluginPrivate
|
||||
{
|
||||
public:
|
||||
NimPluginPrivate()
|
||||
: toolsSettingsPage(&settings)
|
||||
{
|
||||
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath());
|
||||
QObject::connect(&settings, &NimSettings::nimSuggestPathChanged,
|
||||
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.value());
|
||||
QObject::connect(&settings.nimSuggestPath, &StringAspect::valueChanged,
|
||||
&Suggest::NimSuggestCache::instance(),
|
||||
&Suggest::NimSuggestCache::setExecutablePath);
|
||||
}
|
||||
@@ -96,7 +94,7 @@ public:
|
||||
NimCompilerBuildStepFactory buildStepFactory;
|
||||
NimCompilerCleanStepFactory cleanStepFactory;
|
||||
NimCodeStyleSettingsPage codeStyleSettingsPage;
|
||||
NimToolsSettingsPage toolsSettingsPage;
|
||||
NimToolsSettingsPage toolsSettingsPage{&settings};
|
||||
NimCodeStylePreferencesFactory codeStylePreferencesPage;
|
||||
NimToolChainFactory toolChainFactory;
|
||||
};
|
||||
|
||||
@@ -28,24 +28,37 @@
|
||||
|
||||
#include "../nimconstants.h"
|
||||
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/codestylepool.h>
|
||||
#include <texteditor/simplecodestylepreferences.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <texteditor/codestylepool.h>
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
#include <texteditor/simplecodestylepreferences.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
using namespace TextEditor;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Nim {
|
||||
|
||||
static SimpleCodeStylePreferences *m_globalCodeStyle = nullptr;
|
||||
|
||||
NimSettings::NimSettings(QObject *parent)
|
||||
: QObject(parent)
|
||||
NimSettings::NimSettings()
|
||||
{
|
||||
setAutoApply(false);
|
||||
setSettingsGroups("Nim", "NimSuggest");
|
||||
|
||||
InitializeCodeStyleSettings();
|
||||
InitializeNimSuggestSettings();
|
||||
|
||||
registerAspect(&nimSuggestPath);
|
||||
nimSuggestPath.setSettingsKey("Command");
|
||||
nimSuggestPath.setDisplayStyle(StringAspect::PathChooserDisplay);
|
||||
nimSuggestPath.setExpectedKind(PathChooser::ExistingCommand);
|
||||
nimSuggestPath.setLabelText(tr("Path:"));
|
||||
|
||||
readSettings(Core::ICore::settings());
|
||||
}
|
||||
|
||||
NimSettings::~NimSettings()
|
||||
@@ -53,30 +66,6 @@ NimSettings::~NimSettings()
|
||||
TerminateCodeStyleSettings();
|
||||
}
|
||||
|
||||
QString NimSettings::nimSuggestPath() const
|
||||
{
|
||||
return m_nimSuggestPath;
|
||||
}
|
||||
|
||||
void NimSettings::setNimSuggestPath(const QString &path)
|
||||
{
|
||||
if (m_nimSuggestPath == path)
|
||||
return;
|
||||
m_nimSuggestPath = path;
|
||||
emit nimSuggestPathChanged(path);
|
||||
}
|
||||
|
||||
void NimSettings::save()
|
||||
{
|
||||
QSettings *s = Core::ICore::settings();
|
||||
s->beginGroup(Constants::C_NIM_SETTINGS_GROUP);
|
||||
s->beginGroup(Constants::C_NIM_SETTINGS_NIMSUGGEST_GROUP);
|
||||
s->setValue(QString::fromStdString(Constants::C_NIM_SETTINGS_COMMAND), nimSuggestPath());
|
||||
s->endGroup();
|
||||
s->endGroup();
|
||||
s->sync();
|
||||
}
|
||||
|
||||
SimpleCodeStylePreferences *NimSettings::globalCodeStyle()
|
||||
{
|
||||
return m_globalCodeStyle;
|
||||
@@ -127,17 +116,6 @@ void NimSettings::InitializeCodeStyleSettings()
|
||||
Nim::Constants::C_NIMLANGUAGE_ID);
|
||||
}
|
||||
|
||||
void NimSettings::InitializeNimSuggestSettings()
|
||||
{
|
||||
QSettings *s = Core::ICore::settings();
|
||||
s->beginGroup(Constants::C_NIM_SETTINGS_GROUP);
|
||||
s->beginGroup(Constants::C_NIM_SETTINGS_NIMSUGGEST_GROUP);
|
||||
setNimSuggestPath(s->value(QString::fromStdString(Constants::C_NIM_SETTINGS_COMMAND),
|
||||
QString()).toString());
|
||||
s->endGroup();
|
||||
s->endGroup();
|
||||
}
|
||||
|
||||
void NimSettings::TerminateCodeStyleSettings()
|
||||
{
|
||||
TextEditorSettings::unregisterCodeStyle(Nim::Constants::C_NIMLANGUAGE_ID);
|
||||
@@ -148,4 +126,28 @@ void NimSettings::TerminateCodeStyleSettings()
|
||||
m_globalCodeStyle = nullptr;
|
||||
}
|
||||
|
||||
|
||||
// NimToolSettingsPage
|
||||
|
||||
NimToolsSettingsPage::NimToolsSettingsPage(NimSettings *settings)
|
||||
{
|
||||
setId(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_ID);
|
||||
setDisplayName(NimSettings::tr(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_DISPLAY));
|
||||
setCategory(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_CATEGORY);
|
||||
setDisplayCategory(NimSettings::tr("Nim"));
|
||||
setCategoryIconPath(":/nim/images/settingscategory_nim.png");
|
||||
setSettings(settings);
|
||||
|
||||
setLayouter([settings](QWidget *widget) {
|
||||
using namespace Layouting;
|
||||
Column {
|
||||
Group {
|
||||
Title("Nimsuggest"),
|
||||
settings->nimSuggestPath
|
||||
},
|
||||
Stretch()
|
||||
}.attachTo(widget);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Nim
|
||||
|
||||
@@ -25,38 +25,34 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <utils/aspects.h>
|
||||
|
||||
namespace TextEditor { class SimpleCodeStylePreferences; }
|
||||
|
||||
namespace Nim {
|
||||
|
||||
class NimSettings : public QObject
|
||||
class NimSettings : public QObject, public Utils::AspectContainer
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_TR_FUNCTIONS(Nim::NimSettings)
|
||||
|
||||
public:
|
||||
NimSettings(QObject *parent = nullptr);
|
||||
~NimSettings() override;
|
||||
NimSettings();
|
||||
~NimSettings();
|
||||
|
||||
QString nimSuggestPath() const;
|
||||
void setNimSuggestPath(const QString &path);
|
||||
|
||||
void save();
|
||||
Utils::StringAspect nimSuggestPath;
|
||||
|
||||
static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();
|
||||
|
||||
signals:
|
||||
void nimSuggestPathChanged(QString path);
|
||||
|
||||
private:
|
||||
void InitializeCodeStyleSettings();
|
||||
void TerminateCodeStyleSettings();
|
||||
};
|
||||
|
||||
void InitializeNimSuggestSettings();
|
||||
void TerminateNimSuggestSettings();
|
||||
|
||||
QString m_nimSuggestPath;
|
||||
class NimToolsSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
explicit NimToolsSettingsPage(NimSettings *settings);
|
||||
};
|
||||
|
||||
} // namespace Nim
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
||||
** Contact: http://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 "nimtoolssettingspage.h"
|
||||
#include "nimconstants.h"
|
||||
#include "nimsettings.h"
|
||||
#include "ui_nimtoolssettingswidget.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
namespace Nim {
|
||||
|
||||
NimToolsSettingsWidget::NimToolsSettingsWidget() : ui(new Ui::NimToolsSettingsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->pathWidget->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
}
|
||||
|
||||
NimToolsSettingsWidget::~NimToolsSettingsWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString NimToolsSettingsWidget::command() const
|
||||
{
|
||||
return ui->pathWidget->filePath().toString();
|
||||
}
|
||||
|
||||
void NimToolsSettingsWidget::setCommand(const QString &filename)
|
||||
{
|
||||
ui->pathWidget->setPath(filename);
|
||||
}
|
||||
|
||||
NimToolsSettingsPage::NimToolsSettingsPage(NimSettings *settings)
|
||||
: m_settings(settings)
|
||||
{
|
||||
setId(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_ID);
|
||||
setDisplayName(NimToolsSettingsWidget::tr(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_DISPLAY));
|
||||
setCategory(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_CATEGORY);
|
||||
setDisplayCategory(NimToolsSettingsWidget::tr("Nim"));
|
||||
setCategoryIconPath(":/nim/images/settingscategory_nim.png");
|
||||
}
|
||||
|
||||
NimToolsSettingsPage::~NimToolsSettingsPage() = default;
|
||||
|
||||
QWidget *NimToolsSettingsPage::widget()
|
||||
{
|
||||
if (!m_widget)
|
||||
m_widget.reset(new NimToolsSettingsWidget);
|
||||
m_widget->setCommand(m_settings->nimSuggestPath());
|
||||
return m_widget.get();
|
||||
}
|
||||
|
||||
void NimToolsSettingsPage::apply()
|
||||
{
|
||||
m_settings->setNimSuggestPath(m_widget->command());
|
||||
m_settings->save();
|
||||
}
|
||||
|
||||
void NimToolsSettingsPage::finish()
|
||||
{
|
||||
m_widget.reset();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
||||
** Contact: http://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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Nim {
|
||||
|
||||
class NimSettings;
|
||||
|
||||
namespace Ui { class NimToolsSettingsWidget; }
|
||||
|
||||
class NimToolsSettingsWidget : public QWidget
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Nim::ToolSettingsPage)
|
||||
|
||||
public:
|
||||
NimToolsSettingsWidget();
|
||||
|
||||
~NimToolsSettingsWidget();
|
||||
|
||||
QString command() const;
|
||||
void setCommand(const QString &filename);
|
||||
|
||||
private:
|
||||
Ui::NimToolsSettingsWidget *ui;
|
||||
};
|
||||
|
||||
class NimToolsSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
explicit NimToolsSettingsPage(NimSettings *settings);
|
||||
|
||||
~NimToolsSettingsPage();
|
||||
|
||||
QWidget *widget() final;
|
||||
void apply() final;
|
||||
void finish() final;
|
||||
|
||||
private:
|
||||
std::unique_ptr<NimToolsSettingsWidget> m_widget;
|
||||
NimSettings *m_settings = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Nim::NimToolsSettingsWidget</class>
|
||||
<widget class="QWidget" name="Nim::NimToolsSettingsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Nimsuggest</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="pathLabel">
|
||||
<property name="text">
|
||||
<string>Path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Utils::PathChooser" name="pathWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
<slots>
|
||||
<signal>editingFinished()</signal>
|
||||
<signal>browsingFinished()</signal>
|
||||
</slots>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user