Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335985 - Adapt the KeyController model to the e4 model
Summary: Adapt the KeyController model to the e4 model
Status: RESOLVED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.1 M7   Edit
Assignee: Jesse CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 317299
  Show dependency tree
 
Reported: 2011-02-01 11:36 EST by Paul Webster CLA
Modified: 2011-04-28 14:58 EDT (History)
3 users (show)

See Also:


Attachments
To allow the NewKeysPreferencePage to make Binding changes (40.49 KB, patch)
2011-02-16 14:55 EST, Jesse CLA
no flags Details | Diff
Second patch. Everything functional this time. (56.97 KB, text/plain)
2011-03-07 14:01 EST, Jesse CLA
no flags Details
Second patch. Everything functional this time. (278.36 KB, text/plain)
2011-03-07 15:26 EST, Jesse CLA
no flags Details
Fixed Patch (51.07 KB, patch)
2011-03-07 20:06 EST, Jesse CLA
no flags Details | Diff
Fixed patch v05 (35.34 KB, patch)
2011-03-08 16:07 EST, Paul Webster CLA
no flags Details | Diff
KeyBinding Patch (37.96 KB, patch)
2011-03-14 22:21 EDT, Jesse CLA
no flags Details | Diff
Keys for Default Scheme (87.29 KB, patch)
2011-03-22 19:22 EDT, Jesse CLA
no flags Details | Diff
Multiple scheme support (92.52 KB, patch)
2011-03-24 21:46 EDT, Jesse CLA
no flags Details | Diff
Multiple scheme support (93.17 KB, patch)
2011-03-25 14:19 EDT, Jesse CLA
no flags Details | Diff
Keys pref page v11 (92.29 KB, patch)
2011-04-26 17:47 EDT, Paul Webster CLA
no flags Details | Diff
Keys pref page v15 (90.12 KB, patch)
2011-04-28 14:52 EDT, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Webster CLA 2011-02-01 11:36:45 EST
See org.eclipse.ui.internal.keys.NewKeysPreferencePage
org.eclipse.ui.internal.keys.model.KeyController
org.eclipse.ui.internal.keys.model.BindingModel

We need to be able to adapt the e4 model to the pattern that BindingModel and ContextModel use.

PW
Comment 1 Jesse CLA 2011-02-16 14:55:00 EST
Created attachment 189127 [details]
To allow the NewKeysPreferencePage to make Binding changes

Here's patch #1. 

All modifications take effect immediately (as they should), and will be persisted. Unfortunately, any SYSTEM key bindings that are unbound will not be remembered for the next start up (unless overwritten by a USER binding). This will be done eventually (patch #2)
Comment 2 Paul Webster CLA 2011-02-18 10:34:41 EST
I'd like to re-order some stuff to spread the responsibilities around.


org.eclipse.e4.ui.bindings provides the runtime binding service.  It has no knowledge of the model, or the complexities of the 3.x system.

It looks like we should enhance org.eclipse.e4.ui.bindings.EBindingService.createBinding(TriggerSequence, ParameterizedCommand, String, String) so that it takes all of the important parameters for a KeyBinding:  locale, platform, and bindingType (SYSTEM, USER)


org.eclipse.e4.ui.workbench.swt is responsible for using the model to manage the runtime binding system.  We need to make sure that BindingProcessingAddon can add and remove bindings from the runtime system.  I would propose that we store some information we need as tags on the MKeyBinding:

"type:user" and "type:system" can then be translated into Binding.USER and Binding.SYSTEM.  We can also mark system bindings for delete using a "deleted" tag.  Storing this information in the model would remove the need to have BindingCopies, I think.  The BindingProcessingAddon is then responsible for interacting with the tags to keep the running system up to date.


org.eclipse.ui.workbench is the compatibility layer part that can see the extension points.

Just some notes:

org.eclipse.ui.internal.keys.BindingService.readRegistryAndPreferences(ICommandService)  ... using BindingPersistence on the BindingService BindingManager will replace whatever is there, possibly overwriting or merging.  I wouldn't do that.  We don't have a good story yet for keeping the BindingService bindingManager up to date, as technically it should reflect the the running system (somehow).

I think you having the new keys pref page/BindingModel updates OK.  I think then you'll just have to update your algorithm in org.eclipse.ui.internal.keys.BindingService.savePreferences(Scheme, Binding[])

1) if it's a new binding, add the MKeyBinding to the correct MBindingTable with the type:user tag.

2) if it's a "new binding" that shows up, but really it's a system binding that had its delete marker removed, remove the "deleted" tag from the existing MKeyBinding

3) if a binding has been deleted, if it's a type:user binding simply remove it from the model

4) if a binding has been deleted and its a system binding, tag it as "deleted"

PW
Comment 3 Jesse CLA 2011-03-07 14:01:46 EST
Created attachment 190585 [details]
Second patch. Everything functional this time.
Comment 4 Jesse CLA 2011-03-07 15:02:11 EST
Some comments:

- org.eclipse.e4.ui.bindings.EBindingService.createBinding(TriggerSequence,
ParameterizedCommand, String, String) was to be enhanced such that it takes ALL params for a KeyBinding. It gets called from the BindingProcessingAddon class which reads in all MKeyBindings and converts them to KeyBindings, then adds them to the BindingTableManager on startup. The information String locale, String platform, and String bindingType are not stored in MKeyBindings. The default implementation was to pass a null locale and platform, and SYSTEM bindingType. I provided a workaround for determining the bindingType. Each MKeyBinding is compared with the list of USER Bindings to determine the bindingType. I'm going by the assumption that the list of USER bindings will generally be fairly small, so the check shouldn't be too computationally aggressive. However, I did not put the check in for the locale and platform of each Binding. Going through the list of SYSTEM bindings for each MKeyBinding seems like it might be a little too costly (O(n^2) in the worst case).

- org.eclipse.ui.internal.keys.BindingService.readRegistryAndPreferences(ICommandService)... there is nothing in BindingService's BindingManager on startup, so if we don't use the BindingPersistence on it, then the KeysPreferencePage will crash on load.

- There was one issue I ran into when unbinding a SYSTEM binding (the Activate Editor binding to be exact). Removing SYSTEM bindings from the preferences actually does work properly and gets persisted, but NOT for this binding. Following the code in the debugger for the next startup after a remove for a SYSTEM binding, BindingManager.removeBindings(...) actually finds the binding and tries to remove it, but it doesn't actually get removed. I wasn't able to figure this one out. Removing SYSTEM bindings on every other binding that *I* tried actually does work though.

Regardless, the functionality mimics that of the 3.x keys pref page for the most part. The above comments only explain some of the issues that are "under the hood". If anyone runs into more issues or has any additional comments, then just let me know.

- Jesse
Comment 5 Jesse CLA 2011-03-07 15:26:30 EST
Created attachment 190597 [details]
Second patch. Everything functional this time.
Comment 6 Jesse CLA 2011-03-07 20:06:45 EST
Created attachment 190610 [details]
Fixed Patch

DIREGARD THE FIRST TWO PATCHES!

Sorry for the above two. There were changes in the repo so I had some difficulty syncing everything up. This is the correct patch. Take a look! =)

- Jesse
Comment 7 Jesse CLA 2011-03-07 20:16:11 EST
Oh, I should also mention that after having synced everything up and testing it out, the problem I was having with removing the Activate Editor binding has disappeared. I wonder if it has anything to do with the fact that I was using a Mac when developing this, or it's because of the updated files from the repo... Regardless, everything appears to be working correctly this time, at least when using Windows XP. =)

- Jesse
Comment 8 Paul Webster CLA 2011-03-08 16:07:17 EST
Created attachment 190699 [details]
Fixed patch v05

I've released this patch to HEAD for tonight's build.  I cleaned up the sysouts, and we can look at moving away from using the runtime system after M6

PW
Comment 9 Paul Webster CLA 2011-03-11 08:52:16 EST
I'd like you to revisit how this is organized.

1) start with the org.eclipse.e4.ui.bindings.EBindingService.createBinding(TriggerSequence, ParameterizedCommand, String, String, String, String, int).  In e4, the only important attributes are:
TriggerSequence sequence
ParameterizedCommand command
String contextId

Make the last parameter a Map of attributes.  That will allow us to pass through schemeId, locale, platform, and/or bindingType (which for us can be the string "user").

Then anyone should be able to create a complete KeyBinding with the relevant information.

2) Update org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon to be able to read model tags and generate the attribute map.

You can create more tests in org.eclipse.e4.ui.bindings.tests.BindingTestSuite somewhere.

Let's start with that.

PW
Comment 10 Remy Suen CLA 2011-03-11 10:52:44 EST
I20110310-2200

1. Unbind a command.
2. Commit the changes in the preference dialog.
3. Try to restore the unbound command, it doesn't work.
Comment 11 Jesse CLA 2011-03-14 22:21:29 EDT
Created attachment 191183 [details]
KeyBinding Patch

- Fixes restoring bindings.
- BindingCopies is removed
- Attribute maps generated to properly create KeyBindings

I guess if there are any more problems, I'll hear about them soon enough...

- Jesse
Comment 12 Dani Megert CLA 2011-03-15 07:58:25 EDT
> I guess if there are any more problems, I'll hear about them soon enough...
- Changing the scheme doesn't work.
- Some of the commands seem to appear twice, e.g. 'Save'.
Comment 13 Dani Megert CLA 2011-03-15 11:27:32 EDT
(In reply to comment #12)
> > I guess if there are any more problems, I'll hear about them soon enough...
> - Changing the scheme doesn't work.
> - Some of the commands seem to appear twice, e.g. 'Save'.
Note that this is based on 4.1 M6 (not on latest patch).
Comment 14 Paul Webster CLA 2011-03-22 09:53:12 EDT
(In reply to comment #11)
> Created attachment 191183 [details]
> KeyBinding Patch
> 


Hi Jesse,

This patch won't apply on my workspace, although you can still use it as a reference.

You need to:

1) reset your workspace, and then sync it up with head.  I would go to the sync view (where you can see your changes) and use context menu>Override and Update to get rid of them.  Then sync with CVS and accept all incoming changes so your environment matches HEAD

2) then move on to comment #9
Binding createBinding(TriggerSequence sequence, ParameterizedCommand command, String schemeId, String contextId, String locale, String platform, int bindingType);

I'd like that to become
Binding createBinding(TriggerSequence sequence, ParameterizedCommand command, String contextId, Map<String, String> attributes);

attributes can be one of "schemeId", "locale", "platform", "type"

When the attributes should be stored in the MKeyBinding, use getTags() and store them in there.  tags are usually of the form "tagName:tagValue"

The type can just be "type:user" since you'll be able to search for that directly.

Modify BindingProcessingAddon so it can parse the tags and make an attribute map when creating bindings though createBindings().

Add a test class similar to BindingLookupTest to BindingTestSuite.  In it, create key model elements with various tags and test that createBinding() returns the correct KeyBindings.

Once you get that far, attach a patch and we'll give it a review.

PW
Comment 15 Jesse CLA 2011-03-22 19:22:30 EDT
Created attachment 191714 [details]
Keys for Default Scheme

Okay, let's try this one... It's good for the default scheme, has the implementation changes that you've asked for, and includes some new tests. I'm going to try to figure out a way to properly allow switching schemes without messing anything up tonight.

- Jesse
Comment 16 Jesse CLA 2011-03-22 21:04:05 EDT
Also, I think I may have found out the reason for the duplicate 'save' commands that show up in the keys pref page. Going through the commands list from the command manager, there are a number of different save commands:

(IDs)
org.eclipse.e4.ui.saveAllCommands
org.eclipse.ui.file.save
org.eclipse.ui.edit.revertToSaved
org.eclipse.e4.ui.saveCommands
org.eclipse.ui.window.savePerspective
org.eclipse.ui.file.saveAll
org.eclipse.ui.file.saveAs

(Names)
Save All
Save
Revert to Saved
Save
Save Perspective As
Save All
Save As

Some of these commands have the same name, so I think that's the cause. I'll try to dig a little deeper and see what else I can find out about this.

- Jesse
Comment 17 Jesse CLA 2011-03-24 21:46:42 EDT
Created attachment 191882 [details]
Multiple scheme support

Okay,

This patch will support multiple schemes. However there are some things that I should note:

1. As of right now, the binding table manager doesn't handle conflicts very well so they will just be ignored. This kind of screws over a few emacs key bindings (I think around 5 or 6). I will be working on a fix for this as it relates to https://bugs.eclipse.org/bugs/show_bug.cgi?id=317201.

2. The issue in 3.x when switching back and forth between schemes occurs here as well. If you switch schemes from the comboview in the keys pref page more then twice, it doesn't update again until you hit restore defaults. I'm still looking into this...

3. I'm not sure what the difference is between org.eclipse.ui.file.save and org.eclipse.e4.ui.saveCommands or any of the other bindings listed above that have the same name. They seem to be doing the same thing when executed. It's being read in from the commands extension point, so there's got to be some reason why it's there.

- Jesse
Comment 18 Jesse CLA 2011-03-25 01:02:10 EDT
Comment on attachment 191882 [details]
Multiple scheme support

AGH! I just noticed I posted the wrong patch... jeez. Sorry about this. I'll repost tomorrow.
Comment 19 Jesse CLA 2011-03-25 14:19:46 EDT
Created attachment 191929 [details]
Multiple scheme support

The notes from comment 17 still apply.
Comment 20 Paul Webster CLA 2011-04-26 17:47:51 EDT
Created attachment 194113 [details]
Keys pref page v11

iteration 11 - use the BindingManager to manage active keybindings at the compatibility level, and propagate changes into the model.

Looks like we need to hook up more listeners in BindingProcessingAddon.  Tests can be found in dev.eclipse.org:/cvsroot/eclipse e4/org.eclipse.e4.compatibility/tests/org.eclipse.e4.ui.keybinding.tests and we should add and remove Bindings through the IBindingService to prove they work in the runtime.

PW
Comment 21 Paul Webster CLA 2011-04-28 14:52:13 EDT
Created attachment 194304 [details]
Keys pref page v15

Iteration 15, changing schemes now works.
Comment 22 Paul Webster CLA 2011-04-28 14:58:27 EDT
(In reply to comment #21)
> Created attachment 194304 [details]
> Keys pref page v15

Released.  I've opened bug 344181 and bug 344182 for some further issues.

Thanx Jesse!

PW