diff options
author | Paul Webster | 2010-04-09 00:18:23 +0000 |
---|---|---|
committer | Paul Webster | 2010-04-09 00:18:23 +0000 |
commit | b6f52b3a0c701dd10e2bfe1c6a1330f931e62e13 (patch) | |
tree | cac47b239d8fed0e864cffef1f96733447af9b71 /bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui | |
parent | e8b4817fb98b0ee7a4e0a589637f5ee4a9a05859 (diff) | |
download | eclipse.platform.ui-b6f52b3a0c701dd10e2bfe1c6a1330f931e62e13.tar.gz eclipse.platform.ui-b6f52b3a0c701dd10e2bfe1c6a1330f931e62e13.tar.xz eclipse.platform.ui-b6f52b3a0c701dd10e2bfe1c6a1330f931e62e13.zip |
Bug 304920 - [Compatibility] activate some keybindingsv20100408-2100
Diffstat (limited to 'bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui')
4 files changed, 141 insertions, 466 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/KeyBindingService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/KeyBindingService.java index ff06d8aad82..67d49f8525e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/KeyBindingService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/KeyBindingService.java @@ -10,28 +10,20 @@ *******************************************************************************/ package org.eclipse.ui.internal; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; import java.util.Set; - +import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.core.commands.contexts.Context; +import org.eclipse.e4.ui.services.EContextService; import org.eclipse.jface.action.IAction; import org.eclipse.ui.IKeyBindingService; import org.eclipse.ui.INestableKeyBindingService; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ActionHandler; -import org.eclipse.ui.commands.HandlerSubmission; -import org.eclipse.ui.commands.IHandler; -import org.eclipse.ui.commands.Priority; -import org.eclipse.ui.contexts.EnabledSubmission; import org.eclipse.ui.internal.actions.CommandAction; +import org.eclipse.ui.internal.e4.compatibility.E4Util; import org.eclipse.ui.internal.handlers.CommandLegacyActionWrapper; /** @@ -43,13 +35,6 @@ import org.eclipse.ui.internal.handlers.CommandLegacyActionWrapper; * @since 2.0 */ public final class KeyBindingService implements INestableKeyBindingService { - - /** - * The currently active nested service, if any. If there are no nested - * services or none of them are active, then this value is <code>null</code>. - */ - private IKeyBindingService activeService = null; - /** * Whether this key binding service has been disposed. A disposed key * binding service should not be used again. @@ -61,49 +46,8 @@ public final class KeyBindingService implements INestableKeyBindingService { * counting any nested services). This set may be empty, but it is never * <code>null</code>. */ - private Set enabledContextIds = Collections.EMPTY_SET; + private Set<String> enabledContextIds = Collections.EMPTY_SET; - /** - * The list of context submissions indicating the enabled state of the - * context. This does not include those from nested services. This list may - * be empty, but it is never <code>null</code>. - */ - private List enabledSubmissions = new ArrayList(); - - /** - * The map of handler submissions, sorted by command identifiers. This does - * not include those from nested services. This map may be empty, but it is - * never <code>null</code>. - */ - private Map handlerSubmissionsByCommandId = new HashMap(); - - /** - * The context submissions from the currently active nested service. This - * value is <code>null</code> if there is no currently active nested - * service. - */ - private List nestedEnabledSubmissions = null; - - /** - * The handler submissions from the currently active nested service. This - * value is <code>null</code> if there is no currently active handler - * service. - */ - private List nestedHandlerSubmissions = null; - - /** - * The map of workbench part sites to nested key binding services. This map - * may be empty, but is never <code>null</code>. - */ - private final Map nestedServices = new HashMap(); - - /** - * The parent for this key binding service; <code>null</code> if there is - * no parent. If there is a parent, then this means that it should not do a - * "live" update of its contexts or handlers, but should make a call to the - * parent instead. - */ - private final KeyBindingService parent; /** * The site within the workbench at which this service is provided. This @@ -137,7 +81,7 @@ public final class KeyBindingService implements INestableKeyBindingService { KeyBindingService(IWorkbenchPartSite workbenchPartSite, KeyBindingService parent) { this.workbenchPartSite = workbenchPartSite; - this.parent = parent; + E4Util.unsupported("KeyBindingService: " + parent); //$NON-NLS-1$ } /* @@ -150,223 +94,20 @@ public final class KeyBindingService implements INestableKeyBindingService { return false; } - // Check if we should do a deactivation. - if (nestedSite == null) { - // We should do a deactivation, if there is one active. - if (activeService == null) { - // There is no active service. Do no work. - return false; - } - // Deactivate the currently active nested service. - deactivateNestedService(); - return true; - } - - // Attempt to activate a service. - final IKeyBindingService service = (IKeyBindingService) nestedServices - .get(nestedSite); - - if (service == activeService) { - // The service is already active, or already null - return false; - } - - deactivateNestedService(); - if (service!=null) { - activateNestedService(service); - } + E4Util.unsupported("activateKeyBindingService"); //$NON-NLS-1$ return true; } /** - * Activates the given service without worrying about the currently active - * service. This goes through the work of adding all of the nested context - * ids as enabled submissions. - * - * @param service - * The service to become active; if <code>null</code>, then - * the reference to the active service is set to - * <code>null</code> but nothing else happens. - */ - private final void activateNestedService(final IKeyBindingService service) { - if (disposed) { - return; - } - - /* - * If I have a parent, and I'm the active service, then deactivate so - * that I can make changes. - */ - boolean active = false; - boolean haveParent = (parent != null); - if (haveParent) { - active = (parent.activeService == this); - if (active) { - parent.deactivateNestedService(); - } - } - - // Update the active service. - activeService = service; - - // Check to see that the service isn't null. - if (service == null) { - return; - } - - if (haveParent) { - if (active) { - parent.activateNestedService(this); - } - - } else if (activeService instanceof KeyBindingService) { - // I have no parent, so I can make the changes myself. - final KeyBindingService nestedService = (KeyBindingService) activeService; - - // Update the contexts. - nestedEnabledSubmissions = nestedService.getEnabledSubmissions(); - normalizeSites(nestedEnabledSubmissions); - PlatformUI.getWorkbench().getContextSupport().addEnabledSubmissions( - nestedEnabledSubmissions); - - // Update the handlers. - nestedHandlerSubmissions = nestedService.getHandlerSubmissions(); - normalizeSites(nestedHandlerSubmissions); - PlatformUI.getWorkbench().getCommandSupport().addHandlerSubmissions( - nestedHandlerSubmissions); - } - } - - /** - * Deactives the currently active service. This nulls out the reference, and - * removes all the enabled submissions for the nested service. - */ - private final void deactivateNestedService() { - if (disposed) { - return; - } - - // Don't do anything if there is no active service. - if (activeService == null) { - return; - } - - // Check to see if there is a parent. - boolean active = false; - if (parent != null) { - // Check if I'm the active service. - if (parent.activeService == this) { - active = true; - // Deactivate myself so I can make changes. - parent.deactivateNestedService(); - } - - } else if (activeService instanceof KeyBindingService) { - // Remove all the nested context ids. - PlatformUI.getWorkbench().getContextSupport() - .removeEnabledSubmissions(nestedEnabledSubmissions); - - /* - * Remove all of the nested handler submissions. The handlers here - * weren't created by this instance (but by the nest instance), and - * hence can't be disposed here. - */ - PlatformUI.getWorkbench().getCommandSupport() - .removeHandlerSubmissions(nestedHandlerSubmissions); - - } - - // Clear our reference to the active service. - activeService = null; - - // If necessary, let my parent know that changes have occurred. - if (active) { - parent.activateNestedService(this); - } - } - - /** * Disposes this key binding service. This clears out all of the submissions * held by this service, and its nested services. */ public void dispose() { if (!disposed) { - deactivateNestedService(); disposed = true; - - PlatformUI.getWorkbench() - .getContextSupport() - .removeEnabledSubmissions(new ArrayList(enabledSubmissions)); - enabledSubmissions.clear(); - - /* - * Each removed handler submission, must dispose its corresponding - * handler -- as these handlers only exist inside of this class. - */ - final List submissions = new ArrayList( - handlerSubmissionsByCommandId.values()); - final Iterator submissionItr = submissions.iterator(); - while (submissionItr.hasNext()) { - ((HandlerSubmission) submissionItr.next()).getHandler() - .dispose(); - } - PlatformUI.getWorkbench().getCommandSupport() - .removeHandlerSubmissions(submissions); - handlerSubmissionsByCommandId.clear(); - - for (Iterator iterator = nestedServices.values().iterator(); iterator - .hasNext();) { - KeyBindingService keyBindingService = (KeyBindingService) iterator - .next(); - keyBindingService.dispose(); - } - - nestedEnabledSubmissions = null; - nestedHandlerSubmissions = null; - nestedServices.clear(); } } - /** - * Gets a copy of all the enabled submissions in the nesting chain. - * - * @return All of the nested enabled submissions -- including the ones from - * this service. This list may be empty, but is never - * <code>null</code>. - */ - private final List getEnabledSubmissions() { - if (disposed) { - return null; - } - - final List submissions = new ArrayList(enabledSubmissions); - if (activeService instanceof KeyBindingService) { - final KeyBindingService nestedService = (KeyBindingService) activeService; - submissions.addAll(nestedService.getEnabledSubmissions()); - } - return submissions; - } - - /** - * Gets a copy of all the handler submissions in the nesting chain. - * - * @return All of the nested handler submissions -- including the ones from - * this service. This list may be empty, but is never - * <code>null</code>. - */ - private final List getHandlerSubmissions() { - if (disposed) { - return null; - } - - final List submissions = new ArrayList(handlerSubmissionsByCommandId - .values()); - if (activeService instanceof KeyBindingService) { - final KeyBindingService nestedService = (KeyBindingService) activeService; - submissions.addAll(nestedService.getHandlerSubmissions()); - } - return submissions; - } /* * (non-Javadoc) @@ -382,22 +123,9 @@ public final class KeyBindingService implements INestableKeyBindingService { return null; } - IKeyBindingService service = (IKeyBindingService) nestedServices - .get(nestedSite); - if (service == null) { - // TODO the INestedKeyBindingService API should be based on - // IWorkbenchPartSite.. - if (nestedSite instanceof IWorkbenchPartSite) { - service = new KeyBindingService( - (IWorkbenchPartSite) nestedSite, this); - } else { - service = new KeyBindingService(null, this); - } - - nestedServices.put(nestedSite, service); - } + E4Util.unsupported("getKeyBindingService"); //$NON-NLS-1$ - return service; + return null; } public String[] getScopes() { @@ -405,80 +133,13 @@ public final class KeyBindingService implements INestableKeyBindingService { return null; } - // Get the nested scopes, if any. - final String[] nestedScopes; - if (activeService == null) { - nestedScopes = null; - } else { - nestedScopes = activeService.getScopes(); - } - // Build the list of active scopes final Set activeScopes = new HashSet(); activeScopes.addAll(enabledContextIds); - if (nestedScopes != null) { - for (int i = 0; i < nestedScopes.length; i++) { - activeScopes.add(nestedScopes[i]); - } - } return (String[]) activeScopes.toArray(new String[activeScopes.size()]); } - /** - * Replaces the active workbench site with this service's active workbench - * site. This ensures that the context manager will recognize the context as - * active. Note: this method modifies the list in place; it is - * <em>destructive</em>. - * - * @param submissionsToModify - * The submissions list to modify; must not be <code>null</code>, - * but may be empty. - */ - private final void normalizeSites(final List submissionsToModify) { - if (disposed) { - return; - } - - final int size = submissionsToModify.size(); - for (int i = 0; i < size; i++) { - final Object submission = submissionsToModify.get(i); - final Object replacementSubmission; - - if (submission instanceof EnabledSubmission) { - final EnabledSubmission enabledSubmission = (EnabledSubmission) submission; - if (!workbenchPartSite.equals(enabledSubmission - .getActiveWorkbenchPartSite())) { - replacementSubmission = new EnabledSubmission(null, - enabledSubmission.getActiveShell(), - workbenchPartSite, enabledSubmission.getContextId()); - } else { - replacementSubmission = enabledSubmission; - } - - } else if (submission instanceof HandlerSubmission) { - final HandlerSubmission handlerSubmission = (HandlerSubmission) submission; - if (!workbenchPartSite.equals(handlerSubmission - .getActiveWorkbenchPartSite())) { - replacementSubmission = new HandlerSubmission(null, - handlerSubmission.getActiveShell(), - workbenchPartSite, - handlerSubmission.getCommandId(), handlerSubmission - .getHandler(), handlerSubmission - .getPriority()); - } else { - replacementSubmission = handlerSubmission; - } - - } else { - replacementSubmission = submission; - } - - submissionsToModify.set(i, replacementSubmission); - } - - } - public void registerAction(IAction action) { if (disposed) { return; @@ -499,35 +160,6 @@ public final class KeyBindingService implements INestableKeyBindingService { } unregisterAction(action); - String commandId = action.getActionDefinitionId(); - if (commandId != null) { - /* - * If I have a parent and I'm active, de-activate myself while - * making changes. - */ - boolean active = false; - if ((parent != null) && (parent.activeService == this)) { - active = true; - parent.deactivateNestedService(); - } - - // Create the new submission - IHandler handler = new ActionHandler(action); - HandlerSubmission handlerSubmission = new HandlerSubmission(null, - workbenchPartSite.getShell(), workbenchPartSite, commandId, - handler, Priority.MEDIUM); - handlerSubmissionsByCommandId.put(commandId, handlerSubmission); - - // Either submit the new handler myself, or simply re-activate. - if (parent != null) { - if (active) { - parent.activateNestedService(this); - } - } else { - PlatformUI.getWorkbench().getCommandSupport() - .addHandlerSubmission(handlerSubmission); - } - } } /* @@ -540,16 +172,6 @@ public final class KeyBindingService implements INestableKeyBindingService { return false; } - final IKeyBindingService service = (IKeyBindingService) nestedServices - .remove(nestedSite); - if (service == null) { - return false; - } - - if (service.equals(activeService)) { - deactivateNestedService(); - } - return true; } @@ -557,39 +179,45 @@ public final class KeyBindingService implements INestableKeyBindingService { if (disposed) { return; } - - // Either deactivate myself, or remove the previous submissions myself. - boolean active = false; - if ((parent != null) && (parent.activeService == this)) { - active = true; - parent.deactivateNestedService(); - } else { - PlatformUI.getWorkbench().getContextSupport() - .removeEnabledSubmissions(enabledSubmissions); - } - enabledSubmissions.clear(); - - // Determine the new list of submissions. - enabledContextIds = new HashSet(Arrays.asList(scopes)); - for (Iterator iterator = enabledContextIds.iterator(); iterator - .hasNext();) { - String contextId = (String) iterator.next(); - enabledSubmissions.add(new EnabledSubmission(null, null, - workbenchPartSite, contextId)); - } - - // Submit the new contexts myself, or simply re-active myself. - if (parent != null) { - if (active) { - parent.activateNestedService(this); - } - } else { - PlatformUI.getWorkbench().getContextSupport().addEnabledSubmissions( - enabledSubmissions); + Set<String> oldContextIds = enabledContextIds; + enabledContextIds = new HashSet<String>(Arrays.asList(scopes)); + EContextService cs = (EContextService) workbenchPartSite.getService(EContextService.class); + addParents(cs, scopes); + + for (String id : oldContextIds) { + if (!enabledContextIds.contains(id)) { + cs.deactivateContext(id); + } } + for (String id : enabledContextIds) { + if (!oldContextIds.contains(id)) { + cs.activateContext(id); + } + } } - public void unregisterAction(IAction action) { + /** + * @param cs + * @param scopes + */ + private void addParents(EContextService cs, String[] scopes) { + for (String id : scopes) { + try { + Context current = cs.getContext(id); + String parentId = current.getParentId(); + while (parentId != null && !enabledContextIds.contains(parentId)) { + enabledContextIds.add(parentId); + current = cs.getContext(parentId); + parentId = current.getParentId(); + } + } catch (NotDefinedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public void unregisterAction(IAction action) { if (disposed) { return; } @@ -602,35 +230,5 @@ public final class KeyBindingService implements INestableKeyBindingService { return; } - String commandId = action.getActionDefinitionId(); - - if (commandId != null) { - // Deactivate this service while making changes. - boolean active = false; - if ((parent != null) && (parent.activeService == this)) { - active = true; - parent.deactivateNestedService(); - } - - // Remove the current submission, if any. - HandlerSubmission handlerSubmission = (HandlerSubmission) handlerSubmissionsByCommandId - .remove(commandId); - - /* - * Either activate this service again, or remove the submission - * myself. - */ - if (parent != null) { - if (active) { - parent.activateNestedService(this); - } - } else { - if (handlerSubmission != null) { - PlatformUI.getWorkbench().getCommandSupport() - .removeHandlerSubmission(handlerSubmission); - handlerSubmission.getHandler().dispose(); - } - } - } } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java index 91dbdd6670a..86e10041139 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java @@ -25,10 +25,11 @@ import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.Category; import org.eclipse.core.commands.Command; @@ -37,7 +38,10 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.common.EventManager; import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.core.commands.contexts.Context; import org.eclipse.core.commands.contexts.ContextManager; +import org.eclipse.core.commands.contexts.ContextManagerEvent; +import org.eclipse.core.commands.contexts.IContextManagerListener; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -67,6 +71,7 @@ import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationFactory; +import org.eclipse.e4.ui.model.application.MBindingTable; import org.eclipse.e4.ui.model.application.MCommand; import org.eclipse.e4.ui.model.application.MElementContainer; import org.eclipse.e4.ui.model.application.MPart; @@ -77,14 +82,15 @@ import org.eclipse.e4.ui.workbench.swt.internal.E4Application; import org.eclipse.e4.workbench.ui.UIEvents; import org.eclipse.e4.workbench.ui.internal.E4CommandProcessor; import org.eclipse.e4.workbench.ui.internal.E4Workbench; +import org.eclipse.emf.common.util.EList; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ExternalActionManager; -import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.ExternalActionManager.CommandCallback; import org.eclipse.jface.action.ExternalActionManager.IActiveChecker; import org.eclipse.jface.action.ExternalActionManager.IExecuteApplicable; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.bindings.BindingManager; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.dialogs.ErrorDialog; @@ -1702,6 +1708,30 @@ public final class Workbench extends EventManager implements IWorkbench { return service; } + private void defineBindingTable(String id) { + EList<MBindingTable> bindingTables = application.getBindingTables(); + if (contains(bindingTables, id)) { + return; + } + MBindingTable bt = MApplicationFactory.eINSTANCE.createBindingTable(); + bt.setBindingContextId(id); + bindingTables.add(bt); + } + + /** + * @param bindingTables + * @param id + * @return true if this BT already exists + */ + private boolean contains(EList<MBindingTable> bindingTables, String id) { + for (MBindingTable bt : bindingTables) { + if (id.equals(bt.getBindingContextId())) { + return true; + } + } + return false; + } + /** * Initializes all of the default services for the workbench. For * initializing the command-based services, this also parses the registry @@ -1756,12 +1786,51 @@ public final class Workbench extends EventManager implements IWorkbench { } }); - final IContextService contextService = new ContextService(contextManager); + IContextService cxs = null; + try { + cxs = (IContextService) ContextInjectionFactory.make(ContextService.class, e4Context); + } catch (InvocationTargetException e1) { + e1.printStackTrace(); + } catch (InstantiationException e1) { + e1.printStackTrace(); + } + final IContextService contextService = cxs; StartupThreading.runWithoutExceptions(new StartupRunnable() { public void runWithException() { + HashMap<String, String> contextToParent = new HashMap<String, String>(); + Iterator i = contextManager.getDefinedContextIds().iterator(); + while (i.hasNext()) { + Context c = contextManager.getContext((String) i.next()); + if (c.isDefined()) { + try { + contextToParent.put(c.getId(), c.getParentId()); + } catch (NotDefinedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + contextManager.addContextManagerListener(new IContextManagerListener() { + public void contextManagerChanged(ContextManagerEvent contextManagerEvent) { + if (contextManagerEvent.isContextChanged()) { + String id = contextManagerEvent.getContextId(); + if (id != null) { + defineBindingTable(id); + } + } + } + }); contextService.readRegistry(); + Iterator<Entry<String, String>> e = contextToParent.entrySet().iterator(); + while (e.hasNext()) { + Entry<String, String> entry = e.next(); + Context c = contextManager.getContext(entry.getKey()); + if (!c.isDefined()) { + c.define(entry.getKey(), null, entry.getValue()); + } + } EContextService ecs = (EContextService) e4Context.get(EContextService.class .getName()); ecs.activateContext(IContextService.CONTEXT_ID_DIALOG_AND_WINDOW); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java index e2ae068093f..4f4019d3a29 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java @@ -12,11 +12,12 @@ package org.eclipse.ui.internal.contexts; import java.util.Collection; import java.util.Iterator; - +import javax.inject.Inject; import org.eclipse.core.commands.contexts.Context; import org.eclipse.core.commands.contexts.ContextManager; import org.eclipse.core.commands.contexts.IContextManagerListener; import org.eclipse.core.expressions.Expression; +import org.eclipse.e4.ui.services.EContextService; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ISourceProvider; import org.eclipse.ui.ISources; @@ -42,7 +43,10 @@ public final class ContextService implements IContextService { * The context manager that supports this service. This value is never * <code>null</code>. */ - private final ContextManager contextManager; + private ContextManager contextManager; + + @Inject + private EContextService contextService; /** * The persistence class for this context service. @@ -56,6 +60,7 @@ public final class ContextService implements IContextService { * @param contextManager * The context manager to use; must not be <code>null</code>. */ + @Inject public ContextService(final ContextManager contextManager) { if (contextManager == null) { throw new NullPointerException( @@ -94,6 +99,7 @@ public final class ContextService implements IContextService { final IContextActivation activation = new ContextActivation(contextId, expression, this); contextAuthority.activateContext(activation); + contextService.activateContext(contextId); return activation; } @@ -145,6 +151,7 @@ public final class ContextService implements IContextService { */ public final void deactivateContext(final IContextActivation activation) { if (activation.getContextService() == this) { + contextService.deactivateContext(activation.getContextId()); contextAuthority.deactivateContext(activation); } } @@ -179,7 +186,7 @@ public final class ContextService implements IContextService { * @see org.eclipse.ui.contexts.IContextService#getActiveContextIds() */ public final Collection getActiveContextIds() { - return contextManager.getActiveContextIds(); + return contextService.getActiveContextIds(); } /* @@ -188,7 +195,7 @@ public final class ContextService implements IContextService { * @see org.eclipse.ui.contexts.IContextService#getContext(java.lang.String) */ public final Context getContext(final String contextId) { - return contextManager.getContext(contextId); + return contextService.getContext(contextId); } /* diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java index 411696407ce..c1b9476fbe4 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java @@ -10,16 +10,16 @@ *******************************************************************************/ package org.eclipse.ui.internal.keys; -import org.eclipse.e4.core.di.annotations.Optional; - import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import javax.inject.Inject; import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.e4.core.commands.ECommandService; +import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.bindings.EBindingService; import org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher; import org.eclipse.jface.bindings.Binding; @@ -76,8 +76,7 @@ public final class BindingService implements IBindingService { * .jface.bindings.IBindingManagerListener) */ public void addBindingManagerListener(IBindingManagerListener listener) { - // TODO compat addBindingManagerListener - E4Util.unsupported("addBindingManagerListener"); //$NON-NLS-1$ + manager.addBindingManagerListener(listener); } /* @@ -88,8 +87,7 @@ public final class BindingService implements IBindingService { * eclipse.jface.bindings.IBindingManagerListener) */ public void removeBindingManagerListener(IBindingManagerListener listener) { - // TODO compat removeBindingManagerListener - E4Util.unsupported("removeBindingManagerListener"); //$NON-NLS-1$ + manager.removeBindingManagerListener(listener); } /* @@ -132,9 +130,8 @@ public final class BindingService implements IBindingService { * .core.commands.ParameterizedCommand) */ public TriggerSequence getBestActiveBindingFor(ParameterizedCommand command) { - // TODO compat getBestActiveBindingFor - E4Util.unsupported("getBestActiveBindingFor"); //$NON-NLS-1$ - return null; + TriggerSequence seq = bindingService.getBestSequenceFor(command); + return seq; } /* @@ -145,9 +142,8 @@ public final class BindingService implements IBindingService { * .String) */ public TriggerSequence getBestActiveBindingFor(String commandId) { - // TODO compat getBestActiveBindingFor - E4Util.unsupported("getBestActiveBindingFor"); //$NON-NLS-1$ - return null; + ParameterizedCommand cmd = commandService.createCommand(commandId, null); + return bindingService.getBestSequenceFor(cmd); } /* @@ -323,6 +319,11 @@ public final class BindingService implements IBindingService { public void readRegistryAndPreferences(ICommandService commandService) { BindingPersistence reader = new BindingPersistence(manager, commandService); reader.reRead(); + Iterator i = manager.getActiveBindingsDisregardingContextFlat().iterator(); + while (i.hasNext()) { + Binding b = (Binding) i.next(); + bindingService.activateBinding(b); + } } /* |