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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2009 by Eran Ifrah
// file name : localoptions.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef __localoptions__
#define __localoptions__
#include "VirtualDirectoryColour.h"
#include "codelite_exports.h"
#include "optionsconfig.h"
#include "singleton.h"
#include <list>
#include <map>
#include <wx/colour.h>
#include <wx/filename.h>
// Denotes whether we're dealing with preferences at a global, workspace, project or (maybe one day) file level
enum prefsLevel { pLevel_global, pLevel_workspace, pLevel_project, pLevel_file, pLevel_dunno };
class LocalOptionsConfig;
typedef SmartPtr<LocalOptionsConfig> LocalOptionsConfigPtr;
template <typename T> class validVar
{
bool valid;
T datum;
public:
validVar()
: valid(false)
{
}
void Set(const T info)
{
datum = info;
valid = true;
}
void Reset() { valid = false; }
T GetDatum() const { return datum; }
bool isValid() const { return valid; }
};
class WXDLLIMPEXP_SDK LocalOptionsConfig
{
validVar<bool> m_localdisplayFoldMargin;
validVar<bool> m_localdisplayBookmarkMargin;
validVar<bool> m_localhighlightCaretLine;
validVar<bool> m_localTrimLine;
validVar<bool> m_localAppendLF;
validVar<bool> m_localdisplayLineNumbers;
validVar<bool> m_localshowIndentationGuidelines;
validVar<bool> m_localindentUsesTabs;
validVar<int> m_localindentWidth;
validVar<int> m_localtabWidth;
validVar<wxFontEncoding> m_localfileFontEncoding;
validVar<int> m_localshowWhitspaces;
validVar<wxString> m_localeolMode;
validVar<bool> m_localTrackChanges;
public:
LocalOptionsConfig(); // Used for setting local values
LocalOptionsConfig(OptionsConfigPtr opts,
wxXmlNode* node); // Used for merging local values into the already-found global ones
LocalOptionsConfig(LocalOptionsConfigPtr opts,
wxXmlNode* node); // Used for storing local values in a previously-empty instance
virtual ~LocalOptionsConfig(void) {}
bool IsTrackChangesIsValid() const { return m_localTrackChanges.isValid(); }
bool DisplayFoldMarginIsValid() const { return m_localdisplayFoldMargin.isValid(); }
bool DisplayBookmarkMarginIsValid() const { return m_localdisplayBookmarkMargin.isValid(); }
bool HighlightCaretLineIsValid() const { return m_localhighlightCaretLine.isValid(); }
bool TrimLineIsValid() const { return m_localTrimLine.isValid(); }
bool AppendLFIsValid() const { return m_localAppendLF.isValid(); }
bool DisplayLineNumbersIsValid() const { return m_localdisplayLineNumbers.isValid(); }
bool ShowIndentationGuidelinesIsValid() const { return m_localshowIndentationGuidelines.isValid(); }
bool IndentUsesTabsIsValid() const { return m_localindentUsesTabs.isValid(); }
bool IndentWidthIsValid() const { return m_localindentWidth.isValid(); }
bool TabWidthIsValid() const { return m_localtabWidth.isValid(); }
bool FileFontEncodingIsValid() const { return m_localfileFontEncoding.isValid(); }
bool ShowWhitespacesIsValid() const { return m_localshowWhitspaces.isValid(); }
bool EolModeIsValid() const { return m_localeolMode.isValid(); }
//-------------------------------------
// Setters/Getters
//-------------------------------------
bool IsTrackChanges() const
{
if(m_localTrackChanges.isValid()) {
return m_localTrackChanges.GetDatum();
}
return false; // It's invalid anyway, so false will do as well as anything
}
bool GetDisplayFoldMargin() const
{
if(m_localdisplayFoldMargin.isValid()) {
return m_localdisplayFoldMargin.GetDatum();
}
return false;
}
bool GetDisplayBookmarkMargin() const
{
if(m_localdisplayBookmarkMargin.isValid()) {
return m_localdisplayBookmarkMargin.GetDatum();
}
return false;
}
bool GetHighlightCaretLine() const
{
if(m_localhighlightCaretLine.isValid()) {
return m_localhighlightCaretLine.GetDatum();
}
return false;
}
bool GetTrimLine() const
{
if(m_localTrimLine.isValid()) {
return m_localTrimLine.GetDatum();
}
return false;
}
bool GetAppendLF() const
{
if(m_localAppendLF.isValid()) {
return m_localAppendLF.GetDatum();
}
return false;
}
bool GetDisplayLineNumbers() const
{
if(m_localdisplayLineNumbers.isValid()) {
return m_localdisplayLineNumbers.GetDatum();
}
return false;
}
bool GetShowIndentationGuidelines() const
{
if(m_localshowIndentationGuidelines.isValid()) {
return m_localshowIndentationGuidelines.GetDatum();
}
return false;
}
void SetTrackChanges(bool b) { m_localTrackChanges.Set(b); }
void SetDisplayFoldMargin(bool b) { m_localdisplayFoldMargin.Set(b); }
void SetDisplayBookmarkMargin(bool b) { m_localdisplayBookmarkMargin.Set(b); }
void SetHighlightCaretLine(bool b) { m_localhighlightCaretLine.Set(b); }
void SetTrimLine(bool b) { m_localTrimLine.Set(b); }
void SetAppendLF(bool b) { m_localAppendLF.Set(b); }
void SetDisplayLineNumbers(bool b) { m_localdisplayLineNumbers.Set(b); }
void SetShowIndentationGuidelines(bool b) { m_localshowIndentationGuidelines.Set(b); }
void SetIndentUsesTabs(const bool& indentUsesTabs) { m_localindentUsesTabs.Set(indentUsesTabs); }
bool GetIndentUsesTabs() const
{
if(m_localindentUsesTabs.isValid()) {
return m_localindentUsesTabs.GetDatum();
}
return false;
}
void SetIndentWidth(const int& indentWidth) { m_localindentWidth.Set(indentWidth); }
int GetIndentWidth() const
{
if(m_localindentWidth.isValid()) {
return m_localindentWidth.GetDatum();
}
return wxNOT_FOUND;
}
void SetTabWidth(const int& tabWidth) { m_localtabWidth.Set(tabWidth); }
int GetTabWidth() const
{
if(m_localtabWidth.isValid()) {
return m_localtabWidth.GetDatum();
}
return wxNOT_FOUND;
}
wxFontEncoding GetFileFontEncoding() const
{
if(m_localfileFontEncoding.isValid()) {
return m_localfileFontEncoding.GetDatum();
}
return (wxFontEncoding)(wxFONTENCODING_MAX + 1);
}
void SetFileFontEncoding(const wxString& strFileFontEncoding);
void SetShowWhitespaces(const int& showWhitespaces) { m_localshowWhitspaces.Set(showWhitespaces); }
int GetShowWhitespaces() const
{
if(m_localshowWhitspaces.isValid()) {
return m_localshowWhitspaces.GetDatum();
}
return wxNOT_FOUND;
}
void SetEolMode(const wxString& eolMode) { m_localeolMode.Set(eolMode); }
wxString GetEolMode() const
{
if(m_localeolMode.isValid()) {
return m_localeolMode.GetDatum();
}
return wxT("");
}
/**
* Return an XML representation of this object
* \return XML node
*/
wxXmlNode* ToXml(wxXmlNode* parent = NULL, const wxString& nodename = wxT("Options")) const;
};
class WXDLLIMPEXP_SDK LocalWorkspace
{
public:
enum CC_FLAGS {
EnableCpp11 = 0x00000001,
EnableCpp14 = 0x00000002,
EnableCpp17 = 0x00000004,
EnableSWTLW = 0x00000008, // Save Parse folders to Workspace file.
EnableCpp20 = 0x00000010,
};
private:
friend class LocalWorkspaceST;
wxXmlDocument m_doc;
wxFileName m_fileName;
protected:
/*void SaveWorkspaceOptions(LocalOptionsConfigPtr opts);
void SaveProjectOptions(LocalOptionsConfigPtr opts, const wxString& projectname);*/
bool SanityCheck();
bool Create();
bool SaveXmlFile();
wxFileName DoGetFilePath() const;
public:
/// Constructor
LocalWorkspace() {}
/// Destructor
virtual ~LocalWorkspace() {}
/**
* @brief return list of pinned c++ projects
*/
size_t GetPinnedProjects(wxArrayString& projects);
bool SetPinnedProjects(const wxArrayString& projects);
/**
* @brief flush the XML content to the disk
*/
void Flush() { SaveXmlFile(); }
/**
* @brief Get any local editor preferences, merging the values into the global options
* \param options the global options
* \param projectname the name of the currently active project
*/
void GetOptions(OptionsConfigPtr options, const wxString& projectname);
/**
* @brief Sets any local editor preferences for the current workspace
* \param opts the local options to save
*/
bool SetWorkspaceOptions(LocalOptionsConfigPtr opts);
/**
* @brief Sets any local editor preferences for the named project
* \param opts the local options to save
* \param projectname the name of the project
*/
bool SetProjectOptions(LocalOptionsConfigPtr opts, const wxString& projectname);
/**
* @brief Set virtual folder colours for the workspace
*/
bool SetFolderColours(const FolderColour::Map_t& vdColours);
/**
* @brief Get virtual folder colours for the workspace
*/
bool GetFolderColours(FolderColour::Map_t& vdColours);
/**
* @brief Returns the node where any current local workspace options are stored
*/
wxXmlNode* GetLocalWorkspaceOptionsNode() const;
/**
* @brief Returns the node where any current local project options are stored
* \param projectname the name of the project
*/
wxXmlNode* GetLocalProjectOptionsNode(const wxString& projectname) const;
/**
* @brief return the workspace C++ parser specific include + exclude paths
* @param inclduePaths [output]
* @param excludePaths [output]
*/
void GetParserPaths(wxArrayString& inclduePaths, wxArrayString& excludePaths);
void SetParserPaths(const wxArrayString& inclduePaths, const wxArrayString& excludePaths);
size_t GetParserFlags();
void SetParserFlags(size_t flags);
void GetParserMacros(wxString& macros);
void SetParserMacros(const wxString& macros);
void SetSearchInFilesMask(const wxString& findInFileMask);
void GetSearchInFilesMask(wxString& findInFileMask, const wxString& defaultValue = "");
void SetCustomData(const wxString& name, const wxString& value);
wxString GetCustomData(const wxString& name);
/**
* @brief set and get the currently selected build configuration name
*/
void SetSelectedBuildConfiguration(const wxString& confName);
wxString GetSelectedBuildConfiguration();
/**
* @brief set and get the active environment variables set name
*/
void SetActiveEnvironmentSet(const wxString& setName);
wxString GetActiveEnvironmentSet();
};
#endif // __localoptions__
|