Skip to content

Commit

Permalink
Added all the necessary classes for toolbar design-time functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehighfield committed May 19, 2022
1 parent b633aca commit c248e5e
Show file tree
Hide file tree
Showing 16 changed files with 701 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WinForms.Designer.SDK" Version="1.1.0-prerelease-preview3.22076.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BetterControls.Design.ClientServerProtocol\BetterControls.Design.ClientServerProtocol.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using BetterControls.Design.Protocol;
using Microsoft.DotNet.DesignTools.Client.TypeRouting;
using System.Collections.Generic;

namespace BetterControls.Design
{
/// <summary>
/// Represents the toolbar type routing provider.
/// </summary>
[ExportTypeRoutingDefinitionProvider]
internal class BetterToolbarTypeRoutingProvider : TypeRoutingDefinitionProvider
{
/// <summary>
/// Initialize a new instance of <see cref="BetterToolbarTypeRoutingProvider"/>.
/// </summary>
public BetterToolbarTypeRoutingProvider() { }

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns><inheritdoc/></returns>
public override IEnumerable<TypeRoutingDefinition> GetDefinitions()
{
return new[]
{
new TypeRoutingDefinition(
TypeRoutingKinds.Editor,
nameof(EditorNames.BetterToolbarItemCollectionEditor),
typeof(BetterToolbarItemCollectionEditor)),
new TypeRoutingDefinition(
TypeRoutingKinds.Editor,
nameof(EditorNames.BetterMenuBarItemCollectionEditor),
typeof(BetterMenuBarItemCollectionEditor)),
new TypeRoutingDefinition(
TypeRoutingKinds.Editor,
nameof(EditorNames.BetterMenuItemCollectionEditor),
typeof(BetterMenuItemCollectionEditor)),
new TypeRoutingDefinition(
TypeRoutingKinds.Editor,
nameof(EditorNames.ImageIndexEditor),
typeof(ImageIndexEditor)),
};
}
}
}
19 changes: 19 additions & 0 deletions src/BetterControls.Design.Client/Editors/BetterCollectionEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.DotNet.DesignTools.Client.Editors;
using System;

namespace BetterControls.Design
{
/// <summary>
/// Extend this class to create a collection editor.
/// </summary>
public abstract class BetterCollectionEditor : CollectionEditor
{
/// <summary>
/// Initialize a new instance of <see cref="BetterCollectionEditor"/>.
/// </summary>
/// <param name="collectionType">The type that this collection editor is associated with.</param>
public BetterCollectionEditor(Type collectionType)
: base(collectionType)
{ }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-windows;net472</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WinForms.Designer.SDK" Version="1.1.0-prerelease-preview3.22076.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace WinForms.Tiles.ClientServerProtocol
{
public static class CollectionEditorNames
{
public const string BetterToolbarItemCollectionEditor = nameof(BetterToolbarItemCollectionEditor);
public const string BetterMenuBarItemCollectionEditor = nameof(BetterMenuBarItemCollectionEditor);
public const string BetterMenuItemCollectionEditor = nameof(BetterMenuItemCollectionEditor);
}
}
10 changes: 10 additions & 0 deletions src/BetterControls.Design.ClientServerProtocol/EditorNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BetterControls.Design.Protocol
{
public static class EditorNames
{
public const string BetterToolbarItemCollectionEditor = nameof(BetterToolbarItemCollectionEditor);
public const string BetterMenuBarItemCollectionEditor = nameof(BetterMenuBarItemCollectionEditor);
public const string BetterMenuItemCollectionEditor = nameof(BetterMenuItemCollectionEditor);
public const string ImageIndexEditor = nameof(ImageIndexEditor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.WinForms.Designer.SDK" Version="1.1.0-prerelease-preview3.22076.5" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\BetterControls.Design.ClientServerProtocol\BetterControls.Design.ClientServerProtocol.csproj" />
<ProjectReference Include="..\BetterControls\BetterControls.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.DotNet.DesignTools.TypeRouting;
using System.Collections.Generic;

namespace BetterControls.Design
{
/// <summary>
/// Represents the toolbar type routing provider.
/// </summary>
[ExportTypeRoutingDefinitionProvider]
internal class BetterToolbarTypeRoutingProvider : TypeRoutingDefinitionProvider
{
/// <summary>
/// Initialize a new instance of <see cref="BetterToolbarTypeRoutingProvider"/>.
/// </summary>
public BetterToolbarTypeRoutingProvider() { }

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns><inheritdoc/></returns>
public override IEnumerable<TypeRoutingDefinition> GetDefinitions()
=> new[]
{
new TypeRoutingDefinition(
TypeRoutingKinds.Designer,
nameof(BetterToolbarDesigner),
typeof(BetterToolbarDesigner)),
new TypeRoutingDefinition(
TypeRoutingKinds.Designer,
nameof(BetterToolbarItemDesigner),
typeof(BetterToolbarItemDesigner)),
new TypeRoutingDefinition(
TypeRoutingKinds.Designer,
nameof(BetterToolbarButtonDesigner),
typeof(BetterToolbarButtonDesigner)),
new TypeRoutingDefinition(
TypeRoutingKinds.Designer,
nameof(BetterMenuBarDesigner),
typeof(BetterMenuBarDesigner))
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.DotNet.DesignTools.Designers;
using System.ComponentModel.Design;

namespace BetterControls.Design
{
/// <summary>
/// Extend this class to create a component designer.
/// </summary>
public abstract class BetterComponentDesigner : ComponentDesigner
{
/// <summary>
/// Initialize a new instance of <see cref="BetterComponentDesigner"/>.
/// </summary>
public BetterComponentDesigner() { }

#region Private Member Fields

private IDesignerHost _designerHost;

#endregion

/// <summary>
/// Gets the designer host associated with this component.
/// </summary>
protected IDesignerHost DesignerHost
{
get
{
if (_designerHost is null)
_designerHost = GetService<IDesignerHost>();

return _designerHost;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.DotNet.DesignTools.Designers;
using Microsoft.DotNet.DesignTools.Designers.Actions;
using System;
using System.ComponentModel.Design;

namespace BetterControls.Design
{
/// <summary>
/// Extend from this class to indicate that the implementing class is an action list.
/// </summary>
internal class BetterControlActionList : DesignerActionList
{
/// <summary>
/// Initialize a new instance of <see cref="BetterControlActionList"/>.
/// </summary>
/// <param name="designer">The designer that is associated with this action list.</param>
internal BetterControlActionList(Microsoft.DotNet.DesignTools.Designers.ControlDesigner designer)
: base(designer.Component)
{
Designer = designer ?? throw new ArgumentNullException(nameof(designer));
}

#region Private Member Fields

private IDesignerHost _designerHost;

#endregion

/// <summary>
/// Gets the designer that is associated with this action list.
/// </summary>
protected Microsoft.DotNet.DesignTools.Designers.ControlDesigner Designer { get; }

/// <summary>
/// Gets the designer host associated with this component.
/// </summary>
protected IDesignerHost DesignerHost
{
get
{
if(_designerHost is null)
_designerHost = GetService<IDesignerHost>();

return _designerHost;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.DotNet.DesignTools.Designers;
using System.ComponentModel.Design;

namespace BetterControls.Design
{
/// <summary>
/// Extend this class to create a control designer.
/// </summary>
public abstract class BetterControlDesigner : ControlDesigner
{
/// <summary>
/// Initialize a new instance of <see cref="BetterControlDesigner"/>.
/// </summary>
public BetterControlDesigner() { }

#region Private Member Fields

private IDesignerHost _designerHost;

#endregion

/// <summary>
/// Gets the designer host associated with this component.
/// </summary>
protected IDesignerHost DesignerHost
{
get
{
if (_designerHost is null)
_designerHost = GetService<IDesignerHost>();

return _designerHost;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections;
using System.ComponentModel;

namespace BetterControls.Design
{
/// <summary>
/// Designer for <see cref="BetterToolbarButton"/>.
/// </summary>
internal class BetterToolbarButtonDesigner : BetterToolbarItemDesigner
{
/// <summary>
/// Initialize a new instance of <see cref="BetterToolbarButtonDesigner"/>.
/// </summary>
public BetterToolbarButtonDesigner() { }

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="defaultValues"><inheritdoc/></param>
public override void InitializeNewComponent(IDictionary defaultValues)
{
base.InitializeNewComponent(defaultValues);

PropertyDescriptor nameProperty = TypeDescriptor.GetProperties(Component)["Name"];
if (nameProperty != null && nameProperty.PropertyType == typeof(string))
{
string itemText = (string)nameProperty.GetValue(Component);

PropertyDescriptor textProperty = TypeDescriptor.GetProperties(Component)["Text"];
if (textProperty != null)
{
textProperty.SetValue(Component, itemText);
}
}
}
}
}
Loading

0 comments on commit c248e5e

Please sign in to comment.