Search in sources :

Example 6 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project hale by halestudio.

the class SourceViewerUndoSupport method install.

/**
 * Adds undo support to the given source viewer. Should only be called if
 * for this viewer the undo/redo support is not provided through the
 * workbench.
 *
 * @param viewer the source viewer
 */
public static void install(final SourceViewer viewer) {
    IBindingService bs = PlatformUI.getWorkbench().getService(IBindingService.class);
    TriggerSequence undo = null;
    TriggerSequence redo = null;
    if (bs != null) {
        undo = bs.getBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_UNDO);
        redo = bs.getBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_REDO);
    /*
			 * Note: Curiously this need not be the same as what is displayed in
			 * the main menu. When testing on Linux, CTRL+SHIT+Z was the binding
			 * in the main menu, but here CTRL+Y was returned.
			 */
    }
    try {
        // fall-back bindings
        if (undo == null) {
            undo = KeySequence.getInstance("M1+Z");
        }
        if (redo == null) {
            redo = KeySequence.getInstance("M1+Y");
        }
        final TriggerSequence undoSeq = undo;
        final TriggerSequence redoSeq = redo;
        viewer.getTextWidget().addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
                KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
                if (sequence.equals(undoSeq)) {
                    IUndoManager um = viewer.getUndoManager();
                    if (um.undoable()) {
                        um.undo();
                    }
                } else if (sequence.equals(redoSeq)) {
                    IUndoManager um = viewer.getUndoManager();
                    if (um.redoable()) {
                        um.redo();
                    }
                }
            }
        });
    } catch (ParseException e) {
        log.error("Could not created key sequences for source viewer undo/redo support", e);
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) IUndoManager(org.eclipse.jface.text.IUndoManager) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ParseException(org.eclipse.jface.bindings.keys.ParseException) IBindingService(org.eclipse.ui.keys.IBindingService) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 7 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project hale by halestudio.

the class GroovyScriptPage method addActions.

@Override
protected void addActions(ToolBar toolbar, final CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    try {
        final TriggerSequence astTrigger = KeySequence.getInstance("F8");
        viewer.appendVerifyKeyListener(new VerifyKeyListener() {

            @Override
            public void verifyKey(VerifyEvent event) {
                int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event);
                KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
                if (astTrigger.equals(sequence)) {
                    GroovyASTTray.showTray(GroovyScriptPage.this, viewer);
                    event.doit = false;
                }
            }
        });
    } catch (Exception e) {
        log.error("Error installing AST view listener", e);
    }
}
Also used : TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) BadLocationException(org.eclipse.jface.text.BadLocationException) MultipleCompilationErrorsException(org.codehaus.groovy.control.MultipleCompilationErrorsException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 8 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project archi by archimatetool.

the class FullScreenAction method addKeyBinding.

/**
 * Add a Key binding mapped to an Action
 */
private void addKeyBinding(ActionRegistry registry, IBindingService service, ActionFactory actionFactory) {
    KeySequence seq = (KeySequence) service.getBestActiveBindingFor(actionFactory.getCommandId());
    if (seq != null && seq.getKeyStrokes().length > 0) {
        KeyStroke ks = seq.getKeyStrokes()[0];
        keyBindings.add(new KeyBinding(ks.getModifierKeys(), Character.toLowerCase(ks.getNaturalKey()), registry.getAction(actionFactory.getId())));
    }
}
Also used : KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 9 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project translationstudio8 by heartsome.

the class KeysPreferencePage method createTree.

private void createTree(Composite parent) {
    fPatternFilter = new CategoryPatternFilter(true, fDefaultCategory);
    fPatternFilter.filterCategories(true);
    GridData gridData;
    fFilteredTree = new CategoryFilterTree(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION, fPatternFilter);
    final GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    fFilteredTree.setLayout(layout);
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.verticalAlignment = SWT.FILL;
    fFilteredTree.setLayoutData(gridData);
    viewer = fFilteredTree.getViewer();
    // Make sure the filtered tree has a height of ITEMS_TO_SHOW
    final Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    final Object layoutData = tree.getLayoutData();
    if (layoutData instanceof GridData) {
        gridData = (GridData) layoutData;
        final int itemHeight = tree.getItemHeight();
        if (itemHeight > 1) {
            gridData.heightHint = ITEMS_TO_SHOW * itemHeight;
        }
    }
    BindingModelComparator comparator = new BindingModelComparator();
    comparator.setSortColumn(2);
    viewer.setComparator(comparator);
    final TreeColumn commandNameColumn = new TreeColumn(tree, SWT.LEFT, COMMAND_NAME_COLUMN);
    commandNameColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.commandNameColumn"));
    tree.setSortColumn(commandNameColumn);
    tree.setSortDirection(comparator.isAscending() ? SWT.UP : SWT.DOWN);
    commandNameColumn.addSelectionListener(new ResortColumn(comparator, commandNameColumn, viewer, COMMAND_NAME_COLUMN));
    final TreeViewerColumn triggerSequenceColumn = new TreeViewerColumn(viewer, SWT.LEFT, KEY_SEQUENCE_COLUMN);
    triggerSequenceColumn.getColumn().setText(Messages.getString("preferencepage.KeysPreferencePage.triggerSequenceColumn"));
    triggerSequenceColumn.getColumn().addSelectionListener(new ResortColumn(comparator, triggerSequenceColumn.getColumn(), viewer, KEY_SEQUENCE_COLUMN));
    triggerSequenceColumn.setEditingSupport(new TableViewerEditingSupport(viewer, 1));
    final TreeColumn categoryColumn = new TreeColumn(tree, SWT.LEFT, CATEGORY_COLUMN);
    categoryColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.categoryColumn"));
    categoryColumn.addSelectionListener(new ResortColumn(comparator, categoryColumn, viewer, CATEGORY_COLUMN));
    viewer.setContentProvider(new ModelContentProvider());
    viewer.setLabelProvider(new BindingElementLabelProvider());
    fFilteredTree.getPatternFilter().setIncludeLeadingWildcard(true);
    final TreeColumn[] columns = viewer.getTree().getColumns();
    columns[COMMAND_NAME_COLUMN].setWidth(240);
    columns[KEY_SEQUENCE_COLUMN].setWidth(130);
    columns[CATEGORY_COLUMN].setWidth(130);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        // When the viewer changes selection, update the model's current
        // selection
        public void selectionChanged(SelectionChangedEvent event) {
            changeBackground();
            ModelElement binding = (ModelElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
            model.setSelectedElement(binding);
        }
    });
    IPropertyChangeListener treeUpdateListener = new IPropertyChangeListener() {

        // When the model changes a property, update the viewer
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                Object newVal = event.getNewValue();
                StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(newVal);
                viewer.setSelection(structuredSelection, true);
            } else if (event.getSource() instanceof BindingElement && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
                viewer.update(event.getSource(), null);
            } else if (BindingElement.PROP_CONFLICT.equals(event.getProperty())) {
                viewer.update(event.getSource(), null);
            } else if (BindingModel.PROP_BINDINGS.equals(event.getProperty())) {
            // viewer.refresh();
            } else if (BindingModel.PROP_BINDING_ADD.equals(event.getProperty())) {
                viewer.add(model, event.getNewValue());
            } else if (BindingModel.PROP_BINDING_REMOVE.equals(event.getProperty())) {
                viewer.remove(event.getNewValue());
            } else if (BindingModel.PROP_BINDING_FILTER.equals(event.getProperty())) {
            // viewer.refresh();
            }
            changeBackground();
        // isValid();
        }
    };
    keyController.addPropertyChangeListener(treeUpdateListener);
    // IPropertyChangeListener conflictsListener = new IPropertyChangeListener() {
    // public void propertyChange(PropertyChangeEvent event) {
    // // System.out.println(event.getNewValue().getClass());
    // if (keyController.getConflictModel().getConflicts() != null) {
    // if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
    // // lstConflict.clear();
    // if (event.getNewValue() != null) {
    // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
    // }
    // // conflictViewer.setInput(event.getNewValue());
    // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
    // if (event.getNewValue() != null) {
    // lstConflict.add(event.getNewValue());
    // }
    // // conflictViewer.add(event.getNewValue());
    // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
    // // conflictViewer.remove(event.getNewValue());
    // if (event.getNewValue() != null) {
    // lstConflict.remove(event.getNewValue());
    // }
    // }
    // } else {
    // lstConflict.clear();
    // }
    // // if (event.getSource() == keyController.getConflictModel()
    // // && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
    // // if (keyController.getConflictModel().getConflicts() != null) {
    // // Object newVal = event.getNewValue();
    // // StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(
    // // newVal);
    // // // conflictViewer.setSelection(structuredSelection, true);
    // // }
    // // } else if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
    // // // lstConflict.clear();
    // // if (event.getNewValue() != null) {
    // // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
    // // }
    // // // conflictViewer.setInput(event.getNewValue());
    // // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
    // // if (event.getNewValue() != null) {
    // // lstConflict.clear();
    // // lstConflict.add(event.getNewValue());
    // // }
    // // // conflictViewer.add(event.getNewValue());
    // // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
    // // // conflictViewer.remove(event.getNewValue());
    // // if (event.getNewValue() != null) {
    // // lstConflict.clear();
    // // lstConflict.remove(event.getNewValue());
    // // }
    // // }
    // }
    // };
    // keyController.addPropertyChangeListener(conflictsListener);
    IPropertyChangeListener dataUpdateListener = new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            BindingElement bindingElement = null;
            boolean weCare = false;
            if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                bindingElement = (BindingElement) event.getNewValue();
                weCare = true;
            } else if (event.getSource() == model.getSelectedElement() && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
                bindingElement = (BindingElement) event.getSource();
                weCare = true;
            }
            if (bindingElement == null && weCare) {
                //$NON-NLS-1$
                fBindingText.setText("");
            } else if (bindingElement != null) {
                KeySequence trigger = (KeySequence) bindingElement.getTrigger();
                fKeySequenceText.setKeySequence(trigger);
            }
        }
    };
    keyController.addPropertyChangeListener(dataUpdateListener);
}
Also used : BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModelElement(org.eclipse.ui.internal.keys.model.ModelElement) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) GridData(org.eclipse.swt.layout.GridData) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 10 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project translationstudio8 by heartsome.

the class BindingModel2 method remove.

/**
	 * Removes the <code>bindingElement</code> binding.
	 * @param bindingElement
	 */
public void remove(BindingElement bindingElement) {
    if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) {
        return;
    }
    KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject();
    if (keyBinding.getType() == Binding.USER) {
        bindingManager.removeBinding(keyBinding);
    } else {
        KeySequence keySequence = keyBinding.getKeySequence();
        // Add the delete binding
        bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
        // Unbind any conflicts affected by the delete binding
        ConflictModel conflictModel = controller.getConflictModel();
        conflictModel.updateConflictsFor(bindingElement);
        Collection conflictsList = conflictModel.getConflicts();
        if (conflictsList != null) {
            Object[] conflicts = conflictsList.toArray();
            for (int i = 0; i < conflicts.length; i++) {
                BindingElement be = (BindingElement) conflicts[i];
                if (be == bindingElement) {
                    continue;
                }
                Object modelObject = be.getModelObject();
                if (modelObject instanceof Binding) {
                    Binding binding = (Binding) modelObject;
                    if (binding.getType() != Binding.SYSTEM) {
                        continue;
                    }
                    ParameterizedCommand pCommand = binding.getParameterizedCommand();
                    be.fill(pCommand);
                    commandToElement.put(pCommand, be);
                }
            }
        }
    }
    ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand();
    bindingElement.fill(parameterizedCommand);
    commandToElement.put(parameterizedCommand, bindingElement);
    controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) ConflictModel(org.eclipse.ui.internal.keys.model.ConflictModel) Collection(java.util.Collection) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Aggregations

KeySequence (org.eclipse.jface.bindings.keys.KeySequence)14 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)7 IBindingService (org.eclipse.ui.keys.IBindingService)5 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)3 ParseException (org.eclipse.jface.bindings.keys.ParseException)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2 VerifyEvent (org.eclipse.swt.events.VerifyEvent)2 Point (org.eclipse.swt.graphics.Point)2 BindingElement (org.eclipse.ui.internal.keys.model.BindingElement)2 Collection (java.util.Collection)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 Binding (org.eclipse.jface.bindings.Binding)1 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)1 KeySequenceText (org.eclipse.jface.bindings.keys.KeySequenceText)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1