/** * @return created/edited shortcut. Returns <code>null</code> if shortcut is invalid. */ public MouseShortcut getMouseShortcut(){ if (myButton > 3 && myButton != MouseShortcut.BUTTON_WHEEL_UP && myButton != MouseShortcut.BUTTON_WHEEL_DOWN && getClickCount() == 2) { return null; } if(myButton!=-1 && myModifiers!=-1){ return new MouseShortcut(myButton,myModifiers,getClickCount()); }else{ return null; } }
public static Shortcut convertShortcutFromParent(Shortcut parentShortcut) { if (parentShortcut instanceof MouseShortcut) { return convertMouseShortcut((MouseShortcut)parentShortcut); } KeyboardShortcut key = (KeyboardShortcut)parentShortcut; return new KeyboardShortcut(convertKeyStroke(key.getFirstKeyStroke()), convertKeyStroke(key.getSecondKeyStroke())); }
public void readExternal(Element keymapElement, Keymap[] existingKeymaps) throws InvalidDataException { super.readExternal(keymapElement, existingKeymaps); if (KeymapManager.DEFAULT_IDEA_KEYMAP.equals(getName()) && !SystemInfo.isXWindow) { addShortcut(IdeActions.ACTION_GOTO_DECLARATION, new MouseShortcut(MouseEvent.BUTTON2, 0, 1)); } }
private static void doWithAltClickShortcut(ThrowableRunnable runnable) throws Throwable { Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); MouseShortcut shortcut = new MouseShortcut(1, InputEvent.ALT_DOWN_MASK, 1); try { keymap.addShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut); runnable.run(); } finally { keymap.removeShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut); } }
/** * @return created/edited shortcut. Returns <code>null</code> if shortcut is invalid. */ public MouseShortcut getMouseShortcut(){ if (myButton > 3 && getClickCount() == 2) { return null; } if(myButton!=-1 && myModifiers!=-1){ return new MouseShortcut(myButton,myModifiers,getClickCount()); }else{ return null; } }
private static boolean matchMouseShortcut(final Keymap activeKeymap, @JdkConstants.InputEventMask int modifiers, final String actionId) { final MouseShortcut syntheticShortcut = new MouseShortcut(MouseEvent.BUTTON1, modifiers, 1); for (Shortcut shortcut : activeKeymap.getShortcuts(actionId)) { if (shortcut instanceof MouseShortcut) { final MouseShortcut mouseShortcut = (MouseShortcut)shortcut; if (mouseShortcut.getModifiers() == syntheticShortcut.getModifiers()) { return true; } } } return false; }
private MouseShortcut toMouseShortcut(MouseEvent event) { int button = MouseShortcut.getButton(event); int clickCount = event instanceof MouseWheelEvent ? 1 : event.getClickCount(); if (0 <= button && clickCount <= myClickCount) { int modifiers = event.getModifiersEx(); return new MouseShortcut(button, modifiers, clickCount); } return null; }
/** * @param shortcut dialog will be initialized with this <code>shortcut</code>. It can be <code>null</code> * if dialog is used to create new mouse shortcut. */ public MouseShortcutDialog( JComponent parentComponent, MouseShortcut shortcut, @NotNull Keymap keymap, @NotNull String actiondId, @NotNull Group mainGroup, @NotNull ShortcutRestrictions restrictions ){ super(parentComponent,true); setTitle(KeyMapBundle.message("mouse.shortcut.dialog.title")); myKeymap=keymap; myActionId=actiondId; myMainGroup=mainGroup; myRbSingleClick=new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.single.click.radio")); myRbDoubleClick=new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.double.click.radio")); ButtonGroup buttonGroup=new ButtonGroup(); buttonGroup.add(myRbSingleClick); buttonGroup.add(myRbDoubleClick); myLblPreview=new JLabel(" "); myClickPad=new MyClickPad(); myTarConflicts=new JTextArea(); myTarConflicts.setFocusable(false); myTarConflicts.setEditable(false); myTarConflicts.setBackground(UIUtil.getPanelBackground()); myTarConflicts.setLineWrap(true); myTarConflicts.setWrapStyleWord(true); if(shortcut!=null){ if(shortcut.getClickCount()==1){ myRbSingleClick.setSelected(true); }else{ myRbDoubleClick.setSelected(true); } myButton=shortcut.getButton(); myModifiers=shortcut.getModifiers(); }else{ myRbSingleClick.setSelected(true); myButton=-1; myModifiers=-1; } myRbDoubleClick.setEnabled(restrictions.allowMouseDoubleClick); updatePreviewAndConflicts(); init(); }
/** * Updates all UI controls */ private void updatePreviewAndConflicts(){ if(myButton==-1||myModifiers==-1){ return; } myTarConflicts.setText(null); // Set text into preview area // empty string should have same height myLblPreview.setText(KeymapUtil.getMouseShortcutText(myButton,myModifiers,getClickCount()) + " "); // Detect conflicts final MouseShortcut mouseShortcut=new MouseShortcut(myButton,myModifiers,getClickCount()); if (myButton > 3 && getClickCount() == 2) { myTarConflicts.setForeground(JBColor.RED); myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.side.buttons.with.double.click", myButton)); return; } StringBuilder buffer = new StringBuilder(); String[] actionIds = myKeymap.getActionIds(mouseShortcut); for (String actionId : actionIds) { if (actionId.equals(myActionId)) { continue; } String actionPath = myMainGroup.getActionQualifiedPath(actionId); // actionPath == null for editor actions having corresponding $-actions if (actionPath == null) { continue; } Shortcut[] shortcuts = myKeymap.getShortcuts(actionId); for (Shortcut shortcut1 : shortcuts) { if (!(shortcut1 instanceof MouseShortcut)) { continue; } MouseShortcut shortcut = (MouseShortcut)shortcut1; if (shortcut.getButton() != mouseShortcut.getButton() || shortcut.getModifiers() != mouseShortcut.getModifiers()) { continue; } if (buffer.length() > 1) { buffer.append('\n'); } buffer.append('['); buffer.append(actionPath); buffer.append(']'); break; } } if (buffer.length() == 0) { myTarConflicts.setForeground(UIUtil.getTextAreaForeground()); myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.no.conflicts.area")); } else { myTarConflicts.setForeground(JBColor.RED); myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.assigned.to.area", buffer.toString())); } }
protected String[] getParentActionIds(MouseShortcut shortcut) { return super.getParentActionIds(convertMouseShortcut(shortcut)); }
private static MouseShortcut convertMouseShortcut(MouseShortcut macShortcut) { return new MouseShortcut(macShortcut.getButton(), mapModifiers(macShortcut.getModifiers()), macShortcut.getClickCount()); }
/** * @param shortcut dialog will be initialized with this <code>shortcut</code>. It can be <code>null</code> * if dialog is used to create new mouse shortcut. */ public MouseShortcutDialog( JComponent parentComponent, MouseShortcut shortcut, @NotNull Keymap keymap, @NotNull String actiondId, @NotNull Group mainGroup ){ super(parentComponent,true); setTitle(KeyMapBundle.message("mouse.shortcut.dialog.title")); myKeymap=keymap; myActionId=actiondId; myMainGroup=mainGroup; myRbSingleClick=new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.single.click.radio")); myRbDoubleClick=new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.double.click.radio")); ButtonGroup buttonGroup=new ButtonGroup(); buttonGroup.add(myRbSingleClick); buttonGroup.add(myRbDoubleClick); myLblPreview=new JLabel(" "); myClickPad=new MyClickPad(); myTarConflicts=new JTextArea(); myTarConflicts.setFocusable(false); myTarConflicts.setEditable(false); myTarConflicts.setBackground(UIUtil.getPanelBackground()); myTarConflicts.setLineWrap(true); myTarConflicts.setWrapStyleWord(true); if(shortcut!=null){ if(shortcut.getClickCount()==1){ myRbSingleClick.setSelected(true); }else{ myRbDoubleClick.setSelected(true); } myButton=shortcut.getButton(); myModifiers=shortcut.getModifiers(); }else{ myRbSingleClick.setSelected(true); myButton=-1; myModifiers=-1; } updatePreviewAndConflicts(); init(); }
/** * @param shortcut dialog will be initialized with this <code>shortcut</code>. It can be <code>null</code> * if dialog is used to create new mouse shortcut. */ public MouseShortcutDialog( JComponent parentComponent, MouseShortcut shortcut, @Nonnull Keymap keymap, @Nonnull String actiondId, @Nonnull Group mainGroup, @Nonnull ShortcutRestrictions restrictions ){ super(parentComponent,true); setTitle(KeyMapBundle.message("mouse.shortcut.dialog.title")); myKeymap=keymap; myActionId=actiondId; myMainGroup=mainGroup; myRbSingleClick=new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.single.click.radio")); myRbDoubleClick=new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.double.click.radio")); ButtonGroup buttonGroup=new ButtonGroup(); buttonGroup.add(myRbSingleClick); buttonGroup.add(myRbDoubleClick); myLblPreview=new JLabel(" "); myClickPad=new MyClickPad(); myTarConflicts=new JTextArea(); myTarConflicts.setFocusable(false); myTarConflicts.setEditable(false); myTarConflicts.setBackground(UIUtil.getPanelBackground()); myTarConflicts.setLineWrap(true); myTarConflicts.setWrapStyleWord(true); if(shortcut!=null){ if(shortcut.getClickCount()==1){ myRbSingleClick.setSelected(true); }else{ myRbDoubleClick.setSelected(true); } myButton=shortcut.getButton(); myModifiers=shortcut.getModifiers(); }else{ myRbSingleClick.setSelected(true); myButton=-1; myModifiers=-1; } myRbDoubleClick.setEnabled(restrictions.allowMouseDoubleClick); updatePreviewAndConflicts(); init(); }
public void setShortcut(MouseShortcut shortcut) { MouseShortcut old = getShortcut(); if (old != null || shortcut != null) { super.setShortcut(shortcut); } }
private void setShortcutIfNeeded(MouseShortcut shortcut) { if (shortcut != null) setShortcut(shortcut); }
@Override protected String[] getParentActionIds(MouseShortcut shortcut) { return super.getParentActionIds(convertMouseShortcut(shortcut)); }
/** * @return all actions with specified mouse shortcut. If there are no * such action then the method returns an empty array. */ String[] getActionIds(MouseShortcut shortcut);