PageRenderTime 80ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/ScintillaNET/Configuration/ConfigurationManager.cs

https://bitbucket.org/nekokun/nekokun
C# | 1930 lines | 1507 code | 379 blank | 44 comment | 552 complexity | c0bf5a8fd7d1a7a8734649a649c6c1bf MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. #region Using Directives
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Windows.Forms;
  9. #endregion Using Directives
  10. namespace ScintillaNET.Configuration
  11. {
  12. [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
  13. public class ConfigurationManager : TopLevelHelper
  14. {
  15. #region Fields
  16. private string _appDataFolder;
  17. private bool _clearIndicators = false;
  18. private bool _clearKeyBindings = false;
  19. private bool _clearMargins = false;
  20. private bool _clearMarkers = false;
  21. private bool _clearSnippets = false;
  22. private bool _clearStyles = false;
  23. private string _customLocation;
  24. private bool _isBuiltInEnabled = true;
  25. private bool _isUserEnabled = true;
  26. private string _language;
  27. private ConfigurationLoadOrder _loadOrder = ConfigurationLoadOrder.BuiltInCustomUser;
  28. private string _userFolder;
  29. private bool _useXmlReader = true;
  30. #endregion Fields
  31. #region Methods
  32. public void Configure()
  33. {
  34. if (Scintilla.IsDesignMode || Scintilla.IsInitializing)
  35. return;
  36. Configuration builtInDefault = null,
  37. builtInLang = null,
  38. customDefault = null,
  39. customLang = null,
  40. userDefault = null,
  41. userLang = null;
  42. if (_isBuiltInEnabled)
  43. {
  44. using(Stream s = GetType().Assembly.GetManifestResourceStream("ScintillaNET.Configuration.Builtin.default.xml"))
  45. builtInDefault = new Configuration(s, "default", _useXmlReader);
  46. if (!string.IsNullOrEmpty(_language))
  47. using (Stream s = GetType().Assembly.GetManifestResourceStream("ScintillaNET.Configuration.Builtin." + _language + ".xml"))
  48. if (s != null)
  49. builtInLang = new Configuration(s, _language, _useXmlReader);
  50. }
  51. if (_isUserEnabled)
  52. {
  53. string defPath = Path.Combine(UserFolder, "default.xml");
  54. if (File.Exists(defPath))
  55. userDefault = new Configuration(defPath, "default", _useXmlReader);
  56. if (!string.IsNullOrEmpty(_language))
  57. {
  58. string langPath = Path.Combine(UserFolder, _language + ".xml");
  59. if (File.Exists(langPath))
  60. userLang = new Configuration(langPath, _language, _useXmlReader);
  61. }
  62. }
  63. if (!string.IsNullOrEmpty(_customLocation))
  64. {
  65. string customDefaultPath = GetCustomConfigPath("default");
  66. string customLanguagePath = GetCustomConfigPath(_language);
  67. if (!string.IsNullOrEmpty(customDefaultPath))
  68. customDefault = new Configuration(customDefaultPath, "default", _useXmlReader);
  69. if (!string.IsNullOrEmpty(customLanguagePath))
  70. customLang = new Configuration(customLanguagePath, _language, _useXmlReader);
  71. else
  72. throw new FileNotFoundException("Could not find the custom configuration file.", _customLocation);
  73. }
  74. List<Configuration> configList = new List<Configuration>();
  75. if (_loadOrder == ConfigurationLoadOrder.BuiltInCustomUser)
  76. {
  77. if (builtInDefault != null && builtInDefault.HasData)
  78. configList.Add(builtInDefault);
  79. if (builtInLang != null && builtInLang.HasData)
  80. configList.Add(builtInLang);
  81. if (customDefault != null && customDefault.HasData)
  82. configList.Add(customDefault);
  83. if (customLang != null && customLang.HasData)
  84. configList.Add(customLang);
  85. if (userDefault != null && userDefault.HasData)
  86. configList.Add(userDefault);
  87. if (userLang != null && userLang.HasData)
  88. configList.Add(userLang);
  89. }
  90. else if (_loadOrder == ConfigurationLoadOrder.BuiltInUserCustom)
  91. {
  92. if (builtInDefault != null && builtInDefault.HasData)
  93. configList.Add(builtInDefault);
  94. if (builtInLang != null && builtInLang.HasData)
  95. configList.Add(builtInLang);
  96. if (userDefault != null && userDefault.HasData)
  97. configList.Add(userDefault);
  98. if (userLang != null && userLang.HasData)
  99. configList.Add(userLang);
  100. if (customDefault != null && customDefault.HasData)
  101. configList.Add(customDefault);
  102. if (customLang != null && customLang.HasData)
  103. configList.Add(customLang);
  104. }
  105. else if (_loadOrder == ConfigurationLoadOrder.CustomBuiltInUser)
  106. {
  107. if (customDefault != null && customDefault.HasData)
  108. configList.Add(customDefault);
  109. if (customLang != null && customLang.HasData)
  110. configList.Add(customLang);
  111. if (builtInDefault != null && builtInDefault.HasData)
  112. configList.Add(builtInDefault);
  113. if (builtInLang != null && builtInLang.HasData)
  114. configList.Add(builtInLang);
  115. if (userDefault != null && userDefault.HasData)
  116. configList.Add(userDefault);
  117. if (userLang != null && userLang.HasData)
  118. configList.Add(userLang);
  119. }
  120. else if (_loadOrder == ConfigurationLoadOrder.CustomUserBuiltIn)
  121. {
  122. if (customDefault != null && customDefault.HasData)
  123. configList.Add(customDefault);
  124. if (customLang != null && customLang.HasData)
  125. configList.Add(customLang);
  126. if (userDefault != null && userDefault.HasData)
  127. configList.Add(userDefault);
  128. if (userLang != null && userLang.HasData)
  129. configList.Add(userLang);
  130. if (builtInDefault != null && builtInDefault.HasData)
  131. configList.Add(builtInDefault);
  132. if (builtInLang != null && builtInLang.HasData)
  133. configList.Add(builtInLang);
  134. }
  135. else if (_loadOrder == ConfigurationLoadOrder.UserBuiltInCustom)
  136. {
  137. if (userDefault != null && userDefault.HasData)
  138. configList.Add(userDefault);
  139. if (userLang != null && userLang.HasData)
  140. configList.Add(userLang);
  141. if (builtInDefault != null && builtInDefault.HasData)
  142. configList.Add(builtInDefault);
  143. if (builtInLang != null && builtInLang.HasData)
  144. configList.Add(builtInLang);
  145. if (customDefault != null && customDefault.HasData)
  146. configList.Add(customDefault);
  147. if (customLang != null && customLang.HasData)
  148. configList.Add(customLang);
  149. }
  150. else if (_loadOrder == ConfigurationLoadOrder.UserCustomBuiltIn)
  151. {
  152. if (userDefault != null && userDefault.HasData)
  153. configList.Add(userDefault);
  154. if (userLang != null && userLang.HasData)
  155. configList.Add(userLang);
  156. if (customDefault != null && customDefault.HasData)
  157. configList.Add(customDefault);
  158. if (customLang != null && customLang.HasData)
  159. configList.Add(customLang);
  160. if (builtInDefault != null && builtInDefault.HasData)
  161. configList.Add(builtInDefault);
  162. if (builtInLang != null && builtInLang.HasData)
  163. configList.Add(builtInLang);
  164. }
  165. Configure(configList);
  166. }
  167. public void Configure(Configuration config)
  168. {
  169. Configure(new List<Configuration>(new Configuration[] { config }));
  170. }
  171. internal void Configure(List<Configuration> configList)
  172. {
  173. // So here is the general pattern: We go through each of
  174. // the configurations in the list (which has been ordered
  175. // by priority). If the configuration has a value we're
  176. // looking for it overwrites whatever was before it.
  177. // In the _end if the value isn't null, we set the
  178. // corresponding Scintilla Value to this.
  179. bool? b = null;
  180. int? i = null;
  181. Color co = Color.Empty;
  182. char? ch = null;
  183. string s = null;
  184. foreach (Configuration c in configList)
  185. {
  186. if (c.AutoComplete_AutoHide.HasValue)
  187. b = c.AutoComplete_AutoHide;
  188. }
  189. if (b.HasValue)
  190. Scintilla.AutoComplete.AutoHide = b.Value;
  191. b = null;
  192. foreach (Configuration c in configList)
  193. {
  194. if (c.AutoComplete_AutomaticLengthEntered.HasValue)
  195. b = c.AutoComplete_AutomaticLengthEntered;
  196. }
  197. if (b.HasValue)
  198. Scintilla.AutoComplete.AutomaticLengthEntered = b.Value;
  199. b = null;
  200. foreach (Configuration c in configList)
  201. {
  202. if (c.AutoComplete_CancelAtStart.HasValue)
  203. b = c.AutoComplete_CancelAtStart;
  204. }
  205. if (b.HasValue)
  206. Scintilla.AutoComplete.CancelAtStart = b.Value;
  207. b = null;
  208. foreach (Configuration c in configList)
  209. {
  210. if (c.AutoComplete_DropRestOfWord.HasValue)
  211. b = c.AutoComplete_DropRestOfWord;
  212. }
  213. if (b.HasValue)
  214. Scintilla.AutoComplete.DropRestOfWord = b.Value;
  215. s = null;
  216. foreach (Configuration c in configList)
  217. {
  218. if (c.AutoComplete_FillUpCharacters != null)
  219. s = c.AutoComplete_FillUpCharacters;
  220. }
  221. if (s != null)
  222. Scintilla.AutoComplete.FillUpCharacters = s;
  223. ch = null;
  224. foreach (Configuration c in configList)
  225. {
  226. if (c.AutoComplete_ImageSeperator != null)
  227. ch = c.AutoComplete_ImageSeperator;
  228. }
  229. if (ch != null)
  230. Scintilla.AutoComplete.ImageSeparator = ch.Value;
  231. b = null;
  232. foreach (Configuration c in configList)
  233. {
  234. if (c.AutoComplete_IsCaseSensitive.HasValue)
  235. b = c.AutoComplete_IsCaseSensitive;
  236. }
  237. if (b.HasValue)
  238. Scintilla.AutoComplete.IsCaseSensitive = b.Value;
  239. ch = null;
  240. foreach (Configuration c in configList)
  241. {
  242. if (c.AutoComplete_ListSeperator.HasValue)
  243. ch = c.AutoComplete_ListSeperator;
  244. }
  245. if (ch.HasValue)
  246. Scintilla.AutoComplete.ListSeparator = ch.Value;
  247. string seperator = Scintilla.AutoComplete.ListSeparator.ToString();
  248. s = null;
  249. foreach (Configuration c in configList)
  250. {
  251. // Lists tend to have an extra config property of "inherits".
  252. // It this flag set to false, the list is cleared before setting
  253. // the current config's list. Otherwise the current config adds
  254. // to the previous configs'.
  255. if (c.AutoComplete_List != null)
  256. {
  257. if (!(c.AutoComplete_ListInherits.HasValue && !c.AutoComplete_ListInherits.Value) || string.IsNullOrEmpty(s))
  258. s = c.AutoComplete_List;
  259. else
  260. s += seperator + c.AutoComplete_List;
  261. }
  262. }
  263. if (s != null)
  264. Scintilla.AutoComplete.ListString = s;
  265. i = null;
  266. foreach (Configuration c in configList)
  267. {
  268. if (c.AutoComplete_MaxHeight.HasValue)
  269. i = c.AutoComplete_MaxHeight;
  270. }
  271. if (i.HasValue)
  272. Scintilla.AutoComplete.MaxHeight = i.Value;
  273. i = null;
  274. foreach (Configuration c in configList)
  275. {
  276. if (c.AutoComplete_MaxWidth.HasValue)
  277. i = c.AutoComplete_MaxWidth;
  278. }
  279. if (i.HasValue)
  280. Scintilla.AutoComplete.MaxWidth = i.Value;
  281. b = null;
  282. foreach (Configuration c in configList)
  283. {
  284. if (c.AutoComplete_SingleLineAccept.HasValue)
  285. b = c.AutoComplete_SingleLineAccept;
  286. }
  287. if (b.HasValue)
  288. Scintilla.AutoComplete.SingleLineAccept = b.Value;
  289. s = null;
  290. foreach (Configuration c in configList)
  291. {
  292. if (c.AutoComplete_StopCharacters != null)
  293. s = c.AutoComplete_StopCharacters;
  294. }
  295. if (s != null)
  296. Scintilla.AutoComplete.StopCharacters = s;
  297. co = Color.Empty;
  298. foreach (Configuration c in configList)
  299. {
  300. if (c.CallTip_BackColor != Color.Empty)
  301. co = c.CallTip_BackColor;
  302. }
  303. if (co != Color.Empty)
  304. Scintilla.CallTip.BackColor = co;
  305. co = Color.Empty;
  306. foreach (Configuration c in configList)
  307. {
  308. if (c.CallTip_ForeColor != Color.Empty)
  309. co = c.CallTip_ForeColor;
  310. }
  311. if (co != Color.Empty)
  312. Scintilla.CallTip.ForeColor = co;
  313. co = Color.Empty;
  314. foreach (Configuration c in configList)
  315. {
  316. if (c.CallTip_HighlightTextColor != Color.Empty)
  317. co = c.CallTip_HighlightTextColor;
  318. }
  319. if (co != Color.Empty)
  320. Scintilla.CallTip.HighlightTextColor = co;
  321. i = null;
  322. foreach (Configuration c in configList)
  323. {
  324. if (c.Caret_BlinkRate.HasValue)
  325. i = c.Caret_BlinkRate;
  326. }
  327. if (i.HasValue)
  328. Scintilla.Caret.BlinkRate = i.Value;
  329. co = Color.Empty;
  330. foreach (Configuration c in configList)
  331. {
  332. if (c.Caret_Color != Color.Empty)
  333. co = c.Caret_Color;
  334. }
  335. if (co != Color.Empty)
  336. Scintilla.Caret.Color = co;
  337. i = null;
  338. foreach (Configuration c in configList)
  339. {
  340. if (c.Caret_CurrentLineBackgroundAlpha.HasValue)
  341. i = c.Caret_CurrentLineBackgroundAlpha;
  342. }
  343. if (i.HasValue)
  344. Scintilla.Caret.CurrentLineBackgroundAlpha = i.Value;
  345. co = Color.Empty;
  346. foreach (Configuration c in configList)
  347. {
  348. if (c.Caret_CurrentLineBackgroundColor != Color.Empty)
  349. co = c.Caret_CurrentLineBackgroundColor;
  350. }
  351. if (co != Color.Empty)
  352. Scintilla.Caret.CurrentLineBackgroundColor = co;
  353. b = null;
  354. foreach (Configuration c in configList)
  355. {
  356. if (c.Caret_HighlightCurrentLine.HasValue)
  357. b = c.Caret_HighlightCurrentLine;
  358. }
  359. if (b.HasValue)
  360. Scintilla.Caret.HighlightCurrentLine = b.Value;
  361. b = null;
  362. foreach (Configuration c in configList)
  363. {
  364. if (c.Caret_IsSticky.HasValue)
  365. b = c.Caret_IsSticky;
  366. }
  367. if (b.HasValue)
  368. Scintilla.Caret.IsSticky = b.Value;
  369. CaretStyle? caretStyle = null;
  370. foreach (Configuration c in configList)
  371. {
  372. if (c.Caret_Style.HasValue)
  373. caretStyle = c.Caret_Style;
  374. }
  375. if (caretStyle.HasValue)
  376. Scintilla.Caret.Style = caretStyle.Value;
  377. i = null;
  378. foreach (Configuration c in configList)
  379. {
  380. if (c.Caret_Width.HasValue)
  381. i = c.Caret_Width;
  382. }
  383. if (i.HasValue)
  384. Scintilla.Caret.Width = i.Value;
  385. b = null;
  386. foreach (Configuration c in configList)
  387. {
  388. if (c.Clipboard_ConvertLineBreaksOnPaste.HasValue)
  389. b = c.Clipboard_ConvertLineBreaksOnPaste;
  390. }
  391. if (b.HasValue)
  392. Scintilla.Clipboard.ConvertLineBreaksOnPaste = b.Value;
  393. b = null;
  394. foreach (Configuration c in configList)
  395. {
  396. if (c.Commands_KeyBindingList.AllowDuplicateBindings.HasValue)
  397. b = c.Commands_KeyBindingList.AllowDuplicateBindings;
  398. }
  399. if (b.HasValue)
  400. Scintilla.Commands.AllowDuplicateBindings = b.Value;
  401. if (_clearKeyBindings)
  402. Scintilla.Commands.RemoveAllBindings();
  403. CommandBindingConfigList cbcl = new CommandBindingConfigList();
  404. foreach (Configuration c in configList)
  405. {
  406. if (c.Commands_KeyBindingList.Inherit.HasValue && !c.Commands_KeyBindingList.Inherit.Value)
  407. cbcl.Clear();
  408. foreach (CommandBindingConfig cbc in c.Commands_KeyBindingList)
  409. cbcl.Add(cbc);
  410. }
  411. foreach (CommandBindingConfig cbc in cbcl)
  412. {
  413. // This indicates that we should clear out any
  414. // existing commands bound to this key combination
  415. if (cbc.ReplaceCurrent.HasValue && cbc.ReplaceCurrent.Value)
  416. Scintilla.Commands.RemoveBinding(cbc.KeyBinding.KeyCode, cbc.KeyBinding.Modifiers);
  417. Scintilla.Commands.AddBinding(cbc.KeyBinding.KeyCode, cbc.KeyBinding.Modifiers, cbc.BindableCommand);
  418. }
  419. s = null;
  420. foreach (Configuration c in configList)
  421. {
  422. if (c.DropMarkers_SharedStackName != null)
  423. s = c.DropMarkers_SharedStackName;
  424. }
  425. if (s != null)
  426. Scintilla.DropMarkers.SharedStackName = s;
  427. b = null;
  428. foreach (Configuration c in configList)
  429. {
  430. if (c.EndOfLine_IsVisisble.HasValue)
  431. b = c.EndOfLine_IsVisisble;
  432. }
  433. if (b.HasValue)
  434. Scintilla.EndOfLine.IsVisible = b.Value;
  435. EndOfLineMode? endOfLineMode = null;
  436. foreach (Configuration c in configList)
  437. {
  438. if (c.EndOfLine_Mode.HasValue)
  439. endOfLineMode = c.EndOfLine_Mode;
  440. }
  441. if (endOfLineMode.HasValue)
  442. Scintilla.EndOfLine.Mode = endOfLineMode.Value;
  443. FoldFlag? ff = null;
  444. foreach (Configuration c in configList)
  445. {
  446. if (c.Folding_Flags.HasValue)
  447. ff = c.Folding_Flags;
  448. }
  449. if (ff.HasValue)
  450. Scintilla.Folding.Flags = ff.Value;
  451. // FoldMarkerScheme moved to Markers section
  452. // becuase Markers need to come first as the
  453. // FoldMarkerScheme really just manipulates
  454. // Markers.
  455. b = null;
  456. foreach (Configuration c in configList)
  457. {
  458. if (c.Folding_IsEnabled.HasValue)
  459. b = c.Folding_IsEnabled;
  460. }
  461. if (b.HasValue)
  462. Scintilla.Folding.IsEnabled = b.Value;
  463. b = null;
  464. foreach (Configuration c in configList)
  465. {
  466. if (c.Folding_UseCompactFolding.HasValue)
  467. b = c.Folding_UseCompactFolding;
  468. }
  469. if (b.HasValue)
  470. Scintilla.Folding.UseCompactFolding = b.Value;
  471. co = Color.Empty;
  472. foreach (Configuration c in configList)
  473. {
  474. if (c.Hotspot_ActiveBackColor != Color.Empty)
  475. co = c.Hotspot_ActiveBackColor;
  476. }
  477. if (co != Color.Empty)
  478. Scintilla.HotspotStyle.ActiveBackColor = co;
  479. co = Color.Empty;
  480. foreach (Configuration c in configList)
  481. {
  482. if (c.Hotspot_ActiveForeColor != Color.Empty)
  483. co = c.Hotspot_ActiveForeColor;
  484. }
  485. if (co != Color.Empty)
  486. Scintilla.HotspotStyle.ActiveForeColor = co;
  487. b = null;
  488. foreach (Configuration c in configList)
  489. {
  490. if (c.Hotspot_ActiveUnderline.HasValue)
  491. b = c.Hotspot_ActiveUnderline;
  492. }
  493. if (b.HasValue)
  494. Scintilla.HotspotStyle.ActiveUnderline = b.Value;
  495. b = null;
  496. foreach (Configuration c in configList)
  497. {
  498. if (c.Hotspot_SingleLine.HasValue)
  499. b = c.Hotspot_SingleLine;
  500. }
  501. if (b.HasValue)
  502. Scintilla.HotspotStyle.SingleLine = b.Value;
  503. b = null;
  504. foreach (Configuration c in configList)
  505. {
  506. if (c.Hotspot_UseActiveBackColor.HasValue)
  507. b = c.Hotspot_UseActiveBackColor;
  508. }
  509. if (b.HasValue)
  510. Scintilla.HotspotStyle.UseActiveBackColor = b.Value;
  511. b = null;
  512. foreach (Configuration c in configList)
  513. {
  514. if (c.Hotspot_UseActiveForeColor.HasValue)
  515. b = c.Hotspot_UseActiveForeColor;
  516. }
  517. if (b.HasValue)
  518. Scintilla.HotspotStyle.UseActiveForeColor = b.Value;
  519. b = null;
  520. foreach (Configuration c in configList)
  521. {
  522. if (c.Indentation_BackspaceUnindents.HasValue)
  523. b = c.Indentation_BackspaceUnindents;
  524. }
  525. if (b.HasValue)
  526. Scintilla.Indentation.BackspaceUnindents = b.Value;
  527. i = null;
  528. foreach (Configuration c in configList)
  529. {
  530. if (c.Indentation_IndentWidth.HasValue)
  531. i = c.Indentation_IndentWidth;
  532. }
  533. if (i.HasValue)
  534. Scintilla.Indentation.IndentWidth = i.Value;
  535. b = null;
  536. foreach (Configuration c in configList)
  537. {
  538. if (c.Indentation_ShowGuides.HasValue)
  539. b = c.Indentation_ShowGuides;
  540. }
  541. if (b.HasValue)
  542. Scintilla.Indentation.ShowGuides = b.Value;
  543. b = null;
  544. foreach (Configuration c in configList)
  545. {
  546. if (c.Indentation_TabIndents.HasValue)
  547. b = c.Indentation_TabIndents;
  548. }
  549. if (b.HasValue)
  550. Scintilla.Indentation.TabIndents = b.Value;
  551. i = null;
  552. foreach (Configuration c in configList)
  553. {
  554. if (c.Indentation_TabWidth.HasValue)
  555. i = c.Indentation_TabWidth;
  556. }
  557. if (i.HasValue)
  558. Scintilla.Indentation.TabWidth = i.Value;
  559. b = null;
  560. foreach (Configuration c in configList)
  561. {
  562. if (c.Indentation_UseTabs.HasValue)
  563. b = c.Indentation_UseTabs;
  564. }
  565. if (b.HasValue)
  566. Scintilla.Indentation.UseTabs = b.Value;
  567. SmartIndent? si = null;
  568. foreach (Configuration c in configList)
  569. {
  570. if (c.Indentation_SmartIndentType.HasValue)
  571. si = c.Indentation_SmartIndentType;
  572. }
  573. if (si.HasValue)
  574. Scintilla.Indentation.SmartIndentType = si.Value;
  575. if (_clearIndicators)
  576. Scintilla.Indicators.Reset();
  577. IndicatorConfigList resolvedIndicators = new IndicatorConfigList();
  578. foreach (Configuration c in configList)
  579. {
  580. if (c.Indicator_List.Inherit.HasValue && !c.Indicator_List.Inherit.Value)
  581. resolvedIndicators.Clear();
  582. foreach (IndicatorConfig ic in c.Indicator_List)
  583. {
  584. if (!resolvedIndicators.Contains(ic.Number) || !(ic.Inherit.HasValue && ic.Inherit.Value))
  585. {
  586. resolvedIndicators.Remove(ic.Number);
  587. resolvedIndicators.Add(ic);
  588. }
  589. else
  590. {
  591. IndicatorConfig rc = resolvedIndicators[ic.Number];
  592. if (ic.Color != Color.Empty)
  593. rc.Color = ic.Color;
  594. if (ic.Style.HasValue)
  595. rc.Style = ic.Style;
  596. if (ic.IsDrawnUnder.HasValue)
  597. rc.IsDrawnUnder = ic.IsDrawnUnder;
  598. }
  599. }
  600. }
  601. foreach (IndicatorConfig ic in resolvedIndicators)
  602. {
  603. Indicator ind = Scintilla.Indicators[ic.Number];
  604. if (ic.Color != Color.Empty)
  605. ind.Color = ic.Color;
  606. if (ic.IsDrawnUnder.HasValue)
  607. ind.IsDrawnUnder = ic.IsDrawnUnder.Value;
  608. if (ic.Style.HasValue)
  609. ind.Style = ic.Style.Value;
  610. }
  611. // Hrm... unfortunately there's no way to clear
  612. // Scintilla's Lexing Properties. Guess we'll just
  613. // have to live with adding to the existing list
  614. // and/or just overriding with new values. This
  615. // means that the "Inherit" attribute is really
  616. // meaningless. Nevertheless I'm leaving it in
  617. // just in case it ever becomes useful.
  618. foreach (Configuration c in configList)
  619. {
  620. foreach (KeyValuePair<string,string> item in c.Lexing_Properties)
  621. {
  622. Scintilla.Lexing.SetProperty(item.Key, item.Value);
  623. }
  624. }
  625. s = null;
  626. foreach (Configuration c in configList)
  627. {
  628. if (c.Lexing_WhitespaceChars != null)
  629. s = c.Lexing_WhitespaceChars;
  630. }
  631. if (s != null)
  632. Scintilla.Lexing.WhitespaceChars = s;
  633. s = null;
  634. foreach (Configuration c in configList)
  635. {
  636. if (c.Lexing_WordChars != null)
  637. s = c.Lexing_WordChars;
  638. }
  639. if (s != null)
  640. Scintilla.Lexing.WordChars = s;
  641. s = null;
  642. foreach (Configuration c in configList)
  643. {
  644. if (c.Lexing_LineCommentPrefix != null)
  645. s = c.Lexing_LineCommentPrefix;
  646. }
  647. if (s != null)
  648. Scintilla.Lexing.LineCommentPrefix = s;
  649. s = null;
  650. foreach (Configuration c in configList)
  651. {
  652. if (c.Lexing_StreamCommentPrefix != null)
  653. s = c.Lexing_StreamCommentPrefix;
  654. }
  655. if (s != null)
  656. Scintilla.Lexing.StreamCommentPrefix = s;
  657. s = null;
  658. foreach (Configuration c in configList)
  659. {
  660. if (c.Lexing_StreamCommentSuffix != null)
  661. s = c.Lexing_StreamCommentSuffix;
  662. }
  663. if (s != null)
  664. Scintilla.Lexing.StreamCommentSufix = s;
  665. s = null;
  666. foreach (Configuration c in configList)
  667. {
  668. if (c.Lexing_Language != null)
  669. s = c.Lexing_Language;
  670. }
  671. if (s == null)
  672. {
  673. // None of the configs specified a lexer. First let's see if
  674. // we have a Language-Lexer map defined:
  675. if (Scintilla.Lexing.LexerLanguageMap.ContainsKey(_language))
  676. {
  677. s = Scintilla.Lexing.LexerLanguageMap[_language];
  678. }
  679. else
  680. {
  681. try
  682. {
  683. Enum.Parse(typeof(Lexer), _language, true);
  684. // If we made it here, the language matches one of
  685. // the lexer names, just use that.
  686. s = _language;
  687. }
  688. catch (ArgumentException)
  689. {
  690. // No match, oh well. Don't set the lexer.
  691. }
  692. }
  693. }
  694. Scintilla.Lexing.LexerName = s;
  695. // Issue 32402: After some experimentation I found that keywords
  696. // must be set AFTER the lexer is set.
  697. foreach (Configuration c in configList)
  698. {
  699. foreach (KeyWordConfig kwc in c.Lexing_Keywords)
  700. {
  701. if (kwc.Inherit.HasValue && kwc.Inherit.Value)
  702. Scintilla.Lexing.Keywords[kwc.List] += kwc.Value;
  703. else
  704. Scintilla.Lexing.Keywords[kwc.List] = kwc.Value;
  705. }
  706. }
  707. i = null;
  708. foreach (Configuration c in configList)
  709. {
  710. if (c.LineWrapping_IndentSize.HasValue)
  711. i = c.LineWrapping_IndentSize;
  712. }
  713. if (i.HasValue)
  714. Scintilla.LineWrapping.IndentSize = i.Value;
  715. LineWrappingIndentMode? lwim = null;
  716. foreach (Configuration c in configList)
  717. {
  718. if (c.LineWrapping_IndentMode.HasValue)
  719. lwim = c.LineWrapping_IndentMode;
  720. }
  721. if (lwim.HasValue)
  722. Scintilla.LineWrapping.IndentMode = lwim.Value;
  723. LineWrappingMode? lwm = null;
  724. foreach (Configuration c in configList)
  725. {
  726. if (c.LineWrapping_Mode.HasValue)
  727. lwm = c.LineWrapping_Mode;
  728. }
  729. if (lwm.HasValue)
  730. Scintilla.LineWrapping.Mode = lwm.Value;
  731. LineWrappingVisualFlags? lwvf = null;
  732. foreach (Configuration c in configList)
  733. {
  734. if (c.LineWrapping_VisualFlags.HasValue)
  735. lwvf = c.LineWrapping_VisualFlags;
  736. }
  737. if (lwvf.HasValue)
  738. Scintilla.LineWrapping.VisualFlags = lwvf.Value;
  739. LineWrappingVisualFlagsLocations? lwvfl = null;
  740. foreach (Configuration c in configList)
  741. {
  742. if (c.LineWrapping_VisualFlagsLocations.HasValue)
  743. lwvfl = c.LineWrapping_VisualFlagsLocations;
  744. }
  745. if (lwvfl.HasValue)
  746. Scintilla.LineWrapping.VisualFlagsLocations = lwvfl.Value;
  747. co = Color.Empty;
  748. foreach (Configuration c in configList)
  749. {
  750. if (c.LongLines_EdgeColor != Color.Empty)
  751. co = c.LongLines_EdgeColor;
  752. }
  753. if (co != Color.Empty)
  754. Scintilla.LongLines.EdgeColor = co;
  755. i = null;
  756. foreach (Configuration c in configList)
  757. {
  758. if (c.LongLines_EdgeColumn.HasValue)
  759. i = c.LongLines_EdgeColumn;
  760. }
  761. if (i.HasValue)
  762. Scintilla.LongLines.EdgeColumn = i.Value;
  763. EdgeMode? em = null;
  764. foreach (Configuration c in configList)
  765. {
  766. if (c.LongLines_EdgeMode.HasValue)
  767. em = c.LongLines_EdgeMode;
  768. }
  769. if (em.HasValue)
  770. Scintilla.LongLines.EdgeMode = em.Value;
  771. if (_clearMargins)
  772. Scintilla.Margins.Reset();
  773. Dictionary<int, MarginConfig> margins = new Dictionary<int, MarginConfig>();
  774. foreach (Configuration c in configList)
  775. {
  776. if (c.Margin_List.Inherit.HasValue && !c.Margin_List.Inherit.Value)
  777. margins.Clear();
  778. foreach (MarginConfig mc in c.Margin_List)
  779. {
  780. if (!margins.ContainsKey(mc.Number) || (mc.Inherit.HasValue && !mc.Inherit.Value))
  781. {
  782. margins.Remove(mc.Number);
  783. margins.Add(mc.Number, mc);
  784. }
  785. else
  786. {
  787. MarginConfig m = margins[mc.Number];
  788. if (mc.AutoToggleMarkerNumber.HasValue)
  789. m.AutoToggleMarkerNumber = mc.AutoToggleMarkerNumber.Value;
  790. if (mc.IsClickable.HasValue)
  791. m.IsClickable = mc.IsClickable.Value;
  792. if (mc.IsFoldMargin.HasValue)
  793. m.IsFoldMargin = mc.IsFoldMargin.Value;
  794. if (mc.IsMarkerMargin.HasValue)
  795. m.IsMarkerMargin = mc.IsMarkerMargin.Value;
  796. if (mc.Type.HasValue)
  797. m.Type = mc.Type.Value;
  798. if (mc.Width.HasValue)
  799. m.Width = mc.Width.Value;
  800. }
  801. }
  802. }
  803. foreach (MarginConfig mc in margins.Values)
  804. {
  805. Margin m = Scintilla.Margins[mc.Number];
  806. if (mc.AutoToggleMarkerNumber.HasValue)
  807. m.AutoToggleMarkerNumber = mc.AutoToggleMarkerNumber.Value;
  808. if (mc.IsClickable.HasValue)
  809. m.IsClickable = mc.IsClickable.Value;
  810. if (mc.IsFoldMargin.HasValue)
  811. m.IsFoldMargin = mc.IsFoldMargin.Value;
  812. if (mc.IsMarkerMargin.HasValue)
  813. m.IsMarkerMargin = mc.IsMarkerMargin.Value;
  814. if (mc.Type.HasValue)
  815. m.Type = mc.Type.Value;
  816. if (mc.Width.HasValue)
  817. m.Width = mc.Width.Value;
  818. }
  819. if (_clearMarkers)
  820. Scintilla.Markers.Reset();
  821. MarkersConfigList resolvedMarkers = new MarkersConfigList();
  822. foreach (Configuration c in configList)
  823. {
  824. if (c.Markers_List.Inherit.HasValue && !c.Markers_List.Inherit.Value)
  825. resolvedMarkers.Clear();
  826. foreach (MarkersConfig mc in c.Markers_List)
  827. {
  828. if (!resolvedMarkers.Contains(mc.Number.Value) || (mc.Inherit.HasValue && !mc.Inherit.Value))
  829. {
  830. resolvedMarkers.Remove(mc.Number.Value);
  831. resolvedMarkers.Add(mc);
  832. }
  833. else
  834. {
  835. if (!mc.Number.HasValue)
  836. mc.Number = (int)(MarkerOutline)Enum.Parse(typeof(MarkerOutline), mc.Name, true);
  837. MarkersConfig m = resolvedMarkers[mc.Number.Value];
  838. if (mc.Alpha.HasValue)
  839. m.Alpha = mc.Alpha;
  840. if (mc.BackColor != Color.Empty)
  841. m.BackColor = mc.BackColor;
  842. if (mc.ForeColor != Color.Empty)
  843. m.ForeColor = mc.ForeColor;
  844. if (mc.Symbol.HasValue)
  845. m.Symbol = mc.Symbol;
  846. }
  847. }
  848. }
  849. foreach (MarkersConfig mc in resolvedMarkers)
  850. {
  851. Marker m = Scintilla.Markers[mc.Number.Value];
  852. if (mc.Alpha.HasValue)
  853. m.Alpha = mc.Alpha.Value;
  854. if (mc.BackColor != Color.Empty)
  855. m.BackColor = mc.BackColor;
  856. if (mc.ForeColor != Color.Empty)
  857. m.ForeColor = mc.ForeColor;
  858. if (mc.Symbol.HasValue)
  859. m.Symbol = mc.Symbol.Value;
  860. }
  861. FoldMarkerScheme? fms = null;
  862. foreach (Configuration c in configList)
  863. {
  864. if (c.Folding_MarkerScheme.HasValue)
  865. fms = c.Folding_MarkerScheme;
  866. }
  867. if (fms.HasValue)
  868. Scintilla.Folding.MarkerScheme = fms.Value;
  869. b = null;
  870. foreach (Configuration c in configList)
  871. {
  872. if (c.Scrolling_EndAtLastLine.HasValue)
  873. b = c.Scrolling_EndAtLastLine;
  874. }
  875. if (b.HasValue)
  876. Scintilla.Scrolling.EndAtLastLine = b.Value;
  877. i = null;
  878. foreach (Configuration c in configList)
  879. {
  880. if (c.Scrolling_HorizontalWidth.HasValue)
  881. i = c.Scrolling_HorizontalWidth;
  882. }
  883. if (i.HasValue)
  884. Scintilla.Scrolling.HorizontalWidth = i.Value;
  885. ScrollBars? sb = null;
  886. foreach (Configuration c in configList)
  887. {
  888. if (c.Scrolling_ScrollBars.HasValue)
  889. sb = c.Scrolling_ScrollBars;
  890. }
  891. if (sb.HasValue)
  892. Scintilla.Scrolling.ScrollBars = sb.Value;
  893. i = null;
  894. foreach (Configuration c in configList)
  895. {
  896. if (c.Scrolling_XOffset.HasValue)
  897. i = c.Scrolling_XOffset;
  898. }
  899. if (i.HasValue)
  900. Scintilla.Scrolling.XOffset = i.Value;
  901. co = Color.Empty;
  902. foreach (Configuration c in configList)
  903. {
  904. if (c.Selection_BackColor != Color.Empty)
  905. co = c.Selection_BackColor;
  906. }
  907. if (co != Color.Empty)
  908. Scintilla.Selection.BackColor = co;
  909. co = Color.Empty;
  910. foreach (Configuration c in configList)
  911. {
  912. if (c.Selection_BackColorUnfocused != Color.Empty)
  913. co = c.Selection_BackColorUnfocused;
  914. }
  915. if (co != Color.Empty)
  916. Scintilla.Selection.BackColorUnfocused = co;
  917. co = Color.Empty;
  918. foreach (Configuration c in configList)
  919. {
  920. if (c.Selection_ForeColor != Color.Empty)
  921. co = c.Selection_ForeColor;
  922. }
  923. if (co != Color.Empty)
  924. Scintilla.Selection.ForeColor = co;
  925. co = Color.Empty;
  926. foreach (Configuration c in configList)
  927. {
  928. if (c.Selection_ForeColorUnfocused != Color.Empty)
  929. co = c.Selection_ForeColorUnfocused;
  930. }
  931. if (co != Color.Empty)
  932. Scintilla.Selection.ForeColorUnfocused = co;
  933. b = null;
  934. foreach (Configuration c in configList)
  935. {
  936. if (c.Selection_Hidden.HasValue)
  937. b = c.Selection_Hidden;
  938. }
  939. if (b.HasValue)
  940. Scintilla.Selection.Hidden = b.Value;
  941. b = null;
  942. foreach (Configuration c in configList)
  943. {
  944. if (c.Selection_HideSelection.HasValue)
  945. b = c.Selection_HideSelection;
  946. }
  947. if (b.HasValue)
  948. Scintilla.Selection.HideSelection = b.Value;
  949. SelectionMode? selectionMode = null;
  950. foreach (Configuration c in configList)
  951. {
  952. if (c.Selection_Mode.HasValue)
  953. selectionMode = c.Selection_Mode;
  954. }
  955. if (selectionMode.HasValue)
  956. Scintilla.Selection.Mode = selectionMode.Value;
  957. if (_clearSnippets)
  958. Scintilla.Snippets.List.Clear();
  959. b = null;
  960. foreach (Configuration c in configList)
  961. {
  962. if (c.SnippetsConfigList.IsEnabled.HasValue)
  963. b = c.SnippetsConfigList.IsEnabled;
  964. }
  965. if (b.HasValue)
  966. Scintilla.Snippets.IsEnabled = b.Value;
  967. b = null;
  968. foreach (Configuration c in configList)
  969. {
  970. if (c.SnippetsConfigList.IsOneKeySelectionEmbedEnabled.HasValue)
  971. b = c.SnippetsConfigList.IsOneKeySelectionEmbedEnabled;
  972. }
  973. if (b.HasValue)
  974. Scintilla.Snippets.IsOneKeySelectionEmbedEnabled = b.Value;
  975. char? defaultDelimeter = null;
  976. foreach (Configuration c in configList)
  977. {
  978. if (c.SnippetsConfigList.DefaultDelimeter.HasValue)
  979. defaultDelimeter = c.SnippetsConfigList.DefaultDelimeter;
  980. }
  981. if (!ch.HasValue)
  982. Scintilla.Snippets.DefaultDelimeter = '$';
  983. SnippetList snips = new SnippetList(null);
  984. foreach (Configuration c in configList)
  985. {
  986. if (c.SnippetsConfigList.Inherit.HasValue && !c.SnippetsConfigList.Inherit.Value)
  987. snips.Clear();
  988. foreach (SnippetsConfig sc in c.SnippetsConfigList)
  989. {
  990. if (snips.Contains(sc.Shortcut))
  991. snips.Remove(sc.Shortcut);
  992. Snippet snip;
  993. if (sc.Delimeter.HasValue)
  994. snip = snips.Add(sc.Shortcut, sc.Code, sc.Delimeter.Value);
  995. else
  996. snip = snips.Add(sc.Shortcut, sc.Code, Scintilla.Snippets.DefaultDelimeter);
  997. if (sc.IsSurroundsWith.HasValue)
  998. snip.IsSurroundsWith = sc.IsSurroundsWith.Value;
  999. }
  1000. }
  1001. SnippetList sl = Scintilla.Snippets.List;
  1002. foreach (Snippet sc in snips)
  1003. {
  1004. if (sl.Contains(sc.Shortcut))
  1005. sl.Remove(sc.Shortcut);
  1006. sl.Add(sc.Shortcut, sc.Code, Scintilla.Snippets.DefaultDelimeter, sc.IsSurroundsWith);
  1007. }
  1008. sl.Sort();
  1009. co = Color.Empty;
  1010. foreach (Configuration c in configList)
  1011. {
  1012. if (c.SnippetsConfigList.ActiveSnippetColor != Color.Empty)
  1013. co = c.SnippetsConfigList.ActiveSnippetColor;
  1014. }
  1015. if (co != Color.Empty)
  1016. Scintilla.Snippets.ActiveSnippetColor = co;
  1017. IndicatorStyle? indicatorStyle = null;
  1018. foreach (Configuration c in configList)
  1019. {
  1020. if (c.SnippetsConfigList.ActiveSnippetIndicatorStyle.HasValue)
  1021. indicatorStyle = c.SnippetsConfigList.ActiveSnippetIndicatorStyle;
  1022. }
  1023. if (indicatorStyle.HasValue)
  1024. Scintilla.Snippets.ActiveSnippetIndicatorStyle = indicatorStyle.Value;
  1025. i = null;
  1026. foreach (Configuration c in configList)
  1027. {
  1028. if (c.SnippetsConfigList.ActiveSnippetIndicator.HasValue)
  1029. i = c.SnippetsConfigList.ActiveSnippetIndicator;
  1030. }
  1031. if (i.HasValue)
  1032. Scintilla.Snippets.ActiveSnippetIndicator = i.Value;
  1033. co = Color.Empty;
  1034. foreach (Configuration c in configList)
  1035. {
  1036. if (c.SnippetsConfigList.InactiveSnippetColor != Color.Empty)
  1037. co = c.SnippetsConfigList.InactiveSnippetColor;
  1038. }
  1039. if (co != Color.Empty)
  1040. Scintilla.Snippets.InactiveSnippetColor = co;
  1041. i = null;
  1042. foreach (Configuration c in configList)
  1043. {
  1044. if (c.SnippetsConfigList.InactiveSnippetIndicator.HasValue)
  1045. i = c.SnippetsConfigList.InactiveSnippetIndicator;
  1046. }
  1047. if (i.HasValue)
  1048. Scintilla.Snippets.InactiveSnippetIndicator = i.Value;
  1049. IndicatorStyle? ics = null;
  1050. foreach (Configuration c in configList)
  1051. {
  1052. if (c.SnippetsConfigList.ActiveSnippetIndicatorStyle.HasValue)
  1053. ics = c.SnippetsConfigList.ActiveSnippetIndicatorStyle;
  1054. }
  1055. if (ics.HasValue)
  1056. Scintilla.Snippets.ActiveSnippetIndicatorStyle = ics.Value;
  1057. indicatorStyle = null;
  1058. foreach (Configuration c in configList)
  1059. {
  1060. if (c.SnippetsConfigList.InactiveSnippetIndicatorStyle.HasValue)
  1061. indicatorStyle = c.SnippetsConfigList.InactiveSnippetIndicatorStyle;
  1062. }
  1063. if (indicatorStyle.HasValue)
  1064. Scintilla.Snippets.InactiveSnippetIndicatorStyle = indicatorStyle.Value;
  1065. b = null;
  1066. foreach (Configuration c in configList)
  1067. {
  1068. if (c.UndoRedoIsUndoEnabled.HasValue)
  1069. b = c.UndoRedoIsUndoEnabled;
  1070. }
  1071. if (b.HasValue)
  1072. Scintilla.UndoRedo.IsUndoEnabled = b.Value;
  1073. co = Color.Empty;
  1074. foreach (Configuration c in configList)
  1075. {
  1076. if (c.Whitespace_BackColor != Color.Empty)
  1077. co = c.Whitespace_BackColor;
  1078. }
  1079. if (co != Color.Empty)
  1080. Scintilla.Whitespace.BackColor = co;
  1081. co = Color.Empty;
  1082. foreach (Configuration c in configList)
  1083. {
  1084. if (c.Whitespace_ForeColor != Color.Empty)
  1085. co = c.Whitespace_ForeColor;
  1086. }
  1087. if (co != Color.Empty)
  1088. Scintilla.Whitespace.ForeColor = co;
  1089. WhitespaceMode? wsm = null;
  1090. foreach (Configuration c in configList)
  1091. {
  1092. if (c.Whitespace_Mode.HasValue)
  1093. wsm = c.Whitespace_Mode;
  1094. }
  1095. if (wsm.HasValue)
  1096. Scintilla.Whitespace.Mode = wsm.Value;
  1097. // OK so we saved the best for last instead of going in
  1098. // strict lexical order. Styles! This is really the section
  1099. // that people care about most in the config, and is also
  1100. // the most complex.
  1101. if (_clearStyles)
  1102. Scintilla.Styles.Reset();
  1103. i = null;
  1104. foreach (Configuration c in configList)
  1105. {
  1106. if (c.Styles.Bits.HasValue)
  1107. i = c.Styles.Bits;
  1108. }
  1109. #pragma warning disable 618
  1110. if (i.HasValue)
  1111. Scintilla.Styles.Bits = i.Value;
  1112. #pragma warning restore 618
  1113. Dictionary<string, int> styleNameMap = Scintilla.Lexing.StyleNameMap;
  1114. ResolvedStyleList resolvedStyles = new ResolvedStyleList();
  1115. int _unmappedStyleNumber = -1;
  1116. Dictionary<string, int> _unmappedStyleMap = new Dictionary<string,int>();
  1117. foreach (Configuration c in configList)
  1118. {
  1119. if (c.Styles.Inherit.HasValue && !c.Styles.Inherit.Value)
  1120. resolvedStyles.Clear();
  1121. foreach (StyleConfig sc in c.Styles)
  1122. {
  1123. i = sc.Number;
  1124. if (!i.HasValue)
  1125. {
  1126. if (!styleNameMap.ContainsKey(sc.Name))
  1127. {
  1128. if (_unmappedStyleMap.ContainsKey(sc.Name))
  1129. {
  1130. i = _unmappedStyleMap[sc.Name];
  1131. sc.Number = i;
  1132. }
  1133. else
  1134. {
  1135. i = _unmappedStyleNumber--;
  1136. sc.Number = i;
  1137. _unmappedStyleMap[sc.Name] = sc.Number.Value;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. i = styleNameMap[sc.Name];
  1143. sc.Number = i;
  1144. }
  1145. }
  1146. StyleConfig baseStyleConfig = null;
  1147. if (!string.IsNullOrEmpty(sc.Name) && sc.Name.Contains("."))
  1148. {
  1149. baseStyleConfig = resolvedStyles.FindByName(sc.Name.Substring(sc.Name.IndexOf(".") + 1));
  1150. }
  1151. if (!resolvedStyles.ContainsKey(i.Value) || (sc.Inherit.HasValue && !sc.Inherit.Value))
  1152. {
  1153. resolvedStyles.Remove(i.Value);
  1154. resolvedStyles.Add(i.Value, sc);
  1155. }
  1156. StyleConfig rs = resolvedStyles[i.Value];
  1157. if (sc.BackColor != Color.Empty)
  1158. rs.BackColor = sc.BackColor;
  1159. else if (baseStyleConfig !=

Large files files are truncated, but you can click here to view the full file