Community
Participate
Working Groups
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
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".
Created attachment 10967 [details] patch to org.eclipse.ui - new view category
Created attachment 10968 [details] patch to org.eclipse.ui.workbench (ViewDescriptor, ShowViewHandler
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
doug, please submit this in the next build
This fix is not going into RC1. It will wait for RC2.
this is not currently going into RC1, will mark for RC2
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.
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?
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.
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?
possible in theory but programmatically registering commands isn't trivial (context management etc.) so I cannot recommend it.
fixed in HEAD
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".
Verified in I20040611 (0800).