org.eclipse.jface.bindings.keys.KeyStroke Java Examples

The following examples show how to use org.eclipse.jface.bindings.keys.KeyStroke. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBManagement.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public DatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		ts.menuDBManagement().click();
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new DatabaseManagementDialog(DatabaseManagementDialog.MANAGEMENT);
	return dialog;
}
 
Example #2
Source File: MemoryDBManagement.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public MemoryDatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		if (isMemory){
			ts.menuDBManagement().click();
		} else {
			ts.menuTeriDBManagement().click();
		}
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new MemoryDatabaseManagementDialog(MemoryDatabaseManagementDialog.MANAGEMENT,isMemory?"dlgTitleMemoryManagement":"dlgTitletreiTbManagement");
	return dialog;
}
 
Example #3
Source File: KeyBindingHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static boolean internalMatchesKeybinding(int keyCode, int stateMask, TriggerSequence seq)
{
	KeySequence keySequence = (KeySequence) seq;
	KeyStroke[] keyStrokes = keySequence.getKeyStrokes();

	if (keyStrokes.length > 1)
	{
		return false; // Only handling one step binding... the code below does not support things as "CTRL+X R" for
						// redo.
	}
	for (KeyStroke keyStroke : keyStrokes)
	{
		if (keyStroke.getNaturalKey() == keyCode && keyStroke.getModifierKeys() == stateMask)
		{

			return true;
		}
	}
	return false;
}
 
Example #4
Source File: DBManagement.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public DatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		ts.menuDBManagement().click();
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new DatabaseManagementDialog(DatabaseManagementDialog.MANAGEMENT);
	return dialog;
}
 
Example #5
Source File: MemoryDBManagement.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public MemoryDatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		if (isMemory){
			ts.menuDBManagement().click();
		} else {
			ts.menuTeriDBManagement().click();
		}
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new MemoryDatabaseManagementDialog(MemoryDatabaseManagementDialog.MANAGEMENT,isMemory?"dlgTitleMemoryManagement":"dlgTitletreiTbManagement");
	return dialog;
}
 
Example #6
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check for a binding that is not a full command and was not handled by the minibuffer
 * Remove the partial binding and add the command id entry
 * 
 * @param cmdId
 * @param trigger
 * @param onExit - it is the endMacro command, ignore id entry
 */

void checkTrigger(String cmdId, Map<?,?> parameters, Event trigger, boolean onExit) {
	int index = macro.size() -1;
	if (!macro.isEmpty() && trigger != null && macro.get(index).isSubCmd()) {
		Event event = macro.get(index).getEvent();
		// have trigger and previous entry is a subCmd type 
		KeyStroke key = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(event.keyCode));
		IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		Collection<Binding> values = EmacsPlusUtils.getPartialMatches(bindingService,KeySequence.getInstance(key)).values();
		// Check partial binding
		for (Binding v : values) {
			if (cmdId.equals((v.getParameterizedCommand().getId()))) {
				// remove (possibly partial) binding
				macro.remove(index);
				// flag for minibuffer exit
				macro.add(new KbdEvent(true));
				break;
			}
		}
	}
	if (!onExit) {
		macro.add(new KbdEvent(cmdId, parameters));
	}
}
 
Example #7
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check for a full command binding that was executed directly by the minibuffer
 * Remove the binding entry and add the command id entry
 * 
 * @param binding
 */
void checkBinding(Binding binding) {
	boolean processed = false;
	int index = macro.size() -1;
	Event keyevent = macro.get(index).getEvent();
	if (keyevent != null) {
		KeyStroke keyStroke = KeyStroke.getInstance(keyevent.stateMask, (int)Character.toUpperCase((char)keyevent.keyCode));
		if (keyStroke.equals(binding.getTriggerSequence().getTriggers()[0])) {
			// remove (possibly partial) binding
			macro.remove(index);
			// flag for minibuffer exit
			addExit();
			// and insert command
			macro.add(new KbdEvent(binding.getParameterizedCommand().getId()));
			processed = true;
		}
	}			
	if (!processed) {
		// then it's a command unto itself (e.g. ARROW_RIGHT) 
		// flag for minibuffer exit
		addExit();
		// and insert command
		macro.add(new KbdEvent(binding.getParameterizedCommand().getId()));
		processed = true;	
	}
}
 
Example #8
Source File: UniversalMinibuffer.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adapt the prefix display in the minibuffer to the actual key binding
 * 
 * @param keyCode
 * @param stateMask
 * @return the trigger string
 */
public String getTrigger(int keyCode, int stateMask) {
	StringBuilder result = new StringBuilder();
	String c = new String(Character.toChars(keyCode));
	switch (stateMask) {
	case SWT.CTRL:
		result.append(CPREFIX);
		result.append(c);
		break;
	case SWT.ALT:
		result.append(MPREFIX);
		result.append(c);
		break;
	case SWT.CTRL|SWT.ALT:
		result.append(CPREFIX);
		result.append(MPREFIX);
		result.append(c);
		break;
	default:
		result.append(KeyStroke.getInstance(stateMask,keyCode).format());
	}
	if (result.length() > 0) {
		result.append(' ');
	}
	return result.toString();
}
 
Example #9
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open the preferences dialog and return the corresponding shell. See also
 * {@link #pressOKishButtonInPreferences(SWTBot)} to close the dialog.
 *
 * @param bot
 *            a given workbench bot
 * @param text
 *            an alternative text for the preferences dialog, useful when a
 *            specific preference page was previously selected
 * @return the preferences shell
 */
public static SWTBotShell openPreferences(SWTBot bot, String text) {
    SWTBotShell mainShell = focusMainWindow(bot.shells());
    if (SWTUtils.isMac()) {
        // On Mac, the Preferences menu item is under the application name.
        // For some reason, we can't access the application menu anymore so
        // we use the keyboard shortcut.
        try {
            mainShell.pressShortcut(KeyStroke.getInstance(IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(","));
        } catch (ParseException e) {
            fail();
        }
    } else {
        mainShell.bot().menu(WINDOW_MENU).menu(PREFERENCES_MENU_ITEM).click();
    }

    if (text != null) {
        return anyShellOf(bot, PREFERENCES_SHELL, text).activate();
    }
    return bot.shell(PREFERENCES_SHELL).activate();
}
 
Example #10
Source File: CommandDataDialog.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
private ContentProposalAdapter addContentAssistSimple(Text textControl) {
    char[] autoActivationCharacters = new char[] { '$', '{' };
    KeyStroke keyStroke = null;
    try {
        keyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // assume that myTextControl has already been created in some way
    List<Variable> variables = Variable.getVisibleVariables();
    String[] proposals = new String [variables.size()];
    for(int i=0;i<variables.size();i++) {
        proposals[i] = variables.get(i).getFullVariableName();
    }
    ContentProposalAdapter adapter = new ContentProposalAdapter(
            textControl , new TextContentAdapter(),
        new SimpleContentProposalProvider(proposals),
        keyStroke, autoActivationCharacters);
    adapter.setPropagateKeys(false);
    adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE);
    //adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    return adapter;
}
 
Example #11
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean hasBinding(KeyEvent event, int mode) {
	boolean result = false;
	// ensure key is upper case
	KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(event.keyCode));
	boolean isFilterDisabled = !getKeyFilter();
	try {
		if (isFilterDisabled) {
			setKeyFilter(true);
		}
		result = bindingService.isPerfectMatch(KeySequence.getInstance(key));
	} finally {
		if (isFilterDisabled) {
			setKeyFilter(false);
		}
	}
	return result;
}
 
Example #12
Source File: ResourcesViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test keyboard marker navigation using '.' and ','
 */
@Test
public void testKeyboardSelectNextPreviousMarker() {
    SWTBotView viewBot = getViewBot();
    SWTBotCanvas canvas = viewBot.bot().canvas(1);
    testNextPreviousMarker(
            () -> {
                canvas.setFocus();
                canvas.pressShortcut(KeyStroke.getInstance('.'));
            },
            () -> {
                canvas.setFocus();
                canvas.pressShortcut(Keystrokes.SHIFT, KeyStroke.getInstance('.'));
            },
            () -> {
                canvas.setFocus();
                canvas.pressShortcut(KeyStroke.getInstance(','));
            },
            () -> {
                canvas.setFocus();
                canvas.pressShortcut(Keystrokes.SHIFT, KeyStroke.getInstance(','));
            });
}
 
Example #13
Source File: AutoCompleteTextCellEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public AutoCompleteTextCellEditor(ColumnViewer viewer) {
    super((Composite) viewer.getControl());
    Optional<KeyStroke> eclipseContentAssistKeyStroke = retrieveEclipseContentAssistKeyStroke();
    if (eclipseContentAssistKeyStroke.isPresent()) {
        contentAssistKeyStroke = eclipseContentAssistKeyStroke.get();
    } else {
        BonitaStudioLog.warning(
                "Unable to retrieve eclipse content assist binding. Content assist won't be available in editors. Check key binding for the `Content Assist` command in the eclipse preferences.",
                UIPlugin.PLUGIN_ID);
    }
}
 
Example #14
Source File: ISearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Dynamically determine the bindings for forward and reverse i-search
 * For repeat search, Emacs treats i-search and i-search-regexp identically
 * 
 * @param event
 * @return the FORWARD, REVERSE, or the source keyCode
 */
private int checkKeyCode(VerifyEvent event) {
	int result = event.keyCode;
	Integer val = keyHash.get(Integer.valueOf(event.keyCode + event.stateMask));
	if (val == null) { 
		KeyStroke keyst = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(result));
		IBindingService bindingService = getBindingService();
		Binding binding = bindingService.getPerfectMatch(KeySequence.getInstance(keyst));
		if (binding != null) {
			if (ISF.equals(binding.getParameterizedCommand().getId())){
				result = FORWARD;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(FORWARD));
			} else if (ISB.equals(binding.getParameterizedCommand().getId())) {
				result = REVERSE;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(REVERSE));
			} else if (ISRF.equals(binding.getParameterizedCommand().getId())) {
				result = FORWARD;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(FORWARD));
			} else if (ISRB.equals(binding.getParameterizedCommand().getId())) {
				result = REVERSE;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(REVERSE));
			} 
		}
	} else {
		result = val;
	}
	return result;
}
 
Example #15
Source File: SarosView.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private void selectConnectAccount(String baseJID) throws RemoteException {
  SWTBotToolbarDropDownButton b = view.toolbarDropDownButton(TB_CONNECT);
  @SuppressWarnings("static-access")
  Matcher<MenuItem> withRegex = WidgetMatcherFactory.withRegex(Pattern.quote(baseJID) + ".*");
  b.menuItem(withRegex).click();
  try {
    b.pressShortcut(KeyStroke.getInstance("ESC"));
  } catch (ParseException e) {
    log.debug("", e);
  }
}
 
Example #16
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void pressShortcut(String... keys) throws RemoteException {
  widget.setFocus();
  for (String key : keys) {
    try {
      widget.pressShortcut(KeyStroke.getInstance(key));
    } catch (ParseException e) {
      throw new RemoteException("could not parse \"" + key + "\"", e);
    }
  }
}
 
Example #17
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Based on the KeyEvent, get the perfect match binding
 * 
 * @param event
 * @param checkEnabled if true, the command in the binding must be enabled
 * @return a binding that perfectly matches the KeyEvent, or null
 */
// TODO explain why always force ALT in normal case?
private Binding getBinding(KeyEvent event, int mode, boolean checkEnabled) {

	Binding result = null;
	// ensure key is upper case
	KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(event.keyCode));
	boolean isFilterDisabled = !getKeyFilter();
	try {
		if (isFilterDisabled) {
			setKeyFilter(true);
		}
		// Shadowed commands shouldn't be enabled, but they are ... so protect
		// (e.g. C-x will perfect match and be enabled even though shadowed by C-x C-x)
		if (checkEnabled && bindingService.isPartialMatch(KeySequence.getInstance(key))) {
			result = null;
		} else {
			result = bindingService.getPerfectMatch(KeySequence.getInstance(key));
			if (result != null && checkEnabled && !result.getParameterizedCommand().getCommand().isEnabled()) {
				result = null;
			} 
		}
	} finally {
		if (isFilterDisabled) {
			setKeyFilter(false);
		}
	}
	return result;
}
 
Example #18
Source File: UniversalHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private Event makeEvent(IUniversalResult ua) {
	Event result = new Event();
	KeySequence keys = ua.getTrigger();
	if (keys != null) {
		Trigger[] triggers = keys.getTriggers();
		if (triggers[0] instanceof KeyStroke) {	// really, all it can be anyway
			KeyStroke ks = (KeyStroke)triggers[triggers.length - 1];
			result.keyCode = ks.getNaturalKey();
			result.stateMask = ks.getModifierKeys() & SWT.MODIFIER_MASK;
		}
	}
	return result;
}
 
Example #19
Source File: WorkspaceWizardPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the active key binding for content assist.
 *
 * If no binding is set null is returned.
 */
private KeyStroke getActiveContentAssistBinding() {
	IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
	TriggerSequence[] activeBindingsFor = bindingService
			.getActiveBindingsFor(CONTENT_ASSIST_ECLIPSE_COMMAND_ID);

	if (activeBindingsFor.length > 0 && activeBindingsFor[0] instanceof KeySequence) {
		KeyStroke[] strokes = ((KeySequence) activeBindingsFor[0]).getKeyStrokes();
		if (strokes.length == 1) {
			return strokes[0];
		}
	}
	return null;
}
 
Example #20
Source File: EmacsHelpHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	EmacsPlusConsole console = EmacsPlusConsole.getInstance();
	console.clear();
	console.activate();
	IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
	String id = (event.getCommand() != null ? event.getCommand().getId() : null);
	if (id != null) {
		try {
			TriggerSequence trigger = bindingService.getBestActiveBindingFor(event.getCommand().getId());
			Trigger[] trigs = trigger.getTriggers();
			KeyStroke key = (KeyStroke)trigs[0];
			Collection<Binding> partials = EmacsPlusUtils.getPartialMatches(bindingService,KeySequence.getInstance(key)).values();

			for (Binding bind : partials) {
				ParameterizedCommand cmd = bind.getParameterizedCommand();
				if (cmd.getId().startsWith(EmacsPlusUtils.MULGASOFT)) {
					console.printBold(bind.getTriggerSequence().toString());
					console.print(SWT.TAB + cmd.getCommand().getName());
					String desc =  cmd.getCommand().getDescription();
					if (desc != null) {
						desc = desc.replaceAll(CR, EMPTY_STR);
						console.print(" - " + desc + CR);	//$NON-NLS-1$ 
					} else {
						console.print(CR);
					}
				}
			}
		} catch (Exception e) {}
		console.setFocus(true);
	}
	return null;
}
 
Example #21
Source File: IndentForTabHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the exact binding if it exists and is enabled, else null
 * 
 * @param editor
 * @param keyCode
 * @param mode
 * @return binding if it exists and is enabled, else null
 */
private Binding getBinding(ITextEditor editor, char keyCode, int mode) {

	Binding result = null;
	// ensure key is upper case
	IBindingService bindingService = (IBindingService) editor.getSite().getService(IBindingService.class);
	KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(keyCode));
	result = bindingService.getPerfectMatch(KeySequence.getInstance(key));
	if (result != null && !result.getParameterizedCommand().getCommand().isEnabled()) {
		result = null;
	}
	return result;
}
 
Example #22
Source File: AutoCompleteTextCellEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Optional<KeyStroke> retrieveEclipseContentAssistKeyStroke() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    return Optional
            .ofNullable(bindingService.getBestActiveBindingFor("org.eclipse.ui.edit.text.contentAssist.proposals"))
            .map(triggerSequence -> {
                List<Trigger> triggers = Arrays.asList(triggerSequence.getTriggers());
                return triggers.size() > 1
                        ? null // auto complete cell editor doesn't handle sequence
                        : triggers.stream()
                                .filter(KeyStroke.class::isInstance)
                                .map(KeyStroke.class::cast)
                                .findFirst()
                                .orElse(null);
            });
}
 
Example #23
Source File: TextWidget.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Optional<KeyStroke> retrieveEclipseContentAssistKeyStroke() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    return Optional
            .ofNullable(bindingService.getBestActiveBindingFor("org.eclipse.ui.edit.text.contentAssist.proposals"))
            .map(triggerSequence -> {
                List<Trigger> triggers = Arrays.asList(triggerSequence.getTriggers());
                return triggers.size() > 1
                        ? null // auto complete cell editor doesn't handle sequence
                        : triggers.stream()
                                .filter(KeyStroke.class::isInstance)
                                .map(KeyStroke.class::cast)
                                .findFirst()
                                .orElse(null);
            });
}
 
Example #24
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, KeySequence keySequence) {
    KeyStroke[] keyStrokes = keySequence.getKeyStrokes();

    for (KeyStroke keyStroke : keyStrokes) {

        if (keyStroke.getNaturalKey() == keyCode
                && ((keyStroke.getModifierKeys() & stateMask) != 0 || keyStroke.getModifierKeys() == stateMask)) {

            return true;
        }
    }
    return false;
}
 
Example #25
Source File: EmacsMovementHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Does the trigger for this movement command contain the SHIFT key?
 * 
 * Enforce that the <binding> and <binding>+SHIFT belong to the same Command. 
 * If not, don't apply shift selection (if enabled) for this command (i.e. return false).
 *  
 * @param event the Execution event that invoked this command
 * 
 * @return true if SHIFT modifier was set, else false
 */
private boolean getShifted(ExecutionEvent event) {
	// NB: only single keystroke commands are valid 
	boolean result = false;
	Object trigger = event.getTrigger();
	Event e = null;
	if (trigger != null && trigger instanceof Event && ((e = (Event)trigger).stateMask & SWT.SHIFT )!= 0) {
		String cmdId = event.getCommand().getId();
		int mask = (e.stateMask & SWT.MODIFIER_MASK) ^ SWT.SHIFT;
		int u_code = Character.toUpperCase((char)e.keyCode);
		IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		if (cmdId != null && bs != null) {
			TriggerSequence[] sequences = bs.getActiveBindingsFor(cmdId);
			for (TriggerSequence s : sequences) {
				if (s instanceof KeySequence) {
					KeyStroke[] strokes = ((KeySequence)s).getKeyStrokes();
					if (strokes.length == 1) {
						KeyStroke k = strokes[strokes.length - 1];
						// if keyCode is alpha, then we test uppercase, else keyCode
						if (k.getModifierKeys() == mask
								&& (k.getNaturalKey() == u_code || k.getNaturalKey() == e.keyCode)) {
							result = true;
							break;
						}
					}
				}
			}
		} 
	}
	return result;
}
 
Example #26
Source File: KbdMacroBindHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for C-x C-k <key> binding conflict
 * 
 * @param editor
 * @param c
 * @return IBindingResult with C-x C-k <key> information
 */
private IBindingResult getBinding(ITextEditor editor, char c) {
	IBindingResult result = null;
	try {
		final KeySequence sequence = KeySequence.getInstance(KeySequence.getInstance(STD_KBD_PREFIX), KeyStroke.getInstance(c));
		final Binding binding = checkForBinding(editor, sequence);
		result = new IBindingResult() {
			public Binding getKeyBinding() { return binding; }
			public String getKeyString() { return sequence.format(); }
			public KeySequence getTrigger() { return sequence; }
		};
	} catch (ParseException e) { }
	return result;
}
 
Example #27
Source File: FieldAssistHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param keyStroke
 * @param triggerKey
 * @return
 */
private KeyStroke getKeyStroke( String triggerKey )
{
	try
	{
		return KeyStroke.getInstance( triggerKey );
	}
	catch ( Exception e ) // Catch all exceptions to avoid breaking UI.
	{
		return KeyStroke.getInstance( SWT.F10 );
	}
}
 
Example #28
Source File: FieldAssistHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param control
 * @param contentAdapter
 * @param values
 */
public void installContentProposalAdapter( Control control,
		IControlContentAdapter contentAdapter, String[] values )
{
	IPreferenceStore store = getPreferenceStore( );
	boolean propagate = store.getBoolean( PreferenceConstants.PREF_CONTENTASSISTKEY_PROPAGATE );
	KeyStroke keyStroke = null;
	char[] autoActivationCharacters = null;
	int autoActivationDelay = store.getInt( PreferenceConstants.PREF_CONTENTASSISTDELAY );
	String triggerKey = getTriggerKey( );
	if ( triggerKey == null )
	{
		keyStroke = null;
	}
	else
	{
		keyStroke = getKeyStroke( triggerKey );
	}

	ContentProposalAdapter adapter = new ContentProposalAdapter( control,
			contentAdapter,
			getContentProposalProvider( values ),
			keyStroke,
			autoActivationCharacters );
	adapter.setAutoActivationDelay( autoActivationDelay );
	adapter.setPropagateKeys( propagate );
	adapter.setFilterStyle( getContentAssistFilterStyle( ) );
	adapter.setProposalAcceptanceStyle( getContentAssistAcceptance( ) );
}
 
Example #29
Source File: ProjectCreate.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * 从指定的入口打开新建对话框
	 * @param from
	 * @throws ParseException
	 */
	public void openCreateProjectDialog(Entry from) {
		switch (from) {
		case MENU: {
			ts.menuFileNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
			break;
		}
		case SHORTCUT: {
			try {
				ProjectTreeView.getTree().pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), KeyStroke.getInstance("N"));
			} catch (ParseException e) {
				assertTrue("快捷键解析错误。", false);
			}
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
		case CONTEXT_MENU: {
			ProjectTreeView.getTree().contextMenu("新建记忆库...").click();
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
//		case CONTEXT_MENU_ALT: {
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
//			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
//			break;
//		}
		default: {
			assertTrue("参数错误:创建项目入口 from 不正确。", false);
		}
		}
		assertTrue(dialog.isActive());

		// 选择新建类型为 Project,下一步
//		dialog.treeiProject().select();
//		assertTrue(dialog.btnNext().isEnabled());
//		dialog.btnNext().click();
	}
 
Example #30
Source File: ProjectCreate.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * 从指定的入口打开新建对话框
	 * @param from
	 * @throws ParseException
	 */
	public void openCreateProjectDialog(Entry from) {
		switch (from) {
		case MENU: {
			ts.menuFileNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
			break;
		}
		case SHORTCUT: {
			try {
				ProjectTreeView.getTree().pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), KeyStroke.getInstance("N"));
			} catch (ParseException e) {
				assertTrue("快捷键解析错误。", false);
			}
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
		case CONTEXT_MENU: {
			ProjectTreeView.getTree().contextMenu("新建记忆库...").click();
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
//		case CONTEXT_MENU_ALT: {
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
//			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
//			break;
//		}
		default: {
			assertTrue("参数错误:创建项目入口 from 不正确。", false);
		}
		}
		assertTrue(dialog.isActive());

		// 选择新建类型为 Project,下一步
//		dialog.treeiProject().select();
//		assertTrue(dialog.btnNext().isEnabled());
//		dialog.btnNext().click();
	}