Skip to content

Commit

Permalink
Update CreateComponentTool.cs
Browse files Browse the repository at this point in the history
fix for breaking change
  • Loading branch information
hjqcan authored Jun 3, 2024
1 parent 3249bd7 commit ffb1d87
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions WpfDesign.Designer/Project/Services/CreateComponentTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ public class CreateComponentTool : ITool
/// <summary>
/// Creates a new CreateComponentTool instance.
/// </summary>
public CreateComponentTool(Type componentType)
public CreateComponentTool(Type componentType):this(componentType, null)
{
if (componentType == null)
throw new ArgumentNullException("componentType");
this.componentType = componentType;
}

/// <summary>
Expand All @@ -56,10 +53,10 @@ public CreateComponentTool(Type componentType)
public CreateComponentTool(Type componentType, object[] arguments)
{
if (componentType == null)
throw new ArgumentNullException("componentType");
throw new ArgumentNullException(nameof(componentType));
this.componentType = componentType;
this.arguments = arguments;
}
this.arguments = arguments;
}

/// <summary>
/// Gets the type of the component to be created.
Expand Down Expand Up @@ -239,7 +236,15 @@ protected virtual DesignItem[] CreateItems(DesignContext context)
/// <summary>
/// Is called to create the item used by the CreateComponentTool.
/// </summary>
public static DesignItem CreateItem(DesignContext context, Type type, object[] arguments = null)
public static DesignItem CreateItem(DesignContext context, Type type)
{
return CreateItem(context,type,null);
}

/// <summary>
/// Is called to create the item used by the CreateComponentTool.
/// </summary>
public static DesignItem CreateItem(DesignContext context, Type type, object[] arguments)
{
object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(type, arguments);
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance);
Expand All @@ -254,12 +259,22 @@ public static DesignItem CreateItem(DesignContext context, Type type, object[] a
protected virtual void SetPropertiesForDrawnItem(DesignItem designItem)
{ }

public static bool AddItemWithCustomSizePosition(DesignItem container, Type createdItem, Size size, Point position)
{
return AddItemWithCustomSizePosition(container, createdItem, null, size, position);
}

public static bool AddItemWithCustomSizePosition(DesignItem container, Type createdItem, object[] arguments, Size size, Point position)
{
CreateComponentTool cct = new CreateComponentTool(createdItem, arguments);
return AddItemsWithCustomSize(container, new[] { cct.CreateItem(container.Context) }, new[] { new Rect(position, size) });
}


public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, Size size)
{
return AddItemWithDefaultSize(container, createdItem, null, size);
}

public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, object[] arguments, Size size)
{
CreateComponentTool cct = new CreateComponentTool(createdItem, arguments);
Expand Down

0 comments on commit ffb1d87

Please sign in to comment.