Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a ControlDesigner that makes ScrollWidth visible & serialized only when ScrollWidthTracking is false #123

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -19,6 +19,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;
}
}
}
Loading