/
settings.cc
145 lines (119 loc) · 4.83 KB
/
settings.cc
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "settings.h"
#include "printutils.h"
#include <boost/assign/std/vector.hpp>
using namespace boost::assign; // bring 'operator+=()' into scope
namespace Settings {
static std::list<SettingsEntry *> entries;
SettingsEntry::SettingsEntry(const std::string category, const std::string name, const Value range, const Value def)
: _category(category), _name(name), _value(def), _range(range), _default(def)
{
entries.push_back(this);
}
SettingsEntry::~SettingsEntry()
{
}
const std::string & SettingsEntry::category() const
{
return _category;
}
const std::string & SettingsEntry::name() const
{
return _name;
}
const Value & SettingsEntry::defaultValue() const
{
return _default;
}
const Value & SettingsEntry::range() const
{
return _range;
}
bool SettingsEntry::is_default() const
{
return _value == _default;
}
static Value value(std::string s1, std::string s2) {
Value::VectorType v;
v += ValuePtr(s1), ValuePtr(s2);
return v;
}
static Value values(std::string s1, std::string s1disp, std::string s2, std::string s2disp) {
Value::VectorType v;
v += ValuePtr(value(s1, s1disp)), ValuePtr(value(s2, s2disp));
return v;
}
static Value values(std::string s1, std::string s1disp, std::string s2, std::string s2disp, std::string s3, std::string s3disp) {
Value::VectorType v;
v += ValuePtr(value(s1, s1disp)), ValuePtr(value(s2, s2disp)), ValuePtr(value(s3, s3disp));
return v;
}
static Value values(std::string s1, std::string s1disp, std::string s2, std::string s2disp, std::string s3, std::string s3disp, std::string s4, std::string s4disp) {
Value::VectorType v;
v += ValuePtr(value(s1, s1disp)), ValuePtr(value(s2, s2disp)), ValuePtr(value(s3, s3disp)), ValuePtr(value(s4, s4disp));
return v;
}
Settings *Settings::inst(bool erase)
{
static Settings *instance = new Settings;
if (erase) {
delete instance;
instance = NULL;
}
return instance;
}
Settings::Settings()
{
}
Settings::~Settings()
{
}
void Settings::visit(Visitor& visitor)
{
for (std::list<SettingsEntry *>::iterator it = entries.begin();it != entries.end();it++) {
visitor.handle(*(*it));
}
}
const Value &Settings::defaultValue(const SettingsEntry& entry)
{
return entry._default;
}
const Value &Settings::get(const SettingsEntry& entry)
{
return entry._value;
}
void Settings::set(SettingsEntry& entry, const Value &val)
{
entry._value = val;
}
Visitor::Visitor()
{
}
Visitor::~Visitor()
{
}
/*
* Supported settings entry types are: bool / int and string selection
*
* String selection is used to handle comboboxes and has two values
* per config selection. The first value is used internally for both
* finding the combobox selection and for storing the value in the
* external settings file. The second value is the display value that
* can be translated.
*/
SettingsEntry Settings::showWarningsIn3dView("3dview", "showWarningsIn3dView", Value(true), Value(true));
SettingsEntry Settings::indentationWidth("editor", "indentationWidth", Value(RangeType(1, 16)), Value(4));
SettingsEntry Settings::tabWidth("editor", "tabWidth", Value(RangeType(1, 16)), Value(4));
SettingsEntry Settings::lineWrap("editor", "lineWrap", values("None", _("None"), "Char", _("Wrap at character boundaries"), "Word", _("Wrap at word boundaries")), Value("Word"));
SettingsEntry Settings::lineWrapIndentationStyle("editor", "lineWrapIndentationStyle", values("Fixed", _("Fixed"), "Same", _("Same"), "Indented", _("Indented")), Value("Fixed"));
SettingsEntry Settings::lineWrapIndentation("editor", "lineWrapIndentation", Value(RangeType(0, 999)), Value(4));
SettingsEntry Settings::lineWrapVisualizationBegin("editor", "lineWrapVisualizationBegin", values("None", _("None"), "Text", _("Text"), "Border", _("Border"), "Margin", _("Margin")), Value("None"));
SettingsEntry Settings::lineWrapVisualizationEnd("editor", "lineWrapVisualizationEnd", values("None", _("None"), "Text", _("Text"), "Border", _("Border"), "Margin", _("Margin")), Value("Border"));
SettingsEntry Settings::showWhitespace("editor", "showWhitespaces", values("Never", _("Never"), "Always", _("Always"), "AfterIndentation", _("After indentation")), Value("Never"));
SettingsEntry Settings::showWhitespaceSize("editor", "showWhitespacesSize", Value(RangeType(1, 16)), Value(2));
SettingsEntry Settings::autoIndent("editor", "autoIndent", Value(true), Value(true));
SettingsEntry Settings::indentStyle("editor", "indentStyle", values("Spaces", _("Spaces"), "Tabs", _("Tabs")), Value("Spaces"));
SettingsEntry Settings::tabKeyFunction("editor", "tabKeyFunction", values("Indent", _("Indent"), "InsertTab", _("Insert Tab")), Value("Indent"));
SettingsEntry Settings::highlightCurrentLine("editor", "highlightCurrentLine", Value(true), Value(true));
SettingsEntry Settings::enableBraceMatching("editor", "enableBraceMatching", Value(true), Value(true));
SettingsEntry Settings::enableLineNumbers("editor", "enableLineNumbers", Value(true), Value(true));
}