NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
Options.h
Go to the documentation of this file.
1#ifndef OPTIONS_H
2#define OPTIONS_H
3
4#include <wx/wx.h>
5#include <wx/fileconf.h>
6#include <wx/tokenzr.h>
7
8#include <vector>
9
10#include "datastructures.h"
11#include "../kernel/core/settings.hpp"
12#include "../kernel/core/utils/stringtools.hpp"
13
14// copied from stc.h
15// PrintColourMode - force black text on white background for printing.
16#define wxSTC_PRINT_BLACKONWHITE 2
17
18// PrintColourMode - text stays coloured, but all background is forced to be white for printing.
19#define wxSTC_PRINT_COLOURONWHITE 3
20
27{
28 wxColour foreground;
29 wxColour background;
30 bool bold;
31 bool italics;
34
43 wxColour StrToColorNew(const wxString& colorstring) const
44 {
45 wxArrayString channels = wxStringTokenize(colorstring, ":");
46 return wxColour(StrToInt(channels[0].ToStdString()), StrToInt(channels[1].ToStdString()), StrToInt(channels[2].ToStdString()));
47 }
48
58 wxColour StrToColorOld(const wxString& colorstring) const
59 {
60 unsigned char channel_r = StrToInt(colorstring.substr(0,3).ToStdString());
61 unsigned char channel_g = StrToInt(colorstring.substr(3,3).ToStdString());
62 unsigned char channel_b = StrToInt(colorstring.substr(6,3).ToStdString());
63 return wxColour(channel_r, channel_g, channel_b);
64 }
65
75 void importNew(const wxString& styleDef)
76 {
77 wxArrayString styles = wxStringTokenize(styleDef, "-");
78
79 foreground = StrToColorNew(styles[0]);
80 background = StrToColorNew(styles[1]);
81
82 bold = styles[2][0] == '1';
83 italics = styles[2][1] == '1';
84 underline = styles[2][2] == '1';
85 defaultbackground = styles[2][3] == '1';
86 }
87
97 void importOld(const wxString& styleDef)
98 {
99 if (styleDef.length() < 21)
100 return;
101
102 foreground = StrToColorOld(styleDef.substr(0,9));
103 background = StrToColorOld(styleDef.substr(9,9));
104
105 if (styleDef[18] == '1')
106 bold = true;
107
108 if (styleDef[19] == '1')
109 italics = true;
110
111 if (styleDef[20] == '1')
112 underline = true;
113
114 if (styleDef.length() > 21)
115 {
116 if (styleDef[21] == '0')
117 defaultbackground = false;
118 }
119 else
120 defaultbackground = false;
121 }
122
131 std::string to_string() const
132 {
133 std::string style;
134
135 style = toString((int)foreground.Red()) + ":" + toString((int)foreground.Green()) + ":" + toString((int)foreground.Blue()) + "-";
136 style += toString((int)background.Red()) + ":" + toString((int)background.Green()) + ":" + toString((int)background.Blue()) + "-";
137 style += bold ? "1" : "0";
138 style += italics ? "1" : "0";
139 style += underline ? "1" : "0";
140 style += defaultbackground ? "1" : "0";
141
142 return style;
143 }
144
149 SyntaxStyles() : foreground(*wxBLACK), background(*wxWHITE), bold(false), italics(false), underline(false), defaultbackground(true) {}
150
159 SyntaxStyles(const wxString& styleDef) : SyntaxStyles()
160 {
161 if (styleDef.find(':') != std::string::npos)
162 importNew(styleDef);
163 else
164 importOld(styleDef);
165 }
166};
167
168
169
170
171
177class Options : public Settings
178{
179 friend class OptionsDialog;
180
181 public:
182 Options();
183 ~Options();
184
185 // Modifiers:
186 void SetEditorFont(wxFont font)
187 {
188 font.SetEncoding(wxFONTENCODING_CP1252);
189 m_settings[SETTING_S_EDITORFONT].stringval() = font.GetNativeFontInfoUserDesc().ToStdString();
190 }
191
192 void SetPrintStyle(int style)
195 {m_settings[SETTING_V_BUFFERSIZE].value() = size;}
196 void SetShowToolbarText(bool useText)
197 {m_settings[SETTING_B_TOOLBARTEXT].active() = useText;}
198 void SetShowPathOnTabs(bool useText)
199 {m_settings[SETTING_B_PATHSONTABS].active() = useText;}
200 void SetLineNumberPrinting(bool printLineNumbers)
201 {m_settings[SETTING_B_PRINTLINENUMBERS].active() = printLineNumbers;}
202 void SetSaveSession(bool saveSession)
203 {m_settings[SETTING_B_SAVESESSION].active() = saveSession;}
206 void SetFormatBeforeSaving(bool formatBeforeSave)
207 {m_settings[SETTING_B_FORMATBEFORESAVING].active() = formatBeforeSave;}
208 void SetLaTeXRoot(const wxString& root)
209 {m_settings[SETTING_S_LATEXROOT].stringval() = root.ToStdString();}
210 void SetKeepBackupFile(bool keepFile)
211 {m_settings[SETTING_B_USEREVISIONS].active() = keepFile;}
212 void SetCaretBlinkTime(int nTime)
213 {m_settings[SETTING_V_CARETBLINKTIME].value() = nTime;}
214 void SetDebuggerFocusLine(int nLine)
215 {m_settings[SETTING_V_FOCUSEDLINE].value() = nLine;}
217 {m_settings[SETTING_B_LINESINSTACK].active() = show;}
219 {m_settings[SETTING_B_MODULESINSTACK].active() = show;}
221 {m_settings[SETTING_B_PROCEDUREARGS].active() = show;}
223 {m_settings[SETTING_B_GLOBALVARS].active() = show;}
224 void SetFoldDuringLoading(bool fold)
225 {m_settings[SETTING_B_FOLDLOADEDFILE].active() = fold;}
226 void SetHighlightLocalVariables(bool highlight)
227 {m_settings[SETTING_B_HIGHLIGHTLOCALS].active() = highlight;}
228
229
230 // Accessors: (inlined)
231 wxFont GetEditorFont() const
232 {
233 return toFont(m_settings.at(SETTING_S_EDITORFONT).stringval());
234 }
235 int GetPrintStyle() const
237 wxString GetLaTeXRoot() const
238 {return m_settings.at(SETTING_S_LATEXROOT).stringval();}
240 {return m_settings.at(SETTING_B_TOOLBARTEXT).active();}
241 bool GetShowPathOnTabs() const
242 {return m_settings.at(SETTING_B_PATHSONTABS).active();}
244 {return m_settings.at(SETTING_B_PRINTLINENUMBERS).active();}
245 bool GetSaveSession() const
246 {return m_settings.at(SETTING_B_SAVESESSION).active();}
248 {return m_settings.at(SETTING_B_SAVEBOOKMARKS).active();}
250 {return m_settings.at(SETTING_B_FORMATBEFORESAVING).active();}
251 bool GetKeepBackupFile() const
252 {return m_settings.at(SETTING_B_USEREVISIONS).active();}
254 {return m_settings.at(SETTING_V_BUFFERSIZE).value();}
256 {return m_settings.at(SETTING_V_CARETBLINKTIME).value();}
258 {return m_settings.at(SETTING_V_FOCUSEDLINE).value();}
260 {return m_settings.at(SETTING_B_LINESINSTACK).active();}
262 {return m_settings.at(SETTING_B_MODULESINSTACK).active();}
264 {return m_settings.at(SETTING_B_PROCEDUREARGS).active();}
266 {return m_settings.at(SETTING_B_GLOBALVARS).active();}
268 {return m_settings.at(SETTING_B_FOLDLOADEDFILE).active();}
270 {return m_settings.at(SETTING_B_HIGHLIGHTLOCALS).active();}
271
277 {
302 };
303
309 {
333 };
334
335 SyntaxStyles GetDefaultSyntaxStyle(size_t i) const;
336 SyntaxStyles GetSyntaxStyle(size_t i) const;
337 void SetSyntaxStyle(size_t i, const SyntaxStyles& styles);
338
339 void SetAnalyzerOption(AnalyzerOptions opt, int nVal);
340 int GetAnalyzerOption(AnalyzerOptions opt) const;
341
342 void readColoursFromConfig(wxFileConfig* _config);
343 void readAnalyzerOptionsFromConfig(wxFileConfig* _config);
344
345 wxArrayString GetStyleIdentifier() const;
346 size_t GetIdByIdentifier(const wxString& identifier) const;
347
348 static wxFont toFont(const std::string& sFontDescr)
349 {
350 wxFont font;
351 font.SetNativeFontInfoUserDesc(sFontDescr);
352 return font;
353 }
354
355 static std::string toString(wxFont font)
356 {
357 font.SetEncoding(wxFONTENCODING_CP1252);
358 return font.GetNativeFontInfoUserDesc().ToStdString();
359 }
360
361 private:
362 std::string analyzerOptsToString(AnalyzerOptions opt) const;
363 std::string syntaxStylesToString(Styles style) const;
364};
365
366
367
368#endif
#define wxSTC_PRINT_BLACKONWHITE
Definition: Options.h:16
#define wxSTC_PRINT_COLOURONWHITE
Definition: Options.h:19
This class represents the settings dialog in memory.
This class implements an interface of the internal Settings object adapted to be usable from the GUI.
Definition: Options.h:178
bool GetShowModulesInStackTrace() const
Definition: Options.h:261
static wxFont toFont(const std::string &sFontDescr)
Definition: Options.h:348
void SetShowModulesInStackTrace(bool show)
Definition: Options.h:218
std::string analyzerOptsToString(AnalyzerOptions opt) const
Convert the static code analyzer enumeration values into the new settings strings.
Definition: options.cpp:332
void SetSyntaxStyle(size_t i, const SyntaxStyles &styles)
Update a selected syntax style by converting the passed SyntaxStyles object into a style string and s...
Definition: options.cpp:133
size_t GetIdByIdentifier(const wxString &identifier) const
This member function returns the ID of a syntax style by passing the style identifier as a string.
Definition: options.cpp:315
bool GetHighlightLocalVariables() const
Definition: Options.h:269
int GetPrintStyle() const
Definition: Options.h:235
wxFont GetEditorFont() const
Definition: Options.h:231
void SetEditorFont(wxFont font)
Definition: Options.h:186
bool GetShowGlobalVariables() const
Definition: Options.h:265
Styles
An enumeration of all available syntax styles.
Definition: Options.h:277
@ INCLUDES
Definition: Options.h:292
@ FUNCTION
Definition: Options.h:285
@ OPERATOR
Definition: Options.h:293
@ STRING
Definition: Options.h:290
@ CONSOLE_STD
Definition: Options.h:279
@ COMMAND
Definition: Options.h:280
@ SPECIALVAL
Definition: Options.h:289
@ CLUSTER
Definition: Options.h:287
@ NUMBER
Definition: Options.h:295
@ STYLE_END
Definition: Options.h:301
@ INSTALL
Definition: Options.h:298
@ DEFAULT_VARS
Definition: Options.h:299
@ DOCKEYWORD
Definition: Options.h:283
@ COMMENT
Definition: Options.h:281
@ STANDARD
Definition: Options.h:278
@ ACTIVE_LINE
Definition: Options.h:300
@ PROCEDURE
Definition: Options.h:294
@ DOCCOMMENT
Definition: Options.h:282
@ STRINGPARSER
Definition: Options.h:291
@ OPTION
Definition: Options.h:284
@ CUSTOM_FUNCTION
Definition: Options.h:286
@ CONSTANT
Definition: Options.h:288
@ PROCEDURE_COMMAND
Definition: Options.h:296
@ METHODS
Definition: Options.h:297
bool GetShowProcedureArguments() const
Definition: Options.h:263
void readColoursFromConfig(wxFileConfig *_config)
Legacy syntax style import function from file configuration.
Definition: options.cpp:150
void SetShowGlobalVariables(bool show)
Definition: Options.h:222
void SetShowToolbarText(bool useText)
Definition: Options.h:196
bool GetFormatBeforeSaving() const
Definition: Options.h:249
void SetKeepBackupFile(bool keepFile)
Definition: Options.h:210
bool GetLineNumberPrinting() const
Definition: Options.h:243
int GetAnalyzerOption(AnalyzerOptions opt) const
Return the value of the selected static code analyzer option.
Definition: options.cpp:256
void SetHighlightLocalVariables(bool highlight)
Definition: Options.h:226
bool GetSaveSession() const
Definition: Options.h:245
void SetDebuggerFocusLine(int nLine)
Definition: Options.h:214
AnalyzerOptions
An enumeration of all available static analyzer options.
Definition: Options.h:309
@ THISFILE_NAMESPACE
Definition: Options.h:328
@ PROGRESS_RUNTIME
Definition: Options.h:329
@ ARGUMENT_UNDERSCORE
Definition: Options.h:324
@ SWITCH_FALLTHROUGH
Definition: Options.h:330
@ COMMENT_DENSITY
Definition: Options.h:313
@ TYPE_ORIENTATION
Definition: Options.h:322
@ LINES_OF_CODE
Definition: Options.h:314
@ VARIABLE_LENGTH
Definition: Options.h:325
@ MAGIC_NUMBERS
Definition: Options.h:316
@ ANALYZER_OPTIONS_END
Definition: Options.h:332
@ UNUSED_VARIABLES
Definition: Options.h:326
@ INLINE_IF
Definition: Options.h:318
@ USE_WARNINGS
Definition: Options.h:311
@ CONSTANT_EXPRESSION
Definition: Options.h:319
@ USE_ERRORS
Definition: Options.h:312
@ USE_NOTES
Definition: Options.h:310
@ COMPLEXITY
Definition: Options.h:315
@ RESULT_ASSIGNMENT
Definition: Options.h:321
@ GLOBAL_VARIABLES
Definition: Options.h:331
@ MISLEADING_TYPE
Definition: Options.h:323
@ ALWAYS_SHOW_METRICS
Definition: Options.h:317
@ RESULT_SUPPRESSION
Definition: Options.h:320
@ PROCEDURE_LENGTH
Definition: Options.h:327
void SetShowLinesInStackTrace(bool show)
Definition: Options.h:216
void readAnalyzerOptionsFromConfig(wxFileConfig *_config)
Legacy analyzer import function from file configuration.
Definition: options.cpp:205
int GetTerminalHistorySize() const
Definition: Options.h:253
void SetShowPathOnTabs(bool useText)
Definition: Options.h:198
bool GetShowToolbarText() const
Definition: Options.h:239
SyntaxStyles GetSyntaxStyle(size_t i) const
Return the selected syntax style by constructing it from the style string.
Definition: options.cpp:112
~Options()
Definition: options.cpp:16
bool GetSaveBookmarksInSession() const
Definition: Options.h:247
bool GetFoldDuringLoading() const
Definition: Options.h:267
int GetCaretBlinkTime() const
Definition: Options.h:255
void SetTerminalHistorySize(int size)
Definition: Options.h:194
int GetDebuggerFocusLine() const
Definition: Options.h:257
void SetFormatBeforeSaving(bool formatBeforeSave)
Definition: Options.h:206
SyntaxStyles GetDefaultSyntaxStyle(size_t i) const
Return the default syntax style as defined by the programmers.
Definition: options.cpp:45
Options()
Definition: options.cpp:12
void SetLaTeXRoot(const wxString &root)
Definition: Options.h:208
bool GetKeepBackupFile() const
Definition: Options.h:251
void SetSaveSession(bool saveSession)
Definition: Options.h:202
bool GetShowPathOnTabs() const
Definition: Options.h:241
void SetPrintStyle(int style)
Definition: Options.h:192
bool GetShowLinesInStackTrace() const
Definition: Options.h:259
void SetFoldDuringLoading(bool fold)
Definition: Options.h:224
void SetLineNumberPrinting(bool printLineNumbers)
Definition: Options.h:200
void SetCaretBlinkTime(int nTime)
Definition: Options.h:212
wxArrayString GetStyleIdentifier() const
This member function returns an array of the style enumeration identifiers converted to a string.
Definition: options.cpp:275
wxString GetLaTeXRoot() const
Definition: Options.h:237
void SetAnalyzerOption(AnalyzerOptions opt, int nVal)
Change a static code analyzer setting.
Definition: options.cpp:28
void SetSaveBookmarksInSession(bool save)
Definition: Options.h:204
void SetShowProcedureArguments(bool show)
Definition: Options.h:220
static std::string toString(wxFont font)
Definition: Options.h:355
std::string syntaxStylesToString(Styles style) const
Convert the syntax style enumeration values into the new settings strings.
Definition: options.cpp:396
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
std::map< std::string, SettingsValue > m_settings
Definition: settings.hpp:676
void save(const std::string &_sWhere, bool bMkBackUp=false)
Saves the setting values to the corresponding config file. Does only save the setting values,...
Definition: settings.cpp:187
int StrToInt(const std::string &)
Converts a string into an integer.
#define SETTING_B_TOOLBARTEXT
Definition: settings.hpp:76
#define SETTING_B_SAVEBOOKMARKS
Definition: settings.hpp:86
#define SETTING_B_USEREVISIONS
Definition: settings.hpp:88
#define SETTING_B_FORMATBEFORESAVING
Definition: settings.hpp:87
#define SETTING_S_EDITORFONT
Definition: settings.hpp:101
#define SETTING_S_LATEXROOT
Definition: settings.hpp:68
#define SETTING_V_FOCUSEDLINE
Definition: settings.hpp:70
#define SETTING_B_PROCEDUREARGS
Definition: settings.hpp:74
#define SETTING_B_PATHSONTABS
Definition: settings.hpp:77
#define SETTING_B_HIGHLIGHTLOCALS
Definition: settings.hpp:93
#define SETTING_B_LINESINSTACK
Definition: settings.hpp:71
#define SETTING_V_BUFFERSIZE
Definition: settings.hpp:54
#define SETTING_B_GLOBALVARS
Definition: settings.hpp:73
#define SETTING_B_MODULESINSTACK
Definition: settings.hpp:72
#define SETTING_B_PRINTINCOLOR
Definition: settings.hpp:83
#define SETTING_B_SAVESESSION
Definition: settings.hpp:85
#define SETTING_B_FOLDLOADEDFILE
Definition: settings.hpp:92
#define SETTING_B_PRINTLINENUMBERS
Definition: settings.hpp:84
#define SETTING_V_CARETBLINKTIME
Definition: settings.hpp:69
This structure contains the necessary data to completely define a style for a distinctive syntax elem...
Definition: Options.h:27
wxColour StrToColorNew(const wxString &colorstring) const
Convert a colorstring (r:g:b) into an actual color instance.
Definition: Options.h:43
bool bold
Definition: Options.h:30
void importOld(const wxString &styleDef)
Imports an old syntax style string (rrrgggbbbrrrgggbbbBIUD) and converts it into actual usable variab...
Definition: Options.h:97
std::string to_string() const
Transforms the internal data into a string style representation according the following scheme: r:g:b...
Definition: Options.h:131
wxColour background
Definition: Options.h:29
SyntaxStyles()
Default constructor. Creates a "style- less" style.
Definition: Options.h:149
void importNew(const wxString &styleDef)
Imports a new syntax style string (r:g:b-r:g:b-BIUD) and converts it into actual usable variables.
Definition: Options.h:75
bool italics
Definition: Options.h:31
SyntaxStyles(const wxString &styleDef)
Generic constructor. Creates an instance of this class by importing a style string in new or old fash...
Definition: Options.h:159
bool defaultbackground
Definition: Options.h:33
wxColour foreground
Definition: Options.h:28
bool underline
Definition: Options.h:32
wxColour StrToColorOld(const wxString &colorstring) const
Convert a colorstring of the old representation (rrrgggbbb) into an actual color instance.
Definition: Options.h:58
std::string toString(int)
Converts an integer to a string without the Settings bloat.