From 00556140187aacba413704bb07a59f892e5ba982 Mon Sep 17 00:00:00 2001 From: Ahmet Sait Date: Sun, 12 May 2024 21:01:24 +0300 Subject: [PATCH] Implement a `ControlDesigner` that makes `ScrollWidth` visible & serialized only when `ScrollWidthTracking` is `false` --- Scintilla.NET/Scintilla.NET.csproj | 9 +++---- Scintilla.NET/Scintilla.cs | 1 + Scintilla.NET/ScintillaDesigner.cs | 42 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 Scintilla.NET/ScintillaDesigner.cs diff --git a/Scintilla.NET/Scintilla.NET.csproj b/Scintilla.NET/Scintilla.NET.csproj index 5d5939d..9c901f8 100644 --- a/Scintilla.NET/Scintilla.NET.csproj +++ b/Scintilla.NET/Scintilla.NET.csproj @@ -32,12 +32,6 @@ Jacob Slusser, VPKSoft, cyber960, desjarlais README.md - - 7 - - - 7 - True @@ -62,6 +56,9 @@ true + + + diff --git a/Scintilla.NET/Scintilla.cs b/Scintilla.NET/Scintilla.cs index 9fd904c..ef9585b 100644 --- a/Scintilla.NET/Scintilla.cs +++ b/Scintilla.NET/Scintilla.cs @@ -19,6 +19,7 @@ namespace ScintillaNET /// Represents a Scintilla editor control. /// [Docking(DockingBehavior.Ask)] + [Designer(typeof(ScintillaDesigner))] public class Scintilla : Control { static Scintilla() diff --git a/Scintilla.NET/ScintillaDesigner.cs b/Scintilla.NET/ScintillaDesigner.cs new file mode 100644 index 0000000..cc1d003 --- /dev/null +++ b/Scintilla.NET/ScintillaDesigner.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms.Design; + +namespace ScintillaNET; + +internal class ScintillaDesigner : ControlDesigner +{ + protected override void PreFilterProperties(IDictionary properties) + { + base.PreFilterProperties(properties); + + var scrollWidthTracking = (PropertyDescriptor)properties[nameof(Scintilla.ScrollWidthTracking)]; + scrollWidthTracking = TypeDescriptor.CreateProperty( + scrollWidthTracking.ComponentType, + scrollWidthTracking, + scrollWidthTracking.Attributes.Cast().Concat([new RefreshPropertiesAttribute(RefreshProperties.All)]).ToArray() + ); + properties[nameof(Scintilla.ScrollWidthTracking)] = scrollWidthTracking; + + var scrollWidth = (PropertyDescriptor)properties[nameof(Scintilla.ScrollWidth)]; + if ((bool)scrollWidthTracking.GetValue(Component)) + { + scrollWidth = TypeDescriptor.CreateProperty( + scrollWidth.ComponentType, + scrollWidth, + scrollWidth.Attributes.Cast().Concat( + [ + new BrowsableAttribute(false), + new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden), + ] + ).ToArray() + ); + properties[nameof(Scintilla.ScrollWidth)] = scrollWidth; + } + } +}