Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

Need a way to cancel `InvokeCommand`

Open tig opened this issue 1 year ago • 1 comments

As a user of a View that defines a command, e.g. with AddCommand (Command.Accept, OnAccept);, I sometimes want to prevent the command from being executed.

AddCommand etc... are private, so I can't remove the command binding.

View.OnAccept is not virtual, so I can't override it.

The View.Accept event invokes subscribers in a non-deterministic way, so I can't subscribe can do e.Cancel = true.

I think what I want is:

view.InvokingCommand += (s, e) => { e.Cancel = true; }

Or something.

tig avatar Mar 05 '24 20:03 tig

Ideally, it should use a CancellationToken, so others can react accordingly.

dodexahedron avatar Mar 07 '24 02:03 dodexahedron