Bug 62243 - [Workbench] Support to directly activate views via a keyboard short cut
Summary: [Workbench] Support to directly activate views via a keyboard short cut
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 RC2   Edit
Assignee: Michael Van Meekeren CLA
QA Contact:
URL:
Whiteboard:
Keywords: polish
Depends on:
Blocks:
 
Reported: 2004-05-14 07:03 EDT by Erich Gamma CLA
Modified: 2004-06-11 14:17 EDT (History)
4 users (show)

See Also:


Attachments
patch to org.eclipse.ui - new view category (1.29 KB, patch)
2004-05-21 16:53 EDT, Erich Gamma CLA
no flags Details | Diff
patch to org.eclipse.ui.workbench (ViewDescriptor, ShowViewHandler (4.51 KB, patch)
2004-05-21 16:59 EDT, Erich Gamma CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erich Gamma CLA 2004-05-14 07:03:29 EDT
It is currently not possible to activate a view via a short cut.

Window>Navigation>Next/Previous View provides support to activate a view via 
the keyboard, but once you have many views in a perspective the menu grows and 
the quick access is lost.

For 3.0 we should come up with a simple solution.
* view providers register a command with the command service.
* the workbench renders the view short cuts in the Window>Show View menu and 
the Window>Show View>Others... dialog
Comment 1 Erich Gamma CLA 2004-05-21 16:49:34 EDT
Here is the proposed solution. Patches follow...

Clients contributing a view need to:
* Define a command with the view's id as the command ID
Here is the example for a command to show the Hierarchy view
      <command
            name="Hierarchy"
            description="Show the Hiearchy View"
            category="org.eclipse.ui.category.views"
            id="org.eclipse.jdt.ui.TypeHierarchy">
      </command>

* if the view should have an initial keybinding then define a keybinding
using the existing markup to define a keybinding:
      <keyBinding
            string="Alt+Shift+T"
            scope="org.eclipse.ui.globalScope"
            command="org.eclipse.jdt.ui.TypeHierarchy"
            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
      </keyBinding>


Implementation:
* The workbench defines a command category for views:
      <category
            name="%category.view.name"
            description="%category.view.description"
            id="org.eclipse.ui.category.views">
      </category>
  Clients contribute views to this category.

* The workbench registers a command handler for each view. The command handler 
is a custom handler (ShowViewHandler). The handler is registered for the 
view's id. This is done in the ViewDescriptor class when the ViewDescriptor is 
created.
	public ViewDescriptor(IConfigurationElement e, String desc)
	        throws CoreException {
		configElement = e;
		description = desc;
		loadFromExtension();
>>>>		registerShowViewHandler();
	}
    
	private void registerShowViewHandler() {
		id = configElement.getAttribute(ATT_ID);
        IHandler showViewHandler = new ShowViewHandler(id);
        HandlerSubmission showViewSubmission = new HandlerSubmission(null, 
null, null, id, showViewHandler, Priority.MEDIUM);
    	PlatformUI.getWorkbench().getCommandSupport().addHandlerSubmission
(showViewSubmission);
	}

* Here is a sketch for the ShowViewHandler
public class ShowViewHandler extends AbstractHandler {
	private String viewId;

	public ShowViewHandler(String viewId) {
		this.viewId = viewId;
	}
	public Object execute(Map parameterValuesByName) throws 
ExecutionException {
     >>>> show the view with the given Id in the active page
}

* With this the keybinding will work but it isn't shown to the user in the 
Show View menu. To make the keybinding appear in the Show View menu we simply 
associate the ShowViewAction with the command id:
	action = new ShowViewAction(window, desc);
	action.setActionDefinitionId(id); >>> id is the View Id

ISSUES
* for simplicity, the current solution uses the viewID as the commandID. There 
is a potential that an existing command is already using the same id as view. 
The potential for this is small. If we consider this serious we can add an 
attribute to the view markup to define a commandId.

* we need to find some key bindings... (not all views will have an initial key 
binding) but there are almost no keys left. So I suggest to use a multi key 
binding with a common prefix key, e.g., Alt+Shift+V. So the Show Package 
explorer action would become "Alt+Shift+V, P".
Comment 2 Erich Gamma CLA 2004-05-21 16:53:04 EDT
Created attachment 10967 [details]
patch to org.eclipse.ui - new view category
Comment 3 Erich Gamma CLA 2004-05-21 16:59:24 EDT
Created attachment 10968 [details]
patch to org.eclipse.ui.workbench (ViewDescriptor, ShowViewHandler
Comment 4 Erich Gamma CLA 2004-05-27 18:54:11 EDT
Here is a test scenario:

1) add the following command and keybinding to org.eclipse.ui.ide
      <command
            name="Resource Navigator"
            description="Resource Navigator"
            category="org.eclipse.ui.category.views"
            id="org.eclipse.ui.views.ResourceNavigator">
      </command>
      <keyBinding
            string="Ctrl+Shift+6"
            scope="org.eclipse.ui.globalScope"
            command="org.eclipse.ui.views.ResourceNavigator"
            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
      </keyBinding>

2) start up eclipse
- open Window>Preferences>Keys
verify that there is a Views category and that Resource Navigator is listed in 
it
- press the key binding Ctrl+Shift+6 and verify that the resource navigator is 
activated
- open Window>Show View and verify that the key binding shows up in the menu

Comment 5 Michael Van Meekeren CLA 2004-05-28 13:26:08 EDT
doug, please submit this in the next build
Comment 6 Douglas Pollock CLA 2004-05-28 15:32:43 EDT
This fix is not going into RC1.  It will wait for RC2. 
Comment 7 Michael Van Meekeren CLA 2004-05-28 16:54:52 EDT
this is not currently going into RC1, will mark for RC2
Comment 8 Erich Gamma CLA 2004-06-03 04:43:13 EDT
Most of the code of the patch is already in HEAD with the exception of the 
registration from the view handler. 

	public ViewDescriptor(IConfigurationElement e, String desc)
		throws CoreException {
		configElement = e;
		description = desc;
		loadFromExtension();
		//TODO:temporarily commented out, need to resolve test failure
		//registerShowViewHandler();
	}
Is this the failure ViewTests.testFindViewInRegistry()? When I ran the test it 
was a timing issue increasing the wait time made the test pass. However, I 
didn't track down why this results in a timing issue.
Comment 9 Christian Köstlin CLA 2004-06-06 05:56:06 EDT
The View shortcuts will be a real great feature. One question:
Is it possible for a plugin to create commands without contributing them?
Or have the commands a more static character?
Comment 10 Erich Gamma CLA 2004-06-06 08:09:50 EDT
Commands should be contributed otherwise you run into the typical lazy loading 
issues, i.e., the plug-in which adds the commands programmatically has to be 
loaded etc.

However, this should not be a serious issue since the intent is that the view 
contributors contribute a command, but only a few will define a short cut. 
Comment 11 Christian Köstlin CLA 2004-06-06 08:41:51 EDT
I was just wondering. The lazy loading is an argument.
But would it be theoretically possible to have some single plugin listening
to the plugin registry an registering commands for each view that is contributed?
Comment 12 Erich Gamma CLA 2004-06-06 10:54:37 EDT
possible in theory but programmatically registering commands isn't trivial 
(context management etc.) so I cannot recommend it.
Comment 13 Michael Van Meekeren CLA 2004-06-07 16:46:39 EDT
fixed in HEAD
Comment 14 Markus Keller CLA 2004-06-09 04:20:06 EDT
Just for the records:

Eclipse now uses multi-stroke keyboard shortcuts for opening views. The first
stroke is always "Alt+Shift+Q", and the second is a non-conflicting single
letter (e.g. O for Outline, P for Package Explorer, S for Search, X for
Problems, Y for Synchronize, T for Java Type Hierarchy).

I made a bunch of patches for all components which declare views. All these PRs
are titled "Polish patch: support view activation via a keyboard shortcut".
Comment 15 Debbie Wilson CLA 2004-06-11 14:17:57 EDT
Verified in I20040611 (0800).