mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
find in path uses new UsageView
This commit is contained in:
@@ -2,6 +2,7 @@ package com.intellij.usages;
|
||||
|
||||
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -19,4 +20,10 @@ public interface UsageViewManager {
|
||||
Factory<UsageSearcher> searcherFactory,
|
||||
boolean showPanelIfOnlyOneUsage,
|
||||
boolean showNotFoundMessage, UsageViewPresentation presentation);
|
||||
|
||||
UsageView searchAndShowUsages(UsageTarget[] searchFor,
|
||||
Factory<UsageSearcher> searcherFactory,
|
||||
boolean showPanelIfOnlyOneUsage,
|
||||
boolean showNotFoundMessage, UsageViewPresentation presentation,
|
||||
Factory<ProgressIndicator> progressIndicatorFactory);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public class UsageViewPresentation {
|
||||
private boolean myShowReadOnlyStatusAsRed = false;
|
||||
private boolean myShowCancelButton = false;
|
||||
private boolean myOpenInNewTab = true;
|
||||
private boolean myCodeUsages = true;
|
||||
|
||||
public UsageViewPresentation() {
|
||||
}
|
||||
@@ -92,5 +93,13 @@ public class UsageViewPresentation {
|
||||
public void setOpenInNewTab(boolean openInNewTab) {
|
||||
myOpenInNewTab = openInNewTab;
|
||||
}
|
||||
|
||||
public boolean isCodeUsages() {
|
||||
return myCodeUsages;
|
||||
}
|
||||
|
||||
public void setCodeUsages(final boolean codeUsages) {
|
||||
myCodeUsages = codeUsages;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,18 +47,22 @@ public class UsageFilteringRuleProviderImpl implements UsageFilteringRuleProvide
|
||||
|
||||
public AnAction[] createFilteringActions(UsageView view) {
|
||||
final UsageViewImpl impl = (UsageViewImpl)view;
|
||||
final ShowImportsAction showImportsAction = new ShowImportsAction(impl);
|
||||
showImportsAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)), view.getComponent());
|
||||
if(view.getPresentation().isCodeUsages()) {
|
||||
final ShowImportsAction showImportsAction = new ShowImportsAction(impl);
|
||||
showImportsAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)), view.getComponent());
|
||||
|
||||
final ReadWriteState readWriteSharedState = new ReadWriteState();
|
||||
final ReadWriteState readWriteSharedState = new ReadWriteState();
|
||||
|
||||
final ShowReadAccessUsagesAction showReadAccessUsagesAction = new ShowReadAccessUsagesAction(impl, readWriteSharedState);
|
||||
showReadAccessUsagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK)), view.getComponent());
|
||||
final ShowReadAccessUsagesAction showReadAccessUsagesAction = new ShowReadAccessUsagesAction(impl, readWriteSharedState);
|
||||
showReadAccessUsagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK)), view.getComponent());
|
||||
|
||||
final ShowWriteAccessUsagesAction showWriteAccessUsagesAction = new ShowWriteAccessUsagesAction(impl, readWriteSharedState);
|
||||
showWriteAccessUsagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK)), view.getComponent());
|
||||
final ShowWriteAccessUsagesAction showWriteAccessUsagesAction = new ShowWriteAccessUsagesAction(impl, readWriteSharedState);
|
||||
showWriteAccessUsagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK)), view.getComponent());
|
||||
|
||||
return new AnAction[] {showImportsAction, showReadAccessUsagesAction, showWriteAccessUsagesAction};
|
||||
return new AnAction[] {showImportsAction, showReadAccessUsagesAction, showWriteAccessUsagesAction};
|
||||
} else {
|
||||
return AnAction.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
private class ShowImportsAction extends RuleAction {
|
||||
|
||||
@@ -51,12 +51,19 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider,
|
||||
|
||||
public AnAction[] createGroupingActions(UsageView view) {
|
||||
final UsageViewImpl impl = (UsageViewImpl)view;
|
||||
return new AnAction[] {
|
||||
new GroupByUsageTypeAction(impl),
|
||||
new GroupByModuleTypeAction(impl),
|
||||
new GroupByPackageAction(impl),
|
||||
new GroupByFileStructureAction(impl)
|
||||
};
|
||||
if(view.getPresentation().isCodeUsages()) {
|
||||
return new AnAction[] {
|
||||
new GroupByUsageTypeAction(impl),
|
||||
new GroupByModuleTypeAction(impl),
|
||||
new GroupByPackageAction(impl),
|
||||
new GroupByFileStructureAction(impl)
|
||||
};
|
||||
} else {
|
||||
return new AnAction[] {
|
||||
new GroupByModuleTypeAction(impl),
|
||||
new GroupByFileStructureAction(impl)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class GroupByUsageTypeAction extends RuleAction {
|
||||
|
||||
@@ -50,20 +50,25 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
private MyPanel myRootPanel;
|
||||
private JTree myTree = new JTree();
|
||||
private Content myContent;
|
||||
|
||||
private UsageViewPresentation myPresentation;
|
||||
private UsageTarget[] myTargets;
|
||||
private Factory<UsageSearcher> myUsageSearcherFactory;
|
||||
private Project myProject;
|
||||
|
||||
private TreeExpander myTreeExpander;
|
||||
private boolean mySearchInProgress = true;
|
||||
private ExporterToTextFile myTextFileExporter;
|
||||
private Alarm myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
|
||||
|
||||
private Alarm myFlushAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
|
||||
private UsageModelTracker myModelTracker;
|
||||
private Map<Usage, UsageNode> myUsageNodes = new HashMap<Usage, UsageNode>();
|
||||
private ButtonPanel myButtonPanel = new ButtonPanel();
|
||||
|
||||
private boolean myChangesDetected = false;
|
||||
private List<Usage> myUsagesToFlush = new ArrayList<Usage>();
|
||||
private Factory<ProgressIndicator> myIndicatorFactory;
|
||||
|
||||
public UsageViewImpl(UsageViewPresentation presentation,
|
||||
UsageTarget[] targets,
|
||||
@@ -387,24 +392,33 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
private void doReRun() {
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
|
||||
application.runProcessWithProgressSynchronously(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
setSearchInProgress(true);
|
||||
final Runnable process = new Runnable() {
|
||||
public void run() {
|
||||
setSearchInProgress(true);
|
||||
|
||||
myChangesDetected = false;
|
||||
UsageSearcher usageSearcher = myUsageSearcherFactory.create();
|
||||
usageSearcher.generate(new Processor<Usage>() {
|
||||
public boolean process(final Usage usage) {
|
||||
appendUsageLater(usage);
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
return indicator != null ? !indicator.isCanceled() : true;
|
||||
}
|
||||
});
|
||||
myChangesDetected = false;
|
||||
UsageSearcher usageSearcher = myUsageSearcherFactory.create();
|
||||
usageSearcher.generate(new Processor<Usage>() {
|
||||
public boolean process(final Usage usage) {
|
||||
appendUsageLater(usage);
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
return indicator != null ? !indicator.isCanceled() : true;
|
||||
}
|
||||
});
|
||||
|
||||
setSearchInProgress(false);
|
||||
}
|
||||
}, UsageViewManagerImpl.getProgressTitile(myPresentation), true, myProject);
|
||||
setSearchInProgress(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (myIndicatorFactory!=null) {
|
||||
UsageViewImplUtil.runProcessWithProgress(myIndicatorFactory.create(), process, new Runnable() {
|
||||
public void run() {}
|
||||
});
|
||||
} else {
|
||||
application.runProcessWithProgressSynchronously(
|
||||
process, UsageViewManagerImpl.getProgressTitle(myPresentation), true, myProject
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
@@ -914,4 +928,8 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setProgressIndicatorFactory(final Factory<ProgressIndicator> indicatorFactory) {
|
||||
myIndicatorFactory = indicatorFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,78 +67,54 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
|
||||
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
application.runProcessWithProgressSynchronously(
|
||||
new Runnable() {
|
||||
private int myUsageCount = 0;
|
||||
private Usage myFirstUsage = null;
|
||||
|
||||
private void activateView() {
|
||||
if (usageView[0] != null) return;
|
||||
|
||||
usageView[0] = new UsageViewImpl(presentation, searchFor, searcherFactory, myProject);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
addContent(usageView[0], presentation);
|
||||
activateToolwindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (!showNotFoundMessage) activateView();
|
||||
UsageSearcher usageSearcher = searcherFactory.create();
|
||||
usageSearcher.generate(new Processor<Usage>() {
|
||||
public boolean process(final Usage usage) {
|
||||
myUsageCount++;
|
||||
if (myUsageCount == 1 && !showPanelIfOnlyOneUsage) {
|
||||
myFirstUsage = usage;
|
||||
}
|
||||
if (myUsageCount == 2 ||
|
||||
(showPanelIfOnlyOneUsage && myUsageCount == 1)) {
|
||||
activateView();
|
||||
if (myFirstUsage != null) {
|
||||
usageView[0].appendUsageLater(myFirstUsage);
|
||||
}
|
||||
usageView[0].appendUsageLater(usage);
|
||||
}
|
||||
else if (myUsageCount > 2) {
|
||||
usageView[0].appendUsageLater(usage);
|
||||
}
|
||||
|
||||
ProgressIndicator indicator = ProgressManager.getInstance()
|
||||
.getProgressIndicator();
|
||||
return indicator != null
|
||||
? !indicator.isCanceled()
|
||||
: true;
|
||||
}
|
||||
});
|
||||
|
||||
if (myUsageCount == 0 && showNotFoundMessage) {
|
||||
application.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
Messages.showMessageDialog(myProject, "No " + presentation.getUsagesString() + " found in " + presentation.getScopeText(), "Information",
|
||||
Messages.getInformationIcon());
|
||||
}
|
||||
}, ModalityState.NON_MMODAL);
|
||||
}
|
||||
else if (myUsageCount == 1 && !showPanelIfOnlyOneUsage) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (myFirstUsage.canNavigate()) {
|
||||
myFirstUsage.navigate(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
usageView[0].setSearchInProgress(false);
|
||||
}
|
||||
}
|
||||
}, getProgressTitile(presentation), true, myProject);
|
||||
createSearchRunnable(usageView, presentation, searchFor, searcherFactory, showNotFoundMessage, showPanelIfOnlyOneUsage, application),
|
||||
getProgressTitle(presentation),
|
||||
true,
|
||||
myProject
|
||||
);
|
||||
|
||||
return usageView[0];
|
||||
}
|
||||
|
||||
static String getProgressTitile(UsageViewPresentation presentation) {
|
||||
private Runnable createSearchRunnable(final UsageViewImpl[] usageView,
|
||||
final UsageViewPresentation presentation,
|
||||
final UsageTarget[] searchFor,
|
||||
final Factory<UsageSearcher> searcherFactory,
|
||||
final boolean showNotFoundMessage,
|
||||
final boolean showPanelIfOnlyOneUsage,
|
||||
final Application application) {
|
||||
return new SearchForUsagesRunnable(usageView, presentation, searchFor, searcherFactory, showNotFoundMessage, showPanelIfOnlyOneUsage, application);
|
||||
}
|
||||
|
||||
public UsageView searchAndShowUsages(UsageTarget[] searchFor,
|
||||
Factory<UsageSearcher> searcherFactory,
|
||||
boolean showPanelIfOnlyOneUsage,
|
||||
boolean showNotFoundMessage,
|
||||
UsageViewPresentation presentation,
|
||||
final Factory<ProgressIndicator> progressIndicatorFactory) {
|
||||
final UsageViewImpl[] usageView = new UsageViewImpl[]{null};
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
final SearchForUsagesRunnable runnable = (SearchForUsagesRunnable)createSearchRunnable(usageView, presentation, searchFor, searcherFactory, showNotFoundMessage, showPanelIfOnlyOneUsage, application);
|
||||
|
||||
UsageViewImplUtil.runProcessWithProgress(
|
||||
progressIndicatorFactory.create(),
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
runnable.searchUsages();
|
||||
if (usageView[0] != null) usageView[0].setProgressIndicatorFactory(progressIndicatorFactory);
|
||||
}
|
||||
},
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
runnable.endSearchForUsages();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return usageView[0];
|
||||
}
|
||||
|
||||
static String getProgressTitle(UsageViewPresentation presentation) {
|
||||
final String scopeText = presentation.getScopeText();
|
||||
if (scopeText == null) return "Searching for " + presentation.getUsagesString() + "...";
|
||||
return "Searching for " + presentation.getUsagesString() + " in " + scopeText + "...";
|
||||
@@ -169,4 +145,102 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
|
||||
|
||||
public void projectClosed() { }
|
||||
|
||||
private class SearchForUsagesRunnable implements Runnable {
|
||||
private int myUsageCount = 0;
|
||||
private Usage myFirstUsage = null;
|
||||
private final UsageViewImpl[] myUsageView;
|
||||
private final UsageViewPresentation myPresentation;
|
||||
private final UsageTarget[] mySearchFor;
|
||||
private final Factory<UsageSearcher> mySearcherFactory;
|
||||
private final boolean myShowNotFoundMessage;
|
||||
private final boolean myShowPanelIfOnlyOneUsage;
|
||||
private final Application myApplication;
|
||||
|
||||
public SearchForUsagesRunnable(final UsageViewImpl[] usageView,
|
||||
final UsageViewPresentation presentation,
|
||||
final UsageTarget[] searchFor,
|
||||
final Factory<UsageSearcher> searcherFactory,
|
||||
final boolean showNotFoundMessage,
|
||||
final boolean showPanelIfOnlyOneUsage,
|
||||
final Application application) {
|
||||
myUsageView = usageView;
|
||||
myPresentation = presentation;
|
||||
mySearchFor = searchFor;
|
||||
mySearcherFactory = searcherFactory;
|
||||
myShowNotFoundMessage = showNotFoundMessage;
|
||||
myShowPanelIfOnlyOneUsage = showPanelIfOnlyOneUsage;
|
||||
myApplication = application;
|
||||
}
|
||||
|
||||
private void activateView() {
|
||||
if (myUsageView[0] != null) return;
|
||||
|
||||
myUsageView[0] = new UsageViewImpl(myPresentation, mySearchFor, mySearcherFactory, myProject);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
addContent(myUsageView[0], myPresentation);
|
||||
activateToolwindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void run() {
|
||||
searchUsages();
|
||||
|
||||
endSearchForUsages();
|
||||
}
|
||||
|
||||
private void searchUsages() {
|
||||
if (!myShowNotFoundMessage) activateView();
|
||||
UsageSearcher usageSearcher = mySearcherFactory.create();
|
||||
usageSearcher.generate(new Processor<Usage>() {
|
||||
public boolean process(final Usage usage) {
|
||||
myUsageCount++;
|
||||
if (myUsageCount == 1 && !myShowPanelIfOnlyOneUsage) {
|
||||
myFirstUsage = usage;
|
||||
}
|
||||
if (myUsageCount == 2 ||
|
||||
(myShowPanelIfOnlyOneUsage && myUsageCount == 1)) {
|
||||
activateView();
|
||||
if (myFirstUsage != null) {
|
||||
myUsageView[0].appendUsageLater(myFirstUsage);
|
||||
}
|
||||
myUsageView[0].appendUsageLater(usage);
|
||||
}
|
||||
else if (myUsageCount > 2) {
|
||||
myUsageView[0].appendUsageLater(usage);
|
||||
}
|
||||
|
||||
ProgressIndicator indicator = ProgressManager.getInstance()
|
||||
.getProgressIndicator();
|
||||
return indicator != null
|
||||
? !indicator.isCanceled()
|
||||
: true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void endSearchForUsages() {
|
||||
if (myUsageCount == 0 && myShowNotFoundMessage) {
|
||||
myApplication.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
Messages.showMessageDialog(myProject, "No " + myPresentation.getUsagesString() + " found in " + myPresentation.getScopeText(), "Information",
|
||||
Messages.getInformationIcon());
|
||||
}
|
||||
}, ModalityState.NON_MMODAL);
|
||||
}
|
||||
else if (myUsageCount == 1 && !myShowPanelIfOnlyOneUsage) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (myFirstUsage.canNavigate()) {
|
||||
myFirstUsage.navigate(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
myUsageView[0].setSearchInProgress(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,16 @@ public class FindProgressIndicator extends ProgressWindow {
|
||||
public void background() {
|
||||
myIsBackground = true;
|
||||
myStatusBar.addProgress();
|
||||
myStatusBar.showCancelButton(
|
||||
IconLoader.getIcon("/actions/suspend.png"),
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancel();
|
||||
}
|
||||
},
|
||||
"Stop background search"
|
||||
);
|
||||
super.background();
|
||||
|
||||
ToolWindow toolWindow = ToolWindowManager.getInstance(getProject()).getToolWindow(ToolWindowId.FIND);
|
||||
if (!toolWindow.isActive()) toolWindow.activate(null);
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
@@ -46,7 +52,9 @@ public class FindProgressIndicator extends ProgressWindow {
|
||||
}
|
||||
|
||||
public void setFraction(double fraction) {
|
||||
if (!myIsBackground) super.setFraction(fraction);
|
||||
if (!myIsBackground) {
|
||||
super.setFraction(fraction);
|
||||
}
|
||||
else {
|
||||
myStatusBar.setProgressValue(getPercentage(fraction));
|
||||
}
|
||||
@@ -62,7 +70,9 @@ public class FindProgressIndicator extends ProgressWindow {
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
if (myIsBackground) myStatusBar.hideProgress();
|
||||
if (myIsBackground) {
|
||||
myStatusBar.hideCancelButton();
|
||||
}
|
||||
super.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,19 @@ import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.usageView.*;
|
||||
import com.intellij.usageView.UsageViewManager;
|
||||
import com.intellij.usages.*;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.util.Processor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FindInProjectManager implements ProjectComponent {
|
||||
@@ -98,78 +106,191 @@ public class FindInProjectManager implements ProjectComponent {
|
||||
myToOpenInNewTab = toOpenInNewTab[0] = findModel.isOpenInNewTab();
|
||||
}
|
||||
|
||||
AsyncFindUsagesCommand command = new AsyncFindUsagesCommand() {
|
||||
FindProgressIndicator progress;
|
||||
com.intellij.usages.UsageViewManager manager = myProject.getComponent(com.intellij.usages.UsageViewManager.class);
|
||||
class StringUsageTarget implements UsageTarget {
|
||||
private String myStringToFind;
|
||||
private ItemPresentation myItemPresentation = new ItemPresentation() {
|
||||
public String getPresentableText() {
|
||||
return "String '" + myStringToFind + "'";
|
||||
}
|
||||
|
||||
public void findUsages(final AsyncFindUsagesProcessListener consumer) {
|
||||
myIsFindInProgress = true;
|
||||
findManager.getFindInProjectModel().copyFrom(findModel);
|
||||
public String getLocationString() {
|
||||
return myStringToFind + "!!";
|
||||
}
|
||||
|
||||
// [jeka] should use a _copy_ of findModel, because of RefreshCommand, findModel is reused by later FindUsages commands!!!!
|
||||
final FindModel findModelCopy = (FindModel)findModel.clone();
|
||||
progress = new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(findModelCopy));
|
||||
final Runnable findUsagesRunnable = new Runnable() {
|
||||
public void run() {
|
||||
FindInProjectUtil.findUsages(findModelCopy, psiDirectory, myProject, consumer);
|
||||
}
|
||||
};
|
||||
public Icon getIcon(boolean open) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Runnable showUsagesPanelRunnable = new Runnable() {
|
||||
public void run() {
|
||||
myIsFindInProgress = false;
|
||||
if (consumer.getCount()==0) {
|
||||
if (!progress.isCanceled()) {
|
||||
String title = "No occurrences of '" + findModel.getStringToFind() + "' found in " + FindInProjectUtil.getTitleForScope(findModelCopy);
|
||||
|
||||
Messages.showMessageDialog(
|
||||
myProject,
|
||||
title,
|
||||
"Find in Path",
|
||||
Messages.getInformationIcon()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FindInProjectUtil.runProcessWithProgress(progress, findUsagesRunnable, showUsagesPanelRunnable, myProject);
|
||||
public StringUsageTarget(String _stringToFind) {
|
||||
myStringToFind = _stringToFind;
|
||||
}
|
||||
|
||||
public void stopAsyncSearch() {
|
||||
progress.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
showUsagesPanel(
|
||||
new FindInProjectViewDescriptor(findModel,command),
|
||||
toOpenInNewTab[0]
|
||||
);
|
||||
}
|
||||
|
||||
private void showUsagesPanel(final FindInProjectViewDescriptor viewDescriptor, boolean toOpenInNewTab) {
|
||||
String stringToFind = viewDescriptor.getFindModel().getStringToFind();
|
||||
String name = "Search result";
|
||||
if (stringToFind != null) {
|
||||
if (stringToFind.length() > 15) {
|
||||
stringToFind = stringToFind.substring(0, 15) + "...";
|
||||
}
|
||||
name = "Occurrences of '"+stringToFind + "'";
|
||||
}
|
||||
|
||||
if (viewDescriptor.getFindModel().isMultipleFiles() ) {
|
||||
name += " in " +FindInProjectUtil.getTitleForScope(viewDescriptor.getFindModel());
|
||||
}
|
||||
UsageViewManager.getInstance(myProject).addContent(name, viewDescriptor, true, toOpenInNewTab, true, new ProgressFactory () {
|
||||
public ProgressIndicator createProgress() {
|
||||
return new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(viewDescriptor.getFindModel()));
|
||||
public void findUsages() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean continueOnCancel() {
|
||||
public void findUsagesInEditor(FileEditor editor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public VirtualFile[] getFiles() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myStringToFind;
|
||||
}
|
||||
|
||||
public ItemPresentation getPresentation() {
|
||||
return myItemPresentation;
|
||||
}
|
||||
|
||||
public FileStatus getFileStatus() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void navigate(boolean requestFocus) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean canNavigate() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (manager!=null) {
|
||||
findManager.getFindInProjectModel().copyFrom(findModel);
|
||||
final FindModel findModelCopy = (FindModel)findModel.clone();
|
||||
|
||||
final UsageViewPresentation presentation = new UsageViewPresentation();
|
||||
|
||||
presentation.setScopeText(FindInProjectUtil.getTitleForScope(findModelCopy));
|
||||
presentation.setUsagesString("occurrences of '" + findModelCopy.getStringToFind() + "'");
|
||||
presentation.setOpenInNewTab(myToOpenInNewTab);
|
||||
presentation.setCodeUsages(false);
|
||||
|
||||
manager.searchAndShowUsages(
|
||||
new UsageTarget[] { new StringUsageTarget(findModel.getStringToFind()) },
|
||||
new Factory<UsageSearcher>() {
|
||||
public UsageSearcher create() {
|
||||
return new UsageSearcher() {
|
||||
|
||||
public void generate(final Processor<Usage> processor) {
|
||||
myIsFindInProgress = true;
|
||||
|
||||
FindInProjectUtil.findUsages(findModelCopy, psiDirectory, myProject, new AsyncFindUsagesProcessListener() {
|
||||
int count;
|
||||
|
||||
public void foundUsage(UsageInfo info) {
|
||||
++count;
|
||||
processor.process(new UsageInfo2UsageAdapter(info));
|
||||
}
|
||||
|
||||
public void findUsagesCompleted() {
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
});
|
||||
myIsFindInProgress = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
false,
|
||||
true,
|
||||
presentation,
|
||||
new Factory<ProgressIndicator>() {
|
||||
public ProgressIndicator create() {
|
||||
return new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(findModelCopy));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//AsyncFindUsagesCommand command = new AsyncFindUsagesCommand() {
|
||||
// FindProgressIndicator progress;
|
||||
//
|
||||
// public void findUsages(final AsyncFindUsagesProcessListener consumer) {
|
||||
// myIsFindInProgress = true;
|
||||
// findManager.getFindInProjectModel().copyFrom(findModel);
|
||||
//
|
||||
// // [jeka] should use a _copy_ of findModel, because of RefreshCommand, findModel is reused by later FindUsages commands!!!!
|
||||
// final FindModel findModelCopy = (FindModel)findModel.clone();
|
||||
// progress = new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(findModelCopy));
|
||||
// final Runnable findUsagesRunnable = new Runnable() {
|
||||
// public void run() {
|
||||
// FindInProjectUtil.findUsages(findModelCopy, psiDirectory, myProject, consumer);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// Runnable showUsagesPanelRunnable = new Runnable() {
|
||||
// public void run() {
|
||||
// myIsFindInProgress = false;
|
||||
// if (consumer.getCount()==0) {
|
||||
// if (!progress.isCanceled()) {
|
||||
// String title = "No occurrences of '" + findModel.getStringToFind() + "' found in " + FindInProjectUtil.getTitleForScope(findModelCopy);
|
||||
//
|
||||
// Messages.showMessageDialog(
|
||||
// myProject,
|
||||
// title,
|
||||
// "Find in Path",
|
||||
// Messages.getInformationIcon()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// FindInProjectUtil.runProcessWithProgress(progress, findUsagesRunnable, showUsagesPanelRunnable, myProject);
|
||||
// }
|
||||
//
|
||||
// public void stopAsyncSearch() {
|
||||
// progress.cancel();
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//showUsagesPanel(
|
||||
// new FindInProjectViewDescriptor(findModel,command),
|
||||
// toOpenInNewTab[0]
|
||||
//);
|
||||
}
|
||||
|
||||
//private void showUsagesPanel(final FindInProjectViewDescriptor viewDescriptor, boolean toOpenInNewTab) {
|
||||
// String stringToFind = viewDescriptor.getFindModel().getStringToFind();
|
||||
// String name = "Search result";
|
||||
// if (stringToFind != null) {
|
||||
// if (stringToFind.length() > 15) {
|
||||
// stringToFind = stringToFind.substring(0, 15) + "...";
|
||||
// }
|
||||
// name = "Occurrences of '"+stringToFind + "'";
|
||||
// }
|
||||
//
|
||||
// if (viewDescriptor.getFindModel().isMultipleFiles() ) {
|
||||
// name += " in " +FindInProjectUtil.getTitleForScope(viewDescriptor.getFindModel());
|
||||
// }
|
||||
// UsageViewManager.getInstance(myProject).addContent(name, viewDescriptor, true, toOpenInNewTab, true, new ProgressFactory () {
|
||||
// public ProgressIndicator createProgress() {
|
||||
// return new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(viewDescriptor.getFindModel()));
|
||||
// }
|
||||
//
|
||||
// public boolean continueOnCancel() {
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
|
||||
public boolean isWorkInProgress() {
|
||||
return myIsFindInProgress;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.find.impl;
|
||||
|
||||
import com.intellij.Patches;
|
||||
import com.intellij.usages.impl.UsageViewImplUtil;
|
||||
import com.intellij.find.FindManager;
|
||||
import com.intellij.find.FindModel;
|
||||
import com.intellij.find.FindResult;
|
||||
@@ -202,7 +203,6 @@ public class FindInProjectUtil {
|
||||
ProgressManager.getInstance().checkCanceled();
|
||||
final VirtualFile virtualFile = virtualFiles[i];
|
||||
final int index = i;
|
||||
final int occurencesBeforeFileSearch = consumer.getCount();
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
@@ -224,17 +224,6 @@ public class FindInProjectUtil {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (occurencesBeforeFileSearch == consumer.getCount()) {
|
||||
// we have not waited after having found the results so wait a little bit
|
||||
synchronized (project) {
|
||||
try {
|
||||
project.wait(1);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
@@ -262,15 +251,6 @@ public class FindInProjectUtil {
|
||||
|
||||
UsageInfo info = new UsageInfo(psiFile, result.getStartOffset(), result.getEndOffset());
|
||||
consumer.foundUsage(info);
|
||||
// we need to sleep a little bit to allow AWT thread to handle added usages
|
||||
// this is especially important iff number of usages grows very quickly
|
||||
synchronized (project) {
|
||||
try {
|
||||
project.wait(2);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
final int prevOffset = offset;
|
||||
offset = result.getEndOffset();
|
||||
@@ -292,27 +272,7 @@ public class FindInProjectUtil {
|
||||
final ProgressIndicator progressIndicator1 = Patches.MAC_HIDE_QUIT_HACK
|
||||
? (ProgressIndicator)progressIndicator
|
||||
: new SmoothProgressAdapter(progressIndicator, project);
|
||||
Thread thread = new Thread("Process with progress") {
|
||||
public void run() {
|
||||
try {
|
||||
ProgressManager.getInstance().runProcess(findUsagesRunnable, progressIndicator1);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(showResultsRunnable, ModalityState.NON_MMODAL);
|
||||
}
|
||||
};
|
||||
|
||||
synchronized (findUsagesRunnable) {
|
||||
thread.start();
|
||||
try {
|
||||
findUsagesRunnable.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
UsageViewImplUtil.runProcessWithProgress(progressIndicator1, findUsagesRunnable, showResultsRunnable);
|
||||
}
|
||||
|
||||
public static String getTitleForScope(final FindModel findModel) {
|
||||
|
||||
Reference in New Issue
Block a user