blob: d99ae2974b83b0ca8ba817a0225acd534b84d301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "nimsettings.h"
#include "../nimconstants.h"
#include "../nimtr.h"
#include "nimcodestylepreferencesfactory.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()
{
setSettingsGroups("Nim", "NimSuggest");
setId(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_ID);
setDisplayName(Tr::tr("Tools"));
setCategory(Nim::Constants::C_NIMTOOLSSETTINGSPAGE_CATEGORY);
setDisplayCategory(Tr::tr("Nim"));
setCategoryIconPath(":/nim/images/settingscategory_nim.png");
setLayouter([this](QWidget *widget) {
using namespace Layouting;
Column {
Group {
title("Nimsuggest"),
Column { nimSuggestPath }
},
st
}.attachTo(widget);
});
// code style factory
auto factory = new NimCodeStylePreferencesFactory();
TextEditorSettings::registerCodeStyleFactory(factory);
// code style pool
auto pool = new CodeStylePool(factory, this);
TextEditorSettings::registerCodeStylePool(Nim::Constants::C_NIMLANGUAGE_ID, pool);
m_globalCodeStyle = new SimpleCodeStylePreferences();
m_globalCodeStyle->setDelegatingPool(pool);
m_globalCodeStyle->setDisplayName(Tr::tr("Global", "Settings"));
m_globalCodeStyle->setId(Nim::Constants::C_NIMGLOBALCODESTYLE_ID);
pool->addCodeStyle(m_globalCodeStyle);
TextEditorSettings::registerCodeStyle(Nim::Constants::C_NIMLANGUAGE_ID, m_globalCodeStyle);
auto nimCodeStyle = new SimpleCodeStylePreferences();
nimCodeStyle->setId("nim");
nimCodeStyle->setDisplayName(Tr::tr("Nim"));
nimCodeStyle->setReadOnly(true);
TabSettings nimTabSettings;
nimTabSettings.m_tabPolicy = TabSettings::SpacesOnlyTabPolicy;
nimTabSettings.m_tabSize = 2;
nimTabSettings.m_indentSize = 2;
nimTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent;
nimCodeStyle->setTabSettings(nimTabSettings);
pool->addCodeStyle(nimCodeStyle);
m_globalCodeStyle->setCurrentDelegate(nimCodeStyle);
pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool)
QSettings *s = Core::ICore::settings();
m_globalCodeStyle->fromSettings(QLatin1String(Nim::Constants::C_NIMLANGUAGE_ID), s);
TextEditorSettings::registerMimeTypeForLanguageId(Nim::Constants::C_NIM_MIMETYPE,
Nim::Constants::C_NIMLANGUAGE_ID);
TextEditorSettings::registerMimeTypeForLanguageId(Nim::Constants::C_NIM_SCRIPT_MIMETYPE,
Nim::Constants::C_NIMLANGUAGE_ID);
registerAspect(&nimSuggestPath);
nimSuggestPath.setSettingsKey("Command");
nimSuggestPath.setDisplayStyle(StringAspect::PathChooserDisplay);
nimSuggestPath.setExpectedKind(PathChooser::ExistingCommand);
nimSuggestPath.setLabelText(Tr::tr("Path:"));
readSettings(Core::ICore::settings());
}
NimSettings::~NimSettings()
{
TextEditorSettings::unregisterCodeStyle(Nim::Constants::C_NIMLANGUAGE_ID);
TextEditorSettings::unregisterCodeStylePool(Nim::Constants::C_NIMLANGUAGE_ID);
TextEditorSettings::unregisterCodeStyleFactory(Nim::Constants::C_NIMLANGUAGE_ID);
delete m_globalCodeStyle;
m_globalCodeStyle = nullptr;
}
SimpleCodeStylePreferences *NimSettings::globalCodeStyle()
{
return m_globalCodeStyle;
}
} // namespace Nim
|