void (@NotNull AnActionEvent e) { final Project project = getProject(e); assert project != null; DefaultActionGroup group = new DefaultActionGroup(); final WorkingContextManager manager = WorkingContextManager.getInstance(project); List<ContextInfo> history = manager.getContextHistory(); List<ContextHolder> infos = new ArrayList<>(ContainerUtil.map(history, info -> new ContextHolder() { @Override void load(final boolean clear) { LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, info.name); UndoableCommand.execute(project, undoableAction, TaskBundle.message("command.name.load.context", info.comment), "Context"); } @Override void remove() { manager.removeContext(info.name); } @Override Date getDate() { return new Date(info.date); } @Override String getComment() { return info.comment; } @Override Icon getIcon() { return TasksCoreIcons.SavedContext; } })); final TaskManager taskManager = TaskManager.getManager(project); List<LocalTask> tasks = taskManager.getLocalTasks(); infos.addAll(ContainerUtil.mapNotNull(tasks, (NullableFunction<LocalTask, ContextHolder>)task -> { if (task.isActive()) { return null; } return new ContextHolder() { @Override void load(boolean clear) { LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, task); UndoableCommand.execute(project, undoableAction, TaskBundle.message("command.name.load.context", TaskUtil.getTrimmedSummary(task)), "Context"); } @Override void remove() { SwitchTaskAction.removeTask(project, task, taskManager); } @Override Date getDate() { return task.getUpdated(); } @Override String getComment() { return TaskUtil.getTrimmedSummary(task); } @Override Icon getIcon() { return task.getIcon(); } }; })); infos.sort((o1, o2) -> o2.getDate().compareTo(o1.getDate())); final Ref<Boolean> shiftPressed = Ref.create(false); boolean today = true; Calendar now = Calendar.getInstance(); for (final ContextHolder info : infos) { Calendar calendar = Calendar.getInstance(); calendar.setTime(info.getDate()); if (today && (calendar.get(Calendar.YEAR) != now.get(Calendar.YEAR) || calendar.get(Calendar.DAY_OF_YEAR) != now.get(Calendar.DAY_OF_YEAR))) { group.addSeparator(); today = false; } group.add(createItem(info, shiftPressed)); } ListPopup popup = JBPopupFactory.getInstance() .createActionGroupPopup(TaskBundle.message("popup.title.load.context"), group, e.getDataContext(), false, null, MAX_ROW_COUNT); var popupImpl = (popup instanceof ListPopupImpl) ? (ListPopupImpl)popup : null; if (popupImpl != null) { //todo: RDCT-627 popupImpl.setAdText(TaskBundle.message("popup.advertisement.press.shift.to.merge.with.current.context")); 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.load.context")); } }); popupImpl.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { popup.handleSelect(true); } }); } popup.showCenteredInCurrentWindow(project); }