Skip to content

Commit

Permalink
Merge pull request #123 from ahmetsait/designer
Browse files Browse the repository at this point in the history
Implement a `ControlDesigner` that makes `ScrollWidth` visible & serialized only when `ScrollWidthTracking` is `false`
  • Loading branch information
desjarlais authored May 13, 2024
2 parents 9b05b78 + 0055614 commit 3f549de
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Scintilla.NET/Scintilla.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
<Authors>Jacob Slusser, VPKSoft, cyber960, desjarlais</Authors>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-windows|AnyCPU'">
<WarningLevel>7</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-windows|AnyCPU'">
<WarningLevel>7</WarningLevel>
</PropertyGroup>
<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
Expand All @@ -62,6 +56,9 @@
<Pack>true</Pack>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<Reference Include="System.Design" />
</ItemGroup>
<Target Name="PostPack" AfterTargets="Pack">
<Exec Command="powershell .\nupkg.ps1 -MSBuildProjectDirectory '$(MSBuildProjectDirectory)' -NuGetPackageRoot '$(NuGetPackageRoot)' -NuGetPackageSourceDir '$(SolutionDir)\registry' -PackageOutputPath '$(PackageOutputPath)' -PackageId '$(PackageId)' -PackageVersion '$(PackageVersion)'" />
</Target>
Expand Down
1 change: 1 addition & 0 deletions Scintilla.NET/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace ScintillaNET
/// Represents a Scintilla editor control.
/// </summary>
[Docking(DockingBehavior.Ask)]
[Designer(typeof(ScintillaDesigner))]
public class Scintilla : Control
{
static Scintilla()
Expand Down
42 changes: 42 additions & 0 deletions Scintilla.NET/ScintillaDesigner.cs
Original file line number Diff line number Diff line change
@@ -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<Attribute>().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<Attribute>().Concat(
[
new BrowsableAttribute(false),
new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
]
).ToArray()
);
properties[nameof(Scintilla.ScrollWidth)] = scrollWidth;
}
}
}

0 comments on commit 3f549de

Please sign in to comment.