From f7926ea1b07ac9b4fac268a44e42036f719b5d42 Mon Sep 17 00:00:00 2001 From: WMJ Date: Wed, 26 Dec 2018 10:30:27 +0800 Subject: [PATCH] + Added filter to import part of syntax highlight themes (#69) --- Codist/Config.cs | 48 +++- .../Options/SyntaxHighlightPage.Designer.cs | 233 ++++++++++++------ Codist/Options/SyntaxHighlightPage.cs | 22 +- Codist/SyntaxHighlight/StyleBase.cs | 45 +++- 4 files changed, 244 insertions(+), 104 deletions(-) diff --git a/Codist/Config.cs b/Codist/Config.cs index 5077c0d4..6f8ab861 100644 --- a/Codist/Config.cs +++ b/Codist/Config.cs @@ -74,7 +74,7 @@ public static Config InitConfig() { return config; } try { - return InternalLoadConfig(ConfigPath, false); + return InternalLoadConfig(ConfigPath, StyleFilters.None); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); @@ -82,16 +82,16 @@ public static Config InitConfig() { } } - public static void LoadConfig(string configPath, bool stylesOnly = false) { + public static void LoadConfig(string configPath, StyleFilters styleFilter = StyleFilters.None) { if (Interlocked.Exchange(ref _LoadingConfig, 1) != 0) { return; } Debug.WriteLine("Load config: " + configPath); try { - Instance = InternalLoadConfig(configPath, stylesOnly); + Instance = InternalLoadConfig(configPath, styleFilter); //TextEditorHelper.ResetStyleCache(); Loaded?.Invoke(Instance, EventArgs.Empty); - Updated?.Invoke(Instance, new ConfigUpdatedEventArgs(stylesOnly ? Features.SyntaxHighlight : Features.All)); + Updated?.Invoke(Instance, new ConfigUpdatedEventArgs(styleFilter != StyleFilters.None ? Features.SyntaxHighlight : Features.All)); } catch(Exception ex) { Debug.WriteLine(ex.ToString()); @@ -102,7 +102,7 @@ public static void LoadConfig(string configPath, bool stylesOnly = false) { } } - static Config InternalLoadConfig(string configPath, bool stylesOnly) { + static Config InternalLoadConfig(string configPath, StyleFilters styleFilter) { var configContent = configPath == LightTheme ? Properties.Resources.Light : configPath == DarkTheme ? Properties.Resources.Dark : configPath == SimpleTheme ? Properties.Resources.Simple @@ -114,7 +114,7 @@ static Config InternalLoadConfig(string configPath, bool stylesOnly) { args.ErrorContext.Handled = true; // ignore json error } }); - if (stylesOnly == false) { + if (styleFilter == StyleFilters.None) { var l = config.Labels; for (var i = l.Count - 1; i >= 0; i--) { if (String.IsNullOrWhiteSpace(l[i].Label)) { @@ -132,7 +132,7 @@ static Config InternalLoadConfig(string configPath, bool stylesOnly) { LoadStyleEntries(config.CodeStyles, removeFontNames); LoadStyleEntries(config.XmlCodeStyles, removeFontNames); LoadStyleEntries(config.SymbolMarkerStyles, removeFontNames); - if (stylesOnly) { + if (styleFilter == StyleFilters.All) { // don't override other settings if loaded from predefined themes or syntax config file ResetCodeStyle(Instance.GeneralStyles, config.GeneralStyles); ResetCodeStyle(Instance.CommentStyles, config.CommentStyles); @@ -144,6 +144,18 @@ static Config InternalLoadConfig(string configPath, bool stylesOnly) { _LastLoaded = DateTime.Now; return Instance; } + else if (styleFilter != StyleFilters.None) { + MergeCodeStyle(Instance.GeneralStyles, config.GeneralStyles, styleFilter); + MergeCodeStyle(Instance.CommentStyles, config.CommentStyles, styleFilter); + MergeCodeStyle(Instance.CodeStyles, config.CodeStyles, styleFilter); + MergeCodeStyle(Instance.CppStyles, config.CppStyles, styleFilter); + MergeCodeStyle(Instance.XmlCodeStyles, config.XmlCodeStyles, styleFilter); + MergeCodeStyle(Instance.SymbolMarkerStyles, config.SymbolMarkerStyles, styleFilter); + //MergeCodeStyle(Instance.MarkerSettings, config.MarkerSettings, styleFilter); + ResetCodeStyle(Instance.MarkerSettings, config.MarkerSettings); + _LastLoaded = DateTime.Now; + return Instance; + } _LastLoaded = DateTime.Now; Debug.WriteLine("Config loaded"); return config; @@ -307,6 +319,17 @@ static void ResetCodeStyle(List source, IEnumerable targ source.Clear(); source.AddRange(target); } + static void MergeCodeStyle(List source, IEnumerable target, StyleFilters styleFilters) where TStyle : StyleBase { + foreach (var item in target) { + if (item.IsSet == false) { + continue; + } + var s = source.Find(i => i.Id == item.Id); + if (s != null) { + item.CopyTo(s, styleFilters); + } + } + } internal static CommentStyle[] GetDefaultCommentStyles() { return new CommentStyle[] { new CommentStyle(CommentStyleTypes.Emphasis, Constants.CommentColor) { Bold = true, FontSize = 10 }, @@ -476,6 +499,17 @@ public enum SpecialHighlightOptions AllBraces = DeclarationBrace | ParameterBrace | BranchBrace | LoopBrace | ResourceBrace | SpecialPunctuation } + [Flags] + public enum StyleFilters + { + None, + Color = 1, + FontFamily = 1 << 1, + FontSize = 1 << 2, + FontStyle = 1 << 3, + All = Color | FontFamily | FontSize | FontStyle + } + [Flags] public enum MarkerOptions { diff --git a/Codist/Options/SyntaxHighlightPage.Designer.cs b/Codist/Options/SyntaxHighlightPage.Designer.cs index fa35183d..8a7a0c88 100644 --- a/Codist/Options/SyntaxHighlightPage.Designer.cs +++ b/Codist/Options/SyntaxHighlightPage.Designer.cs @@ -25,54 +25,168 @@ protected override void Dispose(bool disposing) { /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { - this._LightThemeButton = new System.Windows.Forms.Button(); + this._SyntaxHighlightTabs = new System.Windows.Forms.TabControl(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.customGroupBox1 = new Codist.Controls.CustomGroupBox(); + this._HighlightSpecialCommentBox = new System.Windows.Forms.CheckBox(); this.groupBox2 = new Codist.Controls.CustomGroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this._FontFamilyBox = new System.Windows.Forms.CheckBox(); + this._ColorBox = new System.Windows.Forms.CheckBox(); + this._FontSizeBox = new System.Windows.Forms.CheckBox(); + this._FontStyleBox = new System.Windows.Forms.CheckBox(); + this.titleLabel2 = new Codist.Controls.TitleLabel(); + this.titleLabel1 = new Codist.Controls.TitleLabel(); this._LoadButton = new System.Windows.Forms.Button(); this._SaveButton = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); this._ResetThemeButton = new System.Windows.Forms.Button(); this._SimpleThemeButton = new System.Windows.Forms.Button(); this._DarkThemeButton = new System.Windows.Forms.Button(); - this._SyntaxHighlightTabs = new System.Windows.Forms.TabControl(); - this.tabPage2 = new System.Windows.Forms.TabPage(); - this.customGroupBox1 = new Codist.Controls.CustomGroupBox(); - this._HighlightSpecialCommentBox = new System.Windows.Forms.CheckBox(); - this.groupBox2.SuspendLayout(); + this._LightThemeButton = new System.Windows.Forms.Button(); this._SyntaxHighlightTabs.SuspendLayout(); this.tabPage2.SuspendLayout(); this.customGroupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // - // _LightThemeButton + // _SyntaxHighlightTabs // - this._LightThemeButton.Location = new System.Drawing.Point(9, 24); - this._LightThemeButton.Name = "_LightThemeButton"; - this._LightThemeButton.Size = new System.Drawing.Size(110, 23); - this._LightThemeButton.TabIndex = 1; - this._LightThemeButton.Text = "&Light theme"; - this._LightThemeButton.UseVisualStyleBackColor = true; + this._SyntaxHighlightTabs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this._SyntaxHighlightTabs.Controls.Add(this.tabPage2); + this._SyntaxHighlightTabs.Location = new System.Drawing.Point(3, 3); + this._SyntaxHighlightTabs.Name = "_SyntaxHighlightTabs"; + this._SyntaxHighlightTabs.SelectedIndex = 0; + this._SyntaxHighlightTabs.Size = new System.Drawing.Size(569, 322); + this._SyntaxHighlightTabs.TabIndex = 4; + // + // tabPage2 + // + this.tabPage2.Controls.Add(this.customGroupBox1); + this.tabPage2.Controls.Add(this.groupBox2); + this.tabPage2.Location = new System.Drawing.Point(4, 25); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(561, 293); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "General"; + this.tabPage2.UseVisualStyleBackColor = true; + // + // customGroupBox1 + // + this.customGroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.customGroupBox1.Controls.Add(this._HighlightSpecialCommentBox); + this.customGroupBox1.Location = new System.Drawing.Point(6, 219); + this.customGroupBox1.Name = "customGroupBox1"; + this.customGroupBox1.Size = new System.Drawing.Size(549, 68); + this.customGroupBox1.TabIndex = 8; + this.customGroupBox1.TabStop = false; + this.customGroupBox1.Text = "Extra Syntax Highlight"; + // + // _HighlightSpecialCommentBox + // + this._HighlightSpecialCommentBox.AutoSize = true; + this._HighlightSpecialCommentBox.Location = new System.Drawing.Point(6, 24); + this._HighlightSpecialCommentBox.Name = "_HighlightSpecialCommentBox"; + this._HighlightSpecialCommentBox.Size = new System.Drawing.Size(141, 19); + this._HighlightSpecialCommentBox.TabIndex = 7; + this._HighlightSpecialCommentBox.Text = "Comment tagger"; + this._HighlightSpecialCommentBox.UseVisualStyleBackColor = true; // // groupBox2 // this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Controls.Add(this._FontFamilyBox); + this.groupBox2.Controls.Add(this._ColorBox); + this.groupBox2.Controls.Add(this._FontSizeBox); + this.groupBox2.Controls.Add(this._FontStyleBox); + this.groupBox2.Controls.Add(this.titleLabel2); + this.groupBox2.Controls.Add(this.titleLabel1); this.groupBox2.Controls.Add(this._LoadButton); this.groupBox2.Controls.Add(this._SaveButton); - this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this._ResetThemeButton); this.groupBox2.Controls.Add(this._SimpleThemeButton); this.groupBox2.Controls.Add(this._DarkThemeButton); this.groupBox2.Controls.Add(this._LightThemeButton); this.groupBox2.Location = new System.Drawing.Point(6, 6); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(549, 157); + this.groupBox2.Size = new System.Drawing.Size(549, 207); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; - this.groupBox2.Text = "Super Syntax Highlight Presets"; + this.groupBox2.Text = "Manage Syntax Highlight Themes"; + // + // label1 + // + this.label1.Location = new System.Drawing.Point(6, 154); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(537, 50); + this.label1.TabIndex = 12; + this.label1.Text = "1. Press one of the above button to quickly setup syntax highlight styles.\r\n2. Op" + + "en a document to see highlight effects"; + // + // _FontFamilyBox + // + this._FontFamilyBox.AutoSize = true; + this._FontFamilyBox.Location = new System.Drawing.Point(357, 78); + this._FontFamilyBox.Name = "_FontFamilyBox"; + this._FontFamilyBox.Size = new System.Drawing.Size(117, 19); + this._FontFamilyBox.TabIndex = 11; + this._FontFamilyBox.Text = "Font family"; + this._FontFamilyBox.UseVisualStyleBackColor = true; + // + // _ColorBox + // + this._ColorBox.AutoSize = true; + this._ColorBox.Location = new System.Drawing.Point(9, 78); + this._ColorBox.Name = "_ColorBox"; + this._ColorBox.Size = new System.Drawing.Size(69, 19); + this._ColorBox.TabIndex = 11; + this._ColorBox.Text = "Color"; + this._ColorBox.UseVisualStyleBackColor = true; + // + // _FontSizeBox + // + this._FontSizeBox.AutoSize = true; + this._FontSizeBox.Location = new System.Drawing.Point(242, 78); + this._FontSizeBox.Name = "_FontSizeBox"; + this._FontSizeBox.Size = new System.Drawing.Size(101, 19); + this._FontSizeBox.TabIndex = 11; + this._FontSizeBox.Text = "Font size"; + this._FontSizeBox.UseVisualStyleBackColor = true; + // + // _FontStyleBox + // + this._FontStyleBox.AutoSize = true; + this._FontStyleBox.Location = new System.Drawing.Point(125, 78); + this._FontStyleBox.Name = "_FontStyleBox"; + this._FontStyleBox.Size = new System.Drawing.Size(109, 19); + this._FontStyleBox.TabIndex = 11; + this._FontStyleBox.Text = "Font style"; + this._FontStyleBox.UseVisualStyleBackColor = true; + // + // titleLabel2 + // + this.titleLabel2.Location = new System.Drawing.Point(6, 60); + this.titleLabel2.Name = "titleLabel2"; + this.titleLabel2.Size = new System.Drawing.Size(371, 15); + this.titleLabel2.TabIndex = 10; + this.titleLabel2.Text = "Load following parts when importing themes"; + // + // titleLabel1 + // + this.titleLabel1.Location = new System.Drawing.Point(6, 109); + this.titleLabel1.Name = "titleLabel1"; + this.titleLabel1.Size = new System.Drawing.Size(371, 15); + this.titleLabel1.TabIndex = 9; + this.titleLabel1.Text = "Import predefined theme"; // // _LoadButton // - this._LoadButton.Location = new System.Drawing.Point(9, 118); + this._LoadButton.Location = new System.Drawing.Point(9, 24); this._LoadButton.Name = "_LoadButton"; this._LoadButton.Size = new System.Drawing.Size(111, 23); this._LoadButton.TabIndex = 8; @@ -81,29 +195,16 @@ private void InitializeComponent() { // // _SaveButton // - this._SaveButton.Location = new System.Drawing.Point(125, 118); + this._SaveButton.Location = new System.Drawing.Point(125, 24); this._SaveButton.Name = "_SaveButton"; this._SaveButton.Size = new System.Drawing.Size(111, 23); this._SaveButton.TabIndex = 8; this._SaveButton.Text = "Save..."; this._SaveButton.UseVisualStyleBackColor = true; - // - // label1 - // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label1.Location = new System.Drawing.Point(6, 61); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(537, 54); - this.label1.TabIndex = 3; - this.label1.Text = "Tip: 1) You can quickly load or reset syntax theme by pressing the buttons above." + - " 2) Open a C# code file to see effects immediately.\r\nNote: If you changed the VS" + - " Theme, you may need to restart VS."; // // _ResetThemeButton // - this._ResetThemeButton.Location = new System.Drawing.Point(373, 24); + this._ResetThemeButton.Location = new System.Drawing.Point(242, 24); this._ResetThemeButton.Name = "_ResetThemeButton"; this._ResetThemeButton.Size = new System.Drawing.Size(111, 23); this._ResetThemeButton.TabIndex = 2; @@ -112,7 +213,7 @@ private void InitializeComponent() { // // _SimpleThemeButton // - this._SimpleThemeButton.Location = new System.Drawing.Point(242, 24); + this._SimpleThemeButton.Location = new System.Drawing.Point(242, 128); this._SimpleThemeButton.Name = "_SimpleThemeButton"; this._SimpleThemeButton.Size = new System.Drawing.Size(111, 23); this._SimpleThemeButton.TabIndex = 0; @@ -121,58 +222,21 @@ private void InitializeComponent() { // // _DarkThemeButton // - this._DarkThemeButton.Location = new System.Drawing.Point(125, 24); + this._DarkThemeButton.Location = new System.Drawing.Point(125, 128); this._DarkThemeButton.Name = "_DarkThemeButton"; this._DarkThemeButton.Size = new System.Drawing.Size(111, 23); this._DarkThemeButton.TabIndex = 0; this._DarkThemeButton.Text = "&Dark theme"; this._DarkThemeButton.UseVisualStyleBackColor = true; // - // _SyntaxHighlightTabs - // - this._SyntaxHighlightTabs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._SyntaxHighlightTabs.Controls.Add(this.tabPage2); - this._SyntaxHighlightTabs.Location = new System.Drawing.Point(3, 3); - this._SyntaxHighlightTabs.Name = "_SyntaxHighlightTabs"; - this._SyntaxHighlightTabs.SelectedIndex = 0; - this._SyntaxHighlightTabs.Size = new System.Drawing.Size(569, 322); - this._SyntaxHighlightTabs.TabIndex = 4; - // - // tabPage2 - // - this.tabPage2.Controls.Add(this.customGroupBox1); - this.tabPage2.Controls.Add(this.groupBox2); - this.tabPage2.Location = new System.Drawing.Point(4, 25); - this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(561, 293); - this.tabPage2.TabIndex = 1; - this.tabPage2.Text = "General"; - this.tabPage2.UseVisualStyleBackColor = true; - // - // customGroupBox1 - // - this.customGroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.customGroupBox1.Controls.Add(this._HighlightSpecialCommentBox); - this.customGroupBox1.Location = new System.Drawing.Point(6, 169); - this.customGroupBox1.Name = "customGroupBox1"; - this.customGroupBox1.Size = new System.Drawing.Size(549, 68); - this.customGroupBox1.TabIndex = 8; - this.customGroupBox1.TabStop = false; - this.customGroupBox1.Text = "Extra Syntax Highlight"; - // - // _HighlightSpecialCommentBox + // _LightThemeButton // - this._HighlightSpecialCommentBox.AutoSize = true; - this._HighlightSpecialCommentBox.Location = new System.Drawing.Point(6, 24); - this._HighlightSpecialCommentBox.Name = "_HighlightSpecialCommentBox"; - this._HighlightSpecialCommentBox.Size = new System.Drawing.Size(141, 19); - this._HighlightSpecialCommentBox.TabIndex = 7; - this._HighlightSpecialCommentBox.Text = "Comment tagger"; - this._HighlightSpecialCommentBox.UseVisualStyleBackColor = true; + this._LightThemeButton.Location = new System.Drawing.Point(8, 128); + this._LightThemeButton.Name = "_LightThemeButton"; + this._LightThemeButton.Size = new System.Drawing.Size(111, 23); + this._LightThemeButton.TabIndex = 1; + this._LightThemeButton.Text = "&Light theme"; + this._LightThemeButton.UseVisualStyleBackColor = true; // // SyntaxHighlightPage // @@ -182,11 +246,12 @@ private void InitializeComponent() { this.Name = "SyntaxHighlightPage"; this.Size = new System.Drawing.Size(575, 328); this.Load += new System.EventHandler(this.SyntaxHighlightPage_Load); - this.groupBox2.ResumeLayout(false); this._SyntaxHighlightTabs.ResumeLayout(false); this.tabPage2.ResumeLayout(false); this.customGroupBox1.ResumeLayout(false); this.customGroupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.ResumeLayout(false); } @@ -196,7 +261,6 @@ private void InitializeComponent() { private Codist.Controls.CustomGroupBox groupBox2; private System.Windows.Forms.Button _ResetThemeButton; private System.Windows.Forms.Button _DarkThemeButton; - private System.Windows.Forms.Label label1; private System.Windows.Forms.TabControl _SyntaxHighlightTabs; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.Button _SimpleThemeButton; @@ -204,5 +268,12 @@ private void InitializeComponent() { private System.Windows.Forms.Button _SaveButton; private System.Windows.Forms.Button _LoadButton; private Controls.CustomGroupBox customGroupBox1; + private Controls.TitleLabel titleLabel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.CheckBox _FontFamilyBox; + private System.Windows.Forms.CheckBox _ColorBox; + private System.Windows.Forms.CheckBox _FontSizeBox; + private System.Windows.Forms.CheckBox _FontStyleBox; + private Controls.TitleLabel titleLabel2; } } diff --git a/Codist/Options/SyntaxHighlightPage.cs b/Codist/Options/SyntaxHighlightPage.cs index beb98917..7d7a01e1 100644 --- a/Codist/Options/SyntaxHighlightPage.cs +++ b/Codist/Options/SyntaxHighlightPage.cs @@ -9,6 +9,7 @@ public partial class SyntaxHighlightPage : UserControl { readonly UiLock _UI = new UiLock(); readonly ConfigPage _servicePage; + StyleFilters _StyleFilters = StyleFilters.All; bool _Loaded; public SyntaxHighlightPage() { @@ -16,6 +17,11 @@ public SyntaxHighlightPage() { } internal SyntaxHighlightPage(ConfigPage page) : this() { _servicePage = page; + _ColorBox.Checked = _FontFamilyBox.Checked = _FontSizeBox.Checked = _FontStyleBox.Checked = true; + _ColorBox.CheckedChanged += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.Color, _ColorBox.Checked); + _FontFamilyBox.CheckedChanged += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.FontFamily, _FontFamilyBox.Checked); + _FontSizeBox.CheckedChanged += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.FontSize, _FontSizeBox.Checked); + _FontStyleBox.CheckedChanged += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.FontStyle, _FontStyleBox.Checked); _UI.CommonEventAction += () => Config.Instance.FireConfigChangedEvent(Features.SyntaxHighlight); } private void SyntaxHighlightPage_Load(object sender, EventArgs e) { @@ -25,13 +31,13 @@ private void SyntaxHighlightPage_Load(object sender, EventArgs e) { LoadConfig(Config.Instance); _DarkThemeButton.Click += (s, args) => { - Config.LoadConfig(Config.DarkTheme, true); + LoadTheme(Config.DarkTheme); }; _LightThemeButton.Click += (s, args) => { - Config.LoadConfig(Config.LightTheme, true); + LoadTheme(Config.LightTheme); }; _SimpleThemeButton.Click += (s, args) => { - Config.LoadConfig(Config.SimpleTheme, true); + LoadTheme(Config.SimpleTheme); }; _ResetThemeButton.Click += (s, args) => { if (MessageBox.Show("Do you want to reset the syntax highlight settings to default?", nameof(Codist), MessageBoxButtons.YesNo) == DialogResult.Yes) { @@ -47,7 +53,7 @@ private void SyntaxHighlightPage_Load(object sender, EventArgs e) { }) { if (d.ShowDialog() == DialogResult.OK) { try { - Config.LoadConfig(d.FileName, true); + LoadTheme(d.FileName); } catch (Exception ex) { MessageBox.Show("Error occured while loading style file: " + ex.Message, nameof(Codist)); @@ -77,5 +83,13 @@ void LoadConfig(Config config) { _HighlightSpecialCommentBox.Checked = config.SpecialHighlightOptions.MatchFlags(SpecialHighlightOptions.SpecialComment); }); } + + void LoadTheme(string path) { + if (_StyleFilters == StyleFilters.None) { + MessageBox.Show("Select at least one style filter to apply the syntax theme.", nameof(Codist)); + return; + } + Config.LoadConfig(path, _StyleFilters); + } } } diff --git a/Codist/SyntaxHighlight/StyleBase.cs b/Codist/SyntaxHighlight/StyleBase.cs index f7c17fd3..7574816f 100644 --- a/Codist/SyntaxHighlight/StyleBase.cs +++ b/Codist/SyntaxHighlight/StyleBase.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Text.RegularExpressions; using System.Windows.Media; +using AppHelpers; using Microsoft.VisualStudio.Text.Classification; namespace Codist.SyntaxHighlight @@ -65,17 +66,37 @@ public string BackgroundColor { internal StyleBase Clone() { return (StyleBase)MemberwiseClone(); } - internal void CopyTo(StyleBase style) { - style.Bold = Bold; - style.Italic = Italic; - style.OverLine = OverLine; - style.Underline = Underline; - style.Strikethrough = Strikethrough; - style.FontSize = FontSize; - style.BackgroundEffect = BackgroundEffect; - style.Font = Font; - style.ForeColor = ForeColor; - style.BackColor = BackColor; + internal void CopyTo(StyleBase target) { + target.Bold = Bold; + target.Italic = Italic; + target.OverLine = OverLine; + target.Underline = Underline; + target.Strikethrough = Strikethrough; + target.FontSize = FontSize; + target.BackgroundEffect = BackgroundEffect; + target.Font = Font; + target.ForeColor = ForeColor; + target.BackColor = BackColor; + } + internal void CopyTo(StyleBase target, StyleFilters filters) { + if (filters.MatchFlags(StyleFilters.Color)) { + target.ForeColor = ForeColor; + target.BackColor = BackColor; + target.BackgroundEffect = BackgroundEffect; + } + if (filters.MatchFlags(StyleFilters.FontFamily)) { + target.Font = Font; + } + if (filters.MatchFlags(StyleFilters.FontSize)) { + target.FontSize = FontSize; + } + if (filters.MatchFlags(StyleFilters.FontStyle)) { + target.Bold = Bold; + target.Italic = Italic; + target.OverLine = OverLine; + target.Underline = Underline; + target.Strikethrough = Strikethrough; + } } internal void Reset() { Bold = Italic = OverLine = Underline = Strikethrough = null; @@ -85,7 +106,7 @@ internal void Reset() { ForeColor = BackColor = default; } } - abstract class StyleBase : StyleBase where TStyle : struct + abstract class StyleBase : StyleBase where TStyle : Enum { string _ClassficationType, _Description;