You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found View.KeyBindings, View.AddCommand, and View.InvokeCommand, etc... to work really well. However, I also realized the implementation is way too coupled with KeyBindings`. Specifically, there are many cases where commands need to be invoked from mouse events.
is to build the mouse equvalent of View.KeyBindings: View.MouseBindings so devs could do:
AddCommand(Command.Context,ShowContextMenu);KeyBindings.Add(Application.ContextKey,Command.Context);MouseBindings.Add(MouseFlags.Button3Clicked,Command.Context);// btn3 is right
To address this I'd like to refactor KeyBindings to be generic (KeyBindings<Key>, KeyBindings<MouseFlags>,?) and make the Command API not have any KeyBinding specific knowledge. For example,:
publicbool?InvokeCommand(Commandcommand,Key?key=null,KeyBinding?keyBinding=null)...would become
```cs
publicbool?InvokeCommand<BindingType>(Commandcommand,BindingTypebinding)
In #3677 I tweaked CommandContext to be able to hold arbitrary context data:
publicrecordstructCommandContext{/// <summary>/// Initializes a new instance of <see cref="CommandContext"/> with the specified <see cref="Command"/>,/// </summary>/// <param name="command"></param>/// <param name="key"></param>/// <param name="keyBinding"></param>/// <param name="data"></param>publicCommandContext(Commandcommand,Key?key,KeyBinding?keyBinding=null,object?data=null){Command=command;Key=key;KeyBinding=keyBinding;Data=data;}/// <summary>/// The <see cref="Command"/> that is being invoked./// </summary>publicCommandCommand{get;set;}/// <summary>/// The <see cref="Key"/> that is being invoked. This is the key that was pressed to invoke the <see cref="Command"/>./// </summary>publicKey?Key{get;set;}/// <summary>/// The KeyBinding that was used to invoke the <see cref="Command"/>, if any./// </summary>publicKeyBinding?KeyBinding{get;set;}/// <summary>/// Arbitrary data./// </summary>publicobject?Data{get;set;}}
This struct needs to be like this instead:
/// <summary>/// Provides context for a <see cref="Command"/> that is being invoked./// </summary>/// <remarks>/// <para>/// To define a <see cref="Command"/> that is invoked with context,/// use <see cref="View.AddCommand(Command,Func{CommandContext,System.Nullable{bool}})"/>./// </para>/// </remarks>
#pragma warning restore CS1574// XML comment has cref attribute that could not be resolvedpublicrecordstructCommandContext<BindingType>{/// <summary>/// Initializes a new instance of <see cref="CommandContext"/> with the specified <see cref="Command"/>,/// </summary>/// <param name="command"></param>/// <param name="key"></param>/// <param name="binding"></param>/// <param name="data"></param>publicCommandContext(Commandcommand,BindingType?binding,object?data=null){Command=command;Binding=binding;Data=data;}/// <summary>/// The <see cref="Command"/> that is being invoked./// </summary>publicCommandCommand{get;set;}/// <summary>/// The keyboard or mouse minding that was used to invoke the <see cref="Command"/>, if any./// </summary>publicBindingType?Binding{get;set;}/// <summary>/// Arbitrary data./// </summary>publicobject?Data{get;set;}}
The text was updated successfully, but these errors were encountered:
In
I found
View.KeyBindings,
View.AddCommand, and
View.InvokeCommand, etc... to work really well. However, I also realized the implementation is way too coupled with
KeyBindings`. Specifically, there are many cases where commands need to be invoked from mouse events.In fact, I now believe the correct fix for
MouseEvent
andMouseEventEventArgs
to simplify #3029is to build the mouse equvalent of
View.KeyBindings
:View.MouseBindings
so devs could do:To address this I'd like to refactor
KeyBindings
to be generic (KeyBindings<Key>
,KeyBindings<MouseFlags>
,?) and make theCommand
API not have anyKeyBinding
specific knowledge. For example,:In #3677 I tweaked
CommandContext
to be able to hold arbitrary context data:This struct needs to be like this instead:
The text was updated successfully, but these errors were encountered: