Skip to content

Commit

Permalink
[API Proposal]: add ToolStripItem.SelectedChanged event dotnet#8548
Browse files Browse the repository at this point in the history
  • Loading branch information
Epica3055 committed Nov 17, 2023
1 parent f6eee83 commit 78a7f28
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/System.Windows.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ System.Windows.Forms.ListViewGroupCollection.AddRange(params System.Windows.Form
System.Windows.Forms.ListViewItem.ListViewSubItemCollection.AddRange(params string![]! items) -> void
System.Windows.Forms.ListViewItem.ListViewSubItemCollection.AddRange(params System.Windows.Forms.ListViewItem.ListViewSubItem![]! items) -> void
System.Windows.Forms.TabControl.TabPageCollection.AddRange(params System.Windows.Forms.TabPage![]! pages) -> void
System.Windows.Forms.ToolStripItem.SelectedChanged -> System.EventHandler?
System.Windows.Forms.ToolStripItemCollection.AddRange(params System.Windows.Forms.ToolStripItem![]! toolStripItems) -> void
System.Windows.Forms.ToolStripPanel.ToolStripPanelRowCollection.AddRange(params System.Windows.Forms.ToolStripPanelRow![]! value) -> void
virtual System.Windows.Forms.Control.ControlCollection.AddRange(params System.Windows.Forms.Control![]! controls) -> void
virtual System.Windows.Forms.ListView.ColumnHeaderCollection.AddRange(params System.Windows.Forms.ColumnHeader![]! values) -> void
virtual System.Windows.Forms.ToolStripItem.OnSelectedChanged(System.EventArgs! e) -> void
virtual System.Windows.Forms.TreeNodeCollection.AddRange(params System.Windows.Forms.TreeNode![]! nodes) -> void
3 changes: 3 additions & 0 deletions src/System.Windows.Forms/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5889,6 +5889,9 @@ Stack trace where the illegal operation occurred was:
<data name="ToolStripItemsDescr" xml:space="preserve">
<value>Collection of items to display on the ToolStrip.</value>
</data>
<data name="ToolStripItemSelectedChangedDescr" xml:space="preserve">
<value>Occurs when the Selected property value changes.</value>
</data>
<data name="ToolStripItemSize" xml:space="preserve">
<value>The size of the item.</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public abstract partial class ToolStripItem : BindableComponent,
internal static readonly object s_ownerChangedEvent = new();
internal static readonly object s_paintEvent = new();
internal static readonly object s_textChangedEvent = new();
internal static readonly object s_selectedChangedEvent = new();

internal static readonly object s_commandChangedEvent = new();
internal static readonly object s_commandParameterChangedEvent = new();
Expand Down Expand Up @@ -319,7 +320,7 @@ public ToolStripItemAlignment Alignment
/// <summary>
/// Determines if this item can be dragged.
/// This is EXACTLY like Control.AllowDrop - setting this to true WILL call
/// the droptarget handlers. The ToolStripDropTargetManager is the one that
/// the dropTarget handlers. The ToolStripDropTargetManager is the one that
/// handles the routing of DropTarget events to the ToolStripItem's IDropTarget
/// methods.
/// </summary>
Expand Down Expand Up @@ -850,6 +851,7 @@ public virtual bool Enabled
if (wasSelected)
{
KeyboardToolTipStateMachine.Instance.NotifyAboutLostFocus(this);
OnSelectedChanged(EventArgs.Empty);
}
}

Expand Down Expand Up @@ -1434,7 +1436,7 @@ internal bool MouseDownAndUpMustBeInSameItem

/// <summary>
/// Name of this control. The designer will set this to the same
/// as the programatic Id "(name)" of the control. The name can be
/// as the programmatic Id "(name)" of the control. The name can be
/// used as a key into the ControlCollection.
/// </summary>
[Browsable(false)]
Expand All @@ -1454,7 +1456,7 @@ internal bool MouseDownAndUpMustBeInSameItem
}

/// <summary>
/// The owner of this ToolStripItem. The owner is essentially a backpointer to
/// The owner of this ToolStripItem. The owner is essentially a backPointer to
/// the ToolStrip who contains this item in it's item collection. Handy for getting
/// to things such as the ImageList, which would be defined on the ToolStrip.
/// </summary>
Expand All @@ -1475,7 +1477,7 @@ internal bool MouseDownAndUpMustBeInSameItem
}

/// <summary>
/// Returns the "parent" item on the preceeding menu which has spawned this item.
/// Returns the "parent" item on the preceding menu which has spawned this item.
/// e.g. File->Open the OwnerItem of Open is File.
/// </summary>
[Browsable(false)]
Expand Down Expand Up @@ -1824,6 +1826,18 @@ public virtual bool Selected
(ParentInternal is not null && ParentInternal.IsSelectionSuspended &&
ParentInternal.LastMouseDownedItem == this));

[SRDescription(nameof(SR.ToolStripItemSelectedChangedDescr))]
public event EventHandler? SelectedChanged
{
add => Events.AddHandler(s_selectedChangedEvent, value);
remove => Events.RemoveHandler(s_selectedChangedEvent, value);
}

protected virtual void OnSelectedChanged(EventArgs e)
{
RaiseEvent(s_selectedChangedEvent, e);
}

protected internal virtual bool ShowKeyboardCues
=> DesignMode || ToolStripManager.ShowMenuFocusCues;

Expand Down Expand Up @@ -2227,7 +2241,7 @@ public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects, B
iwdata.SetData(data);
}

dataObject = (IComDataObject)iwdata;
dataObject = iwdata;
}

DROPEFFECT finalEffect;
Expand Down Expand Up @@ -2570,10 +2584,16 @@ private void HandleLeave()
{
if (_state[s_stateMouseDownAndNoDrag] || _state[s_statePressed] || _state[s_stateSelected])
{
bool wasSelected = _state[s_stateSelected];
_state[s_stateMouseDownAndNoDrag | s_statePressed | s_stateSelected] = false;

KeyboardToolTipStateMachine.Instance.NotifyAboutLostFocus(this);

if (wasSelected)
{
OnSelectedChanged(EventArgs.Empty);
}

Invalidate();
}
}
Expand Down Expand Up @@ -3232,6 +3252,8 @@ internal void Select(bool forceRaiseAccessibilityFocusChanged)

KeyboardToolTipStateMachine.Instance.NotifyAboutGotFocus(this);

OnSelectedChanged(EventArgs.Empty);

forceRaiseAccessibilityFocusChanged = true;
}

Expand Down Expand Up @@ -3624,6 +3646,8 @@ internal void Unselect()

KeyboardToolTipStateMachine.Instance.NotifyAboutLostFocus(this);
}

OnSelectedChanged(EventArgs.Empty);
}
}

Expand Down

0 comments on commit 78a7f28

Please sign in to comment.