Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -12,14 +12,10 @@ internal sealed partial class DesignerActionPanel
{
private sealed class CheckBoxPropertyLine : PropertyLine
{
private CheckBox _checkBox;
private readonly CheckBox _checkBox;

public CheckBoxPropertyLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
private CheckBoxPropertyLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
: base(serviceProvider, actionPanel)
{
}

protected override void AddControls(List<Control> controls)
{
_checkBox = new CheckBox
{
Expand All @@ -31,10 +27,10 @@ protected override void AddControls(List<Control> controls)
};
_checkBox.CheckedChanged += new EventHandler(OnCheckBoxCheckedChanged);

controls.Add(_checkBox);
AddedControls.Add(_checkBox);
}

public sealed override void Focus() => _checkBox.Focus();
public override void Focus() => _checkBox.Focus();

public override Size LayoutControls(int top, int width, bool measureOnly)
{
Expand Down Expand Up @@ -66,5 +62,15 @@ protected override void OnValueChanged()
{
_checkBox.Checked = (bool)Value;
}

public sealed class Info(DesignerActionList list, DesignerActionPropertyItem item) : PropertyLineInfo(list, item)
{
public override Line CreateLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
{
return new CheckBoxPropertyLine(serviceProvider, actionPanel);
}

public override Type LineType => typeof(CheckBoxPropertyLine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ internal sealed partial class DesignerActionPanel
{
private sealed partial class EditorPropertyLine : TextBoxPropertyLine, IWindowsFormsEditorService, IServiceProvider
{
private EditorButton _button;
private readonly EditorButton _button;
private UITypeEditor _editor;
private bool _hasSwatch;
private Image _swatch;
private FlyoutDialog _dropDownHolder;
private bool _ignoreNextSelectChange;
private bool _ignoreDropDownValue;

public EditorPropertyLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
private EditorPropertyLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
: base(serviceProvider, actionPanel)
{
_button = new EditorButton();
_button.Click += new EventHandler(OnButtonClick);
_button.GotFocus += new EventHandler(OnButtonGotFocus);

AddedControls.Add(_button);
}

private unsafe void ActivateDropDown()
Expand Down Expand Up @@ -122,17 +127,6 @@ private unsafe void ActivateDropDown()
}
}

protected override void AddControls(List<Control> controls)
{
base.AddControls(controls);

_button = new EditorButton();
_button.Click += new EventHandler(OnButtonClick);
_button.GotFocus += new EventHandler(OnButtonGotFocus);

controls.Add(_button);
}

private void CloseDropDown()
{
if (_dropDownHolder is not null)
Expand Down Expand Up @@ -231,7 +225,7 @@ private void OnListBoxSelectedIndexChanged(object sender, EventArgs e)

protected override void OnPropertyTaskItemUpdated(ToolTip toolTip, ref int currentTabIndex)
{
_editor = (UITypeEditor)PropertyDescriptor.GetEditor(typeof(UITypeEditor));
_editor = PropertyDescriptor.GetEditor<UITypeEditor>();

base.OnPropertyTaskItemUpdated(toolTip, ref currentTabIndex);

Expand Down Expand Up @@ -268,7 +262,7 @@ protected override void OnReadOnlyTextBoxLabelClick(object sender, MouseEventArg

if (e.Button == MouseButtons.Left)
{
if (ActionPanel.DropDownActive)
if (ActionPanel._dropDownActive)
{
_ignoreDropDownValue = true;
CloseDropDown();
Expand Down Expand Up @@ -320,11 +314,11 @@ protected internal override bool ProcessDialogKey(Keys keyData)
// VS is going to eat the F4 in PreProcessMessage, preventing it from ever
// getting to an OnKeyDown on this control. Doing it here also allow to not
// hook up to multiple events for each button.
if (!_button.Focused && !_button.Ellipsis)
if (_button is { Focused: false, Ellipsis: false })
{
if ((keyData == (Keys.Alt | Keys.Down)) || (keyData == (Keys.Alt | Keys.Up)) || (keyData == Keys.F4))
if (keyData is (Keys.Alt | Keys.Down) or (Keys.Alt | Keys.Up) or Keys.F4)
{
if (!ActionPanel.DropDownActive)
if (!ActionPanel._dropDownActive)
{
ActivateDropDown();
}
Expand Down Expand Up @@ -426,7 +420,7 @@ void IWindowsFormsEditorService.DropDownControl(Control control)

DialogResult IWindowsFormsEditorService.ShowDialog(Form dialog)
{
IUIService uiService = (IUIService)ServiceProvider.GetService(typeof(IUIService));
IUIService uiService = ServiceProvider.GetService<IUIService>();
if (uiService is not null)
{
return uiService.ShowDialog(dialog);
Expand Down Expand Up @@ -480,5 +474,15 @@ protected override bool ProcessDialogKey(Keys keyData)
return base.ProcessDialogKey(keyData);
}
}

public new sealed class Info(DesignerActionList list, DesignerActionPropertyItem item) : PropertyLineInfo(list, item)
{
public override Line CreateLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
{
return new EditorPropertyLine(serviceProvider, actionPanel);
}

public override Type LineType => typeof(EditorPropertyLine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ internal sealed partial class DesignerActionPanel
{
private sealed class HeaderLine : TextLine
{
public HeaderLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel) : base(serviceProvider, actionPanel)
private HeaderLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel) : base(serviceProvider, actionPanel)
{
}

protected override Font GetFont() => new(ActionPanel.Font, FontStyle.Bold);

public new sealed class Info(DesignerActionList list, DesignerActionTextItem item) : StandardLineInfo(list)
{
public override DesignerActionTextItem Item { get; } = item;
public override Line CreateLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
{
return new HeaderLine(serviceProvider, actionPanel);
}

public override Type LineType => typeof(HeaderLine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,32 @@ internal sealed partial class DesignerActionPanel
{
private abstract class Line
{
private readonly DesignerActionPanel _actionPanel;
private List<Control> _addedControls;
private readonly IServiceProvider _serviceProvider;
protected readonly List<Control> AddedControls = new();

public Line(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
protected Line(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
{
_serviceProvider = serviceProvider;
_actionPanel = actionPanel.OrThrowIfNull();
ServiceProvider = serviceProvider;
ActionPanel = actionPanel.OrThrowIfNull();
}

protected DesignerActionPanel ActionPanel
{
get => _actionPanel;
}
protected DesignerActionPanel ActionPanel { get; }

public abstract string FocusId
{
get;
}

protected IServiceProvider ServiceProvider
{
get => _serviceProvider;
}

protected abstract void AddControls(List<Control> controls);
protected IServiceProvider ServiceProvider { get; }

internal List<Control> GetControls()
{
_addedControls = new List<Control>();
AddControls(_addedControls);
// Tag all the controls with the Line so we know who owns it
foreach (Control c in _addedControls)
foreach (Control c in AddedControls)
{
c.Tag = this;
}

return _addedControls;
return AddedControls;
}

public abstract void Focus();
Expand All @@ -64,14 +52,13 @@ public virtual void PaintLine(Graphics g, int lineWidth, int lineHeight)

internal void RemoveControls(ControlCollection controls)
{
for (int i = 0; i < _addedControls.Count; i++)
foreach (Control c in AddedControls)
{
Control c = _addedControls[i];
c.Tag = null;
controls.Remove(c);
}
}

internal abstract void UpdateActionItem(DesignerActionList actionList, DesignerActionItem actionItem, ToolTip toolTip, ref int currentTabIndex);
internal abstract void UpdateActionItem(LineInfo lineInfo, ToolTip toolTip, ref int currentTabIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ namespace System.ComponentModel.Design;

internal sealed partial class DesignerActionPanel
{
private class LineInfo
private abstract class LineInfo
{
public Line Line;
public DesignerActionItem Item;
public DesignerActionList List;
public abstract DesignerActionItem? Item { get; }

public LineInfo(DesignerActionList list, DesignerActionItem item, Line line)
{
Debug.Assert(line is not null);
Line = line;
Item = item;
List = list;
}
public abstract Line CreateLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel);
public abstract Type LineType { get; }
}

private abstract class StandardLineInfo(DesignerActionList list) : LineInfo
{
public abstract override DesignerActionItem Item { get; }
public DesignerActionList List { get; } = list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@ private sealed class MethodLine : Line
{
private DesignerActionList _actionList;
private DesignerActionMethodItem _methodItem;
private MethodItemLinkLabel _linkLabel;
public MethodLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel) : base(serviceProvider, actionPanel)
{
}

public sealed override string FocusId
{
get => $"METHOD:{_actionList.GetType().FullName}.{_methodItem.MemberName}";
}

protected override void AddControls(List<Control> controls)
private readonly MethodItemLinkLabel _linkLabel;
private MethodLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel) : base(serviceProvider, actionPanel)
{
_linkLabel = new MethodItemLinkLabel
{
Expand All @@ -39,10 +30,12 @@ protected override void AddControls(List<Control> controls)
VisitedLinkColor = ActionPanel.LinkColor
};
_linkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(OnLinkLabelLinkClicked);
controls.Add(_linkLabel);
AddedControls.Add(_linkLabel);
}

public sealed override void Focus()
public override string FocusId => $"METHOD:{_actionList.GetType().FullName}.{_methodItem.MemberName}";

public override void Focus()
{
_linkLabel.Focus();
}
Expand Down Expand Up @@ -87,13 +80,14 @@ private void OnLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs
}
}

internal override void UpdateActionItem(DesignerActionList actionList, DesignerActionItem actionItem, ToolTip toolTip, ref int currentTabIndex)
internal override void UpdateActionItem(LineInfo lineInfo, ToolTip toolTip, ref int currentTabIndex)
{
_actionList = actionList;
_methodItem = (DesignerActionMethodItem)actionItem;
Info info = (Info)lineInfo;
_actionList = info.List;
_methodItem = info.Item;
toolTip.SetToolTip(_linkLabel, _methodItem.Description);
_linkLabel.Text = StripAmpersands(_methodItem.DisplayName);
_linkLabel.AccessibleDescription = actionItem.Description;
_linkLabel.AccessibleDescription = _methodItem.Description;
_linkLabel.TabIndex = currentTabIndex++;
}

Expand All @@ -115,5 +109,16 @@ protected override bool ProcessDialogKey(Keys keyData)
return base.ProcessDialogKey(keyData);
}
}

public sealed class Info(DesignerActionList list, DesignerActionMethodItem item) : StandardLineInfo(list)
{
public override DesignerActionMethodItem Item { get; } = item;
public override Line CreateLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
{
return new MethodLine(serviceProvider, actionPanel);
}

public override Type LineType => typeof(MethodLine);
}
}
}
Loading