Search in sources :

Example 1 with Context

use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.

the class ContextProcessingAddon method defineContexts.

private void defineContexts(MBindingContext parent, MBindingContext current) {
    if (current.getName() == null || current.getElementId() == null) {
        // $NON-NLS-1$
        logger.error("Binding context name or id is null for: " + current);
        return;
    }
    Context context = contextManager.getContext(current.getElementId());
    if (!context.isDefined()) {
        String localizedName = LocalizationHelper.getLocalized(current.getName(), current, application.getContext());
        String localizedDescriptor = LocalizationHelper.getLocalized(current.getDescription(), current, application.getContext());
        context.define(localizedName, localizedDescriptor, parent == null ? null : parent.getElementId());
    }
    for (MBindingContext child : current.getChildren()) {
        defineContexts(current, child);
    }
}
Also used : Context(org.eclipse.core.commands.contexts.Context) MBindingContext(org.eclipse.e4.ui.model.application.commands.MBindingContext) MBindingContext(org.eclipse.e4.ui.model.application.commands.MBindingContext)

Example 2 with Context

use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.

the class ContextProcessingAddon method undefineContext.

private void undefineContext(MBindingContext current) {
    Context context = contextManager.getContext(current.getElementId());
    context.undefine();
}
Also used : Context(org.eclipse.core.commands.contexts.Context) MBindingContext(org.eclipse.e4.ui.model.application.commands.MBindingContext)

Example 3 with Context

use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.

the class ContextPersistence method readContextsFromRegistry.

/**
 * Reads all of the command definitions from the commands extension point.
 *
 * @param configurationElements     The configuration elements in the commands
 *                                  extension point; must not be
 *                                  <code>null</code>, but may be empty.
 * @param configurationElementCount The number of configuration elements that
 *                                  are really in the array.
 * @param contextManager            The context manager to which the commands
 *                                  should be added; must not be
 *                                  <code>null</code>.
 */
private static void readContextsFromRegistry(final IConfigurationElement[] configurationElements, final int configurationElementCount, final ContextManager contextManager) {
    final List<IStatus> warningsToLog = new ArrayList<>(1);
    for (int i = 0; i < configurationElementCount; i++) {
        final IConfigurationElement configurationElement = configurationElements[i];
        // Read out the command identifier.
        // $NON-NLS-1$
        final String contextId = readRequired(configurationElement, ATT_ID, warningsToLog, "Contexts need an id");
        if (contextId == null) {
            continue;
        }
        // Read out the name.
        final String name = readRequired(// $NON-NLS-1$
        configurationElement, // $NON-NLS-1$
        ATT_NAME, // $NON-NLS-1$
        warningsToLog, // $NON-NLS-1$
        "Contexts need a name", contextId);
        if (name == null) {
            continue;
        }
        // Read out the description.
        final String description = readOptional(configurationElement, ATT_DESCRIPTION);
        // Read out the parent id.
        String parentId = configurationElement.getAttribute(ATT_PARENT_ID);
        if ((parentId == null) || (parentId.isEmpty())) {
            parentId = configurationElement.getAttribute(ATT_PARENT);
            if ((parentId == null) || (parentId.isEmpty())) {
                parentId = configurationElement.getAttribute(ATT_PARENT_SCOPE);
            }
        }
        if ((parentId != null) && (parentId.isEmpty())) {
            parentId = null;
        }
        final Context context = contextManager.getContext(contextId);
        if (!context.isDefined()) {
            context.define(name, description, parentId);
        }
    }
    logWarnings(warningsToLog, // $NON-NLS-1$
    "Warnings while parsing the contexts from the 'org.eclipse.ui.contexts', 'org.eclipse.ui.commands' and 'org.eclipse.ui.acceleratorScopes' extension points.");
}
Also used : Context(org.eclipse.core.commands.contexts.Context) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 4 with Context

use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.

the class BindingTableTests method testContextSetSibling.

@Test
public void testContextSetSibling() {
    BindingTableManager manager = ContextInjectionFactory.make(BindingTableManager.class, workbenchContext);
    ArrayList<Context> all = new ArrayList<>();
    for (int i = 0; i < CONTEXTS.length; i += 3) {
        Context context = contextManager.getContext(CONTEXTS[i]);
        all.add(context);
    }
    ContextSet set = manager.createContextSet(all);
    assertContextSet(set, ORDERED_IDS);
}
Also used : BindingTableManager(org.eclipse.e4.ui.bindings.internal.BindingTableManager) Context(org.eclipse.core.commands.contexts.Context) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ContextSet(org.eclipse.e4.ui.bindings.internal.ContextSet) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Context

use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.

the class BindingTableTests method testContextSet.

@Test
public void testContextSet() {
    BindingTableManager manager = ContextInjectionFactory.make(BindingTableManager.class, workbenchContext);
    ArrayList<Context> window = new ArrayList<>();
    Context winContext = contextManager.getContext(ID_WINDOW);
    Context dawContext = contextManager.getContext(ID_DIALOG_AND_WINDOW);
    window.add(winContext);
    window.add(dawContext);
    ContextSet windowSet = manager.createContextSet(window);
    assertContextSet(windowSet, new String[] { ID_DIALOG_AND_WINDOW, ID_WINDOW });
    ArrayList<Context> text = new ArrayList<>(window);
    Context textContext = contextManager.getContext(ID_TEXT);
    text.add(textContext);
    ContextSet textSet = manager.createContextSet(text);
    assertContextSet(textSet, new String[] { ID_DIALOG_AND_WINDOW, ID_WINDOW, ID_TEXT });
}
Also used : BindingTableManager(org.eclipse.e4.ui.bindings.internal.BindingTableManager) Context(org.eclipse.core.commands.contexts.Context) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ContextSet(org.eclipse.e4.ui.bindings.internal.ContextSet) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Context (org.eclipse.core.commands.contexts.Context)69 Binding (org.eclipse.jface.bindings.Binding)41 Test (org.junit.Test)36 HashSet (java.util.HashSet)32 Scheme (org.eclipse.jface.bindings.Scheme)31 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)21 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)21 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)13 ArrayList (java.util.ArrayList)12 Command (org.eclipse.core.commands.Command)12 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)10 ContextSet (org.eclipse.e4.ui.bindings.internal.ContextSet)7 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)7 BindingTableManager (org.eclipse.e4.ui.bindings.internal.BindingTableManager)6 MBindingContext (org.eclipse.e4.ui.model.application.commands.MBindingContext)6 KeySequence (org.eclipse.jface.bindings.keys.KeySequence)6 HashMap (java.util.HashMap)4 Category (org.eclipse.core.commands.Category)4 BindingTable (org.eclipse.e4.ui.bindings.internal.BindingTable)4 IContextService (org.eclipse.ui.contexts.IContextService)4