com.intellij.ui.popup.PopupFactoryImpl Java Examples

The following examples show how to use com.intellij.ui.popup.PopupFactoryImpl. 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: WelcomePopupAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void showPopup(DataContext context, ListPopup popup, JComponent contextComponent) {
  Component focusedComponent = contextComponent != null ? contextComponent : context.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (focusedComponent != null) {
    if (popup instanceof PopupFactoryImpl.ActionGroupPopup && focusedComponent instanceof JLabel) {
      ((PopupFactoryImpl.ActionGroupPopup)popup).showUnderneathOfLabel((JLabel)focusedComponent);
    } else {
      popup.showUnderneathOf(focusedComponent);
    }
  }
  else {
    Rectangle r;
    int x;
    int y;
    focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent((Project)null);
    r = WindowManagerEx.getInstanceEx().getScreenBounds();
    x = r.x + r.width / 2;
    y = r.y + r.height / 2;
    Point point = new Point(x, y);
    SwingUtilities.convertPointToScreen(point, focusedComponent.getParent());

    popup.showInScreenCoordinates(focusedComponent.getParent(), point);
  }
}
 
Example #2
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showHintInEditor(AbstractPopup hint, Editor editor, Context context) {
  closeHint();
  myMouseMovementTracker.reset();
  myKeepPopupOnMouseMove = false;
  editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, context.getPopupPosition(editor));
  try {
    PopupPositionManager.positionPopupInBestPosition(hint, editor, null);
  }
  finally {
    editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
  }
  Window window = hint.getPopupWindow();
  if (window != null) {
    window.setFocusableWindowState(true);
    IdeEventQueue.getInstance().addDispatcher(e -> {
      if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getSource() == window) {
        myKeepPopupOnMouseMove = true;
      }
      return false;
    }, hint);
  }
}
 
Example #3
Source File: RunAnythingChooseContextAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) {
    return;
  }

  JComponent component = e.getPresentation().getClientProperty(CustomComponentAction.COMPONENT_KEY);
  if (component == null) {
    return;
  }

  Runnable updateToolbar = () -> {
    ActionToolbar toolbar = UIUtil.uiParents(component, true).filter(ActionToolbar.class).first();
    toolbar.updateActionsImmediately();
  };

  DataContext dataContext = e.getDataContext();
  List<PopupFactoryImpl.ActionItem> actionItems = ActionPopupStep.createActionItems(new DefaultActionGroup(createItems()), dataContext, false, false, true, true, ActionPlaces.POPUP, null);

  ChooseContextPopup popup = new ChooseContextPopup(new ChooseContextPopupStep(actionItems, dataContext, updateToolbar), dataContext);
  popup.setSize(new Dimension(300, 300));
  popup.setRequestFocus(false);
  popup.showUnderneathOf(component);
}
 
Example #4
Source File: FlatWelcomePanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private JComponent createActionLink(final String text, final String groupId, Icon icon, boolean focusListOnLeft) {
  final Ref<ActionLink> ref = new Ref<>(null);
  AnAction action = new AnAction() {
    @RequiredUIAccess
    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      ActionGroup configureGroup = (ActionGroup)ActionManager.getInstance().getAction(groupId);
      final PopupFactoryImpl.ActionGroupPopup popup = (PopupFactoryImpl.ActionGroupPopup)JBPopupFactory.getInstance()
              .createActionGroupPopup(null, new IconsFreeActionGroup(configureGroup), e.getDataContext(), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false, ActionPlaces.WELCOME_SCREEN);
      popup.showUnderneathOfLabel(ref.get());
      UsageTrigger.trigger("welcome.screen." + groupId);
    }
  };
  JComponent panel = createActionLink(text, icon, ref, action);
  installFocusable(panel, action, KeyEvent.VK_UP, KeyEvent.VK_DOWN, focusListOnLeft);
  return panel;
}
 
Example #5
Source File: RequestRunnable.java    From GoogleTranslation with Apache License 2.0 5 votes vote down vote up
private void showPopupBalloon(final String result) {
    ApplicationManager.getApplication().invokeLater(() -> {
        mEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);//解决因为TranslationPlugin而导致的泡泡显示错位问题
        JBPopupFactory factory = JBPopupFactory.getInstance();
        factory.createHtmlTextBalloonBuilder(result, null, new JBColor(Gray._242, Gray._0), null)
                .createBalloon()
                .show(factory.guessBestPopupLocation(mEditor), Balloon.Position.below);
    });
}
 
Example #6
Source File: QuickRunMavenGoalAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
private void registerActions(final ListPopupImpl popup) {
	if (ApplicationSettings.get().isEnableDelete()) {
		popup.registerAction("delete", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), new AbstractAction() {
			public void actionPerformed(ActionEvent e) {
				JList list = popup.getList();
				int selectedIndex = list.getSelectedIndex();
				ListPopupModel model = (ListPopupModel) list.getModel();
				PopupFactoryImpl.ActionItem selectedItem = (PopupFactoryImpl.ActionItem) model.get(selectedIndex);

				if (selectedItem != null && selectedItem.getAction() instanceof MyActionGroup) {
					MyActionGroup action = (MyActionGroup) selectedItem.getAction();
					boolean deleted = ApplicationService.getInstance().getState().removeGoal(action.getGoal());

					if (deleted) {
						model.deleteItem(selectedItem);
						if (selectedIndex == list.getModel().getSize()) { // is last
							list.setSelectedIndex(selectedIndex - 1);
						} else {
							list.setSelectedIndex(selectedIndex);
						}
					}
				}
			}
		});

	}
}
 
Example #7
Source File: FlatSpeedSearchPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static <T> T getSpecificAction(Object value, @Nonnull Class<T> clazz) {
  if (value instanceof PopupFactoryImpl.ActionItem) {
    AnAction action = ((PopupFactoryImpl.ActionItem)value).getAction();
    if (clazz.isInstance(action)) {
      return clazz.cast(action);
    }
    else if (action instanceof EmptyAction.MyDelegatingActionGroup) {
      ActionGroup group = ((EmptyAction.MyDelegatingActionGroup)action).getDelegate();
      return clazz.isInstance(group) ? clazz.cast(group) : null;
    }
  }
  return null;
}
 
Example #8
Source File: RunAnythingChooseContextAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected ListCellRenderer getListElementRenderer() {
  return new PopupListElementRenderer<PopupFactoryImpl.ActionItem>(this) {
    private JLabel myInfoLabel;

    @Override
    protected JComponent createItemComponent() {
      myTextLabel = new ErrorLabel();
      myInfoLabel = new JLabel();
      myTextLabel.setBorder(JBUI.Borders.empty(10));

      JPanel textPanel = new JPanel(new BorderLayout());
      textPanel.add(myTextLabel, BorderLayout.WEST);
      textPanel.add(myInfoLabel, BorderLayout.CENTER);
      return layoutComponent(textPanel);
    }

    @Override
    protected void customizeComponent(JList<? extends PopupFactoryImpl.ActionItem> list, PopupFactoryImpl.ActionItem actionItem, boolean isSelected) {
      AnActionEvent event = ActionUtil.createEmptyEvent();
      ActionUtil.performDumbAwareUpdate(true, actionItem.getAction(), event, false);

      String description = event.getPresentation().getDescription();
      if (description != null) {
        myInfoLabel.setText(description);
      }

      myTextLabel.setText(event.getPresentation().getText());
      myInfoLabel.setForeground(isSelected ? UIUtil.getListSelectionForeground(true) : UIUtil.getInactiveTextColor());
    }
  };
}
 
Example #9
Source File: RunAnythingChooseContextAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ListSeparator getSeparatorAbove(PopupFactoryImpl.ActionItem value) {
  AnAction action = value.getAction();
  if (action instanceof BrowseDirectoryItem) {
    return new ListSeparator(IdeBundle.message("run.anything.context.separator.directories"));
  }
  else if (action instanceof ModuleItem && action == ContainerUtil.filter(myActions, it -> it.getAction() instanceof ModuleItem).get(0).getAction()) {
    return new ListSeparator(IdeBundle.message("run.anything.context.separator.modules"));
  }
  return super.getSeparatorAbove(value);
}
 
Example #10
Source File: SymfonyProfilerWidget.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ListPopup getPopupStep() {
    ActionGroup popupGroup = getActions();
    return new PopupFactoryImpl.ActionGroupPopup("Symfony Profiler", popupGroup, SimpleDataContext.getProjectContext(getProject()), false, false, false, true, null, -1, null, null);
}
 
Example #11
Source File: FlatSpeedSearchPopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean shouldBeShowing(Object value) {
  if (!super.shouldBeShowing(value)) return false;
  if (!(value instanceof PopupFactoryImpl.ActionItem)) return true;
  return shouldBeShowing(((PopupFactoryImpl.ActionItem)value).getAction());
}
 
Example #12
Source File: QuickDocOnMouseOverManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  Ref<PsiElement> targetElementRef = new Ref<>();

  QuickDocUtil.runInReadActionWithWriteActionPriorityWithRetries(() -> {
    if (originalElement.isValid()) {
      targetElementRef.set(docManager.findTargetElement(editor, offset, originalElement.getContainingFile(), originalElement));
    }
  }, 5000, 100, myProgressIndicator);

  Ref<String> documentationRef = new Ref<>();
  if (!targetElementRef.isNull()) {
    try {
      documentationRef.set(docManager.generateDocumentation(targetElementRef.get(), originalElement, true));
    }
    catch (Exception e) {
      LOG.info(e);
    }
  }

  ApplicationManager.getApplication().invokeLater(() -> {
    myCurrentRequest = null;

    if (editor.isDisposed() || (IdeTooltipManager.getInstance().hasCurrent() || IdeTooltipManager.getInstance().hasScheduled()) && !docManager.hasActiveDockedDocWindow()) {
      return;
    }

    PsiElement targetElement = targetElementRef.get();
    String documentation = documentationRef.get();
    if (targetElement == null || StringUtil.isEmpty(documentation)) {
      closeQuickDocIfPossible();
      return;
    }

    myAlarm.cancelAllRequests();

    if (!originalElement.equals(SoftReference.dereference(myActiveElements.get(editor)))) {
      return;
    }

    // Skip the request if there is a control shown as a result of explicit 'show quick doc' (Ctrl + Q) invocation.
    if (docManager.getDocInfoHint() != null && !docManager.isCloseOnSneeze()) {
      return;
    }

    editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, editor.offsetToVisualPosition(originalElement.getTextRange().getStartOffset()));
    docManager.showJavaDocInfo(editor, targetElement, originalElement, new MyCloseDocCallback(editor), documentation, true, false);
    myDocumentationManager = new WeakReference<>(docManager);
  }, ApplicationManager.getApplication().getNoneModalityState());
}
 
Example #13
Source File: QuickDocOnMouseOverManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  myActiveElements.clear();
  myEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
  myDocumentationManager = null;
}
 
Example #14
Source File: RunAnythingChooseContextAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ChooseContextPopupStep(List<PopupFactoryImpl.ActionItem> actions, DataContext dataContext, Runnable updateToolbar) {
  super(actions, IdeBundle.message("run.anything.context.title.working.directory"), () -> dataContext, null, true, Conditions.alwaysFalse(), false, true, null);
  myActions = actions;
  myUpdateToolbar = updateToolbar;
}