mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
duplicate code merged
This commit is contained in:
@@ -281,16 +281,13 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
|
||||
|
||||
@NotNull
|
||||
public static ProgressIndicator startProcessUsages(@NotNull FindUsagesHandler handler,
|
||||
public static ProgressIndicator startProcessUsages(@NotNull final FindUsagesHandler handler,
|
||||
@NotNull final PsiElement[] primaryElements,
|
||||
@NotNull final PsiElement[] secondaryElements,
|
||||
@NotNull final Processor<Usage> processor,
|
||||
@NotNull FindUsagesOptions findUsagesOptions,
|
||||
@NotNull final FindUsagesOptions findUsagesOptions,
|
||||
@NotNull final Runnable onComplete) {
|
||||
final UsageSearcher usageSearcher = createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, null);
|
||||
|
||||
final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
|
||||
dropResolveCacheRegularly(indicator, handler.getProject());
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -298,6 +295,7 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final UsageSearcher usageSearcher = createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, null);
|
||||
usageSearcher.generate(processor);
|
||||
}
|
||||
}, indicator);
|
||||
@@ -344,6 +342,14 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
return new UsageSearcher() {
|
||||
@Override
|
||||
public void generate(@NotNull final Processor<Usage> processor) {
|
||||
Project project = ApplicationManager.getApplication().runReadAction(new Computable<Project>() {
|
||||
@Override
|
||||
public Project compute() {
|
||||
return scopeFile != null ? scopeFile.getProject() : primaryElements[0].getProject();
|
||||
}
|
||||
});
|
||||
dropResolveCacheRegularly(ProgressManager.getInstance().getProgressIndicator(), project);
|
||||
|
||||
if (scopeFile != null) {
|
||||
optionsClone.searchScope = new LocalSearchScope(scopeFile);
|
||||
}
|
||||
@@ -362,12 +368,6 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
final Iterable<PsiElement> elements = ContainerUtil.concat(primaryElements, secondaryElements);
|
||||
|
||||
optionsClone.fastTrack = new SearchRequestCollector(new SearchSession());
|
||||
Project project = ApplicationManager.getApplication().runReadAction(new Computable<Project>() {
|
||||
@Override
|
||||
public Project compute() {
|
||||
return scopeFile != null ? scopeFile.getProject() : primaryElements[0].getProject();
|
||||
}
|
||||
});
|
||||
//optionsClone.searchScope = optionsClone.searchScope.union(GlobalSearchScope.projectScope(project));
|
||||
try {
|
||||
for (final PsiElement element : elements) {
|
||||
@@ -439,14 +439,13 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
myAnotherManager.searchAndShowUsages(targets, new Factory<UsageSearcher>() {
|
||||
@Override
|
||||
public UsageSearcher create() {
|
||||
dropResolveCacheRegularly(ProgressManager.getInstance().getProgressIndicator(), myProject);
|
||||
return createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, null);
|
||||
}
|
||||
}, !toSkipUsagePanelWhenOneUsage, true, createPresentation(primaryElements[0], findUsagesOptions, shouldOpenInNewTab()), null);
|
||||
myHistory.add((ConfigurableUsageTarget)targets[0]);
|
||||
}
|
||||
|
||||
private static void dropResolveCacheRegularly(ProgressIndicator indicator, final Project project) {
|
||||
private static void dropResolveCacheRegularly(ProgressIndicator indicator, @NotNull final Project project) {
|
||||
if (indicator instanceof ProgressIndicatorEx) {
|
||||
((ProgressIndicatorEx)indicator).addStateDelegate(new ProgressIndicatorBase() {
|
||||
volatile long lastCleared = System.currentTimeMillis();
|
||||
|
||||
@@ -26,12 +26,11 @@ import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.progress.util.TooManyUsagesStatus;
|
||||
import com.intellij.openapi.progress.util.ProgressWrapper;
|
||||
import com.intellij.openapi.progress.util.TooManyUsagesStatus;
|
||||
import com.intellij.openapi.project.DumbModeAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
@@ -135,12 +134,18 @@ public class UsageViewManagerImpl extends UsageViewManager {
|
||||
final boolean showNotFoundMessage,
|
||||
@NotNull final UsageViewPresentation presentation,
|
||||
@Nullable final UsageViewStateListener listener) {
|
||||
final AtomicReference<UsageViewImpl> usageViewRef = new AtomicReference<UsageViewImpl>();
|
||||
|
||||
final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
|
||||
processPresentation.setShowNotFoundMessage(showNotFoundMessage);
|
||||
processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);
|
||||
|
||||
return doSearchAndShow(searchFor, searcherFactory, presentation, processPresentation, listener);
|
||||
}
|
||||
|
||||
private UsageView doSearchAndShow(final UsageTarget[] searchFor,
|
||||
final Factory<UsageSearcher> searcherFactory,
|
||||
final UsageViewPresentation presentation,
|
||||
final FindUsagesProcessPresentation processPresentation, final UsageViewStateListener listener) {
|
||||
final AtomicReference<UsageViewImpl> usageViewRef = new AtomicReference<UsageViewImpl>();
|
||||
Task.Backgroundable task = new Task.Backgroundable(myProject, getProgressTitle(presentation), true, new SearchInBackgroundOption()) {
|
||||
@Override
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
@@ -170,32 +175,7 @@ public class UsageViewManagerImpl extends UsageViewManager {
|
||||
@NotNull FindUsagesProcessPresentation processPresentation,
|
||||
@NotNull UsageViewPresentation presentation,
|
||||
@Nullable UsageViewStateListener listener) {
|
||||
final AtomicReference<UsageViewImpl> usageView = new AtomicReference<UsageViewImpl>();
|
||||
final SearchForUsagesRunnable runnable = new SearchForUsagesRunnable(myProject, usageView, presentation, searchFor, searcherFactory, processPresentation, listener);
|
||||
final Factory<ProgressIndicator> progressIndicatorFactory = processPresentation.getProgressIndicatorFactory();
|
||||
|
||||
final ProgressIndicator progressIndicator = progressIndicatorFactory == null ? null : progressIndicatorFactory.create();
|
||||
|
||||
final AtomicBoolean findUsagesStartedShown = new AtomicBoolean();
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.searchUsages(findUsagesStartedShown);
|
||||
}
|
||||
}, progressIndicator);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
//ignore
|
||||
}
|
||||
finally {
|
||||
runnable.endSearchForUsages(findUsagesStartedShown);
|
||||
}
|
||||
}
|
||||
});
|
||||
doSearchAndShow(searchFor, searcherFactory, presentation, processPresentation, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user