| 1 |
#ifndef ELEPHANT_SETTINGS |
|---|
| 2 |
#define ELEPHANT_SETTINGS |
|---|
| 3 |
|
|---|
| 4 |
#include "ElSettings.h" |
|---|
| 5 |
#include "../stdincludes.h" |
|---|
| 6 |
#include "../StringFunctions.h" |
|---|
| 7 |
|
|---|
| 8 |
class ElephantBaseSettings : public ISettings { |
|---|
| 9 |
public: |
|---|
| 10 |
ElephantBaseSettings(const string& p,const string& m = "BaseSettings") : ISettings(p,m) {} |
|---|
| 11 |
}; |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
struct ElephantColor |
|---|
| 15 |
{ |
|---|
| 16 |
COLORREF fore; |
|---|
| 17 |
COLORREF back; |
|---|
| 18 |
}; |
|---|
| 19 |
|
|---|
| 20 |
class ColorSettings : public ISettings { |
|---|
| 21 |
public: |
|---|
| 22 |
ISettings* settings; |
|---|
| 23 |
map<string,ElephantColor> colors; |
|---|
| 24 |
public: |
|---|
| 25 |
ColorSettings(ISettings* _settings) : ISettings("","") , settings(_settings) |
|---|
| 26 |
{ |
|---|
| 27 |
|
|---|
| 28 |
} |
|---|
| 29 |
void Restore() |
|---|
| 30 |
{ |
|---|
| 31 |
|
|---|
| 32 |
string keywordTypes = settings->GetCache("keywordTypes"); |
|---|
| 33 |
vector<string> keywords; |
|---|
| 34 |
Split(keywordTypes,",",keywords ); |
|---|
| 35 |
for ( int i = 0;i < keywords.size();i++ ) |
|---|
| 36 |
{ |
|---|
| 37 |
string key = keywords[i] + "_color"; |
|---|
| 38 |
string colorFore, colorBack, strColors = settings->GetCache(key); |
|---|
| 39 |
Split(strColors,colorFore,colorBack); |
|---|
| 40 |
|
|---|
| 41 |
ElephantColor color; |
|---|
| 42 |
color.fore = atol(colorFore.c_str()); |
|---|
| 43 |
color.back = atol(colorBack.c_str()); |
|---|
| 44 |
|
|---|
| 45 |
colors[key] = color; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
} |
|---|
| 51 |
void Save() |
|---|
| 52 |
{ |
|---|
| 53 |
std::map<string,ElephantColor>::iterator p = colors.begin(); |
|---|
| 54 |
while ( p != colors.end() ) |
|---|
| 55 |
{ |
|---|
| 56 |
|
|---|
| 57 |
string key = (*p).first; |
|---|
| 58 |
ElephantColor color = (*p).second; |
|---|
| 59 |
// AfxMessageBox(string(ITOA(color.fore) + " " + ITOA(color.back) ).c_str() ); |
|---|
| 60 |
settings->SetCache(key,ITOA(color.fore) + " " + ITOA(color.back) ); |
|---|
| 61 |
p++; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
} |
|---|
| 65 |
}; |
|---|
| 66 |
|
|---|
| 67 |
class AStyleSettings : public ISettings { |
|---|
| 68 |
public: |
|---|
| 69 |
AStyleSettings(const string& p,const string& m = "AstyleSettings") : ISettings(p,m) {} |
|---|
| 70 |
}; |
|---|
| 71 |
|
|---|
| 72 |
class FileExtensions : public ISettings |
|---|
| 73 |
{ |
|---|
| 74 |
public: |
|---|
| 75 |
FileExtensions(const string& p,const string& m = "FileExtensions") : ISettings(p,m) {} |
|---|
| 76 |
|
|---|
| 77 |
}; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
class EditorSettings : public ISettings |
|---|
| 81 |
{ |
|---|
| 82 |
public: |
|---|
| 83 |
EditorSettings(const string& p,const string& m = "EditorSettings") : ISettings(p,m) {} |
|---|
| 84 |
|
|---|
| 85 |
}; |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
class ScriptSettings : public ISettings |
|---|
| 89 |
{ |
|---|
| 90 |
public: |
|---|
| 91 |
ScriptSettings(const string& p,const string& m = "ScriptSettings") : ISettings(p,m) {} |
|---|
| 92 |
|
|---|
| 93 |
}; |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
class ElephantSettings { |
|---|
| 97 |
public: |
|---|
| 98 |
//vector<string> importPaths; |
|---|
| 99 |
//vector<string> keywords; |
|---|
| 100 |
map<string,vector<string> > tagSets; |
|---|
| 101 |
map<string,string> abbreviations; |
|---|
| 102 |
|
|---|
| 103 |
FileExtensions* extensionSettings; |
|---|
| 104 |
EditorSettings* editorSettings; |
|---|
| 105 |
AStyleSettings* astyleSettings; |
|---|
| 106 |
ElephantBaseSettings *baseSettings; |
|---|
| 107 |
ColorSettings* colorSettings; |
|---|
| 108 |
ScriptSettings* scriptSettings; |
|---|
| 109 |
ProjectSpecSettings* pspecSettings; |
|---|
| 110 |
string path; |
|---|
| 111 |
string fileName; |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
ElephantSettings(const string& _path , const string& file) : path(_path) , fileName(file) |
|---|
| 115 |
{ |
|---|
| 116 |
|
|---|
| 117 |
string p = path + "\\" + fileName; |
|---|
| 118 |
|
|---|
| 119 |
extensionSettings = new FileExtensions(p); |
|---|
| 120 |
editorSettings = new EditorSettings(p); |
|---|
| 121 |
astyleSettings = new AStyleSettings(p); |
|---|
| 122 |
baseSettings = new ElephantBaseSettings(p); |
|---|
| 123 |
scriptSettings = new ScriptSettings(p); |
|---|
| 124 |
colorSettings = new ColorSettings(editorSettings); |
|---|
| 125 |
pspecSettings = new ProjectSpecSettings(path + "\\pspec.ini"); |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
extensionSettings->Restore(); |
|---|
| 130 |
editorSettings->Restore(); |
|---|
| 131 |
astyleSettings->Restore(); |
|---|
| 132 |
baseSettings->Restore(); |
|---|
| 133 |
colorSettings->Restore(); |
|---|
| 134 |
scriptSettings->Restore(); |
|---|
| 135 |
pspecSettings->Restore(); |
|---|
| 136 |
|
|---|
| 137 |
vector<string> rp , newRp; |
|---|
| 138 |
Split(baseSettings->GetCache("recentProjects"),",",rp); |
|---|
| 139 |
for ( int i = 0 ; i < 5; i++ ) |
|---|
| 140 |
{ |
|---|
| 141 |
if ( i >= rp.size() ) break; |
|---|
| 142 |
else newRp.push_back(rp[i]); |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
baseSettings->SetCache("recentProjects",Join(newRp,",") ); |
|---|
| 146 |
|
|---|
| 147 |
// string imports = baseSettings->GetCache("importPaths"); |
|---|
| 148 |
// Split(imports,",",importPaths ); |
|---|
| 149 |
// |
|---|
| 150 |
// string keys = baseSettings->GetCache("keywords"); |
|---|
| 151 |
// Split(keys,",",keywords ); |
|---|
| 152 |
|
|---|
| 153 |
RestoreTagSets(baseSettings->GetCache("tagSets")); |
|---|
| 154 |
RestoreAbbs(baseSettings->GetCache("abbreviations") ); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
~ElephantSettings() |
|---|
| 158 |
{ |
|---|
| 159 |
|
|---|
| 160 |
SaveTagSets(); |
|---|
| 161 |
SaveAbbs(); |
|---|
| 162 |
|
|---|
| 163 |
// baseSettings->SetCache("importPaths",Join(importPaths,",") ); |
|---|
| 164 |
// baseSettings->SetCache("keywords",Join(keywords,",") ); |
|---|
| 165 |
|
|---|
| 166 |
SaveAll(); |
|---|
| 167 |
|
|---|
| 168 |
delete extensionSettings; |
|---|
| 169 |
delete astyleSettings; |
|---|
| 170 |
delete editorSettings; |
|---|
| 171 |
delete baseSettings; |
|---|
| 172 |
delete colorSettings; |
|---|
| 173 |
delete scriptSettings; |
|---|
| 174 |
delete pspecSettings; |
|---|
| 175 |
|
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
void SaveAll() |
|---|
| 179 |
{ |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
baseSettings->Save(); |
|---|
| 184 |
extensionSettings->Save(); |
|---|
| 185 |
astyleSettings->Save(); |
|---|
| 186 |
colorSettings->Save(); |
|---|
| 187 |
editorSettings->Save(); |
|---|
| 188 |
scriptSettings->Save(); |
|---|
| 189 |
pspecSettings->Save(); |
|---|
| 190 |
|
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
private: |
|---|
| 194 |
|
|---|
| 195 |
void RestoreTagSets(const string& s ) { |
|---|
| 196 |
vector<string> sets ; |
|---|
| 197 |
|
|---|
| 198 |
Split(s,",",sets); |
|---|
| 199 |
for ( int i = 0; i < sets.size();i++ ) |
|---|
| 200 |
{ |
|---|
| 201 |
// AfxMessageBox(sets[i].c_str() ); |
|---|
| 202 |
string f = baseSettings->GetCache(sets[i]) ; |
|---|
| 203 |
vector<string> files; |
|---|
| 204 |
Split(f,",",files); |
|---|
| 205 |
tagSets[sets[i]] = files; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
void RestoreAbbs(const string& s ) { |
|---|
| 213 |
abbreviations.clear(); |
|---|
| 214 |
string p = path + "\\" + fileName; |
|---|
| 215 |
//AfxMessageBox(string(p + ".abbs" ).c_str() ); |
|---|
| 216 |
if (!FileExists(p + ".abbs")) return; |
|---|
| 217 |
ifstream in (string(p + ".abbs").c_str() ); |
|---|
| 218 |
string line, abvs = ""; |
|---|
| 219 |
while (!in.eof() ) { |
|---|
| 220 |
std::getline(in,line); |
|---|
| 221 |
abvs += line + "\n"; |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
if ( abvs != "" ) { |
|---|
| 228 |
|
|---|
| 229 |
Strtok token(&abvs,"||~"); |
|---|
| 230 |
while (token.HasMoreTokens() ) { |
|---|
| 231 |
string key = token.NextToken(); |
|---|
| 232 |
|
|---|
| 233 |
if (!token.HasMoreTokens() ) break; // last ||~ |
|---|
| 234 |
|
|---|
| 235 |
abbreviations[key] = token.NextToken(); |
|---|
| 236 |
abbreviations[key] += "||~" + token.NextToken(); // for CUROSR |
|---|
| 237 |
abbreviations[key] += "||~" + token.NextToken(); // for MAINTAIN |
|---|
| 238 |
|
|---|
| 239 |
} |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
in.close(); |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
void SaveTagSets() |
|---|
| 249 |
{ |
|---|
| 250 |
vector<string> keys; |
|---|
| 251 |
GetKeysForMap(tagSets,keys); |
|---|
| 252 |
string tagSetsKey = Join(keys,","); |
|---|
| 253 |
baseSettings->SetCache("tagSets",tagSetsKey); |
|---|
| 254 |
string files = ""; |
|---|
| 255 |
|
|---|
| 256 |
for ( int i = 0;i < keys.size();i++) |
|---|
| 257 |
{ |
|---|
| 258 |
baseSettings->SetCache(keys[i],Join(tagSets[keys[i] ],",") ); |
|---|
| 259 |
|
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
void SaveAbbs() |
|---|
| 266 |
{ |
|---|
| 267 |
ofstream out(string(path + ".abbs").c_str() ); |
|---|
| 268 |
std::map<string,string>::iterator p = abbreviations.begin(); |
|---|
| 269 |
while ( p != abbreviations.end() ) |
|---|
| 270 |
{ |
|---|
| 271 |
|
|---|
| 272 |
string key = (*p).first; |
|---|
| 273 |
out << key << "||~" << abbreviations[key] << "||~"; // this string has ||~CURSOR||~MAINTAIN appended to it, |
|---|
| 274 |
// which we strip out when we insert it |
|---|
| 275 |
p++; |
|---|
| 276 |
} |
|---|
| 277 |
out.close(); |
|---|
| 278 |
|
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
}; |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
#endif |
|---|