com.intellij.openapi.keymap.KeymapUtil Java Examples

The following examples show how to use com.intellij.openapi.keymap.KeymapUtil. 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 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 #2
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 #3
Source File: ActionButton.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean update() {
  AnActionEvent event = createAnEvent(null, 0);

  if (event == null) return false;

  myAction.update(event);
  Presentation p = event.getPresentation();
  boolean changed = !areEqual(p, myPrevPresentation);

  setIcons(p.getIcon(), p.getDisabledIcon(), p.getHoveredIcon());

  if (changed) {
    myButton.setIcons(this);
    String tooltipText = KeymapUtil.createTooltipText(p.getText(), myAction);
    myButton.setToolTipText(tooltipText.length() > 0 ? tooltipText : null);
    myButton.setVisible(p.isEnabled() && p.isVisible());
  }

  myPrevPresentation = p;

  return changed;
}
 
Example #4
Source File: MultilinePopupBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
JBPopup createPopup() {
  JPanel panel = new JPanel(new BorderLayout());
  panel.add(myTextField, BorderLayout.CENTER);
  ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField)
          .setCancelOnClickOutside(true)
          .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish")
          .setRequestFocus(true)
          .setResizable(true)
          .setMayBeParent(true);

  final JBPopup popup = builder.createPopup();
  popup.setMinimumSize(new JBDimension(200, 90));
  AnAction okAction = new DumbAwareAction() {
    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      unregisterCustomShortcutSet(popup.getContent());
      popup.closeOk(e.getInputEvent());
    }
  };
  okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent());
  return popup;
}
 
Example #5
Source File: ActionsTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Object getValueAt(Object value, int column) {
  if (!(value instanceof DefaultMutableTreeNode)) {
    return "???";
  }

  if (column == 0) {
    return value;
  }
  else if (column == 1) {
    Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
    if (userObject instanceof QuickList) {
      userObject = ((QuickList)userObject).getActionId();
    }

    if (userObject instanceof String) {
      Shortcut[] shortcuts = myKeymap.getShortcuts((String)userObject);
      return KeymapUtil.getShortcutsText(shortcuts);
    }
    else {
      return "";
    }
  }
  else {
    return "???";
  }
}
 
Example #6
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isMouseActionEvent(@Nonnull MouseEvent e, String actionId) {
  KeymapManager keymapManager = KeymapManager.getInstance();
  if (keymapManager == null) return false;
  Keymap keymap = keymapManager.getActiveKeymap();
  MouseShortcut mouseShortcut = KeymapUtil.createMouseShortcut(e);
  String[] mappedActions = keymap.getActionIds(mouseShortcut);
  if (!ArrayUtil.contains(actionId, mappedActions)) return false;
  if (mappedActions.length < 2 || e.getID() == MouseEvent.MOUSE_DRAGGED /* 'normal' actions are not invoked on mouse drag */) return true;
  ActionManager actionManager = ActionManager.getInstance();
  for (String mappedActionId : mappedActions) {
    if (actionId.equals(mappedActionId)) continue;
    AnAction action = actionManager.getAction(mappedActionId);
    AnActionEvent actionEvent = AnActionEvent.createFromAnAction(action, e, ActionPlaces.MAIN_MENU, DataManager.getInstance().getDataContext(e.getComponent()));
    if (ActionUtil.lastUpdateAndCheckDumb(action, actionEvent, false)) return false;
  }
  return true;
}
 
Example #7
Source File: LightToolWindow.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ActionButton(AnAction action) {
  myAction = action;

  Presentation presentation = action.getTemplatePresentation();
  InplaceButton button = new InplaceButton(KeymapUtil.createTooltipText(presentation.getText(), action), EmptyIcon.ICON_16, this) {
    @Override
    public boolean isActive() {
      return LightToolWindow.this.isActive();
    }
  };
  button.setHoveringEnabled(!SystemInfo.isMac);
  setContent(button);

  Icon icon = presentation.getIcon();
  Icon hoveredIcon = presentation.getHoveredIcon();
  button.setIcons(icon, icon, hoveredIcon == null ? icon : hoveredIcon);
}
 
Example #8
Source File: RecentLocationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static JBCheckBox createCheckbox(@Nonnull ShortcutSet checkboxShortcutSet, boolean showChanged) {
  String text = "<html>" +
                IdeBundle.message("recent.locations.title.text") +
                " <font color=\"" +
                SHORTCUT_HEX_COLOR +
                "\">" +
                KeymapUtil.getShortcutsText(checkboxShortcutSet.getShortcuts()) +
                "</font>" +
                "</html>";
  JBCheckBox checkBox = new JBCheckBox(text);
  checkBox.setBorder(JBUI.Borders.empty());
  checkBox.setOpaque(false);
  checkBox.setSelected(showChanged);

  return checkBox;
}
 
Example #9
Source File: ChooseRunConfigurationPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected String getAdText(final Executor alternateExecutor) {
  final PropertiesComponent properties = PropertiesComponent.getInstance();
  if (alternateExecutor != null && !properties.isTrueValue(myAddKey)) {
    return String.format("Hold %s to %s", KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke("SHIFT")), alternateExecutor.getActionName());
  }

  if (!properties.isTrueValue("run.configuration.edit.ad")) {
    return String.format("Press %s to Edit", KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke("F4")));
  }

  if (!properties.isTrueValue("run.configuration.delete.ad")) {
    return String.format("Press %s to Delete configuration", KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke("DELETE")));
  }

  return null;
}
 
Example #10
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void registerConsoleEditorActions() {
  Shortcut[] shortcuts = KeymapUtil.getActiveKeymapShortcuts(IdeActions.ACTION_GOTO_DECLARATION).getShortcuts();
  CustomShortcutSet shortcutSet = new CustomShortcutSet(ArrayUtil.mergeArrays(shortcuts, CommonShortcuts.ENTER.getShortcuts()));
  new HyperlinkNavigationAction().registerCustomShortcutSet(shortcutSet, myEditor.getContentComponent());


  if (!myIsViewer) {
    new EnterHandler().registerCustomShortcutSet(CommonShortcuts.ENTER, myEditor.getContentComponent());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_PASTE, new PasteHandler());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_BACKSPACE, new BackSpaceHandler());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_DELETE, new DeleteHandler());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_TAB, new TabHandler());

    registerActionHandler(myEditor, EOFAction.ACTION_ID);
  }
}
 
Example #11
Source File: Switcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static SwitcherPanel createAndShowSwitcher(@Nonnull AnActionEvent e, @Nonnull String title, @Nonnull String actionId, boolean onlyEdited, boolean pinned) {
  Project project = e.getProject();
  if (project == null) return null;
  SwitcherPanel switcher = SWITCHER_KEY.get(project);
  if (switcher != null) {
    boolean sameShortcut = Comparing.equal(switcher.myTitle, title);
    if (sameShortcut) {
      if (switcher.isCheckboxMode() && e.getInputEvent() instanceof KeyEvent && KeymapUtil.isEventForAction((KeyEvent)e.getInputEvent(), TOGGLE_CHECK_BOX_ACTION_ID)) {
        switcher.toggleShowEditedFiles();
      }
      else {
        switcher.goForward();
      }
      return null;
    }
    else if (switcher.isCheckboxMode()) {
      switcher.setShowOnlyEditedFiles(onlyEdited);
      return null;
    }
  }
  return createAndShowSwitcher(project, title, actionId, onlyEdited, pinned);
}
 
Example #12
Source File: SearchReplaceComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private ActionToolbarImpl createSearchToolbar1(@Nonnull DefaultActionGroup group) {
  ActionToolbarImpl toolbar = createToolbar(group);
  toolbar.setSecondaryButtonPopupStateModifier(mySearchToolbar1PopupStateModifier);
  toolbar.setSecondaryActionsTooltip(FindBundle.message("find.popup.show.filter.popup"));
  toolbar.setSecondaryActionsIcon(AllIcons.General.Filter);
  toolbar.setNoGapMode();

  KeyboardShortcut keyboardShortcut = ActionManager.getInstance().getKeyboardShortcut("ShowFilterPopup");
  if (keyboardShortcut != null) {
    toolbar.setSecondaryActionsShortcut(KeymapUtil.getShortcutText(keyboardShortcut));
  }

  new ShowMoreOptions(toolbar, mySearchFieldWrapper);
  return toolbar;
}
 
Example #13
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private InplaceButton createSettingsButton(@Nonnull final FindUsagesHandler handler,
                                           @Nonnull final RelativePoint popupPosition,
                                           final Editor editor,
                                           final int maxUsages,
                                           @Nonnull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, e -> {
    ApplicationManager.getApplication().invokeLater(() -> showDialogAndFindUsages(handler, popupPosition, editor, maxUsages));
    cancelAction.run();
  });
}
 
Example #14
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setShortcutLabel() {
  if (myShortcutLabel != null) remove(myShortcutLabel);

  String upShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_UP);
  String downShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_DOWN);
  if (!myAllowSwitchLabel || myObjects.length <= 1 || !myHandler.supportsOverloadSwitching() || upShortcut.isEmpty() && downShortcut.isEmpty()) {
    myShortcutLabel = null;
  }
  else {
    myShortcutLabel = new JLabel(upShortcut.isEmpty() || downShortcut.isEmpty()
                                 ? CodeInsightBundle.message("parameter.info.switch.overload.shortcuts.single", upShortcut.isEmpty() ? downShortcut : upShortcut)
                                 : CodeInsightBundle.message("parameter.info.switch.overload.shortcuts", upShortcut, downShortcut));
    myShortcutLabel.setForeground(CONTEXT_HELP_FOREGROUND);
    Font labelFont = UIUtil.getLabelFont();
    myShortcutLabel.setFont(labelFont.deriveFont(labelFont.getSize2D() - (SystemInfo.isWindows ? 1 : 2)));
    myShortcutLabel.setBorder(JBUI.Borders.empty(6, 10, 0, 10));
    add(myShortcutLabel, BorderLayout.SOUTH);
  }
}
 
Example #15
Source File: FileTextFieldImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public String getAdText(CompletionResult result) {
  if (result.myCompletionBase == null) return null;
  if (result.myCompletionBase.length() == result.myFieldText.length()) return null;

  String strokeText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("EditorChooseLookupItemReplace"));
  return IdeBundle.message("file.chooser.completion.ad.text", strokeText);
}
 
Example #16
Source File: ContentTabLabel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String getTooltip() {
  String text = KeymapUtil.getShortcutsText(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CLOSE_ACTIVE_TAB));

  return text.isEmpty() || !isSelected() ? ACTION_NAME : ACTION_NAME + " (" + text + ")";
}
 
Example #17
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void showDialogAdvertisement(final String actionId) {
  final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
  final Shortcut[] shortcuts = keymap.getShortcuts(actionId);
  if (shortcuts.length > 0) {
    setAdvertisementText("Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to show dialog with more options");
  }
}
 
Example #18
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@Nonnull FindUsagesOptions options, @Nonnull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!options.searchScope.equals(maximalScope)) {
      return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in " + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example #19
Source File: ToolbarComboBoxAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateTooltipText(String description) {
  String tooltip = KeymapUtil.createTooltipText(description, ToolbarComboBoxAction.this);
  if (Registry.is("ide.helptooltip.enabled") && StringUtil.isNotEmpty(tooltip)) {
    HelpTooltip.dispose(this);
    new HelpTooltip().setDescription(tooltip).setLocation(HelpTooltip.Alignment.BOTTOM).installOn(this);
  }
  else {
    setToolTipText(!tooltip.isEmpty() ? tooltip : null);
  }
}
 
Example #20
Source File: EditorSearchSession.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private String getEmptyText() {
  if (myFindModel.isGlobal() || !myFindModel.getStringToFind().isEmpty()) return "";
  String text = getEditor().getSelectionModel().getSelectedText();
  if (text != null && text.contains("\n")) {
    boolean replaceState = myFindModel.isReplaceState();
    AnAction action = ActionManager.getInstance().getAction(replaceState ? IdeActions.ACTION_REPLACE : IdeActions.ACTION_TOGGLE_FIND_IN_SELECTION_ONLY);
    Shortcut shortcut = ArrayUtil.getFirstElement(action.getShortcutSet().getShortcuts());
    if (shortcut != null) {
      return ApplicationBundle.message("editorsearch.in.selection.with.hint", KeymapUtil.getShortcutText(shortcut));
    }
  }
  return ApplicationBundle.message("editorsearch.in.selection");
}
 
Example #21
Source File: AbstractSlingServerNodeDescriptor.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public static boolean addShortcutText(String actionId, CompositeAppearance appearance) {
    Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] shortcuts = activeKeymap.getShortcuts(actionId);
    if (shortcuts != null && shortcuts.length > 0) {
        appearance.getEnding().addText(" (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
        return true;
    } else return false;
}
 
Example #22
Source File: SwitchToFind.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  if (KeymapUtil.isEmacsKeymap()) {
    // Emacs users are accustomed to the editor that executes 'find next' on subsequent pressing of shortcut that
    // activates 'incremental search'. Hence, we do the similar hack here for them.
    ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT).actionPerformed(e);
    return;
  }

  EditorSearchSession search = e.getRequiredData(EditorSearchSession.SESSION_KEY);
  final FindModel findModel = search.getFindModel();
  FindUtil.configureFindModel(false, e.getDataContext().getData(EDITOR), findModel, false);
  search.getComponent().getSearchTextComponent().selectAll();
}
 
Example #23
Source File: SwitchToFind.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  if (KeymapUtil.isEmacsKeymap()) {
    // Emacs users are accustomed to the editor that executes 'find next' on subsequent pressing of shortcut that
    // activates 'incremental search'. Hence, we do the similar hack here for them.
    ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT).update(e);
  }
  else {
    EditorSearchSession search = e.getData(EditorSearchSession.SESSION_KEY);
    e.getPresentation().setEnabledAndVisible(search != null);
  }
}
 
Example #24
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options,
    @NotNull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
      return "Press "
          + KeymapUtil.getShortcutText(getShowUsagesShortcut())
          + " again to search in "
          + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example #25
Source File: IntentionHintComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void onMouseEnter(final boolean small) {
  myIconLabel.setIcon(myHighlightedIcon);
  myPanel.setBorder(small ? createActiveBorderSmall() : createActiveBorder());

  String acceleratorsText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
  if (!acceleratorsText.isEmpty()) {
    myIconLabel.setToolTipText(CodeInsightBundle.message("lightbulb.tooltip", acceleratorsText));
  }
}
 
Example #26
Source File: ShowAutoImportPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getMessage(final boolean multiple, @Nonnull String name) {
  final String messageKey = multiple ? "import.popup.multiple" : "import.popup.text";
  String hintText = DaemonBundle.message(messageKey, name);
  hintText += " " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
  return hintText;
}
 
Example #27
Source File: DaemonTooltipWithActionRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ShowDocAction(TooltipReloader tooltipReloader, boolean enabled) {
  super("Show Inspection Description");
  myTooltipReloader = tooltipReloader;
  myEnabled = enabled;

  setShortcutSet(KeymapUtil.getActiveKeymapShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION));
}
 
Example #28
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static BrowseMode getBrowseMode(@JdkConstants.InputEventMask int modifiers) {
  if (modifiers != 0) {
    final Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    if (KeymapUtil.matchActionMouseShortcutsModifiers(activeKeymap, modifiers, IdeActions.ACTION_GOTO_DECLARATION)) return BrowseMode.Declaration;
    if (KeymapUtil.matchActionMouseShortcutsModifiers(activeKeymap, modifiers, IdeActions.ACTION_GOTO_TYPE_DECLARATION)) return BrowseMode.TypeDeclaration;
    if (KeymapUtil.matchActionMouseShortcutsModifiers(activeKeymap, modifiers, IdeActions.ACTION_GOTO_IMPLEMENTATION)) return BrowseMode.Implementation;
  }
  return BrowseMode.None;
}
 
Example #29
Source File: HighlightUsagesHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getShortcutText() {
  final Shortcut[] shortcuts = ActionManager.getInstance()
          .getAction(IdeActions.ACTION_HIGHLIGHT_USAGES_IN_FILE)
          .getShortcutSet()
          .getShortcuts();
  if (shortcuts.length == 0) {
    return "<no key assigned>";
  }
  return KeymapUtil.getShortcutText(shortcuts[0]);
}
 
Example #30
Source File: TaskDefaultFavoriteListProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showNotePopup(Project project,
                           final DnDAwareTree tree,
                           final Consumer<String> after, final String initText) {
  final JTextArea textArea = new JTextArea(3, 50);
  textArea.setFont(UIUtil.getTreeFont());
  textArea.setText(initText);
  final JBScrollPane pane = new JBScrollPane(textArea);
  final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea)
    .setCancelOnClickOutside(true)
    .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish")
    .setTitle("Comment")
    .setMovable(true)
    .setRequestFocus(true).setResizable(true).setMayBeParent(true);
  final JBPopup popup = builder.createPopup();
  final JComponent content = popup.getContent();
  final AnAction action = new AnAction() {
    @Override
    public void actionPerformed(AnActionEvent e) {
      popup.closeOk(e.getInputEvent());
      unregisterCustomShortcutSet(content);
      after.consume(textArea.getText());
    }
  };
  action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      popup.showInCenterOf(tree);
    }
  }, ModalityState.NON_MODAL, project.getDisposed());
}