1 #include "ide.h"
2
3 #define METHOD_NAME "Ide::" << UPP_FUNCTION_NAME << "(): "
4
SerializeWorkspace(Stream & s)5 void Ide::SerializeWorkspace(Stream& s) {
6 int i;
7 int version = 19;
8 s / version;
9 s.Magic(0x12354);
10 if(s.IsStoring()) {
11 for(i = 0; i < filedata.GetCount(); i++) {
12 String fn = filedata.GetKey(i);
13 if(!fn.IsEmpty() && FileExists(fn)) {
14 s % fn;
15 s % filedata[i].editpos;
16 if(version >= 1)
17 s % filedata[i].columnline;
18 }
19 }
20 String h;
21 s % h;
22 }
23 else {
24 String fn;
25 filedata.Clear();
26 for(;;) {
27 s % fn;
28 if(fn.IsEmpty()) break;
29 FileData& fd = filedata.GetAdd(fn);
30 fd.Clear();
31 s % fd.editpos;
32 if(version >= 1)
33 s % fd.columnline;
34 }
35 }
36 String pk = GetActivePackage();
37 s % pk;
38 package.FindSetCursor(pk);
39 s % tablru;
40 s % mainconfigname;
41 s % mainconfigparam;
42 s % console.verbosebuild;
43 s % stoponerrors;
44 byte dummy = 0;
45 s % dummy;
46 s % runarg;
47 s % recent_runarg;
48 s % rundir;
49 s % stdout_file % recent_stdout_file / runmode;
50 if(version >= 1)
51 s % runexternal;
52 if(version >= 11) {
53 bool dummy = false;
54 s % dummy;
55 }
56 if(version >= 13)
57 s % consolemode;
58 if(version >= 14)
59 s % console_utf8;
60 if(version >= 17)
61 s % disable_uhd;
62 if(version >= 18)
63 s % darkmode;
64 s % editfile;
65 for(i = 0; i < 10; i++) {
66 s % bookmark[i];
67 }
68 editor.Serialize(s);
69 if(version >= 5)
70 s % editorsplit;
71 if(version == 6) {
72 String n;
73 int v;
74 s / v;
75 for(int i = 0; i < 10; i++) {
76 s % n;
77 s / v;
78 }
79 }
80 if(version >= 8) {
81 bool dummyb = false;
82 String dummy;
83 s % dummyb;
84 s % dummy;
85 }
86 SerializeFindInFiles(s);
87 String om;
88 s % om;
89 s % recentoutput;
90 s % recentflags;
91 s / editortabsize / indent_amount % indent_spaces;
92 if(version < 15)
93 for(int j = 0; j < GetIdeModuleCount(); j++)
94 GetIdeModule(j).Serialize(s);
95 else {
96 VectorMap<String, String> module_cfg;
97 for(int j = 0; j < GetIdeModuleCount(); j++) {
98 IdeModule& m = GetIdeModule(j);
99 module_cfg.Add(m.GetID(), StoreAsString(m));
100 }
101 s % module_cfg;
102 for(int j = 0; j < GetIdeModuleCount(); j++) {
103 IdeModule& m = GetIdeModule(j);
104 LoadFromString(m, module_cfg.Get(m.GetID(), String()));
105 }
106 }
107 SerializeWorkspaceConfigs(s);
108 SerializeOutputMode(s);
109 SerializeClosed(s);
110 if(version >= 10) {
111 bool dotabs = tabs_serialize;
112 if(version >= 19)
113 s % dotabs;
114 if(dotabs)
115 s % tabs;
116 }
117 if(version >= 11) {
118 s % find_file_search_string;
119 }
120 if(version >= 16) {
121 s % find_file_search_in_current_package;
122 }
123 if(version >= 12)
124 SerializePlacement(s);
125 }
126
SerializeLastMain(Stream & s)127 void Ide::SerializeLastMain(Stream& s)
128 {
129 s % main;
130 String varsname = GetVarsName();
131 s % varsname;
132 s % pocfg;
133 if(s.IsLoading())
134 LoadVars(varsname);
135 }
136
EditorMode()137 void Ide::EditorMode()
138 {
139 Logd() << METHOD_NAME;
140
141 editormode = true;
142 main = Null;
143 pocfg = Null;
144
145 // TODO: This is probably bug with CtrlLib tool bar. If
146 // we did not call clear here - we will have blocked two icons
147 // in editor mode :(. This should be investigated with
148 // appropriate test case.
149 toolbar.Clear();
150 SetBar();
151
152 editor.SyncNavigator();
153 }
154
IsEditorMode() const155 bool Ide::IsEditorMode() const
156 {
157 return editormode;
158 }
159
SaveLastMain()160 void Ide::SaveLastMain()
161 {
162 StoreToFile(THISBACK(SerializeLastMain), ConfigFile("lastmain.cfg"));
163 }
164
LoadLastMain()165 void Ide::LoadLastMain()
166 {
167 bool editor = IsEditorMode();
168 LoadFromFile(THISBACK(SerializeLastMain), ConfigFile("lastmain.cfg"));
169 if(editor)
170 main = Null;
171 }
172
Sentinel(Stream & s,const char * txt)173 void Sentinel(Stream& s, const char *txt)
174 {
175 String h;
176 h << "<123456789:" << txt << ":123456789>";
177 Buffer<char> hh(h.GetLength());
178 memcpy(hh, h, h.GetLength());
179 s.SerializeRaw((byte *)~hh, h.GetLength());
180 }
181
Serialize(Stream & s)182 void Ide::Serialize(Stream& s)
183 {
184 int version = 19;
185 Sentinel(s, "before 12341234");
186 s.Magic(0x12341234);
187 Sentinel(s, "after magic");
188 s / version;
189 Sentinel(s, "before first FileSel");
190 s % AnySourceFs();
191 Sentinel(s, "after AnySourceFs");
192 s % BasedSourceFs();
193 Sentinel(s, "after BasedSourceFs");
194 s % AnyPackageFs();
195 Sentinel(s, "after AnyPackageFs");
196 s % pfsplit;
197 if (version >= 12)
198 s % weframe;
199 else {
200 Splitter dummy;
201 s % dummy;
202 }
203 package.SerializeSettings(s);
204 filelist.SerializeSettings(s);
205 s % editorfont;
206 s % tfont;
207 s % veditorfont;
208 s % consolefont;
209 s % font1;
210 s % font2;
211 s % show_status_bar;
212 s % toolbar_in_row;
213 s % filetabs;
214 s % auto_enclose;
215 s % persistent_find_replace;
216 if(version >= 4) {
217 s % find_replace_restore_pos;
218 }
219 s % show_tabs;
220 if(version >= 18)
221 s % show_spaces;
222 if(version >= 7)
223 s % warnwhitespace;
224 s % tabs_icons;
225 s % tabs_crosses;
226 s % tabs_grouping;
227 s % tabs_serialize;
228 s % tabs_stacking;
229 if(version >= 11)
230 s % spellcheck_comments;
231 if(version >= 13) {
232 s % wordwrap_comments;
233 s % wordwrap;
234 }
235 if(version >= 16) {
236 s % setmain_newide;
237 }
238 bool dummy_force_crlf = false;
239 s % dummy_force_crlf;
240 if(version >= 1)
241 s % line_endings;
242 s % no_parenthesis_indent;
243 s % hilite_scope;
244 s % hilite_if_endif;
245 s % hilite_bracket;
246 s % hilite_ifdef;
247 if(version >= 3)
248 s % thousands_separator;
249 if(version >= 5)
250 s % hline;
251 if(version >= 15)
252 s % vline;
253 s % barline;
254 s % qtfsel;
255 s % wrap_console_text;
256 s % mute_sounds;
257 s % line_numbers;
258 s % bookmark_pos;
259 s % use_target;
260 s % default_charset;
261 s % header_guards;
262 s % insert_include;
263 SerializeGlobalConfigs(s);
264 doc.Serialize(s);
265 s % right_split;
266 s % splash_screen;
267 s % editor.auto_assist;
268 if(version >= 9)
269 s % auto_rescan;
270 if(version >= 10)
271 s % auto_check;
272 s % editor.commentdp;
273 s % bordercolumn;
274 s % bordercolor;
275 s % hydra1_threads;
276 if(s.IsLoading())
277 console.SetSlots(hydra1_threads);
278 if(version < 14) {
279 int dummy_gdb_selector = 0;
280 s % dummy_gdb_selector;
281 }
282 s % doc;
283 s % chstyle;
284 s % astyle_BracketIndent;
285 s % astyle_NamespaceIndent;
286 s % astyle_BlockIndent;
287 s % astyle_CaseIndent;
288 s % astyle_ClassIndent;
289 s % astyle_LabelIndent;
290 s % astyle_SwitchIndent;
291 s % astyle_PreprocessorIndent;
292 s % astyle_MinInStatementIndentLength;
293 s % astyle_MaxInStatementIndentLength;
294 s % astyle_BreakClosingHeaderBracketsMode;
295 s % astyle_BreakElseIfsMode;
296 s % astyle_BreakOneLineBlocksMode;
297 s % astyle_SingleStatementsMode;
298 s % astyle_BreakBlocksMode;
299 s % astyle_BreakClosingHeaderBlocksMode;
300 s % astyle_BracketFormatMode;
301 s % astyle_ParensPaddingMode;
302 s % astyle_ParensUnPaddingMode;
303 s % astyle_OperatorPaddingMode;
304 s % astyle_EmptyLineFill;
305 s % astyle_TabSpaceConversionMode;
306 s % astyle_TestBox;
307 if(version >= 6 && version < 8) {
308 String dummy;
309 s % dummy;
310 }
311 s % LinuxHostConsole;
312 editor.SerializeNavigator(s);
313 s % showtime;
314 s % DiffFs();
315 s % sort;
316 s % output_per_assembly;
317 s.Magic();
318 if(version >= 17)
319 s % hlstyle_is_default;
320 if(version >= 19)
321 s % gui_font % gui_font_override;
322 }
323
ConfigTime()324 Time Ide::ConfigTime()
325 {
326 return FileGetTime(ConfigFile());
327 }
328
SaveConfig()329 void Ide::SaveConfig()
330 {
331 SaveChangedFile(ConfigFile(), StoreAsString(*this));
332 if(GetIniKey("DebugClipboard") == "1") {
333 SaveChangedFile(ConfigFile() + ".bak", StoreAsString(*this));
334 StoreToFile(*this, ConfigFile() + ".bak1");
335 }
336 SaveChangedFile(ConfigFile("ide.key"), StoreKeys());
337 SaveChangedFile(ConfigFile("ide.colors"), editor.StoreHlStyles());
338 config_time = ConfigTime();
339 }
340
SaveConfigOnTime()341 void Ide::SaveConfigOnTime()
342 {
343 if(ConfigTime() == config_time)
344 SaveConfig();
345 }
346
LoadConfig()347 void Ide::LoadConfig()
348 {
349 if(!LoadFromFile(*this) && GetIniKey("DebugClipboard") == "1") {
350 Exclamation("LoadConfig has failed!");
351 if(!LoadFromFile(*this, ConfigFile() + ".bak")) {
352 Exclamation("LoadConfig .bak has failed!");
353 if(!LoadFromFile(*this, ConfigFile() + ".bak1"))
354 Exclamation("LoadConfig .bak1 has failed!");
355 }
356 }
357 RestoreKeys(LoadFile(ConfigFile("ide.key")));
358 if(hlstyle_is_default)
359 editor.DefaultHlStyles();
360 else
361 editor.LoadHlStyles(LoadFile(ConfigFile("ide.colors")));
362 config_time = FileGetTime(ConfigFile());
363 UpdateFormat();
364 if(filelist.IsCursor()) {
365 FlushFile();
366 FileCursor();
367 }
368 SaveLoadPackage();
369 }
370