Skip to content

Commit

Permalink
Refactor DropSourceBehaviour and related code to replace ArrayList wi…
Browse files Browse the repository at this point in the history
…th List<T>
  • Loading branch information
elachlan committed Feb 22, 2023
1 parent a5364e2 commit d84e660
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void StartDragOperation(Point initialMouseLocation)

//must identify a required parent to avoid dragging mixes of children
Control requiredParent = _containerControl.Parent;
ArrayList dragControls = new ArrayList();
List<IComponent> dragControls = new();
ICollection selComps = selSvc.GetSelectedComponents();
//create our list of controls-to-drag
foreach (IComponent comp in selComps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed partial class DropSourceBehavior : Behavior, IComparer
{
private struct DragComponent
{
public object dragComponent; //the dragComponent
public IComponent dragComponent; //the dragComponent
public int zorderIndex; //the dragComponent's z-order index
public Point originalControlLocation; //the original control of the control in AdornerWindow coordinates
public Point draggedLocation; //the location of the component after each drag - in AdornerWindow coordinates
Expand Down Expand Up @@ -72,9 +72,9 @@ private struct DragComponent
private int primaryComponentIndex = -1; // Index of the primary component (control) in dragComponents

/// <summary>
/// Constuctor that caches all needed vars for perf reasons.
/// Constructor that caches all needed variables for perf reasons.
/// </summary>
internal DropSourceBehavior(ICollection dragComponents, Control source, Point initialMouseLocation)
internal DropSourceBehavior(List<IComponent> dragComponents, Control source, Point initialMouseLocation)
{
serviceProviderSource = source.Site;
if (serviceProviderSource is null)
Expand Down Expand Up @@ -321,7 +321,7 @@ private void EndDragDrop(bool allowSetChildIndexOnDrop)
}

// We use this list when doing a Drag-Copy, so that we can correctly restore state when we are done. See Copy code below.
ArrayList originalControls = null;
List<IComponent> originalControls = null;
bool performCopy = (lastEffect == DragDropEffects.Copy);

Control dragSource = data.Source;
Expand Down Expand Up @@ -385,21 +385,21 @@ private void EndDragDrop(bool allowSetChildIndexOnDrop)
numberOfOriginalTrayControls = tray is not null ? tray.Controls.Count : 0;

// Get the objects to copy
ArrayList temp = new ArrayList();
List<IComponent> temp = new();
for (int i = 0; i < dragComponents.Length; i++)
{
temp.Add(dragComponents[i].dragComponent);
}

// Create a copy of them
temp = DesignerUtils.CopyDragObjects(temp, serviceProviderTarget) as ArrayList;
temp = DesignerUtils.CopyDragObjects(temp, serviceProviderTarget).Cast<IComponent>().ToList();
if (temp is null)
{
Debug.Fail("Couldn't create copies of the controls we are dragging.");
return;
}

originalControls = new ArrayList();
originalControls = new();
// And stick the copied controls back into the dragComponents array
for (int j = 0; j < temp.Count; j++)
{
Expand Down Expand Up @@ -885,9 +885,9 @@ private void DisableAdorners(IServiceProvider serviceProvider, BehaviorService b
/// <summary>
/// Called when the ControlDesigner starts a drag operation. Here, all adorners are disabled, screen shots of all related controls are taken, and the DragAssistanceManager (for SnapLines) is created.
/// </summary>
private void InitiateDrag(Point initialMouseLocation, ICollection dragComps)
private void InitiateDrag(Point initialMouseLocation, ICollection<IComponent> dragComps)
{
dragObjects = dragComps.Cast<IComponent>().ToList();
dragObjects = dragComps.ToList();
DisableAdorners(serviceProviderSource, behaviorServiceSource, false);
Control primaryControl = dragObjects[0] as Control;
Control primaryParent = primaryControl?.Parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public SelectionManager(IServiceProvider serviceProvider, BehaviorService behavi
_bodyAdorner = new Adorner();
behaviorService.Adorners.Add(_bodyAdorner);
behaviorService.Adorners.Add(_selectionAdorner); //adding this will cause the adorner to get setup with a ptr
//to the beh.svc.
//to the beh.svc.

_componentToDesigner = new Hashtable();

Expand Down Expand Up @@ -282,17 +282,13 @@ private void OnComponentAdded(object source, ComponentEventArgs ce)
/// </summary>
private void OnBeginDrag(object source, BehaviorDragDropEventArgs e)
{
ArrayList dragComps = new ArrayList(e.DragComponents);
ArrayList glyphsToRemove = new ArrayList();
List<IComponent> dragComps = e.DragComponents.Cast<IComponent>().ToList();
List<Glyph> glyphsToRemove = new();
foreach (ControlBodyGlyph g in _bodyAdorner.Glyphs)
{
if (g.RelatedComponent is Control)
if (g.RelatedComponent is Control control && (dragComps.Contains(g.RelatedComponent) || !control.AllowDrop))
{
if (dragComps.Contains(g.RelatedComponent) ||
!((Control)g.RelatedComponent).AllowDrop)
{
glyphsToRemove.Add(g);
}
glyphsToRemove.Add(g);
}
}

Expand Down

0 comments on commit d84e660

Please sign in to comment.