1
//////////////////////////////////////////////////////////////////////////////
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2009 by Eran Ifrah
5
// file name : localoptions.cpp
7
// -------------------------------------------------------------------------
10
// / __ \ | | | | (_) |
11
// | / \/ ___ __| | ___| | _| |_ ___
12
// | | / _ \ / _ |/ _ \ | | | __/ _ )
13
// | \__/\ (_) | (_| | __/ |___| | || __/
14
// \____/\___/ \__,_|\___\_____/_|\__\___|
18
// This program is free software; you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation; either version 2 of the License, or
21
// (at your option) any later version.
23
//////////////////////////////////////////////////////////////////////////////
24
//////////////////////////////////////////////////////////////////////////////
26
#ifndef __localoptions__
27
#define __localoptions__
29
#include <wx/filename.h>
30
#include "singleton.h"
31
#include "optionsconfig.h"
34
// Denotes whether we're dealing with preferences at a global, workspace, project or (maybe one day) file level
35
enum prefsLevel { pLevel_global, pLevel_workspace, pLevel_project, pLevel_file, pLevel_dunno };
37
class LocalOptionsConfig;
38
typedef SmartPtr<LocalOptionsConfig> LocalOptionsConfigPtr;
46
validVar() : valid(false) {}
47
void Set(const T info) {
57
bool isValid() const {
62
class LocalOptionsConfig
64
validVar<bool> m_localdisplayFoldMargin;
65
validVar<bool> m_localdisplayBookmarkMargin;
66
validVar<bool> m_localhighlightCaretLine;
67
validVar<bool> m_localTrimLine;
68
validVar<bool> m_localAppendLF;
69
validVar<bool> m_localdisplayLineNumbers;
70
validVar<bool> m_localshowIndentationGuidelines;
71
validVar<bool> m_localindentUsesTabs;
72
validVar<int> m_localindentWidth;
73
validVar<int> m_localtabWidth;
74
validVar<wxFontEncoding> m_localfileFontEncoding;
75
validVar<int> m_localshowWhitspaces;
76
validVar<wxString> m_localeolMode;
77
validVar<bool> m_localhideChangeMarkerMargin;
80
LocalOptionsConfig(); // Used for setting local values
81
LocalOptionsConfig(OptionsConfigPtr opts, wxXmlNode *node); // Used for merging local values into the already-found global ones
82
LocalOptionsConfig(LocalOptionsConfigPtr opts, wxXmlNode *node); // Used for storing local values in a previously-empty instance
83
virtual ~LocalOptionsConfig(void) {}
85
bool HideChangeMarkerMarginIsValid() const {
86
return m_localhideChangeMarkerMargin.isValid();
88
bool DisplayFoldMarginIsValid() const {
89
return m_localdisplayFoldMargin.isValid();
91
bool DisplayBookmarkMarginIsValid() const {
92
return m_localdisplayBookmarkMargin.isValid();
94
bool HighlightCaretLineIsValid() const {
95
return m_localhighlightCaretLine.isValid();
97
bool TrimLineIsValid() const {
98
return m_localTrimLine.isValid();
100
bool AppendLFIsValid() const {
101
return m_localAppendLF.isValid();
103
bool DisplayLineNumbersIsValid() const {
104
return m_localdisplayLineNumbers.isValid();
106
bool ShowIndentationGuidelinesIsValid() const {
107
return m_localshowIndentationGuidelines.isValid();
109
bool IndentUsesTabsIsValid() const {
110
return m_localindentUsesTabs.isValid();
112
bool IndentWidthIsValid() const {
113
return m_localindentWidth.isValid();
115
bool TabWidthIsValid() const {
116
return m_localtabWidth.isValid();
118
bool FileFontEncodingIsValid() const {
119
return m_localfileFontEncoding.isValid();
121
bool ShowWhitespacesIsValid() const {
122
return m_localshowWhitspaces.isValid();
124
bool EolModeIsValid() const {
125
return m_localeolMode.isValid();
128
//-------------------------------------
130
//-------------------------------------
132
bool GetHideChangeMarkerMargin() const {
133
if (m_localhideChangeMarkerMargin.isValid()) {
134
return m_localhideChangeMarkerMargin.GetDatum();
136
return false;// It's invalid anyway, so false will do as well as anything
138
bool GetDisplayFoldMargin() const {
139
if (m_localdisplayFoldMargin.isValid()) {
140
return m_localdisplayFoldMargin.GetDatum();
144
bool GetDisplayBookmarkMargin() const {
145
if (m_localdisplayBookmarkMargin.isValid()) {
146
return m_localdisplayBookmarkMargin.GetDatum();
150
bool GetHighlightCaretLine() const {
151
if (m_localhighlightCaretLine.isValid()) {
152
return m_localhighlightCaretLine.GetDatum();
156
bool GetTrimLine() const {
157
if (m_localTrimLine.isValid()) {
158
return m_localTrimLine.GetDatum();
162
bool GetAppendLF() const {
163
if (m_localAppendLF.isValid()) {
164
return m_localAppendLF.GetDatum();
168
bool GetDisplayLineNumbers() const {
169
if (m_localdisplayLineNumbers.isValid()) {
170
return m_localdisplayLineNumbers.GetDatum();
174
bool GetShowIndentationGuidelines() const {
175
if (m_localshowIndentationGuidelines.isValid()) {
176
return m_localshowIndentationGuidelines.GetDatum();
181
void SetHideChangeMarkerMargin(bool hideChangeMarkerMargin) {
182
m_localhideChangeMarkerMargin.Set(hideChangeMarkerMargin);
184
void SetDisplayFoldMargin(bool b) {
185
m_localdisplayFoldMargin.Set(b);
187
void SetDisplayBookmarkMargin(bool b) {
188
m_localdisplayBookmarkMargin.Set(b);
190
void SetHighlightCaretLine(bool b) {
191
m_localhighlightCaretLine.Set(b);
193
void SetTrimLine(bool b) {
194
m_localTrimLine.Set(b);
196
void SetAppendLF(bool b) {
197
m_localAppendLF.Set(b);
199
void SetDisplayLineNumbers(bool b) {
200
m_localdisplayLineNumbers.Set(b);
202
void SetShowIndentationGuidelines(bool b) {
203
m_localshowIndentationGuidelines.Set(b);
205
void SetIndentUsesTabs(const bool& indentUsesTabs) {
206
m_localindentUsesTabs.Set(indentUsesTabs);
208
bool GetIndentUsesTabs() const {
209
if (m_localindentUsesTabs.isValid()) {
210
return m_localindentUsesTabs.GetDatum();
214
void SetIndentWidth(const int& indentWidth) {
215
m_localindentWidth.Set(indentWidth);
217
int GetIndentWidth() const {
218
if (m_localindentWidth.isValid()) {
219
return m_localindentWidth.GetDatum();
223
void SetTabWidth(const int& tabWidth) {
224
m_localtabWidth.Set(tabWidth);
226
int GetTabWidth() const {
227
if (m_localtabWidth.isValid()) {
228
return m_localtabWidth.GetDatum();
233
wxFontEncoding GetFileFontEncoding() const {
234
if (m_localfileFontEncoding.isValid()) {
235
return m_localfileFontEncoding.GetDatum();
237
return (wxFontEncoding)(wxFONTENCODING_MAX + 1);
239
void SetFileFontEncoding(const wxString& strFileFontEncoding);
241
void SetShowWhitespaces(const int& showWhitespaces) {
242
m_localshowWhitspaces.Set(showWhitespaces);
244
int GetShowWhitespaces() const {
245
if (m_localshowWhitspaces.isValid()) {
246
return m_localshowWhitspaces.GetDatum();
251
void SetEolMode(const wxString& eolMode) {
252
m_localeolMode.Set(eolMode);
254
wxString GetEolMode() const {
255
if (m_localeolMode.isValid()) {
256
return m_localeolMode.GetDatum();
262
* Return an XML representation of this object
265
wxXmlNode *ToXml(wxXmlNode* parent = NULL, const wxString& nodename = wxT("Options")) const;
271
friend class Singleton<LocalWorkspace>;
273
wxFileName m_fileName;
279
virtual ~LocalWorkspace() {}
282
/*void SaveWorkspaceOptions(LocalOptionsConfigPtr opts);
283
void SaveProjectOptions(LocalOptionsConfigPtr opts, const wxString& projectname);*/
292
* @brief Get any local editor preferences, merging the values into the global options
293
* \param options the global options
294
* \param projectname the name of the currently active project
296
void GetOptions(OptionsConfigPtr options, const wxString& projectname);
298
* @brief Sets any local editor preferences for the current workspace
299
* \param opts the local options to save
301
bool SetWorkspaceOptions(LocalOptionsConfigPtr opts);
303
* @brief Sets any local editor preferences for the named project
304
* \param opts the local options to save
305
* \param projectname the name of the project
307
bool SetProjectOptions(LocalOptionsConfigPtr opts, const wxString& projectname);
309
* @brief Returns the node where any current local workspace options are stored
311
wxXmlNode* GetLocalWorkspaceOptionsNode() const;
313
* @brief Returns the node where any current local project options are stored
314
* \param projectname the name of the project
316
wxXmlNode* GetLocalProjectOptionsNode(const wxString& projectname) const;
319
* @brief return the workspace C++ parser specific include + exclude paths
320
* @param inclduePaths [output]
321
* @param excludePaths [output]
323
void GetParserPaths(wxArrayString &inclduePaths, wxArrayString &excludePaths);
324
void SetParserPaths(const wxArrayString &inclduePaths, const wxArrayString &excludePaths);
327
* @brief set and get the active environment variables set name
329
void SetActiveEnvironmentSet(const wxString &setName);
330
wxString GetActiveEnvironmentSet();
334
typedef Singleton<LocalWorkspace> LocalWorkspaceST;
336
#endif // __localoptions__