ListPopup (@NotNull DataContext dataContext, @Nullable Runnable onDispose, boolean withTitle) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); final Ref<Boolean> shiftPressed = Ref.create(false); List<TaskListItem> items = project == null ? Collections.emptyList() : createPopupActionGroup(project, shiftPressed, PlatformCoreDataKeys.CONTEXT_COMPONENT.getData(dataContext)); final String title = withTitle ? TaskBundle.message("popup.title.switch.to.task") : null; ListPopupStep<TaskListItem> step = new MultiSelectionListPopupStep<>(title, items) { @Override public PopupStep<?> onChosen(List<TaskListItem> selectedValues, boolean finalChoice) { if (finalChoice) { selectedValues.get(0).select(); return FINAL_CHOICE; } ActionGroup group = createActionsStep(selectedValues, project, shiftPressed); DataContext dataContext = DataContext.EMPTY_CONTEXT; return JBPopupFactory.getInstance().createActionsStep( group, dataContext, null, false, false, null, null, true, 0, false); } @Override public Icon getIconFor(TaskListItem aValue) { return aValue.getIcon(); } @NotNull @Override public String getTextFor(TaskListItem value) { return value.getText(); } @Nullable @Override public ListSeparator getSeparatorAbove(TaskListItem value) { return value.getSeparator() == null ? null : new ListSeparator(value.getSeparator()); } @Override public boolean hasSubstep(List<? extends TaskListItem> selectedValues) { return selectedValues.size() > 1 || selectedValues.get(0).getTask() != null; } @Override public boolean isSpeedSearchEnabled() { return true; } }; final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step); if (onDispose != null) { Disposer.register(popup, new Disposable() { @Override public void dispose() { onDispose.run(); } }); } if (items.size() <= 2) { return popup; } popup.setAdText(TaskBundle.message("popup.advertisement.press.shift.to.merge.with.current.context"), SwingConstants.LEFT); var popupImpl = (popup instanceof ListPopupImpl) ? (ListPopupImpl)popup : null; if (popupImpl == null) return popup; //todo: RDCT-627 popupImpl.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { shiftPressed.set(true); popup.setCaption(TaskBundle.message("popup.title.merge.with.current.context")); } }); popupImpl.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { shiftPressed.set(false); popup.setCaption(TaskBundle.message("popup.title.switch.to.task")); } }); popupImpl.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { popup.handleSelect(true); } }); return popup; }