Re: Platform API: Context-sensitive keyboard accelerators

2018-03-06 Thread Jaroslav Tulach
Out of curiosity (as I may still be living in the past), here is one of the
documents I have written when attempting to (re)design the NetBeans action
system:

https://openide.netbeans.org/proposals/actions/index.html

In general my intention was to use [Action.callback](
http://bits.netbeans.org/8.2/javadoc/org-openide-awt/org/openide/awt/Actions.html#callback-java.lang.String-javax.swing.Action-boolean-java.lang.String-java.lang.String-boolean-)
actions to register a generic placeholder with a shortcut that can then do
whatever each component wants.

-jt


2018-02-27 20:44 GMT+01:00 cowwoc :

> Unfortunately, I'm not too familiar with the internals. I filed
> https://issues.apache.org/jira/browse/NETBEANS-432 with a high-level
> overview of what a user expects. Hopefully someone who is familiar with
> this codebase can flesh out what this entails.
>
> Thank you,
> Gili
>
>
> On 2018-02-27 12:49 PM, Tim Boudreau wrote:
>
>> I'd say file an RFE, but best to get as specific as possible about what
>> mechanism needs to be changed and how.  I.e. Exactly the desired behavior,
>> what blocks it, and where the change would need to be.
>>
>> -Tim
>>
>> On Tue, Feb 27, 2018 at 11:00 AM cowwoc  wrote:
>>
>> Is it okay if I file a RFE for this, or do you feel it should stew a bit
>>> longer in the mailing list?
>>>
>>> Gili
>>>
>>> On 2018-02-26 3:47 PM, Christian Lenz wrote:
>>>
>>>> I figured out that problem too, but I don’t know whether this is window
>>>>
>>> specific or not.
>>>
>>>> Sure I think you can add a shortcut to your Code, which is already
>>>>
>>> taken. You got a warning after NetBeans started that says: „there is a
>>> duplicate“.
>>>
>>>> Maybe it overrides it or not, I don’t know atm. But if not and you
>>>>
>>> created an Action, where you can Change the shortcut via KeyMap Options,
>>> you sometimes overrides existing ones (Which Shows you a warning or error
>>> that another one has the same etc.), but yes they should work context
>>> sensitve, and some are still working context sensitive, afaik.
>>>
>>>> I set ctrl + b to Show the git browser for branches etc. This shortcut
>>>>
>>> only Woks, when I select a Project. If I’m in the Editor, it will set a
>>> bookmark or open the bookmark window. So there is smth like a context
>>> sensitive way to implement shortcuts but I don’t know the logic at all.
>>>
>>>> My 2 cents
>>>>
>>>>
>>>> Cheers
>>>>
>>>> Chris
>>>>
>>>> Von: Tim Boudreau
>>>> Gesendet: Montag, 26. Februar 2018 19:59
>>>> An: dev@netbeans.incubator.apache.org
>>>> Betreff: Re: Platform API: Context-sensitive keyboard accelerators
>>>>
>>>> It's been a long time since I worked on the code involved, so my
>>>> recollection may be a little fuzzy, but this may help point you in a
>>>> direction or two:
>>>>
>>>> There is a general problem that NetBeans supports, or at least used to
>>>> support, both single window pseudo-SDI mode and a multiple windows mode.
>>>> And keyboard shortcuts propagate down to the InputMap/KeyMap of the
>>>>
>>> window
>>>
>>>> in question.  My recollection is that this was originally handled with
>>>> an
>>>> AWTEventListener, because that was the one way to guarantee shortcuts
>>>> worked globally, no matter the windowing layout.  I *think* we migrated
>>>> that to something using InputMap/KeyMap around 2003 or so, but there may
>>>> still be workarounds to ensure things work globally.
>>>>
>>>> What I'd suggest to try is an experiment - create a dialog with the
>>>>
>>> dialogs
>>>
>>>> API and try binding a key you know is bound as a global shortcut.  Use
>>>> InputMap/KeyMap and attach it to, most likely, the root pane of the
>>>>
>>> dialog.
>>>
>>>> If it works, then it's just a matter of implementing shortcuts in the
>>>>
>>> right
>>>
>>>> places (make sure to call consume() on the event to stop it propagating
>>>> further).  If it doesn't, then some more fundamental work that's likely
>>>>
>>> to
>>>
>>>> touch how key bindings work globally may be needed.
>>>>
>>>> Also bear in mind that key 

Re: Platform API: Context-sensitive keyboard accelerators

2018-02-26 Thread Tim Boudreau
It's been a long time since I worked on the code involved, so my
recollection may be a little fuzzy, but this may help point you in a
direction or two:

There is a general problem that NetBeans supports, or at least used to
support, both single window pseudo-SDI mode and a multiple windows mode.
And keyboard shortcuts propagate down to the InputMap/KeyMap of the window
in question.  My recollection is that this was originally handled with an
AWTEventListener, because that was the one way to guarantee shortcuts
worked globally, no matter the windowing layout.  I *think* we migrated
that to something using InputMap/KeyMap around 2003 or so, but there may
still be workarounds to ensure things work globally.

What I'd suggest to try is an experiment - create a dialog with the dialogs
API and try binding a key you know is bound as a global shortcut.  Use
InputMap/KeyMap and attach it to, most likely, the root pane of the dialog.

If it works, then it's just a matter of implementing shortcuts in the right
places (make sure to call consume() on the event to stop it propagating
further).  If it doesn't, then some more fundamental work that's likely to
touch how key bindings work globally may be needed.

Also bear in mind that key bindings are different for different platforms -
on Mac OS, the alt key is a compose key for international characters and
cannot have shortcuts bound to it (ctrl is used instead), and some
keybindings are mapped to different keys for consistency with other Mac OS
apps (there's a syntax for defining keybindings in OS-neutral ways, for
declarative bindings).

HTH,

Tim


On Mon, Feb 26, 2018 at 9:11 AM, cowwoc  wrote:

> Hi,
>
> Netbeans has an extremely long (and getting longer) list of keyboard
> shortcuts. Part of the problem is that (for the most part) keyboard
> shortcuts are not context-sensitive nor are they able to be
> context-sensitive. I'll give you a simple example I raised a few years back:
>
> When the editor Find & Replace dialog is focused, we have "Replace" and
> "Replace All" buttons. It would be nice if we could map ALT+A to "Replace
> All" as many other applications do. Unfortunately, ALT+A is already mapped
> to the Refactor pulldown menu. The platform API does not allow mapping the
> same keyboard accelerator to different UI actions depending on the context.
> As a result, we end up with akward combinations like ALT+P for Replace All.
>
> Please see https://netbeans.org/bugzilla/show_bug.cgi?id=222843 for
> additional context.
>
> Is anyone else interested in this issue? Is anyone interested in working
> on it?
>
> Thank you,
> Gili
>
>
> -
> To unsubscribe, e-mail: dev-unsubscr...@netbeans.incubator.apache.org
> For additional commands, e-mail: dev-h...@netbeans.incubator.apache.org
>
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>
>
>
>


-- 
http://timboudreau.com