Skip to content

Commit

Permalink
Remove last TraceSwitches (dotnet#11090)
Browse files Browse the repository at this point in the history
Removes the last of the TraceSwitches. Cleans out Debug.Indent stragglers.
  • Loading branch information
JeremyKuhne authored Mar 21, 2024
1 parent bff7cb9 commit f1cac0d
Show file tree
Hide file tree
Showing 28 changed files with 712 additions and 1,863 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private void OnSelectionChanged(object sender, EventArgs e)
object primary = ((ISelectionService)sender).PrimarySelection;
Invalidate();
_fSelectionChanged = true;

// Accessibility information
foreach (object selObj in _selectedObjects)
{
Expand All @@ -247,7 +248,6 @@ private void OnSelectionChanged(object sender, EventArgs e)
Control c = TrayControl.FromComponent(component);
if (c is not null)
{
Debug.WriteLineIf(CompModSwitches.MSAA.TraceInfo, $"MSAA: SelectionAdd, traycontrol = {c}");
PInvoke.NotifyWinEvent(
(uint)AccessibleEvents.SelectionAdd,
c,
Expand Down Expand Up @@ -847,7 +847,6 @@ protected override void Dispose(bool disposing)
if (disposing && _controls is not null)
{
IExtenderProviderService es = (IExtenderProviderService)GetService(typeof(IExtenderProviderService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (es is not null), "IExtenderProviderService not found");
es?.RemoveExtenderProvider(this);

IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
Expand All @@ -863,12 +862,12 @@ protected override void Dispose(bool disposing)
IComponentChangeService componentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
if (componentChangeService is not null)
{
componentChangeService.ComponentRemoved -= new ComponentEventHandler(OnComponentRemoved);
componentChangeService.ComponentRemoved -= OnComponentRemoved;
}

SystemEvents.DisplaySettingsChanged -= new EventHandler(OnSystemSettingChanged);
SystemEvents.InstalledFontsChanged -= new EventHandler(OnSystemSettingChanged);
SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(OnUserPreferenceChanged);
SystemEvents.DisplaySettingsChanged -= OnSystemSettingChanged;
SystemEvents.InstalledFontsChanged -= OnSystemSettingChanged;
SystemEvents.UserPreferenceChanged -= OnUserPreferenceChanged;
IMenuCommandService mcs = MenuService;
if (mcs is not null)
{
Expand Down Expand Up @@ -1034,7 +1033,6 @@ protected override void OnMouseDoubleClick(MouseEventArgs e)
{
OnLostCapture();
IEventBindingService eps = (IEventBindingService)GetService(typeof(IEventBindingService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (eps is not null), "IEventBindingService not found");
eps?.ShowCode();
}
}
Expand All @@ -1055,14 +1053,15 @@ protected override void OnGiveFeedback(GiveFeedbackEventArgs gfevent)
/// </summary>
protected override void OnDragDrop(DragEventArgs de)
{
// This will be used once during PositionComponent to place the component at the drop point. It is automatically set to null afterwards, so further components appear after the first one dropped.
// This will be used once during PositionComponent to place the component at the drop point. It is automatically
// set to null afterwards, so further components appear after the first one dropped.
_mouseDropLocation = PointToClient(new Point(de.X, de.Y));
_autoScrollPosBeforeDragging = AutoScrollPosition; // save the scroll position
_autoScrollPosBeforeDragging = AutoScrollPosition;

if (_mouseDragTool is not null)
{
ToolboxItem tool = _mouseDragTool;
_mouseDragTool = null;
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (GetService(typeof(IDesignerHost)) is not null), "IDesignerHost not found");
try
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
Expand Down Expand Up @@ -1257,7 +1256,6 @@ protected override void OnMouseDown(MouseEventArgs e)
try
{
ISelectionService ss = (ISelectionService)GetService(typeof(ISelectionService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (ss is not null), "ISelectionService not found");
ss?.SetSelectedComponents(new object[] { _mainDesigner.Component });
}
catch (Exception ex) when (!ex.IsCriticalException())
Expand Down Expand Up @@ -1345,7 +1343,6 @@ protected override void OnMouseUp(MouseEventArgs e)
try
{
ISelectionService ss = (ISelectionService)GetService(typeof(ISelectionService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (ss is not null), "ISelectionService not found");
ss?.SetSelectedComponents(comps);
}
catch (Exception ex) when (!ex.IsCriticalException())
Expand Down Expand Up @@ -1905,10 +1902,9 @@ public TrayControl(ComponentTray tray, IComponent component)
UpdateIconInfo();

IComponentChangeService cs = (IComponentChangeService)tray.GetService(typeof(IComponentChangeService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (cs is not null), "IComponentChangeService not found");
if (cs is not null)
{
cs.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);
cs.ComponentRename += OnComponentRename;
}

ISite site = component.Site;
Expand Down Expand Up @@ -2003,16 +1999,15 @@ protected override void Dispose(bool disposing)
ISite site = _component.Site;
if (site is not null)
{
IComponentChangeService cs = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (cs is not null), "IComponentChangeService not found");
if (cs is not null)
if (site.TryGetService(out IComponentChangeService cs))
{
cs.ComponentRename -= new ComponentRenameEventHandler(OnComponentRename);
cs.ComponentRename -= OnComponentRename;
}

IDictionaryService ds = (IDictionaryService)site.GetService(typeof(IDictionaryService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (ds is not null), "IDictionaryService not found");
ds?.SetValue(typeof(TrayControl), null);
if (site.TryGetService(out IDictionaryService ds))
{
ds.SetValue(typeof(TrayControl), null);
}
}
}

Expand All @@ -2024,24 +2019,17 @@ protected override void Dispose(bool disposing)
/// </summary>
public static TrayControl FromComponent(IComponent component)
{
TrayControl c = null;
if (component is null)
{
return null;
}

ISite site = component.Site;
if (site is not null)
if (component.Site.TryGetService(out IDictionaryService ds))
{
IDictionaryService ds = (IDictionaryService)site.GetService(typeof(IDictionaryService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (ds is not null), "IDictionaryService not found");
if (ds is not null)
{
c = (TrayControl)ds.GetValue(typeof(TrayControl));
}
return (TrayControl)ds.GetValue(typeof(TrayControl));
}

return c;
return null;
}

/// <summary>
Expand Down Expand Up @@ -2131,23 +2119,27 @@ private void OnEndDrag(bool cancel)
protected override void OnMouseDown(MouseEventArgs me)
{
base.OnMouseDown(me);
if (!_tray.TabOrderActive)
if (_tray.TabOrderActive)
{
_tray.FocusDesigner();
// If this is the left mouse button, then begin a drag.
if (me.Button == MouseButtons.Left)
return;
}

_tray.FocusDesigner();

// If this is the left mouse button, then begin a drag.
if (me.Button == MouseButtons.Left)
{
Capture = true;
_mouseDragLast = PointToScreen(new Point(me.X, me.Y));

// If the CTRL key isn't down, select this component, otherwise, we wait until the mouse up.
// Make sure the component is selected.
_ctrlSelect = PInvoke.GetKeyState((int)Keys.ControlKey) != 0;
if (!_ctrlSelect)
{
Capture = true;
_mouseDragLast = PointToScreen(new Point(me.X, me.Y));
// If the CTRL key isn't down, select this component, otherwise, we wait until the mouse up. Make sure the component is selected
_ctrlSelect = PInvoke.GetKeyState((int)Keys.ControlKey) != 0;
if (!_ctrlSelect)
{
ISelectionService sel = (ISelectionService)_tray.GetService(typeof(ISelectionService));
// Make sure the component is selected
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (sel is not null), "ISelectionService not found");
sel?.SetSelectedComponents(new object[] { Component }, SelectionTypes.Primary);
}
ISelectionService sel = (ISelectionService)_tray.GetService(typeof(ISelectionService));
// Make sure the component is selected
sel?.SetSelectedComponents(new object[] { Component }, SelectionTypes.Primary);
}
}
}
Expand Down Expand Up @@ -2443,7 +2435,6 @@ public virtual void ViewDefaultEvent(IComponent component)
PropertyDescriptor defaultPropEvent = null;
bool eventChanged = false;
IEventBindingService eps = (IEventBindingService)GetService(typeof(IEventBindingService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || (eps is not null), "IEventBindingService not found");
if (eps is not null)
{
defaultPropEvent = eps.GetEventProperty(defaultEvent);
Expand All @@ -2453,7 +2444,6 @@ public virtual void ViewDefaultEvent(IComponent component)
if (defaultPropEvent is null || defaultPropEvent.IsReadOnly)
{
eps?.ShowCode();

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1249,22 +1249,14 @@ private void OnStatusMultiSelectNonContained(object sender, EventArgs e)
/// </summary>
protected void OnStatusShowGrid(object sender, EventArgs e)
{
if (site is not null)
if (site.TryGetService(out IDesignerHost host)
&& host.RootComponent is Control baseComponent
&& GetProperty(baseComponent, "DrawGrid") is { } property)
{
IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || host is not null, "IDesignerHost not found");

if (host?.RootComponent is Control baseComponent)
{
PropertyDescriptor prop = GetProperty(baseComponent, "DrawGrid");
if (prop is not null)
{
bool drawGrid = (bool)prop.GetValue(baseComponent);
MenuCommand cmd = (MenuCommand)sender;
cmd.Enabled = true;
cmd.Checked = drawGrid;
}
}
bool drawGrid = (bool)property.GetValue(baseComponent);
MenuCommand cmd = (MenuCommand)sender;
cmd.Enabled = true;
cmd.Checked = drawGrid;
}
}

Expand All @@ -1274,22 +1266,14 @@ protected void OnStatusShowGrid(object sender, EventArgs e)
/// </summary>
protected void OnStatusSnapToGrid(object sender, EventArgs e)
{
if (site is not null)
if (site.TryGetService(out IDesignerHost host)
&& host.RootComponent is Control baseComponent
&& GetProperty(baseComponent, "SnapToGrid") is { } property)
{
IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || host is not null, "IDesignerHost not found");

if (host?.RootComponent is Control baseComponent)
{
PropertyDescriptor prop = GetProperty(baseComponent, "SnapToGrid");
if (prop is not null)
{
bool snapToGrid = (bool)prop.GetValue(baseComponent);
MenuCommand cmd = (MenuCommand)sender;
cmd.Enabled = controlsOnlySelection;
cmd.Checked = snapToGrid;
}
}
bool snapToGrid = (bool)property.GetValue(baseComponent);
MenuCommand cmd = (MenuCommand)sender;
cmd.Enabled = controlsOnlySelection;
cmd.Checked = snapToGrid;
}
}

Expand Down Expand Up @@ -1325,7 +1309,6 @@ private void OnStatusZOrder(object sender, EventArgs e)

// There must also be a control in the mix, and not the base component, and
// it cannot be privately inherited.
//
ICollection selectedComponents = SelectionService.GetSelectedComponents();

enable = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;

Expand Down Expand Up @@ -65,10 +64,6 @@ public override AccessibleStates State

public override AccessibleObject? GetChild(int index)
{
Debug.WriteLineIf(
CompModSwitches.MSAA.TraceInfo,
$"ControlDesignerAccessibleObject.GetChild({index})");

if (_control.AccessibilityObject.GetChild(index) is Control.ControlAccessibleObject childAccObj)
{
AccessibleObject? cao = GetDesignerAccessibleObject(childAccObj);
Expand Down
Loading

0 comments on commit f1cac0d

Please sign in to comment.