mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
task search improved
This commit is contained in:
@@ -43,6 +43,8 @@ public abstract class TaskManager {
|
||||
|
||||
public abstract List<Task> getIssues(@Nullable String query, boolean forceRequest);
|
||||
|
||||
|
||||
public abstract List<Task> getIssues(String query, int max, long since, boolean forceRequest);
|
||||
/**
|
||||
* Returns already cached issues.
|
||||
* @return cached issues.
|
||||
@@ -54,8 +56,6 @@ public abstract class TaskManager {
|
||||
|
||||
public abstract LocalTask[] getLocalTasks();
|
||||
|
||||
public abstract List<LocalTask> getLocalTasks(String query);
|
||||
|
||||
public abstract LocalTask addTask(Task issue);
|
||||
|
||||
public abstract LocalTask createLocalTask(String summary);
|
||||
|
||||
@@ -11,14 +11,12 @@ import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskManager;
|
||||
import com.intellij.tasks.doc.TaskPsiElement;
|
||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||
import com.intellij.tasks.impl.TaskUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
@@ -28,7 +26,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -65,11 +62,52 @@ public class GotoTaskAction extends GotoActionBase {
|
||||
boolean everywhere,
|
||||
@NotNull ProgressIndicator cancelled,
|
||||
@NotNull Processor<Object> consumer) {
|
||||
Object[] elements = base.getModel().getElementsByName("", false, pattern);
|
||||
for (Object element : elements) {
|
||||
List<Task> cachedTasks = new TaskSearchSupport(project).getLocalAndCachedTasks(pattern);
|
||||
List<TaskPsiElement> taskPsiElements = ContainerUtil.map(cachedTasks, new Function<Task, TaskPsiElement>() {
|
||||
@Override
|
||||
public TaskPsiElement fun(Task task) {
|
||||
return new TaskPsiElement(PsiManager.getInstance(project), task);
|
||||
}
|
||||
});
|
||||
|
||||
CREATE_NEW_TASK_ACTION.setTaskName(pattern);
|
||||
cancelled.checkCanceled();
|
||||
if (!consumer.process(CREATE_NEW_TASK_ACTION)) return;
|
||||
|
||||
boolean cachedTasksFound = taskPsiElements.size() != 0;
|
||||
if (cachedTasksFound) {
|
||||
cancelled.checkCanceled();
|
||||
if (!consumer.process(ChooseByNameBase.NON_PREFIX_SEPARATOR)) return;
|
||||
}
|
||||
|
||||
for (Object element : taskPsiElements) {
|
||||
cancelled.checkCanceled();
|
||||
if (!consumer.process(element)) return;
|
||||
}
|
||||
|
||||
//int i = 0;
|
||||
//while (true) {
|
||||
List<Task> tasks = new TaskSearchSupport(project).getRepositoryTasks(pattern, ChooseByNameBase.MAXIMUM_LIST_SIZE_LIMIT, 0, true);
|
||||
if (tasks.size() == 0) return;
|
||||
tasks.removeAll(cachedTasks);
|
||||
taskPsiElements = ContainerUtil.map(tasks, new Function<Task, TaskPsiElement>() {
|
||||
@Override
|
||||
public TaskPsiElement fun(Task task) {
|
||||
return new TaskPsiElement(PsiManager.getInstance(project), task);
|
||||
}
|
||||
});
|
||||
|
||||
if (!cachedTasksFound && taskPsiElements.size() != 0) {
|
||||
cancelled.checkCanceled();
|
||||
if (!consumer.process(ChooseByNameBase.NON_PREFIX_SEPARATOR)) return;
|
||||
}
|
||||
|
||||
for (Object element : taskPsiElements) {
|
||||
cancelled.checkCanceled();
|
||||
if (!consumer.process(element)) return;
|
||||
}
|
||||
//i += ChooseByNameBase.MAXIMUM_LIST_SIZE_LIMIT;
|
||||
//}
|
||||
}
|
||||
}, "", false, 0);
|
||||
popup.setShowListForEmptyPattern(true);
|
||||
@@ -117,12 +155,10 @@ public class GotoTaskAction extends GotoActionBase {
|
||||
|
||||
private static class GotoTaskPopupModel extends SimpleChooseByNameModel {
|
||||
private ListCellRenderer myListCellRenderer;
|
||||
private final Project myProject;
|
||||
|
||||
|
||||
protected GotoTaskPopupModel(@NotNull Project project) {
|
||||
super(project, "Enter task name:", null);
|
||||
myProject = project;
|
||||
myListCellRenderer = new TaskCellRenderer(project);
|
||||
}
|
||||
|
||||
@@ -133,34 +169,7 @@ public class GotoTaskAction extends GotoActionBase {
|
||||
|
||||
@Override
|
||||
protected Object[] getElementsByName(String name, String pattern) {
|
||||
List<Task> tasks = new ArrayList<Task>();
|
||||
tasks.addAll(TaskManager.getManager(myProject).getLocalTasks(pattern));
|
||||
ContainerUtil.sort(tasks, TaskManagerImpl.TASK_UPDATE_COMPARATOR);
|
||||
tasks.addAll(ContainerUtil.filter(TaskManager.getManager(myProject).getIssues(pattern), new Condition<Task>() {
|
||||
@Override
|
||||
public boolean value(Task task) {
|
||||
return TaskManager.getManager(myProject).findTask(task.getId()) == null;
|
||||
}
|
||||
}));
|
||||
|
||||
List<TaskPsiElement> taskPsiElements = ContainerUtil.map(tasks, new Function<Task, TaskPsiElement>() {
|
||||
@Override
|
||||
public TaskPsiElement fun(Task task) {
|
||||
return new TaskPsiElement(PsiManager.getInstance(myProject), task);
|
||||
}
|
||||
});
|
||||
TaskPsiElement[] result2 = new TaskPsiElement[taskPsiElements.size()];
|
||||
ArrayUtil.copy(taskPsiElements, result2, 0);
|
||||
|
||||
final boolean foundTaskListEmpty = taskPsiElements.size() == 0;
|
||||
Object[] result = new Object[taskPsiElements.size() + 1 + (foundTaskListEmpty ? 0 : 1)];
|
||||
result[0] = CREATE_NEW_TASK_ACTION;
|
||||
CREATE_NEW_TASK_ACTION.setTaskName(pattern);
|
||||
if (!foundTaskListEmpty) {
|
||||
result[1] = ChooseByNameBase.NON_PREFIX_SEPARATOR;
|
||||
}
|
||||
ArrayUtil.copy(taskPsiElements, result, foundTaskListEmpty ? 1 : 2);
|
||||
return result;
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.intellij.tasks.actions;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskManager;
|
||||
@@ -25,12 +26,13 @@ import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.Matcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class TaskSearchSupport {
|
||||
protected Matcher myMatcher;
|
||||
private final TaskManagerImpl myManager;
|
||||
@@ -39,6 +41,31 @@ public class TaskSearchSupport {
|
||||
myManager = (TaskManagerImpl)TaskManager.getManager(project);
|
||||
}
|
||||
|
||||
public List<Task> getLocalAndCachedTasks(String pattern) {
|
||||
List<Task> tasks = new ArrayList<Task>();
|
||||
ContainerUtil.addAll(tasks, myManager.getLocalTasks());
|
||||
ContainerUtil.addAll(tasks, ContainerUtil.filter(myManager.getCachedIssues(), new Condition<Task>() {
|
||||
@Override
|
||||
public boolean value(final Task task) {
|
||||
return myManager.findTask(task.getId()) == null;
|
||||
}
|
||||
}));
|
||||
final Matcher matcher = getMatcher(pattern);
|
||||
List<Task> filteredTasks = ContainerUtil.mapNotNull(tasks, new NullableFunction<Task, Task>() {
|
||||
public Task fun(Task task) {
|
||||
return matcher.matches(task.getId()) || matcher.matches(task.getSummary()) ? task : null;
|
||||
}
|
||||
});
|
||||
ContainerUtil.sort(filteredTasks, TaskManagerImpl.TASK_UPDATE_COMPARATOR);
|
||||
return filteredTasks;
|
||||
}
|
||||
|
||||
public List<Task> getRepositoryTasks(String pattern, int max, long since, boolean forceRequest) {
|
||||
List<Task> tasks = myManager.getIssues(pattern, max, since, forceRequest);
|
||||
ContainerUtil.sort(tasks, TaskManagerImpl.TASK_UPDATE_COMPARATOR);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public List<Task> getItems(String pattern, boolean cached, boolean autopopup) {
|
||||
final Matcher matcher = getMatcher(pattern);
|
||||
return ContainerUtil.mapNotNull(getTasks(pattern, cached, autopopup), new NullableFunction<Task, Task>() {
|
||||
|
||||
@@ -253,13 +253,18 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getIssues(String query, boolean forceRequest) {
|
||||
List<Task> tasks = getIssuesFromRepositories(query, 50, 0, forceRequest);
|
||||
public List<Task> getIssues(String query, int max, long since, boolean forceRequest) {
|
||||
List<Task> tasks = getIssuesFromRepositories(query, max, since, forceRequest);
|
||||
if (tasks == null) return getCachedIssues();
|
||||
myIssueCache.putAll(ContainerUtil.newMapFromValues(tasks.iterator(), KEY_CONVERTOR));
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getIssues(String query, boolean forceRequest) {
|
||||
return getIssues(query, 50, 0, forceRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getCachedIssues() {
|
||||
return new ArrayList<Task>(myIssueCache.values());
|
||||
@@ -297,17 +302,6 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalTask> getLocalTasks(final String query) {
|
||||
List<LocalTask> tasks = new ArrayList<LocalTask>();
|
||||
for (LocalTask localTask : getLocalTasks()) {
|
||||
if (TaskUtil.getTrimmedSummary(localTask).toLowerCase().contains(query.toLowerCase())) {
|
||||
tasks.add(localTask);
|
||||
}
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalTask addTask(Task issue) {
|
||||
LocalTaskImpl task = issue instanceof LocalTaskImpl ? (LocalTaskImpl)issue : new LocalTaskImpl(issue);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class YouTrackRepository extends BaseRepositoryImpl {
|
||||
if (request != null) {
|
||||
query += " " + request;
|
||||
}
|
||||
String requestUrl = "/rest/project/issues/?filter=" + encodeUrl(query) + "&max=" + max;
|
||||
String requestUrl = "/rest/project/issues/?filter=" + encodeUrl(query) + "&max=" + max + "&after" + since;
|
||||
HttpMethod method = doREST(requestUrl, false);
|
||||
InputStream stream = method.getResponseBodyAsStream();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user