-
Notifications
You must be signed in to change notification settings - Fork 35
/
cfg.nim
503 lines (462 loc) · 22.9 KB
/
cfg.nim
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#
#
# Aporia - Nim IDE
# (c) Copyright 2011 Dominik Picheta
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
import utils, times, streams, parsecfg, strutils, os, osproc
from gtk2 import getInsert, getOffset, getIterAtMark, TTextIter,
WrapNone, WrapChar, WrapWord, acceleratorParse, acceleratorName,
acceleratorValid
import gdk2
import glib2
from processes import addError
type
CFGParseError* = object of Exception
const KEY_notSet = 0.guint
proc defaultAutoSettings*(): AutoSettings =
result.search = SearchCaseInsens
result.wrapAround = true
result.winWidth = 800
result.winHeight = 600
result.recentlyOpenedFiles = @[]
proc defaultGlobalSettings*(): GlobalSettings =
result.selectHighlightAll = true
result.searchHighlightAll = false
when defined(macosx):
result.font = "Menlo 12"
else:
result.font = "Monospace 10"
result.outputFont = "Monospace 10"
result.colorSchemeID = "piekno"
result.indentWidth = 2
result.showLineNumbers = true
result.highlightMatchingBrackets = true
result.toolBarVisible = true
result.autoIndent = true
result.compileSaveAll = false
result.nimCmd = "$findExe(nim) c --listFullPaths $#"
result.customCmd1 = ""
result.customCmd2 = ""
result.customCmd3 = ""
result.singleInstancePort = 55679
result.showCloseOnAllTabs = false
result.compileUnsavedSave = true
result.nimPath = ""
result.wrapMode = WrapNone
result.scrollPastBottom = false
result.singleInstance = true
result.restoreTabs = true
result.activateErrorTabOnErrors = false
result.truncateLongTitles = true
when defined(macosx):
let mask: guint = MetaMask
else:
let mask: guint = ControlMask
result.keyCommentLines = ShortcutKey(keyval: KEY_slash, state: mask)
result.keyDeleteLine = ShortcutKey(keyval: KEY_d, state: mask)
result.keyDuplicateLines = ShortcutKey(keyval: KEY_notSet, state: 0)
result.keyQuit = ShortcutKey(keyval: KEY_q, state: mask)
result.keyNewFile = ShortcutKey(keyval: KEY_n, state: mask)
result.keyOpenFile = ShortcutKey(keyval: KEY_o, state: mask)
result.keySaveFile = ShortcutKey(keyval: KEY_s, state: mask)
result.keySaveFileAs = ShortcutKey(keyval: KEY_s, state: mask or ShiftMask)
result.keySaveAll = ShortcutKey(keyval: KEY_notSet, state: mask or ShiftMask)
result.keyUndo = ShortcutKey(keyval: KEY_z, state: mask)
result.keyRedo = ShortcutKey(keyval: KEY_z, state: mask or ShiftMask)
result.keyCloseCurrentTab = ShortcutKey(keyval: KEY_w, state: mask)
result.keyCloseAllTabs = ShortcutKey(keyval: KEY_w, state: mask or ShiftMask)
result.keyFind = ShortcutKey(keyval: KEY_f, state: mask)
result.keyReplace = ShortcutKey(keyval: KEY_h, state: mask)
result.keyFindNext = ShortcutKey(keyval: KEY_notSet, state: 0)
result.keyFindPrevious = ShortcutKey(keyval: KEY_notSet, state: 0)
result.keyGoToLine = ShortcutKey(keyval: KEY_g, state: mask)
result.keyGoToDef = ShortcutKey(keyval: KEY_r, state: mask or ShiftMask)
result.keyToggleBottomPanel = ShortcutKey(keyval: KEY_b, state: mask or ShiftMask)
result.keyCompileCurrent = ShortcutKey(keyval: KEY_F4, state: 0)
result.keyCompileRunCurrent = ShortcutKey(keyval: KEY_F5, state: 0)
result.keyCompileProject = ShortcutKey(keyval: KEY_F8, state: 0)
result.keyCompileRunProject = ShortcutKey(keyval: KEY_F9, state: 0)
result.keyStopProcess = ShortcutKey(keyval: KEY_F7, state: 0)
result.keyRunCustomCommand1 = ShortcutKey(keyval: KEY_F1, state: 0)
result.keyRunCustomCommand2 = ShortcutKey(keyval: KEY_F2, state: 0)
result.keyRunCustomCommand3 = ShortcutKey(keyval: KEY_F3, state: 0)
result.keyRunCheck = ShortcutKey(keyval: KEY_F5, state: mask)
proc getName*(shortcut: ShortcutKey): string =
return $acceleratorName(shortcut.keyval, shortcut.state)
proc isValid*(shortcut: ShortcutKey): bool =
return acceleratorValid(shortcut.keyval, shortcut.state)
proc toShortcutKey(shortcutStr: string): (ShortcutKey, bool) =
var key: guint = 0
var mods: guint = 0
acceleratorParse(shortcutStr, addr key, addr mods)
if key == 0 or mods == 0:
result[1] = false
return
if not acceleratorValid(key, mods):
result[1] = false
return
return (ShortcutKey(keyval: key, state: mods), true)
proc toKeyOrDefault(shortcutStr: string, def: ShortcutKey): ShortcutKey =
let (key, valid) = toShortcutKey(shortcutStr)
if valid:
return key
else:
return def
template setShortcutIfValid*(shortcutStr: string, shortcutField: untyped): typed =
`shortcutField` = toKeyOrDefault(shortcutStr, `shortcutField`)
proc writeSection(f: File, sectionName: string) =
f.write("[")
f.write(sectionName)
f.write("]\n")
proc writeKeyVal(f: File, key, val: string) =
f.write(key)
f.write(" = ")
if val.len == 0: f.write("\"\"")
else: f.write(quoteIfContainsWhite(val))
f.write("\n")
proc writeKeyVal(f: File, key: string, val: int) =
f.write(key)
f.write(" = ")
f.write(val)
f.write("\n")
proc writeKeyValRaw(f: File, key: string, val: string) =
f.write(key)
f.write(" = r")
if val.len == 0: f.write("\"\"")
else: f.write("\"" & val & "\"")
f.write("\n")
proc save(settings: AutoSettings, win: var MainWin) =
if not os.existsDir(os.getConfigDir() / "Aporia"):
os.createDir(os.getConfigDir() / "Aporia")
var f: File
if open(f, joinPath(os.getConfigDir(), "Aporia", "config.auto.ini"), fmWrite):
var confInfo = "; Aporia automatically generated configuration file - Last modified: "
confInfo.add($getTime())
f.write(confInfo & "\n")
f.writeKeyVal("searchMethod", $int(settings.search))
f.writeKeyVal("wrapAround", $settings.wrapAround)
f.writeKeyVal("winMaximized", $settings.winMaximized)
f.writeKeyVal("VPanedPos", settings.VPanedPos)
f.writeKeyVal("winWidth", settings.winWidth)
f.writeKeyVal("winHeight", settings.winHeight)
f.writeKeyVal("bottomPanelVisible", $settings.bottomPanelVisible)
if settings.recentlyOpenedFiles.len() > 0:
let frm = max(0, (settings.recentlyOpenedFiles.len-1)-19)
let to = settings.recentlyOpenedFiles.len()-1
f.writeKeyValRaw("recentlyOpenedFiles",
join(settings.recentlyOpenedFiles[frm..to], ";"))
if win.tabs.len != 0:
f.writeSection("session")
var tabs = "tabs = r\""
# Save all the tabs that have a filename.
for i in items(win.tabs):
if i.filename != "":
var cursorIter: TTextIter
i.buffer.getIterAtMark(addr(cursorIter), i.buffer.getInsert())
var cursorPos = getOffset(addr cursorIter)
# Kind of a messy way to save the cursor pos and filename.
tabs.add(i.filename & "|" & $cursorPos & ";")
f.write(tabs & "\"\n")
# Save currently selected tab
var current = win.getCurrentTab()
f.writeKeyValRaw("lastSelectedTab", win.tabs[current].filename)
f.close()
proc save*(settings: GlobalSettings) =
if not os.existsDir(os.getConfigDir() / "Aporia"):
os.createDir(os.getConfigDir() / "Aporia")
# Save the settings to file.
var f: File
if open(f, joinPath(os.getConfigDir(), "Aporia", "config.global.ini"), fmWrite):
var confInfo = "; Aporia global configuration file - Last modified: "
confInfo.add($getTime())
f.write(confInfo & "\n")
f.writeKeyVal("font", settings.font)
f.writeKeyVal("outputFont", settings.outputFont)
f.writeKeyVal("scheme", settings.colorSchemeID)
f.writeKeyVal("indentWidth", settings.indentWidth)
f.writeKeyVal("showLineNumbers", $settings.showLineNumbers)
f.writeKeyVal("highlightMatchingBrackets",
$settings.highlightMatchingBrackets)
f.writeKeyVal("rightMargin", $settings.rightMargin)
f.writeKeyVal("highlightCurrentLine", $settings.highlightCurrentLine)
f.writeKeyVal("autoIndent", $settings.autoIndent)
f.writeKeyVal("suggestFeature", $settings.suggestFeature)
f.writeKeyVal("showCloseOnAllTabs", $settings.showCloseOnAllTabs)
f.writeKeyVal("selectHighlightAll", $settings.selectHighlightAll)
f.writeKeyVal("searchHighlightAll", $settings.searchHighlightAll)
f.writeKeyVal("singleInstance", $settings.singleInstance)
f.writeKeyVal("singleInstancePort", $int(settings.singleInstancePort))
f.writeKeyVal("compileUnsavedSave", $settings.compileUnsavedSave)
f.writeKeyVal("restoreTabs", $settings.restoreTabs)
f.writeKeyVal("activateErrorTabOnErrors", $settings.activateErrorTabOnErrors)
f.writeKeyVal("truncateLongTitles", $settings.truncateLongTitles)
f.writeKeyValRaw("nimPath", $settings.nimPath)
f.writeKeyVal("toolBarVisible", $settings.toolBarVisible)
f.writeKeyVal("wrapMode",
case settings.wrapMode
of WrapNone: "none"
of WrapChar: "char"
of WrapWord: "word"
else:
assert false; ""
)
f.writeKeyVal("scrollPastBottom", $settings.scrollPastBottom)
f.writeKeyVal("compileSaveAll", $settings.compileSaveAll)
f.writeKeyVal("nimCmd", settings.nimCmd)
f.writeKeyVal("customCmd1", settings.customCmd1)
f.writeKeyVal("customCmd2", settings.customCmd2)
f.writeKeyVal("customCmd3", settings.customCmd3)
f.writeSection("ShortcutKeys")
f.writeKeyValRaw("keyQuit", getName(settings.keyQuit))
f.writeKeyValRaw("keyCommentLines", getName(settings.keyCommentLines))
f.writeKeyValRaw("keydeleteline", getName(settings.keyDeleteLine))
f.writeKeyValRaw("keyduplicatelines", getName(settings.keyDuplicateLines))
f.writeKeyValRaw("keyNewFile", getName(settings.keyNewFile))
f.writeKeyValRaw("keyOpenFile", getName(settings.keyOpenFile))
f.writeKeyValRaw("keySaveFile", getName(settings.keySaveFile))
f.writeKeyValRaw("keySaveFileAs", getName(settings.keySaveFileAs))
f.writeKeyValRaw("keySaveAll", getName(settings.keySaveAll))
f.writeKeyValRaw("keyUndo", getName(settings.keyUndo))
f.writeKeyValRaw("keyRedo", getName(settings.keyRedo))
f.writeKeyValRaw("keyCloseCurrentTab", getName(settings.keyCloseCurrentTab))
f.writeKeyValRaw("keyCloseAllTabs", getName(settings.keyCloseAllTabs))
f.writeKeyValRaw("keyFind", getName(settings.keyFind))
f.writeKeyValRaw("keyReplace", getName(settings.keyReplace))
f.writeKeyValRaw("keyFindNext", getName(settings.keyFindNext))
f.writeKeyValRaw("keyFindPrevious", getName(settings.keyFindPrevious))
f.writeKeyValRaw("keyGoToLine", getName(settings.keyGoToLine))
f.writeKeyValRaw("keyGoToDef", getName(settings.keyGoToDef))
f.writeKeyValRaw("keyToggleBottomPanel", getName(settings.keyToggleBottomPanel))
f.writeKeyValRaw("keyCompileCurrent", getName(settings.keyCompileCurrent))
f.writeKeyValRaw("keyCompileRunCurrent", getName(settings.keyCompileRunCurrent))
f.writeKeyValRaw("keyCompileProject", getName(settings.keyCompileProject))
f.writeKeyValRaw("keyCompileRunProject", getName(settings.keyCompileRunProject))
f.writeKeyValRaw("keyStopProcess", getName(settings.keyStopProcess))
f.writeKeyValRaw("keyRunCustomCommand1", getName(settings.keyRunCustomCommand1))
f.writeKeyValRaw("keyRunCustomCommand2", getName(settings.keyRunCustomCommand2))
f.writeKeyValRaw("keyRunCustomCommand3", getName(settings.keyRunCustomCommand3))
f.writeKeyValRaw("keyRunCheck", getName(settings.keyRunCheck))
f.close()
proc save*(win: var MainWin) =
win.autoSettings.save(win)
win.globalSettings.save()
if existsFile(os.getConfigDir() / "Aporia" / "config.ini"):
echo(os.getConfigDir() / "Aporia" / "config.ini")
removeFile(os.getConfigDir() / "Aporia" / "config.ini")
proc istrue(s: string): bool =
result = cmpIgnoreStyle(s, "true") == 0
proc loadOld(cfgErrors: var seq[AporiaError], lastSession: var seq[string]): tuple[a: AutoSettings, g: GlobalSettings] =
var p: CfgParser
var filename = os.getConfigDir() / "Aporia" / "config.ini"
var input = newFileStream(filename, fmRead)
open(p, input, joinPath(os.getConfigDir(), "Aporia", "config.ini"))
# It is important to initialize every field, because some fields may not
# be set in the configuration file:
result.a = defaultAutoSettings()
result.g = defaultGlobalSettings()
while true:
var e = next(p)
case e.kind
of cfgEof:
break
of cfgKeyValuePair:
case normalize(e.key)
of "font": result.g.font = e.value
of "outputfont": result.g.outputFont = e.value
of "scheme": result.g.colorSchemeID = e.value
of "indentwidth": result.g.indentWidth = int32(e.value.parseInt())
of "showlinenumbers": result.g.showLineNumbers = isTrue(e.value)
of "highlightmatchingbrackets":
result.g.highlightMatchingBrackets = isTrue(e.value)
of "rightmargin": result.g.rightMargin = isTrue(e.value)
of "highlightcurrentline": result.g.highlightCurrentLine = isTrue(e.value)
of "autoindent": result.g.autoIndent = isTrue(e.value)
of "suggestfeature": result.g.suggestFeature = isTrue(e.value)
of "showcloseonalltabs": result.g.showCloseOnAllTabs = isTrue(e.value)
of "searchmethod": result.a.search = SearchEnum(e.value.parseInt())
of "selecthighlightall": result.g.selectHighlightAll = isTrue(e.value)
of "searchhighlightall": result.g.searchHighlightAll = isTrue(e.value)
of "singleinstanceport":
result.g.singleInstancePort = int32(e.value.parseInt())
of "winmaximized": result.a.winMaximized = isTrue(e.value)
of "vpanedpos": result.a.VPanedPos = int32(e.value.parseInt())
of "toolbarvisible": result.g.toolBarVisible = isTrue(e.value)
of "bottompanelvisible": result.a.bottomPanelVisible = isTrue(e.value)
of "winwidth": result.a.winWidth = int32(e.value.parseInt())
of "winheight": result.a.winHeight = int32(e.value.parseInt())
of "nimcmd", "nimrodcmd": result.g.nimCmd = e.value
of "customcmd1": result.g.customCmd1 = e.value
of "customcmd2": result.g.customCmd2 = e.value
of "customcmd3": result.g.customCmd3 = e.value
of "tabs":
# Add the filepaths of the last session
for i in e.value.split(';'):
if i != "":
lastSession.add(i)
of "recentlyopenedfiles":
for count, file in pairs(e.value.split(';')):
if file != "":
if count > 19:
cfgErrors.add(AporiaError(kind: TETError, desc: "Too many recent files", file: filename, line: "", column: ""))
result.a.recentlyOpenedFiles.add(file)
of "lastselectedtab":
result.a.lastSelectedTab = e.value
of "compileunsavedsave":
result.g.compileUnsavedSave = isTrue(e.value)
of "nimpath", "nimrodpath":
result.g.nimPath = e.value
else:
cfgErrors.add(AporiaError(kind: TETError, desc: "Key \"" & e.key & "\" is invalid.", file: filename, line: "", column: ""))
of cfgError:
cfgErrors.add(AporiaError(kind: TETError, desc: e.msg, file: filename, line: "", column: ""))
of cfgSectionStart, cfgOption:
discard
input.close()
p.close()
proc loadAuto(cfgErrors: var seq[AporiaError], lastSession: var seq[string]): AutoSettings =
result = defaultAutoSettings()
let filename = os.getConfigDir() / "Aporia" / "config.auto.ini"
if not existsFile(filename): return
var pAuto: CfgParser
var autoStream = newFileStream(filename, fmRead)
open(pAuto, autoStream, filename)
# It is important to initialize every field, because some fields may not
# be set in the configuration file:
while true:
var e = next(pAuto)
case e.kind
of cfgEof:
break
of cfgKeyValuePair:
case normalize(e.key):
of "searchmethod": result.search = SearchEnum(e.value.parseInt())
of "wraparound": result.wrapAround = isTrue(e.value)
of "winmaximized": result.winMaximized = isTrue(e.value)
of "vpanedpos": result.VPanedPos = int32(e.value.parseInt())
of "bottompanelvisible": result.bottomPanelVisible = isTrue(e.value)
of "winwidth": result.winWidth = int32(e.value.parseInt())
of "winheight": result.winHeight = int32(e.value.parseInt())
of "tabs":
# Add the filepaths of the last session
for i in e.value.split(';'):
if i != "":
lastSession.add(i)
of "recentlyopenedfiles":
for count, file in pairs(e.value.split(';')):
if file != "":
if count > 19:
cfgErrors.add(AporiaError(kind: TETError, desc: "Too many recent files", file: filename, line: "", column: ""))
result.recentlyOpenedFiles.add(file)
of "lastselectedtab":
result.lastSelectedTab = e.value
else:
cfgErrors.add(AporiaError(kind: TETError, desc: "Key \"" & e.key & "\" is invalid.", file: filename, line: "", column: ""))
of cfgError:
cfgErrors.add(AporiaError(kind: TETError, desc: e.msg, file: filename, line: "", column: ""))
of cfgSectionStart, cfgOption:
discard
autoStream.close()
pAuto.close()
proc loadGlobal*(cfgErrors: var seq[AporiaError], input: Stream): GlobalSettings =
result = defaultGlobalSettings()
if input == nil: return
var pGlobal: CfgParser
var filename = os.getConfigDir() / "Aporia" / "config.global.ini"
open(pGlobal, input, filename)
while true:
var e = next(pGlobal)
case e.kind
of cfgEof:
break
of cfgKeyValuePair:
case normalize(e.key)
of "font": result.font = e.value
of "outputfont": result.outputFont = e.value
of "scheme": result.colorSchemeID = e.value
of "indentwidth": result.indentWidth = int32(e.value.parseInt())
of "showlinenumbers": result.showLineNumbers = isTrue(e.value)
of "highlightmatchingbrackets":
result.highlightMatchingBrackets = isTrue(e.value)
of "rightmargin": result.rightMargin = isTrue(e.value)
of "highlightcurrentline": result.highlightCurrentLine = isTrue(e.value)
of "autoindent": result.autoIndent = isTrue(e.value)
of "suggestfeature": result.suggestFeature = isTrue(e.value)
of "showcloseonalltabs": result.showCloseOnAllTabs = isTrue(e.value)
of "selecthighlightall": result.selectHighlightAll = isTrue(e.value)
of "searchhighlightall": result.searchHighlightAll = isTrue(e.value)
of "singleinstance": result.singleInstance = isTrue(e.value)
of "singleinstanceport":
result.singleInstancePort = int32(e.value.parseInt())
of "restoretabs": result.restoreTabs = isTrue(e.value)
of "activateerrortabonerrors": result.activateErrorTabOnErrors = isTrue(e.value)
of "truncatelongtitles": result.truncateLongTitles = isTrue(e.value)
of "toolbarvisible": result.toolBarVisible = isTrue(e.value)
of "compilesaveall": result.compileSaveAll = isTrue(e.value)
of "nimcmd", "nimrodcmd": result.nimCmd = e.value
of "customcmd1": result.customCmd1 = e.value
of "customcmd2": result.customCmd2 = e.value
of "customcmd3": result.customCmd3 = e.value
of "compileunsavedsave":
result.compileUnsavedSave = isTrue(e.value)
of "keyquit": result.keyQuit = toKeyOrDefault(e.value, result.keyQuit)
of "keycommentlines": result.keyCommentLines = toKeyOrDefault(e.value, result.keyCommentLines)
of "keydeleteline": result.keyDeleteLine = toKeyOrDefault(e.value, result.keyDeleteLine)
of "keyduplicatelines": result.keyDuplicateLines = toKeyOrDefault(e.value, result.keyDuplicateLines)
of "keynewfile": result.keyNewFile = toKeyOrDefault(e.value, result.keyNewFile)
of "keyopenfile": result.keyOpenFile = toKeyOrDefault(e.value, result.keyOpenFile)
of "keysavefile": result.keySaveFile = toKeyOrDefault(e.value, result.keySaveFile)
of "keysavefileas": result.keySaveFileAs = toKeyOrDefault(e.value, result.keySaveFileAs)
of "keysaveall": result.keySaveAll = toKeyOrDefault(e.value, result.keySaveAll)
of "keyundo": result.keyUndo = toKeyOrDefault(e.value, result.keyUndo)
of "keyredo": result.keyRedo = toKeyOrDefault(e.value, result.keyRedo)
of "keyclosecurrenttab": result.keyCloseCurrentTab = toKeyOrDefault(e.value, result.keyCloseCurrentTab)
of "keyclosealltabs": result.keyCloseAllTabs = toKeyOrDefault(e.value, result.keyCloseAllTabs)
of "keyfind": result.keyFind = toKeyOrDefault(e.value, result.keyFind)
of "keyreplace": result.keyReplace = toKeyOrDefault(e.value, result.keyReplace)
of "keyfindnext": result.keyFindNext = toKeyOrDefault(e.value, result.keyFindNext)
of "keyfindprevious": result.keyFindPrevious = toKeyOrDefault(e.value, result.keyFindPrevious)
of "keygotoline": result.keyGoToLine = toKeyOrDefault(e.value, result.keyGoToLine)
of "keygotodef": result.keyGoToDef = toKeyOrDefault(e.value, result.keyGoToDef)
of "keytogglebottompanel": result.keyToggleBottomPanel = toKeyOrDefault(e.value, result.keyToggleBottomPanel)
of "keycompilecurrent": result.keyCompileCurrent = toKeyOrDefault(e.value, result.keyCompileCurrent)
of "keycompileruncurrent": result.keyCompileRunCurrent = toKeyOrDefault(e.value, result.keyCompileRunCurrent)
of "keycompileproject": result.keyCompileProject = toKeyOrDefault(e.value, result.keyCompileProject)
of "keycompilerunproject": result.keyCompileRunProject = toKeyOrDefault(e.value, result.keyCompileRunProject)
of "keystopprocess": result.keyStopProcess = toKeyOrDefault(e.value, result.keyStopProcess)
of "keyruncustomcommand1": result.keyRunCustomCommand1 = toKeyOrDefault(e.value, result.keyRunCustomCommand1)
of "keyruncustomcommand2": result.keyRunCustomCommand2 = toKeyOrDefault(e.value, result.keyRunCustomCommand2)
of "keyruncustomcommand3": result.keyRunCustomCommand3 = toKeyOrDefault(e.value, result.keyRunCustomCommand3)
of "keyruncheck": result.keyRunCheck = toKeyOrDefault(e.value, result.keyRunCheck)
of "nimpath", "nimrodpath":
result.nimPath = e.value
of "wrapmode":
case e.value.normalize
of "none":
result.wrapMode = WrapNone
of "char":
result.wrapMode = WrapChar
of "word":
result.wrapMode = WrapWord
else:
cfgErrors.add(AporiaError(kind: TETError, desc: "WrapMode invalid, got: '" & e.value & "'", file: filename, line: "", column: ""))
of "scrollpastbottom":
result.scrollPastBottom = isTrue(e.value)
else:
cfgErrors.add(AporiaError(kind: TETError, desc: "Key \"" & e.key & "\" is invalid.", file: filename, line: "", column: ""))
of cfgError:
cfgErrors.add(AporiaError(kind: TETError, desc: e.msg, file: filename, line: "", column: ""))
of cfgSectionStart, cfgOption:
discard
close(pGlobal)
proc load*(cfgErrors: var seq[AporiaError], lastSession: var seq[string]): tuple[a: AutoSettings, g: GlobalSettings] =
if existsFile(os.getConfigDir() / "Aporia" / "config.ini"):
return loadOld(cfgErrors, lastSession)
else:
result.a = loadAuto(cfgErrors, lastSession)
var globalStream = newFileStream(os.getConfigDir() / "Aporia" / "config.global.ini", fmRead)
result.g = loadGlobal(cfgErrors, globalStream)
if globalStream != nil:
globalStream.close()