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);
}
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));
}
}
}
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");
}
}
}
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);
}
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);
}
}
Aggregations