com.intellij.ui.popup.list.ListPopupImpl Java Examples

The following examples show how to use com.intellij.ui.popup.list.ListPopupImpl. 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: PopupFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) {
  final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, yesText, noText) {
    @Override
    public PopupStep onChosen(String selectedValue, final boolean finalChoice) {
      return doFinalStep(selectedValue.equals(yesText) ? onYes : onNo);
    }

    @Override
    public void canceled() {
      onNo.run();
    }

    @Override
    public boolean isMnemonicsNavigationEnabled() {
      return true;
    }
  };
  step.setDefaultOptionIndex(defaultOptionIndex);

  final Application app = ApplicationManager.getApplication();
  return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText);
}
 
Example #2
Source File: ExpressionInputComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showHistory() {
  List<XExpression> expressions = myExpressionEditor.getRecentExpressions();
  if (!expressions.isEmpty()) {
    ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {
      @Override
      public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
        myExpressionEditor.setExpression(selectedValue);
        myExpressionEditor.requestFocusInEditor();
        return FINAL_CHOICE;
      }
    }) {
      @Override
      protected ListCellRenderer getListElementRenderer() {
        return new ColoredListCellRenderer<XExpression>() {
          @Override
          protected void customizeCellRenderer(@Nonnull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
            append(value.getExpression());
          }
        };
      }
    };
    popup.getList().setFont(EditorUtil.getEditorFont());
    popup.showUnderneathOf(myExpressionEditor.getEditorComponent());
  }
}
 
Example #3
Source File: ChooseRunConfigurationPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Action createNumberAction(final int number, final ListPopupImpl listPopup, final Executor executor) {
  return new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      if (listPopup.getSpeedSearch().isHoldingFilter()) return;
      for (final Object item : listPopup.getListStep().getValues()) {
        if (item instanceof ItemWrapper && ((ItemWrapper)item).getMnemonic() == number) {
          listPopup.setFinalRunnable(new Runnable() {
            @Override
            public void run() {
              execute((ItemWrapper)item, executor);
            }
          });
          listPopup.closeOk(null);
        }
      }
    }
  };
}
 
Example #4
Source File: GotoRelatedFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Action createNumberAction(final int mnemonic,
                                         final ListPopupImpl listPopup,
                                         final Map<PsiElement, GotoRelatedItem> itemsMap,
                                         final Processor<Object> processor) {
  return new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      for (final Object item : listPopup.getListStep().getValues()) {
        if (getMnemonic(item, itemsMap) == mnemonic) {
          listPopup.setFinalRunnable(new Runnable() {
            @Override
            public void run() {
              processor.process(item);
            }
          });
          listPopup.closeOk(null);
        }
      }
    }
  };
}
 
Example #5
Source File: ProjectSettingsForm.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) {

		final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, new String[]{yesText, noText}) {
			@Override
			public PopupStep onChosen(String selectedValue, final boolean finalChoice) {
				if (selectedValue.equals(yesText)) {
					onYes.run();
				} else {
					onNo.run();
				}
				return FINAL_CHOICE;
			}

			@Override
			public void canceled() {
			}

			@Override
			public boolean isMnemonicsNavigationEnabled() {
				return true;
			}
		};
		step.setDefaultOptionIndex(defaultOptionIndex);

		final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
		return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText);
	}
 
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: WizardPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected WizardPopup createPopup(WizardPopup parent, PopupStep step, Object parentValue) {
  if (step instanceof AsyncPopupStep) {
    return new AsyncPopupImpl(getProject(), parent, (AsyncPopupStep)step, parentValue);
  }
  if (step instanceof ListPopupStep) {
    return new ListPopupImpl(getProject(), parent, (ListPopupStep)step, parentValue);
  }
  else if (step instanceof TreePopupStep) {
    return new TreePopupImpl(getProject(), parent, (TreePopupStep)step, parentValue);
  }
  else {
    throw new IllegalArgumentException(step.getClass().toString());
  }
}
 
Example #8
Source File: PopupFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ListPopup createListPopup(@Nonnull ListPopupStep step, int maxRowCount) {
  ListPopupImpl popup = new ListPopupImpl(step);
  popup.setMaxRowCount(maxRowCount);
  return popup;
}
 
Example #9
Source File: DebuggerUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void registerExtraHandleShortcuts(final ListPopupImpl popup, String... actionNames) {
  for (String name : actionNames) {
    KeyStroke stroke = KeymapUtil.getKeyStroke(ActionManager.getInstance().getAction(name).getShortcutSet());
    if (stroke != null) {
      popup.registerAction("handleSelection " + stroke, stroke, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
          popup.handleSelect(true);
        }
      });
    }
  }
}
 
Example #10
Source File: NavigationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Action createNumberAction(final int mnemonic, final ListPopupImpl listPopup, final Map<PsiElement, GotoRelatedItem> itemsMap, final Processor<Object> processor) {
  return new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      for (final Object item : listPopup.getListStep().getValues()) {
        if (getMnemonic(item, itemsMap) == mnemonic) {
          listPopup.setFinalRunnable(() -> processor.process(item));
          listPopup.closeOk(null);
        }
      }
    }
  };
}
 
Example #11
Source File: QuickRunMavenGoalAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
@Override
protected void showPopup(AnActionEvent e, ListPopup p) {
	final ListPopupImpl popup = (ListPopupImpl) p;
	registerActions(popup);
	super.showPopup(e, popup);
}
 
Example #12
Source File: PopupFactoryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public ListPopup createListPopup(@Nonnull ListPopupStep step) {
  return new ListPopupImpl(step);
}
 
Example #13
Source File: BranchActionGroupPopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
MyPopupListElementRenderer(ListPopupImpl aPopup) {
  super(aPopup);
}
 
Example #14
Source File: AttachToProcessActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  final Project project = getEventProject(e);
  if (project == null) return;


  new Task.Backgroundable(project, XDebuggerBundle.message("xdebugger.attach.action.collectingItems"), true, PerformInBackgroundOption.DEAF) {
    @Override
    public void run(@Nonnull ProgressIndicator indicator) {

      List<AttachItem> allItems = ContainerUtil.immutableList(getTopLevelItems(indicator, project));

      ApplicationManager.getApplication().invokeLater(() -> {
        AttachListStep step = new AttachListStep(allItems, XDebuggerBundle.message("xdebugger.attach.popup.title.default"), project);

        final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
        final JList mainList = ((ListPopupImpl)popup).getList();

        ListSelectionListener listener = event -> {
          if (event.getValueIsAdjusting()) return;

          Object item = ((JList)event.getSource()).getSelectedValue();

          // if a sub-list is closed, fallback to the selected value from the main list
          if (item == null) {
            item = mainList.getSelectedValue();
          }

          if (item instanceof AttachToProcessItem) {
            popup.setCaption(((AttachToProcessItem)item).getSelectedDebugger().getDebuggerSelectedTitle());
          }

          if (item instanceof AttachHostItem) {
            AttachHostItem hostItem = (AttachHostItem)item;
            String attachHostName = hostItem.getText(project);
            attachHostName = StringUtil.shortenTextWithEllipsis(attachHostName, 50, 0);

            popup.setCaption(XDebuggerBundle.message("xdebugger.attach.host.popup.title", attachHostName));
          }
        };
        popup.addListSelectionListener(listener);

        // force first valueChanged event
        listener.valueChanged(new ListSelectionEvent(mainList, mainList.getMinSelectionIndex(), mainList.getMaxSelectionIndex(), false));

        popup.showCenteredInCurrentWindow(project);
      }, project.getDisposed());
    }
  }.queue();
}
 
Example #15
Source File: PopupListElementRendererWithIcon.java    From consulo with Apache License 2.0 4 votes vote down vote up
public PopupListElementRendererWithIcon(ListPopupImpl aPopup) {
  super(aPopup);
}
 
Example #16
Source File: ChooseRunConfigurationPopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
private RunListElementRenderer(ListPopupImpl popup, boolean hasSideBar) {
  super(popup);

  myPopup1 = popup;
  myHasSideBar = hasSideBar;
}