StyledText and keyboard actions

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

StyledText and keyboard actions

Thomas Singer
Hi,

Currently we are using an ugly hack to modify the behavior of some
default shortcuts and add own shortcuts in a StyledText by having a
subclass of StyledText inside org.eclipse.swt.custom and overriding the
method invokeAction(int actionId).

For example, we can cut/copy without selection or limit
cursor-left/-right to the very line, have a more advanced
delete-previous or Mac-like handling of cursor-up/-down.

What is the designed way of
- replacing default shortcuts with own ones and
- add new shortcuts?

Thanks in advance.

--
Best regards,
Thomas Singer
=============
syntevo GmbH
http://www.syntevo.com
http://www.syntevo.com/blog
_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Leo Ufimtsev-2
Hello Thomas,

I've never worked with styled text or remapped keys, but at glance I noticed  the "keyActionMap" variable.
There is a getKeyBinding(int) and setKeyBinding(int,int) method.

The createKeyBindings() method initializes all default keybindings (which is called from the constructor).

I haven't experiment with it, but you could perhaps override the default mappings. Like if you look inot the createKyBindings() method:
setKeyBinding(SWT.ARROW_UP, ST.LINE_UP);  <<< set these to some of your own.

I don't know if this is what you need or if the above works thou? Is that of any use?

If someone knows of a better approach, please feel free to post.

Regards

Leo




On Thu, Feb 2, 2017 at 7:38 AM, Thomas Singer <[hidden email]> wrote:
Hi,

Currently we are using an ugly hack to modify the behavior of some default shortcuts and add own shortcuts in a StyledText by having a subclass of StyledText inside org.eclipse.swt.custom and overriding the method invokeAction(int actionId).

For example, we can cut/copy without selection or limit cursor-left/-right to the very line, have a more advanced delete-previous or Mac-like handling of cursor-up/-down.

What is the designed way of
- replacing default shortcuts with own ones and
- add new shortcuts?

Thanks in advance.

--
Best regards,
Thomas Singer
=============
syntevo GmbH
http://www.syntevo.com
http://www.syntevo.com/blog
_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev



--
Leo Ufimtsev
Software Engineer, Eclipse team.
Toronto, Canada

Red Hat, Inc.
[hidden email] | http://DeveloperBlog.RedHat.com/

_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Thomas Singer
Hi Leo,

But the main question is how to tell setKeyBinding what own code should
be executed? If I recall correctly, Swing used Actions for that, but
here a simple Runnable would do as well.

How exactly Eclipse injects own shortcuts - assuming that StyledText is
the core control for the code editor?

--
Best regards,
Thomas Singer
=============
syntevo GmbH
http://www.syntevo.com
http://www.syntevo.com/blog


On 02.02.2017 16:05, Leo Ufimtsev wrote:

> Hello Thomas,
>
> I've never worked with styled text or remapped keys, but at glance I
> noticed  the "keyActionMap" variable.
> There is a getKeyBinding(int) and setKeyBinding(int,int) method.
>
> The createKeyBindings() method initializes all default keybindings (which
> is called from the constructor).
>
> I haven't experiment with it, but you could perhaps override the default
> mappings. Like if you look inot the createKyBindings() method:
> setKeyBinding(SWT.ARROW_UP, ST.LINE_UP);  <<< set these to some of your own.
>
> I don't know if this is what you need or if the above works thou? Is that
> of any use?
>
> If someone knows of a better approach, please feel free to post.
>
> Regards
>
> Leo
>
>
>
>
> On Thu, Feb 2, 2017 at 7:38 AM, Thomas Singer <[hidden email]> wrote:
>
>> Hi,
>>
>> Currently we are using an ugly hack to modify the behavior of some default
>> shortcuts and add own shortcuts in a StyledText by having a subclass of
>> StyledText inside org.eclipse.swt.custom and overriding the method
>> invokeAction(int actionId).
>>
>> For example, we can cut/copy without selection or limit cursor-left/-right
>> to the very line, have a more advanced delete-previous or Mac-like handling
>> of cursor-up/-down.
>>
>> What is the designed way of
>> - replacing default shortcuts with own ones and
>> - add new shortcuts?
>>
>> Thanks in advance.
>>
>> --
>> Best regards,
>> Thomas Singer
>> =============
>> syntevo GmbH
>> http://www.syntevo.com
>> http://www.syntevo.com/blog
>> _______________________________________________
>> platform-swt-dev mailing list
>> [hidden email]
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>>
>
>
>
>
>
> _______________________________________________
> platform-swt-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Gunnar Wagenknecht
Hi Thomas,

Have a look at AbstractTextEditor#createNavigationActions. It sounds like it does what you are looking for.

It does:
textWidget.setKeyBinding(SWT.INSERT, SWT.NULL);

And hooks its own VerifyKeyListener and matches keys to actions.

-Gunnar

--
Gunnar Wagenknecht
[hidden email], http://guw.io/






> On 2 Feb 2017, at 20:23, Thomas Singer <[hidden email]> wrote:
>
> Hi Leo,
>
> But the main question is how to tell setKeyBinding what own code should be executed? If I recall correctly, Swing used Actions for that, but here a simple Runnable would do as well.
>
> How exactly Eclipse injects own shortcuts - assuming that StyledText is the core control for the code editor?
>
> --
> Best regards,
> Thomas Singer
> =============
> syntevo GmbH
> http://www.syntevo.com
> http://www.syntevo.com/blog
>
>
> On 02.02.2017 16:05, Leo Ufimtsev wrote:
>> Hello Thomas,
>>
>> I've never worked with styled text or remapped keys, but at glance I
>> noticed  the "keyActionMap" variable.
>> There is a getKeyBinding(int) and setKeyBinding(int,int) method.
>>
>> The createKeyBindings() method initializes all default keybindings (which
>> is called from the constructor).
>>
>> I haven't experiment with it, but you could perhaps override the default
>> mappings. Like if you look inot the createKyBindings() method:
>> setKeyBinding(SWT.ARROW_UP, ST.LINE_UP);  <<< set these to some of your own.
>>
>> I don't know if this is what you need or if the above works thou? Is that
>> of any use?
>>
>> If someone knows of a better approach, please feel free to post.
>>
>> Regards
>>
>> Leo
>>
>>
>>
>>
>> On Thu, Feb 2, 2017 at 7:38 AM, Thomas Singer <[hidden email]> wrote:
>>
>>> Hi,
>>>
>>> Currently we are using an ugly hack to modify the behavior of some default
>>> shortcuts and add own shortcuts in a StyledText by having a subclass of
>>> StyledText inside org.eclipse.swt.custom and overriding the method
>>> invokeAction(int actionId).
>>>
>>> For example, we can cut/copy without selection or limit cursor-left/-right
>>> to the very line, have a more advanced delete-previous or Mac-like handling
>>> of cursor-up/-down.
>>>
>>> What is the designed way of
>>> - replacing default shortcuts with own ones and
>>> - add new shortcuts?
>>>
>>> Thanks in advance.
>>>
>>> --
>>> Best regards,
>>> Thomas Singer
>>> =============
>>> syntevo GmbH
>>> http://www.syntevo.com
>>> http://www.syntevo.com/blog
>>> _______________________________________________
>>> platform-swt-dev mailing list
>>> [hidden email]
>>> To change your delivery options, retrieve your password, or unsubscribe
>>> from this list, visit
>>> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> platform-swt-dev mailing list
>> [hidden email]
>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>>
> _______________________________________________
> platform-swt-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Thomas Singer
Hi all,

The code of StyledText.handleKeyDown (the method that sends the
VerifyKey event) looks like this (shortened by irrelevant parts):

> event.stateMask &= SWT.MODIFIER_MASK;
>
> Event verifyEvent = new Event();
> verifyEvent.character = event.character;
> verifyEvent.keyCode = event.keyCode;
> verifyEvent.keyLocation = event.keyLocation;
> verifyEvent.stateMask = event.stateMask;
> verifyEvent.doit = event.doit;
> notifyListeners(ST.VerifyKey, verifyEvent);
> if (verifyEvent.doit) {
> if ((event.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL && event.keyCode == SWT.SHIFT && isBidiCaret()) {
> newOrientation = event.keyLocation == SWT.LEFT ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT;
> }
> handleKey(event);
> }

The problem is that if the VerifyKey-listener has set verifyEvent.doit
to false, this change is NOT propageted to the KeyDown listener, so if
there is one more KeyDown listener, it will not know whether the event
already has been processed. Looks like a bug to me.

--
Best regards,
Thomas Singer
=============
syntevo GmbH
http://www.syntevo.com
http://www.syntevo.com/blog


On 2017-02-02 21:27, Gunnar Wagenknecht wrote:

> Hi Thomas,
>
> Have a look at AbstractTextEditor#createNavigationActions. It sounds like it does what you are looking for.
>
> It does:
> textWidget.setKeyBinding(SWT.INSERT, SWT.NULL);
>
> And hooks its own VerifyKeyListener and matches keys to actions.
>
> -Gunnar
>
_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Gunnar Wagenknecht
On 3 Feb 2017, at 13:50, Thomas Singer <[hidden email]> wrote:

Event verifyEvent = new Event();
...
verifyEvent.doit = event.doit;
notifyListeners(ST.VerifyKey, verifyEvent);
if (verifyEvent.doit) {

The problem is that if the VerifyKey-listener has set verifyEvent.doit to false, this change is NOT propageted to the KeyDown listener, so if there is one more KeyDown listener, it will not know whether the event already has been processed. Looks like a bug to me.

Can you explain why? Maybe it helps explaining what you are trying to implement. As for the documented contract it seems correct. A VerifyKeyListener can block an event from being handled. If doit is false then other key down listeners should not be informed.

Thank you for the suggestion. In what repository I can find the AbstractTextEditor (I'm only used to SWT)? Thanks in advance.

It's here:

-Gunnar

-- 
Gunnar Wagenknecht
[hidden email], http://guw.io/



_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Thomas Singer
Hi Gunnar,

Thanks again for the help, I've change our shortcut handling with your
suggested one and it seems to work fine.

> Can you explain why? Maybe it helps explaining what you are trying to implement. As for the documented contract it seems correct.

I thought each handled KeyDown event had to be marked as .doit = false,
so additional KeyDown listeners (or display filters) know whether it
already has been processed and can ignore it. But I have an (ugly)
work-around for that, so it's no need for me.

--
Best regards,
Thomas Singer
=============
syntevo GmbH
http://www.syntevo.com
http://www.syntevo.com/blog


On 03.02.2017 14:44, Gunnar Wagenknecht wrote:

>> On 3 Feb 2017, at 13:50, Thomas Singer <[hidden email]> wrote:
>
>>> Event verifyEvent = new Event();
> ...
>>> verifyEvent.doit = event.doit;
>
>>> notifyListeners(ST.VerifyKey, verifyEvent);
>>> if (verifyEvent.doit) {
>
>> The problem is that if the VerifyKey-listener has set verifyEvent.doit to false, this change is NOT propageted to the KeyDown listener, so if there is one more KeyDown listener, it will not know whether the event already has been processed. Looks like a bug to me.
>
> Can you explain why? Maybe it helps explaining what you are trying to implement. As for the documented contract it seems correct. A VerifyKeyListener can block an event from being handled. If doit is false then other key down listeners should not be informed.
>
>> Thank you for the suggestion. In what repository I can find the AbstractTextEditor (I'm only used to SWT)? Thanks in advance.
>
>
> It's here:
> http://git.eclipse.org/c/platform/eclipse.platform.text.git/tree/ <http://git.eclipse.org/c/platform/eclipse.platform.text.git/tree/>
>
> -Gunnar
>
>
>
> _______________________________________________
> platform-swt-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Stephan Aßmus
In reply to this post by Thomas Singer
Hi,

Am 02.02.2017 um 20:23 schrieb Thomas Singer:
> But the main question is how to tell setKeyBinding what own code should
> be executed? If I recall correctly, Swing used Actions for that, but
> here a simple Runnable would do as well.
>
> How exactly Eclipse injects own shortcuts - assuming that StyledText is
> the core control for the code editor?

I've read to the end of the thread, but just thought I could answer the
above question:

After you have overridden actions via setKeyBinding(), or added new
bindings, you can override...

public void invokeAction(int action)

... in your StyledText sub-class to handle what you have defined. You
can also selectively call the super-class version when you want the
action handled by the original code. Hope this helps.

Best regards,
-Stephan

_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StyledText and keyboard actions

Thomas Singer
Hi Stephan,

That's what we've done until my recent rework, but overwriting SWT
classes seems considered to be bad design.

--
Best regards,
Thomas Singer
=============
syntevo GmbH
http://www.syntevo.com
http://www.syntevo.com/blog


On 2017-02-09 8:46, Stephan Aßmus wrote:

> Hi,
>
> Am 02.02.2017 um 20:23 schrieb Thomas Singer:
>> But the main question is how to tell setKeyBinding what own code should
>> be executed? If I recall correctly, Swing used Actions for that, but
>> here a simple Runnable would do as well.
>>
>> How exactly Eclipse injects own shortcuts - assuming that StyledText is
>> the core control for the code editor?
>
> I've read to the end of the thread, but just thought I could answer the
> above question:
>
> After you have overridden actions via setKeyBinding(), or added new
> bindings, you can override...
>
> public void invokeAction(int action)
>
> ... in your StyledText sub-class to handle what you have defined. You
> can also selectively call the super-class version when you want the
> action handled by the original code. Hope this helps.
>
> Best regards,
> -Stephan
>
> _______________________________________________
> platform-swt-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
_______________________________________________
platform-swt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Loading...