~ubuntu-branches/ubuntu/karmic/codelite/karmic-backports

« back to all changes in this revision

Viewing changes to Plugin/localworkspace.h

  • Committer: Bazaar Package Importer
  • Author(s): Ubuntu Archive Backport
  • Date: 2010-03-10 00:42:25 UTC
  • mfrom: (10.1.3 lucid)
  • Revision ID: james.westby@ubuntu.com-20100310004225-ccjgjj2vvdy4q7qs
Tags: 2.2.0.3681+dfsg-0ubuntu1~karmic1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
//////////////////////////////////////////////////////////////////////////////
 
3
//
 
4
// copyright            : (C) 2009 by Eran Ifrah
 
5
// file name            : localoptions.cpp
 
6
//
 
7
// -------------------------------------------------------------------------
 
8
// A
 
9
//              _____           _      _     _ _
 
10
//             /  __ \         | |    | |   (_) |
 
11
//             | /  \/ ___   __| | ___| |    _| |_ ___
 
12
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
 
13
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
 
14
//              \____/\___/ \__,_|\___\_____/_|\__\___|
 
15
//
 
16
//                                                  F i l e
 
17
//
 
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.
 
22
//
 
23
//////////////////////////////////////////////////////////////////////////////
 
24
//////////////////////////////////////////////////////////////////////////////
 
25
 
 
26
#ifndef __localoptions__
 
27
#define __localoptions__
 
28
 
 
29
#include <wx/filename.h>
 
30
#include "singleton.h"
 
31
#include "optionsconfig.h"
 
32
 
 
33
 
 
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 };
 
36
 
 
37
class LocalOptionsConfig;
 
38
typedef SmartPtr<LocalOptionsConfig> LocalOptionsConfigPtr;
 
39
 
 
40
template <typename T>
 
41
class validVar
 
42
{
 
43
        bool valid;
 
44
        T datum;
 
45
public:
 
46
        validVar() : valid(false) {}
 
47
        void Set(const T info) {
 
48
                datum = info;
 
49
                valid = true;
 
50
        }
 
51
        void Reset() {
 
52
                valid = false;
 
53
        }
 
54
        T GetDatum() const {
 
55
                return datum;
 
56
        }
 
57
        bool isValid() const {
 
58
                return valid;
 
59
        }
 
60
};
 
61
 
 
62
class LocalOptionsConfig
 
63
{
 
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;
 
78
 
 
79
public:
 
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) {}
 
84
 
 
85
        bool HideChangeMarkerMarginIsValid() const {
 
86
                return m_localhideChangeMarkerMargin.isValid();
 
87
        }
 
88
        bool DisplayFoldMarginIsValid() const {
 
89
                return m_localdisplayFoldMargin.isValid();
 
90
        }
 
91
        bool DisplayBookmarkMarginIsValid() const {
 
92
                return m_localdisplayBookmarkMargin.isValid();
 
93
        }
 
94
        bool HighlightCaretLineIsValid() const {
 
95
                return m_localhighlightCaretLine.isValid();
 
96
        }
 
97
        bool TrimLineIsValid() const {
 
98
                return m_localTrimLine.isValid();
 
99
        }
 
100
        bool AppendLFIsValid() const {
 
101
                return m_localAppendLF.isValid();
 
102
        }
 
103
        bool DisplayLineNumbersIsValid() const {
 
104
                return m_localdisplayLineNumbers.isValid();
 
105
        }
 
106
        bool ShowIndentationGuidelinesIsValid() const {
 
107
                return m_localshowIndentationGuidelines.isValid();
 
108
        }
 
109
        bool IndentUsesTabsIsValid() const {
 
110
                return m_localindentUsesTabs.isValid();
 
111
        }
 
112
        bool IndentWidthIsValid() const {
 
113
                return m_localindentWidth.isValid();
 
114
        }
 
115
        bool TabWidthIsValid() const {
 
116
                return m_localtabWidth.isValid();
 
117
        }
 
118
        bool FileFontEncodingIsValid() const {
 
119
                return m_localfileFontEncoding.isValid();
 
120
        }
 
121
        bool ShowWhitespacesIsValid() const {
 
122
                return m_localshowWhitspaces.isValid();
 
123
        }
 
124
        bool EolModeIsValid() const {
 
125
                return m_localeolMode.isValid();
 
126
        }
 
127
 
 
128
        //-------------------------------------
 
129
        // Setters/Getters
 
130
        //-------------------------------------
 
131
 
 
132
        bool GetHideChangeMarkerMargin() const {
 
133
                if (m_localhideChangeMarkerMargin.isValid()) {
 
134
                        return m_localhideChangeMarkerMargin.GetDatum();
 
135
                }
 
136
                return false;// It's invalid anyway, so false will do as well as anything
 
137
        }
 
138
        bool GetDisplayFoldMargin() const {
 
139
                if (m_localdisplayFoldMargin.isValid()) {
 
140
                        return m_localdisplayFoldMargin.GetDatum();
 
141
                }
 
142
                return false;
 
143
        }
 
144
        bool GetDisplayBookmarkMargin() const {
 
145
                if (m_localdisplayBookmarkMargin.isValid()) {
 
146
                        return m_localdisplayBookmarkMargin.GetDatum();
 
147
                }
 
148
                return false;
 
149
        }
 
150
        bool GetHighlightCaretLine() const {
 
151
                if (m_localhighlightCaretLine.isValid()) {
 
152
                        return m_localhighlightCaretLine.GetDatum();
 
153
                }
 
154
                return false;
 
155
        }
 
156
        bool GetTrimLine() const {
 
157
                if (m_localTrimLine.isValid()) {
 
158
                        return m_localTrimLine.GetDatum();
 
159
                }
 
160
                return false;
 
161
        }
 
162
        bool GetAppendLF() const {
 
163
                if (m_localAppendLF.isValid()) {
 
164
                        return m_localAppendLF.GetDatum();
 
165
                }
 
166
                return false;
 
167
        }
 
168
        bool GetDisplayLineNumbers() const {
 
169
                if (m_localdisplayLineNumbers.isValid()) {
 
170
                        return m_localdisplayLineNumbers.GetDatum();
 
171
                }
 
172
                return false;
 
173
        }
 
174
        bool GetShowIndentationGuidelines() const {
 
175
                if (m_localshowIndentationGuidelines.isValid()) {
 
176
                        return m_localshowIndentationGuidelines.GetDatum();
 
177
                }
 
178
                return false;
 
179
        }
 
180
 
 
181
        void SetHideChangeMarkerMargin(bool hideChangeMarkerMargin) {
 
182
                m_localhideChangeMarkerMargin.Set(hideChangeMarkerMargin);
 
183
        }
 
184
        void SetDisplayFoldMargin(bool b) {
 
185
                m_localdisplayFoldMargin.Set(b);
 
186
        }
 
187
        void SetDisplayBookmarkMargin(bool b) {
 
188
                m_localdisplayBookmarkMargin.Set(b);
 
189
        }
 
190
        void SetHighlightCaretLine(bool b) {
 
191
                m_localhighlightCaretLine.Set(b);
 
192
        }
 
193
        void SetTrimLine(bool b) {
 
194
                m_localTrimLine.Set(b);
 
195
        }
 
196
        void SetAppendLF(bool b) {
 
197
                m_localAppendLF.Set(b);
 
198
        }
 
199
        void SetDisplayLineNumbers(bool b) {
 
200
                m_localdisplayLineNumbers.Set(b);
 
201
        }
 
202
        void SetShowIndentationGuidelines(bool b) {
 
203
                m_localshowIndentationGuidelines.Set(b);
 
204
        }
 
205
        void SetIndentUsesTabs(const bool& indentUsesTabs) {
 
206
                m_localindentUsesTabs.Set(indentUsesTabs);
 
207
        }
 
208
        bool GetIndentUsesTabs() const {
 
209
                if (m_localindentUsesTabs.isValid()) {
 
210
                        return m_localindentUsesTabs.GetDatum();
 
211
                }
 
212
                return false;
 
213
        }
 
214
        void SetIndentWidth(const int& indentWidth) {
 
215
                m_localindentWidth.Set(indentWidth);
 
216
        }
 
217
        int GetIndentWidth() const {
 
218
                if (m_localindentWidth.isValid()) {
 
219
                        return m_localindentWidth.GetDatum();
 
220
                }
 
221
                return wxNOT_FOUND;
 
222
        }
 
223
        void SetTabWidth(const int& tabWidth) {
 
224
                m_localtabWidth.Set(tabWidth);
 
225
        }
 
226
        int GetTabWidth() const {
 
227
                if (m_localtabWidth.isValid()) {
 
228
                        return m_localtabWidth.GetDatum();
 
229
                }
 
230
                return wxNOT_FOUND;
 
231
        }
 
232
 
 
233
        wxFontEncoding GetFileFontEncoding() const {
 
234
                if (m_localfileFontEncoding.isValid()) {
 
235
                        return m_localfileFontEncoding.GetDatum();
 
236
                }
 
237
                return (wxFontEncoding)(wxFONTENCODING_MAX + 1);
 
238
        }
 
239
        void SetFileFontEncoding(const wxString& strFileFontEncoding);
 
240
 
 
241
        void SetShowWhitespaces(const int& showWhitespaces) {
 
242
                m_localshowWhitspaces.Set(showWhitespaces);
 
243
        }
 
244
        int GetShowWhitespaces() const {
 
245
                if (m_localshowWhitspaces.isValid()) {
 
246
                        return m_localshowWhitspaces.GetDatum();
 
247
                }
 
248
                return wxNOT_FOUND;
 
249
        }
 
250
 
 
251
        void SetEolMode(const wxString& eolMode) {
 
252
                m_localeolMode.Set(eolMode);
 
253
        }
 
254
        wxString GetEolMode() const {
 
255
                if (m_localeolMode.isValid()) {
 
256
                        return m_localeolMode.GetDatum();
 
257
                }
 
258
                return wxT("");
 
259
        }
 
260
 
 
261
        /**
 
262
         * Return an XML representation of this object
 
263
         * \return XML node
 
264
         */
 
265
        wxXmlNode *ToXml(wxXmlNode* parent = NULL, const wxString& nodename = wxT("Options")) const;
 
266
};
 
267
 
 
268
class LocalWorkspace
 
269
{
 
270
private:
 
271
        friend class Singleton<LocalWorkspace>;
 
272
        wxXmlDocument m_doc;
 
273
        wxFileName m_fileName;
 
274
 
 
275
        /// Constructor
 
276
        LocalWorkspace() {}
 
277
 
 
278
        /// Destructor
 
279
        virtual ~LocalWorkspace() {}
 
280
 
 
281
protected:
 
282
        /*void SaveWorkspaceOptions(LocalOptionsConfigPtr opts);
 
283
        void SaveProjectOptions(LocalOptionsConfigPtr opts, const wxString& projectname);*/
 
284
        bool SanityCheck();
 
285
        bool Create();
 
286
        bool SaveXmlFile();
 
287
 
 
288
 
 
289
 
 
290
public:
 
291
        /**
 
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
 
295
        */
 
296
        void GetOptions(OptionsConfigPtr options, const wxString& projectname);
 
297
        /**
 
298
        * @brief Sets any local editor preferences for the current workspace
 
299
        * \param opts the local options to save
 
300
        */
 
301
        bool SetWorkspaceOptions(LocalOptionsConfigPtr opts);
 
302
        /**
 
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
 
306
        */
 
307
        bool SetProjectOptions(LocalOptionsConfigPtr opts, const wxString& projectname);
 
308
        /**
 
309
        * @brief Returns the node where any current local workspace options are stored
 
310
        */
 
311
        wxXmlNode* GetLocalWorkspaceOptionsNode() const;
 
312
        /**
 
313
        * @brief Returns the node where any current local project options are stored
 
314
        * \param projectname the name of the project
 
315
        */
 
316
        wxXmlNode* GetLocalProjectOptionsNode(const wxString& projectname) const;
 
317
 
 
318
        /**
 
319
         * @brief return the workspace C++ parser specific include + exclude paths
 
320
         * @param inclduePaths [output]
 
321
         * @param excludePaths [output]
 
322
         */
 
323
        void GetParserPaths(wxArrayString &inclduePaths, wxArrayString &excludePaths);
 
324
        void SetParserPaths(const wxArrayString &inclduePaths, const wxArrayString &excludePaths);
 
325
 
 
326
        /**
 
327
         * @brief set and get the active environment variables set name
 
328
         */
 
329
        void     SetActiveEnvironmentSet(const wxString &setName);
 
330
        wxString GetActiveEnvironmentSet();
 
331
};
 
332
 
 
333
 
 
334
typedef Singleton<LocalWorkspace> LocalWorkspaceST;
 
335
 
 
336
#endif // __localoptions__