Search in sources :

Example 1 with TaskManager

use of com.intellij.tasks.TaskManager in project intellij-community by JetBrains.

the class SwitchTaskAction method createActionsStep.

private static ActionGroup createActionsStep(final List<TaskListItem> tasks, final Project project, final Ref<Boolean> shiftPressed) {
    SimpleActionGroup group = new SimpleActionGroup();
    final TaskManager manager = TaskManager.getManager(project);
    final LocalTask task = tasks.get(0).getTask();
    if (tasks.size() == 1 && task != null) {
        group.add(new AnAction("&Switch to") {

            public void actionPerformed(AnActionEvent e) {
                manager.activateTask(task, !shiftPressed.get());
            }
        });
        group.add(new AnAction("&Edit") {

            @Override
            public void actionPerformed(AnActionEvent e) {
                EditTaskDialog.editTask((LocalTaskImpl) task, project);
            }
        });
    }
    final AnAction remove = new AnAction("&Remove") {

        @Override
        public void actionPerformed(AnActionEvent e) {
            for (TaskListItem item : tasks) {
                LocalTask itemTask = item.getTask();
                if (itemTask != null) {
                    removeTask(project, itemTask, manager);
                }
            }
        }
    };
    remove.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)), null);
    group.add(remove);
    return group;
}
Also used : SimpleActionGroup(com.intellij.tools.SimpleActionGroup) TaskManager(com.intellij.tasks.TaskManager) LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) LocalTask(com.intellij.tasks.LocalTask)

Example 2 with TaskManager

use of com.intellij.tasks.TaskManager in project intellij-community by JetBrains.

the class SwitchTaskAction method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null || project.isDefault() || project.isDisposed()) {
        presentation.setEnabled(false);
        presentation.setText("");
        presentation.setIcon(null);
    } else {
        TaskManager taskManager = TaskManager.getManager(project);
        LocalTask activeTask = taskManager.getActiveTask();
        presentation.setVisible(true);
        presentation.setEnabled(true);
        if (isImplicit(activeTask) && taskManager.getAllRepositories().length == 0 && !TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO) {
            presentation.setVisible(false);
        } else {
            String s = getText(activeTask);
            presentation.setText(s);
            presentation.setIcon(activeTask.getIcon());
            presentation.setDescription(activeTask.getSummary());
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) TaskManager(com.intellij.tasks.TaskManager) LocalTask(com.intellij.tasks.LocalTask)

Example 3 with TaskManager

use of com.intellij.tasks.TaskManager in project intellij-community by JetBrains.

the class GotoTaskAction method perform.

void perform(final Project project) {
    final Ref<Boolean> shiftPressed = Ref.create(false);
    final ChooseByNamePopup popup = createPopup(project, new GotoTaskPopupModel(project), new TaskItemProvider(project));
    popup.setShowListForEmptyPattern(true);
    popup.setSearchInAnyPlace(true);
    popup.setAlwaysHasMore(true);
    popup.setAdText("<html>Press SHIFT to merge with current context<br/>" + "Pressing " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) + " would show task description and comments</html>");
    popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(true);
        }
    });
    popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(false);
        }
    });
    final DefaultActionGroup group = new DefaultActionGroup(new ConfigureServersAction() {

        @Override
        protected void serversChanged() {
            popup.rebuildList(true);
        }
    });
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
    actionToolbar.updateActionsImmediately();
    actionToolbar.getComponent().setFocusable(false);
    actionToolbar.getComponent().setBorder(null);
    popup.setToolArea(actionToolbar.getComponent());
    popup.setMaximumListSizeLimit(PAGE_SIZE);
    popup.setListSizeIncreasing(PAGE_SIZE);
    showNavigationPopup(new GotoActionCallback<Object>() {

        @Override
        public void elementChosen(ChooseByNamePopup popup, Object element) {
            TaskManager taskManager = TaskManager.getManager(project);
            if (element instanceof TaskPsiElement) {
                Task task = ((TaskPsiElement) element).getTask();
                LocalTask localTask = taskManager.findTask(task.getId());
                if (localTask != null) {
                    taskManager.activateTask(localTask, !shiftPressed.get());
                } else {
                    showOpenTaskDialog(project, task);
                }
            } else if (element == CREATE_NEW_TASK_ACTION) {
                LocalTask localTask = taskManager.createLocalTask(CREATE_NEW_TASK_ACTION.getTaskName());
                showOpenTaskDialog(project, localTask);
            }
        }
    }, null, popup);
}
Also used : Task(com.intellij.tasks.Task) LocalTask(com.intellij.tasks.LocalTask) ActionEvent(java.awt.event.ActionEvent) LocalTask(com.intellij.tasks.LocalTask) TaskPsiElement(com.intellij.tasks.doc.TaskPsiElement) TaskManager(com.intellij.tasks.TaskManager)

Example 4 with TaskManager

use of com.intellij.tasks.TaskManager in project intellij-community by JetBrains.

the class TaskItemProvider method filterElements.

@Override
public boolean filterElements(@NotNull ChooseByNameBase base, @NotNull final String pattern, final boolean everywhere, @NotNull final ProgressIndicator cancelled, @NotNull Processor<Object> consumer) {
    GotoTaskAction.CREATE_NEW_TASK_ACTION.setTaskName(pattern);
    if (!consumer.process(GotoTaskAction.CREATE_NEW_TASK_ACTION))
        return false;
    TaskManager taskManager = TaskManager.getManager(myProject);
    List<Task> allCachedAndLocalTasks = ContainerUtil.concat(taskManager.getCachedIssues(), taskManager.getLocalTasks());
    List<Task> filteredCachedAndLocalTasks = TaskSearchSupport.getLocalAndCachedTasks(taskManager, pattern, everywhere);
    if (!processTasks(filteredCachedAndLocalTasks, consumer, cancelled))
        return false;
    if (filteredCachedAndLocalTasks.size() >= base.getMaximumListSizeLimit()) {
        return true;
    }
    if (myDisposed) {
        return false;
    }
    int delay = myFutureReference.get() == null && pattern.length() > 5 ? 0 : DELAY_PERIOD;
    Future<List<Task>> future = JobScheduler.getScheduler().schedule(() -> fetchFromServer(pattern, everywhere, cancelled), delay, TimeUnit.MILLISECONDS);
    // Newer request always wins
    Future<List<Task>> oldFuture = myFutureReference.getAndSet(future);
    if (oldFuture != null) {
        LOG.debug("Cancelling existing task");
        oldFuture.cancel(true);
    }
    try {
        List<Task> tasks;
        while (true) {
            try {
                tasks = future.get(10, TimeUnit.MILLISECONDS);
                break;
            } catch (TimeoutException ignore) {
            }
        }
        myFutureReference.compareAndSet(future, null);
        // Exclude *all* cached and local issues, not only those returned by TaskSearchSupport.getLocalAndCachedTasks().
        // Previously used approach might lead to the following strange behavior. Local task excluded by getLocalAndCachedTasks()
        // as "locally closed" (i.e. having no associated change list) was indeed *included* in popup because it
        // was contained in server response (as not remotely closed). Moreover on next request with pagination when the
        // same issues was not returned again by server it was *excluded* from popup (thus subsequent update reduced total
        // number of items shown).
        tasks.removeAll(allCachedAndLocalTasks);
        return processTasks(tasks, consumer, cancelled);
    } catch (InterruptedException interrupted) {
        Thread.interrupted();
    } catch (CancellationException e) {
        LOG.debug("Task cancelled");
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof ProcessCanceledException) {
            LOG.debug("Task cancelled via progress indicator");
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else if (cause instanceof Error) {
            throw (Error) cause;
        } else {
            throw new RuntimeException("Unknown checked exception", cause);
        }
    }
    return false;
}
Also used : Task(com.intellij.tasks.Task) TaskManager(com.intellij.tasks.TaskManager) List(java.util.List) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with TaskManager

use of com.intellij.tasks.TaskManager in project intellij-community by JetBrains.

the class LoadContextAction method actionPerformed.

@Override
public void actionPerformed(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.map2List(history, (Function<ContextInfo, ContextHolder>) info -> new ContextHolder() {

        @Override
        void load(final boolean clear) {
            LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, info.name);
            UndoableCommand.execute(project, undoableAction, "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 TasksIcons.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, "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();
            }
        };
    }));
    Collections.sort(infos, (o1, o2) -> o2.getDate().compareTo(o1.getDate()));
    final Ref<Boolean> shiftPressed = Ref.create(false);
    boolean today = true;
    Calendar now = Calendar.getInstance();
    for (int i = 0, historySize = Math.min(MAX_ROW_COUNT, infos.size()); i < historySize; i++) {
        final ContextHolder info = infos.get(i);
        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));
    }
    final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createActionGroupPopup("Load Context", group, e.getDataContext(), false, null, MAX_ROW_COUNT);
    popup.setAdText("Press SHIFT to merge with current context");
    popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(true);
            popup.setCaption("Merge with Current Context");
        }
    });
    popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(false);
            popup.setCaption("Load Context");
        }
    });
    popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            popup.handleSelect(true);
        }
    });
    popup.addPopupListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
        }
    });
    popup.showCenteredInCurrentWindow(project);
}
Also used : ActionEvent(java.awt.event.ActionEvent) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) NullableFunction(com.intellij.util.NullableFunction) Function(com.intellij.util.Function) ContextInfo(com.intellij.tasks.context.ContextInfo) WorkingContextManager(com.intellij.tasks.context.WorkingContextManager) LocalTask(com.intellij.tasks.LocalTask) NullableFunction(com.intellij.util.NullableFunction) Project(com.intellij.openapi.project.Project) LoadContextUndoableAction(com.intellij.tasks.context.LoadContextUndoableAction) TaskManager(com.intellij.tasks.TaskManager) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter)

Aggregations

TaskManager (com.intellij.tasks.TaskManager)12 LocalTask (com.intellij.tasks.LocalTask)7 Project (com.intellij.openapi.project.Project)5 LocalChangeList (com.intellij.openapi.vcs.changes.LocalChangeList)3 Task (com.intellij.tasks.Task)3 ActionEvent (java.awt.event.ActionEvent)3 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)2 TaskPsiElement (com.intellij.tasks.doc.TaskPsiElement)2 LocalTaskImpl (com.intellij.tasks.impl.LocalTaskImpl)2 TaskManagerImpl (com.intellij.tasks.impl.TaskManagerImpl)2 SimpleActionGroup (com.intellij.tools.SimpleActionGroup)2 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)2 NullableFunction (com.intellij.util.NullableFunction)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 DataManager (com.intellij.ide.DataManager)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1