com.intellij.openapi.actionSystem.KeyboardShortcut Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.KeyboardShortcut. 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: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings,
      new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
          });
          cancelAction.run();
        }
      }
  );
}
 
Example #2
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
        }
      });
      cancelAction.run();
    }
  });
}
 
Example #3
Source File: SarosComponent.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
public SarosComponent() {
  loadLoggers();

  Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
  keymap.addShortcut(
      "ActivateSarosToolWindow",
      new KeyboardShortcut(
          KeyStroke.getKeyStroke(KeyEvent.VK_F11, java.awt.event.InputEvent.ALT_DOWN_MASK),
          null));

  try {
    InputStream sarosProperties =
        SarosComponent.class.getClassLoader().getResourceAsStream("saros.properties");

    if (sarosProperties == null) {
      LogLog.warn(
          "could not initialize Saros properties because "
              + "the 'saros.properties' file could not be found on the "
              + "current JAVA class path");
    } else {
      System.getProperties().load(sarosProperties);
      sarosProperties.close();
    }
  } catch (Exception e) {
    LogLog.error("could not load saros property file 'saros.properties'", e);
  }

  IntellijApplicationLifecycle.getInstance().start();
}
 
Example #4
Source File: JumpToSourceAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
@NotNull
private static String getLabel() {
	Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("EditSource");
	if (shortcuts.length > 0) {
		Shortcut shortcut = shortcuts[0];
		if (shortcut.isKeyboard()) {
			KeyboardShortcut key = (KeyboardShortcut) shortcut;
			String s = KeyStrokeAdapter.toString(key.getFirstKeyStroke());
			if (s != null) {
				return "Jump To Source [" + s.toUpperCase() + "]";
			}
		}
	}
	return "Jump To Source";
}
 
Example #5
Source File: SearchForUsagesRunnable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String createOptionsHtml(@NonNls UsageTarget[] searchFor) {
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(searchFor);
  String shortcutText = "";
  if (shortcut != null) {
    shortcutText = " (" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return "<a href='" + FIND_OPTIONS_HREF_TARGET + "'>Find Options...</a>" + shortcutText;
}
 
Example #6
Source File: PrevOccurrenceAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected List<Shortcut> getSingleLineShortcuts() {
  if (mySearch) {
    return ContainerUtil.append(Utils.shortcutsOf(IdeActions.ACTION_EDITOR_MOVE_CARET_UP),
                                new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), null));
  } else {
    return Utils.shortcutsOf(IdeActions.ACTION_EDITOR_MOVE_CARET_UP);
  }
}
 
Example #7
Source File: KeyboardShortcutDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setData(Keymap keymap, KeyboardShortcut shortcut) {
  myKeymap = keymap;
  myEnableSecondKeystroke.setSelected(false);
  if (shortcut != null) {
    myFirstStrokePanel.getShortcutTextField().setKeyStroke(shortcut.getFirstKeyStroke());
    if (shortcut.getSecondKeyStroke() != null) {
      myEnableSecondKeystroke.setSelected(true);
      mySecondStrokePanel.getShortcutTextField().setKeyStroke(shortcut.getSecondKeyStroke());
    }
  }
  handleSecondKey();
  updateCurrentKeyStrokeInfo();
}
 
Example #8
Source File: KeyboardShortcutDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public KeyboardShortcut getKeyboardShortcut() {
  KeyStroke firstStroke = myFirstStrokePanel.getKeyStroke();
  if (firstStroke == null) {
    return null;
  }
  KeyStroke secondStroke = myEnableSecondKeystroke.isSelected() ? mySecondStrokePanel.getKeyStroke() : null;
  return new KeyboardShortcut(firstStroke, secondStroke);
}
 
Example #9
Source File: MacOSDefaultKeymap.java    From consulo with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example #10
Source File: TipUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getShortcutText(String actionId, Keymap keymap) {
  for (final Shortcut shortcut : keymap.getShortcuts(actionId)) {
    if (shortcut instanceof KeyboardShortcut) {
      return KeymapUtil.getShortcutText(shortcut);
    }
  }
  return null;
}
 
Example #11
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
private static KeyboardShortcut getShowUsagesShortcut() {
  return ActionManager.getInstance().getKeyboardShortcut("ShowUsages");
}
 
Example #12
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void onNonConsumedKeyEvent(@Nonnull final MindMapPanel source, @Nonnull final KeyEvent e, @Nonnull final KeyEventType type) {
  if (type == KeyEventType.PRESSED) {
    if (e.getModifiers() == 0) {
      switch (e.getKeyCode()) {
        case KeyEvent.VK_UP:
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_DOWN: {
          e.consume();
        }
        break;
      }
    }
  }

  boolean activated = false;
  final ShortcutSet findAtMindMap = getFindAtMindMapShortcutSet();
  if (findAtMindMap != null) {
    final KeyStroke eventStroke = KeyStroke.getKeyStrokeForEvent(e);
    for (final Shortcut c : findAtMindMap.getShortcuts()) {
      if (c instanceof KeyboardShortcut) {
        final KeyboardShortcut keyboardShortcut = (KeyboardShortcut) c;
        final KeyStroke firstKeyStroke = keyboardShortcut.getFirstKeyStroke();
        final KeyStroke secondKeyStroke = keyboardShortcut.getSecondKeyStroke();

        if (firstKeyStroke != null && firstKeyStroke.getModifiers() == eventStroke.getModifiers() && firstKeyStroke.getKeyCode() == eventStroke.getKeyCode() && firstKeyStroke.getKeyChar() == eventStroke.getKeyChar()) {
          activated = true;
          break;
        }
        if (secondKeyStroke != null && secondKeyStroke.getModifiers() == eventStroke.getModifiers() && secondKeyStroke.getKeyCode() == eventStroke.getKeyCode() && secondKeyStroke.getKeyChar() == eventStroke.getKeyChar()) {
          activated = true;
          break;
        }
      }
    }
  }

  if (activated) {
    e.consume();
    activateTextSearchPanel();
  }

  if (!e.isConsumed() && e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        findTextPanel.deactivate();
      }
    });
  }
}
 
Example #13
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public KeyboardShortcut getShortcut() {
  return UsageViewImpl.getShowUsagesWithSettingsShortcut();
}
 
Example #14
Source File: ReplaceInProjectManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public KeyboardShortcut getShortcut() {
  return ActionManager.getInstance().getKeyboardShortcut("ReplaceInPath");
}
 
Example #15
Source File: KeyboardShortcutDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void updateCurrentKeyStrokeInfo() {
  if (myConflictInfoArea == null || myKeystrokePreview == null){
    return;
  }

  myConflictInfoArea.setText(null);
  myKeystrokePreview.setText(" ");

  if (myKeymap == null){
    return;
  }

  KeyboardShortcut keyboardShortcut = getKeyboardShortcut();
  if (keyboardShortcut == null){
    return;
  }

  String strokeText = getTextByKeyStroke(keyboardShortcut.getFirstKeyStroke());
  String suffixText = getTextByKeyStroke(keyboardShortcut.getSecondKeyStroke());
  if(suffixText != null && suffixText.length() > 0) {
    strokeText += ',' + suffixText;
  }
  myKeystrokePreview.setText(strokeText);

  StringBuffer buffer = new StringBuffer();

  Map<String, ArrayList<KeyboardShortcut>> conflicts = myKeymap.getConflicts(myActionId, keyboardShortcut);

  Set<String> keys = conflicts.keySet();
  String[] actionIds = ArrayUtil.toStringArray(keys);
  boolean loaded = true;
  for (String actionId : actionIds) {
    String actionPath = myMainGroup.getActionQualifiedPath(actionId);
    if (actionPath == null) {
      loaded = false;
    }
    if (buffer.length() > 1) {
      buffer.append('\n');
    }
    buffer.append('[');
    buffer.append(actionPath != null ? actionPath : actionId);
    buffer.append(']');
  }

  if (buffer.length() == 0) {
    myConflictInfoArea.setForeground(UIUtil.getTextAreaForeground());
    myConflictInfoArea.setText(KeyMapBundle.message("no.conflict.info.message"));
  }
  else {
    myConflictInfoArea.setForeground(JBColor.RED);
    if (loaded) {
      myConflictInfoArea.setText(KeyMapBundle.message("assigned.to.info.message", buffer.toString()));
    } else {
      myConflictInfoArea.setText("Assigned to " + buffer.toString() + " which is now not loaded but may be loaded later");
    }
  }
}
 
Example #16
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
private static KeyboardShortcut getShowUsagesShortcut() {
  return ActionManager.getInstance().getKeyboardShortcut("ShowUsages");
}
 
Example #17
Source File: CSharpLambdaNodeProvider.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public Shortcut[] getShortcut()
{
	return new Shortcut[]{KeyboardShortcut.fromString(SystemInfo.isMac ? "meta L" : "control L")};
}
 
Example #18
Source File: Keymap.java    From consulo with Apache License 2.0 votes vote down vote up
Map<String, ArrayList<KeyboardShortcut>> getConflicts(String actionId, KeyboardShortcut keyboardShortcut); 
Example #19
Source File: ConfigurableUsageTarget.java    From consulo with Apache License 2.0 votes vote down vote up
KeyboardShortcut getShortcut();