Search in sources :

Example 11 with LocalTask

use of com.intellij.tasks.LocalTask 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)

Example 12 with LocalTask

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

the class VcsOpenTaskPanel method commit.

@Override
public void commit() {
    myTaskManager.getState().createChangelist = myCreateChangelist.isSelected();
    myTaskManager.getState().createBranch = myCreateBranch.isSelected();
    myTaskManager.getState().useBranch = myUseBranch.isSelected();
    LocalTask localTask = myTaskManager.getActiveTask();
    if (myCreateChangelist.isSelected()) {
        myTaskManager.createChangeList(localTask, myChangelistName.getText());
    }
    if (myCreateBranch.isSelected()) {
        VcsTaskHandler.TaskInfo branchFrom = (VcsTaskHandler.TaskInfo) myBranchFrom.getSelectedItem();
        Runnable createBranch = () -> myTaskManager.createBranch(localTask, myPreviousTask, myBranchName.getText(), branchFrom);
        VcsTaskHandler.TaskInfo[] current = myVcsTaskHandler.getCurrentTasks();
        if (branchFrom != null && (current.length == 0 || !current[0].equals(branchFrom))) {
            myVcsTaskHandler.switchToTask(branchFrom, createBranch);
        } else {
            createBranch.run();
        }
    }
    if (myUseBranch.isSelected()) {
        VcsTaskHandler.TaskInfo branch = (VcsTaskHandler.TaskInfo) myUseBranchCombo.getSelectedItem();
        if (branch != null) {
            VcsTaskHandler.TaskInfo[] tasks = myVcsTaskHandler.getCurrentTasks();
            TaskManagerImpl.addBranches(myPreviousTask, tasks, true);
            myVcsTaskHandler.switchToTask(branch, () -> TaskManagerImpl.addBranches(localTask, new VcsTaskHandler.TaskInfo[] { branch }, false));
        }
    }
}
Also used : VcsTaskHandler(com.intellij.openapi.vcs.VcsTaskHandler) LocalTask(com.intellij.tasks.LocalTask)

Example 13 with LocalTask

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

the class ShowTaskDescription method update.

@Override
public void update(AnActionEvent event) {
    super.update(event);
    if (event.getPresentation().isEnabled()) {
        final Presentation presentation = event.getPresentation();
        final LocalTask activeTask = getActiveTask(event);
        presentation.setEnabled(activeTask != null && activeTask.isIssue() && activeTask.getDescription() != null);
        if (activeTask == null || !activeTask.isIssue()) {
            presentation.setText(getTemplatePresentation().getText());
        } else {
            presentation.setText("Show '" + activeTask.getPresentableName() + "' _Description");
        }
    }
}
Also used : LocalTask(com.intellij.tasks.LocalTask) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 14 with LocalTask

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

the class ShowTaskDescription method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getProject(e);
    assert project != null;
    final LocalTask task = getActiveTask(e);
    FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.quickjavadoc.ctrln");
    CommandProcessor.getInstance().executeCommand(project, () -> DocumentationManager.getInstance(project).showJavaDocInfo(new TaskPsiElement(PsiManager.getInstance(project), task), null), getCommandName(), null);
}
Also used : Project(com.intellij.openapi.project.Project) LocalTask(com.intellij.tasks.LocalTask) TaskPsiElement(com.intellij.tasks.doc.TaskPsiElement)

Example 15 with LocalTask

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

the class SwitchTaskAction method removeTask.

public static void removeTask(@NotNull final Project project, LocalTask task, TaskManager manager) {
    if (task.isDefault()) {
        Messages.showInfoMessage(project, "Default task cannot be removed", "Cannot Remove");
    } else {
        List<ChangeListInfo> infos = task.getChangeLists();
        List<LocalChangeList> lists = ContainerUtil.mapNotNull(infos, (NullableFunction<ChangeListInfo, LocalChangeList>) changeListInfo -> {
            LocalChangeList changeList = ChangeListManager.getInstance(project).getChangeList(changeListInfo.id);
            return changeList != null && !changeList.isDefault() ? changeList : null;
        });
        boolean removeIt = true;
        l: for (LocalChangeList list : lists) {
            if (!list.getChanges().isEmpty()) {
                int result = Messages.showYesNoCancelDialog(project, "Changelist associated with '" + task.getSummary() + "' is not empty.\n" + "Do you want to remove it and move the changes to the active changelist?", "Changelist Not Empty", Messages.getWarningIcon());
                switch(result) {
                    case Messages.YES:
                        break l;
                    case Messages.NO:
                        removeIt = false;
                        break;
                    default:
                        return;
                }
            }
        }
        if (removeIt) {
            for (LocalChangeList list : lists) {
                ChangeListManager.getInstance(project).removeChangeList(list);
            }
        }
        manager.removeTask(task);
    }
}
Also used : TaskSettings(com.intellij.tasks.config.TaskSettings) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) TaskManagerImpl(com.intellij.tasks.impl.TaskManagerImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) ActionCommand(com.intellij.openapi.ui.playback.commands.ActionCommand) Comparing(com.intellij.openapi.util.Comparing) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) LocalTask(com.intellij.tasks.LocalTask) ComboBoxAction(com.intellij.openapi.actionSystem.ex.ComboBoxAction) DumbAware(com.intellij.openapi.project.DumbAware) DataManager(com.intellij.ide.DataManager) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) StringUtil(com.intellij.openapi.util.text.StringUtil) SimpleActionGroup(com.intellij.tools.SimpleActionGroup) NullableFunction(com.intellij.util.NullableFunction) com.intellij.openapi.ui.popup(com.intellij.openapi.ui.popup) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) ChangeListInfo(com.intellij.tasks.ChangeListInfo) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) Collections(java.util.Collections) TaskManager(com.intellij.tasks.TaskManager) javax.swing(javax.swing) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) ChangeListInfo(com.intellij.tasks.ChangeListInfo)

Aggregations

LocalTask (com.intellij.tasks.LocalTask)19 Project (com.intellij.openapi.project.Project)7 TaskManager (com.intellij.tasks.TaskManager)7 LocalTaskImpl (com.intellij.tasks.impl.LocalTaskImpl)6 Repository (com.intellij.dvcs.repo.Repository)4 Task (com.intellij.tasks.Task)4 TaskPsiElement (com.intellij.tasks.doc.TaskPsiElement)3 TaskManagerImpl (com.intellij.tasks.impl.TaskManagerImpl)3 ActionEvent (java.awt.event.ActionEvent)3 NotNull (org.jetbrains.annotations.NotNull)3 TaskRepository (com.intellij.tasks.TaskRepository)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 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 ComboBoxAction (com.intellij.openapi.actionSystem.ex.ComboBoxAction)1