Skip to content

Commit

Permalink
replace ArrayList with List in DesignerUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
halgab committed Oct 11, 2023
1 parent 0a16507 commit f082966
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void EndDragDrop(bool allowSetChildIndexOnDrop)
}

// Create a copy of them
temp = DesignerUtils.CopyDragObjects(temp, serviceProviderTarget).Cast<IComponent>().ToList();
temp = DesignerUtils.CopyDragObjects(temp, serviceProviderTarget);
if (temp is null)
{
Debug.Fail("Couldn't create copies of the controls we are dragging.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void ReParentControls(IList<IComponent> controls, bool copy)
temp!.Clear();
temp.Add(control);

temp = (List<IComponent>)DesignerUtils.CopyDragObjects(temp, _serviceProvider);
temp = DesignerUtils.CopyDragObjects(temp, _serviceProvider);
if (temp is not null)
{
control = (ToolStrip)temp[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public static ICollection FilterGenericTypes(ICollection types)
}

//now we get each Type and add it to the destination collection if its not a generic
ArrayList final = new ArrayList(types.Count);
List<Type> final = new(types.Count);
foreach (Type t in types)
{
if (!t.ContainsGenericParameters)
Expand Down Expand Up @@ -779,7 +779,7 @@ public static IContainer CheckForNestedContainer(IContainer container)
/// <summary>
/// Used to create copies of the objects that we are dragging in a drag operation
/// </summary>
public static ICollection CopyDragObjects(ICollection objects, IServiceProvider svcProvider)
public static List<IComponent> CopyDragObjects(ICollection objects, IServiceProvider svcProvider)
{
if (objects is null || svcProvider is null)
{
Expand Down Expand Up @@ -813,20 +813,16 @@ public static ICollection CopyDragObjects(ICollection objects, IServiceProvider
// Now, copyObjects contains a flattened list of all the controls contained in the original drag objects,
// that's not what we want to return. We only want to return the root drag objects,
// so that the caller gets an identical copy - identical in terms of objects.Count
ArrayList newObjects = new ArrayList(objects.Count);
List<IComponent> newObjects = new(objects.Count);
foreach (IComponent comp in copyObjects)
{
Control c = comp as Control;
if (c is not null && c.Parent is null)
if (comp is Control { Parent: null })
{
newObjects.Add(comp);
}
else if (c is null)
else if (comp is ToolStripItem item && item.GetCurrentParent() is null)
{ // this happens when we are dragging a toolstripitem
if (comp is ToolStripItem item && item.GetCurrentParent() is null)
{
newObjects.Add(comp);
}
newObjects.Add(comp);
}
}

Expand All @@ -849,7 +845,7 @@ private static ICollection GetCopySelection(ICollection objects, IDesignerHost h
return null;
}

ArrayList copySelection = new ArrayList();
List<IComponent> copySelection = new();
foreach (IComponent comp in objects)
{
copySelection.Add(comp);
Expand All @@ -859,14 +855,9 @@ private static ICollection GetCopySelection(ICollection objects, IDesignerHost h
return copySelection;
}

internal static void GetAssociatedComponents(IComponent component, IDesignerHost host, ArrayList list)
internal static void GetAssociatedComponents(IComponent component, IDesignerHost host, List<IComponent> list)
{
if (host is null)
{
return;
}

if (!(host.GetDesigner(component) is ComponentDesigner designer))
if (host?.GetDesigner(component) is not ComponentDesigner designer)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,8 @@ private void ControlAddedInternal(Control control, Point newControlPosition, boo
//Need to do this after the transaction has been created
if (localCopy)
{
ArrayList temp = new ArrayList();
temp.Add(control);
temp = DesignerUtils.CopyDragObjects(temp, Component.Site) as ArrayList;
List<IComponent> temp = new() { control };
temp = DesignerUtils.CopyDragObjects(temp, Component.Site);
control = temp[0] as Control;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ protected override void OnDragDrop(DragEventArgs de)
}

string transDesc;
ArrayList components = data.DragComponents;
IList components = data.DragComponents;
ToolStripItem primaryItem = data.PrimarySelection;
int primaryIndex = -1;
bool copy = (de.Effect == DragDropEffects.Copy);
Expand Down Expand Up @@ -1853,7 +1853,7 @@ protected override void OnDragDrop(DragEventArgs de)
KeyboardHandlingService.CopyInProgress = true;
}

components = DesignerUtils.CopyDragObjects(components, Component.Site) as ArrayList;
components = DesignerUtils.CopyDragObjects(components, Component.Site);
if (KeyboardHandlingService is not null)
{
KeyboardHandlingService.CopyInProgress = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public override void OnDragDrop(Glyph g, DragEventArgs e)
//Do DragDrop only if currentDropItem has changed.
if (currentDropItem != selectedItem && designerHost is not null)
{
ArrayList components = data.DragComponents;
IList components = data.DragComponents;
ToolStrip parentToolStrip = currentDropItem.GetCurrentParent();
int primaryIndex = -1;
string transDesc;
Expand Down Expand Up @@ -687,7 +687,7 @@ public override void OnDragDrop(Glyph g, DragEventArgs e)
keyboardHandlingService.CopyInProgress = true;
}

components = DesignerUtils.CopyDragObjects(components, currentDropItem.Site) as ArrayList;
components = DesignerUtils.CopyDragObjects(components, currentDropItem.Site);
if (keyboardHandlingService is not null)
{
keyboardHandlingService.CopyInProgress = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2655,7 +2655,7 @@ public override void OnDragDrop(Glyph g, DragEventArgs e)
if (ownerItem is not null && host is not null)
{
string transDesc;
ArrayList components = data.DragComponents;
IList components = data.DragComponents;
int primaryIndex = -1;
bool copy = (e.Effect == DragDropEffects.Copy);
if (components.Count == 1)
Expand Down Expand Up @@ -2695,7 +2695,7 @@ public override void OnDragDrop(Glyph g, DragEventArgs e)
keyboardHandlingService.CopyInProgress = true;
}

components = DesignerUtils.CopyDragObjects(components, primaryItem.Site) as ArrayList;
components = DesignerUtils.CopyDragObjects(components, primaryItem.Site);

if (keyboardHandlingService is not null)
{
Expand Down

0 comments on commit f082966

Please sign in to comment.