Debian Codegraph @

CodeLite/cl_config.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : cl_config.h
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 CLCONFIG_H
27 #define CLCONFIG_H
28
29 #include "JSON.h"
30 #include "codelite_exports.h"
31 #include "wx/filename.h"
32 #include <functional>
33 #include <map>
34
35 ////////////////////////////////////////////////////////
36
37 class WXDLLIMPEXP_CL clConfigItem
38 {
39 protected:
40 wxString m_name;
41
42 public:
43 clConfigItem(const wxString& name)
44 : m_name(name)
45 {
46 }
47
48 virtual ~clConfigItem()
49 {
50 }
51
52 const wxString& GetName() const
53 {
54 return m_name;
55 }
56
57 void SetName(const wxString& name)
58 {
59 this->m_name = name;
60 }
61 virtual void FromJSON(const JSONItem& json) = 0;
62 virtual JSONItem ToJSON() const = 0;
63 };
64
65 ////////////////////////////////////////////////////////
66
67 #define kConfigLLDBTooltipW "LLDBTooltipW"
68 #define kConfigLLDBTooltipH "LLDBTooltipH"
69 #define kConfigBuildAutoScroll "build-auto-scroll"
70 #define kConfigCreateVirtualFoldersOnDisk "CreateVirtualFoldersOnDisk"
71 #define kConfigLogVerbosity "LogVerbosity"
72 #define kConfigRedirectLogOutput "RedirectLogOutput"
73 #define kConfigSingleInstance "SingleInstance"
74 #define kConfigCheckForNewVersion "CheckForNewVersion"
75 #define kConfigMaxItemsInFindReplaceDialog "MaxItemsInFindReplaceDialog"
76 #define kConfigMaxOpenedTabs "MaxOpenedTabs"
77 #define kConfigRestoreLastSession "RestoreLastSession"
78 #define kConfigFrameTitlePattern "FrameTitlePattern"
79 #define kConfigStatusbarShowLine "StatusbarShowLine"
80 #define kConfigStatusbarShowColumn "StatusbarShowColumn"
81 #define kConfigStatusbarShowPosition "StatusbarShowPosition"
82 #define kConfigStatusbarShowLength "StatusbarShowLength"
83 #define kConfigStatusbarShowSelectedChars "StatusbarShowSelChars"
84 #define kConfigToolbarGroupSpacing "ToolbarGroupSpacing"
85 #define kConfigAutoDetectCompilerOnStartup "AutoDetectCompilerOnStartup"
86 #define kConfigBootstrapCompleted "BootstrapCompleted"
87 #define kConfigUpdateParserPaths "updateParserPaths"
88 #define kConfigShowToolBar "ShowToolBar"
89 #define kConfigShowTabBar "ShowTabBar"
90 #define kConfigShowMenuBar "ShowMenuBar"
91 #define kConfigShowStatusBar "ShowStatusBar"
92 #define kConfigWorkspaceTabSashPosition "WorkspaceTabSashPosition"
93 #define kConfigTabsPaneSortAlphabetically "TabsPaneSortAlphabetically"
94 #define kConfigFileExplorerBookmarks "FileExplorerBookmarks"
95
96 class WXDLLIMPEXP_CL clConfig
97 {
98 protected:
99 wxFileName m_filename;
100 JSON* m_root;
101 std::map<wxString, wxArrayString> m_cacheRecentItems;
102
103 protected:
104 void DoDeleteProperty(const wxString& property);
105 JSONItem GetGeneralSetting();
106
107 void DoAddRecentItem(const wxString& propName, const wxString& filename);
108 wxArrayString DoGetRecentItems(const wxString& propName) const;
109 void DoClearRecentItems(const wxString& propName);
110
111 public:
112 // We provide a global configuration
113 // and the ability to allocate a private copy with a different file
114 clConfig(const wxString& filename = "codelite.conf");
115 virtual ~clConfig();
116 static clConfig& Get();
117
118 // Re-read the content from the disk
119 void Reload();
120 // Save the content to a give file name
121 void Save(const wxFileName& fn);
122 // Save the content the file passed on the construction
123 void Save();
124
125 // Utility functions
126 //------------------------------
127
128 // Merge 2 arrays of strings into a single array with all duplicate entries removed
129 wxArrayString MergeArrays(const wxArrayString& arr1, const wxArrayString& arr2) const;
130 wxStringMap_t MergeStringMaps(const wxStringMap_t& map1, const wxStringMap_t& map2) const;
131 // Workspace history
132 void AddRecentWorkspace(const wxString& filename)
133 {
134 DoAddRecentItem("RecentWorkspaces", filename);
135 }
136 wxArrayString GetRecentWorkspaces() const
137 {
138 return DoGetRecentItems("RecentWorkspaces");
139 }
140 void ClearRecentWorkspaces()
141 {
142 DoClearRecentItems("RecentWorkspaces");
143 }
144
145 // File history
146 void AddRecentFile(const wxString& filename)
147 {
148 DoAddRecentItem("RecentFiles", filename);
149 }
150 wxArrayString GetRecentFiles() const
151 {
152 return DoGetRecentItems("RecentFiles");
153 }
154 void ClearRecentFiles()
155 {
156 DoClearRecentItems("RecentFiles");
157 }
158
159 // Workspace tab order
160 //------------------------------
161 void SetWorkspaceTabOrder(const wxArrayString& tabs, int selected);
162 bool GetWorkspaceTabOrder(wxArrayString& tabs, int& selected);
163
164 // Output tab order
165 //------------------------------
166 void SetOutputTabOrder(const wxArrayString& tabs, int selected);
167 bool GetOutputTabOrder(wxArrayString& tabs, int& selected);
168
169 // General objects
170 // -----------------------------
171 bool ReadItem(clConfigItem* item, const wxString& differentName = wxEmptyString);
172 void WriteItem(const clConfigItem* item, const wxString& differentName = wxEmptyString);
173 // bool
174 bool Read(const wxString& name, bool defaultValue);
175 void Write(const wxString& name, bool value);
176 // int
177 int Read(const wxString& name, int defaultValue);
178 void Write(const wxString& name, int value);
179 // wxString
180 wxString Read(const wxString& name, const wxString& defaultValue);
181 void Write(const wxString& name, const wxString& value);
182
183 // wxArrayString
184 wxArrayString Read(const wxString& name, const wxArrayString& defaultValue);
185 void Write(const wxString& name, const wxArrayString& value);
186
187 // wxFont
188 wxFont Read(const wxString& name, const wxFont& defaultValue);
189 void Write(const wxString& name, const wxFont& value);
190
191 // wxColour
192 wxColour Read(const wxString& name, const wxColour& defaultValue);
193 void Write(const wxString& name, const wxColour& value);
194
195 // Custom items, using lambda
196 // A general purpose method that writes JSONItem created by a user defined function
197 //
198 // Write("my_item_name", []() -> JSONItem {
199 // JSONItem item = JSON::createObject();
200 // item.addProperty("name", "eran");
201 // item.addProperty("last_name", "ifrah");
202 // return item;
203 // });
204 // Note: if configFile is valid, parameter is IGNORED and the JSONItem is written ino the configFile instead
205 // as an anonymous object, e.g. if configFile is set to /tmp/my_config.json, then its content will be written
206 // like this:
207 // {
208 // "name" : "eran",
209 // "last_name" : "ifrah"
210 // }
211 bool Write(const wxString& name, std::function<JSONItem()> serialiser_func, const wxFileName& configFile = {});
212
213 // read custom items, using lambda:
214 // Read("my_item_name", [&my_struct](const JSONItem& item) {
215 // my_struct.name = item["name"].toString();
216 // my_struct.last_name = item["last_name"].toString();
217 // });
218 // Note: if configFile is valid, `name` is ignored (see comment for Write() method above)
219 void Read(const wxString& name, std::function<void(const JSONItem& item)> deserialiser_func,
220 const wxFileName& configFile = {});
221
222 // Quick Find Bar history
223 void AddQuickFindSearchItem(const wxString& str);
224 void AddQuickFindReplaceItem(const wxString& str);
225 wxArrayString GetQuickFindSearchItems() const;
226 wxArrayString GetQuickFindReplaceItems() const;
227 void SetQuickFindSearchItems(const wxArrayString& items);
228 void SetQuickFindReplaceItems(const wxArrayString& items);
229
230 // standard IDs for annoying dialogs
231 int GetAnnoyingDlgAnswer(const wxString& name, int defaultValue = wxNOT_FOUND);
232 void SetAnnoyingDlgAnswer(const wxString& name, int value);
233 void ClearAnnoyingDlgAnswers();
234 };
235
236 #endif // CLCONFIG_H