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

Refactor SelectionManager to replace Hashtable with Dictionary #8664

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal sealed class SelectionManager : IDisposable
private Adorner _bodyAdorner; //used to track all body glyphs for each control
private BehaviorService _behaviorService; //ptr back to our BehaviorService
private IServiceProvider _serviceProvider; //standard service provider
private readonly Hashtable _componentToDesigner; //used for quick look up of designers related to comps
private readonly Dictionary<IComponent, ControlDesigner> _componentToDesigner; //used for quick look up of designers related to comps
elachlan marked this conversation as resolved.
Show resolved Hide resolved
private readonly Control _rootComponent; //root component being designed
private ISelectionService _selSvc; //we cache the selection service for perf.
private IDesignerHost _designerHost; //we cache the designerhost for perf.
Expand Down Expand Up @@ -66,9 +66,9 @@ 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.
elachlan marked this conversation as resolved.
Show resolved Hide resolved

_componentToDesigner = new Hashtable();
_componentToDesigner = new();

IComponentChangeService cs = (IComponentChangeService)serviceProvider.GetService(typeof(IComponentChangeService));
if (cs is not null)
Expand Down Expand Up @@ -152,12 +152,11 @@ private void AddAllControlGlyphs(Control parent, ArrayList selComps, object prim
/// <summary>
/// Recursive method that goes through and adds all the glyphs of every child to our global Adorner.
/// </summary>
private void AddControlGlyphs(Control c, GlyphSelectionType selType)
private void AddControlGlyphs(Control control, GlyphSelectionType selType)
{
ControlDesigner cd = (ControlDesigner)_componentToDesigner[c];
if (cd is not null)
if (_componentToDesigner.TryGetValue(control, out ControlDesigner controlDesigner))
elachlan marked this conversation as resolved.
Show resolved Hide resolved
{
ControlBodyGlyph bodyGlyph = cd.GetControlGlyphInternal(selType);
ControlBodyGlyph bodyGlyph = controlDesigner.GetControlGlyphInternal(selType);
if (bodyGlyph is not null)
{
_bodyAdorner.Glyphs.Add(bodyGlyph);
Expand All @@ -175,7 +174,7 @@ private void AddControlGlyphs(Control c, GlyphSelectionType selType)
}
}

GlyphCollection glyphs = cd.GetGlyphs(selType);
GlyphCollection glyphs = controlDesigner.GetGlyphs(selType);
if (glyphs is not null)
{
_selectionAdorner.Glyphs.AddRange(glyphs);
Expand Down Expand Up @@ -271,9 +270,9 @@ private void OnComponentAdded(object source, ComponentEventArgs ce)
{
IComponent component = ce.Component;
IDesigner designer = _designerHost.GetDesigner(component);
if (designer is ControlDesigner)
if (designer is ControlDesigner controlDesigner)
{
_componentToDesigner.Add(component, designer);
_componentToDesigner.Add(component, controlDesigner);
}
}

Expand Down Expand Up @@ -331,10 +330,7 @@ private void OnComponentChanged(object source, ComponentChangedEventArgs ce)
/// </summary>
private void OnComponentRemoved(object source, ComponentEventArgs ce)
{
if (_componentToDesigner.Contains(ce.Component))
{
_componentToDesigner.Remove(ce.Component);
}
_componentToDesigner.Remove(ce.Component);

//remove the associated designeractionpanel
_designerActionUI?.RemoveActionGlyph(ce.Component);
Expand Down