new usageview for SS/SR

This commit is contained in:
Maxim Mossienko
2005-03-09 21:46:21 +03:00
parent 857021235b
commit 855cc5860d
10 changed files with 194 additions and 89 deletions
@@ -0,0 +1,58 @@
package com.intellij.usages;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.util.Factory;
import javax.swing.*;
import java.util.List;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* User: max
* Date: Dec 21, 2004
* Time: 9:15:39 PM
* To change this template use File | Settings | File Templates.
*/
public class FindUsagesProcessPresentation {
public static final String NAME_WITH_MNEMONIC_KEY = "NameWithMnemonic";
private List<Action> myNotFoundActions;
private boolean myShowPanelIfOnlyOneUsage;
private boolean myShowNotFoundMessage;
private Factory<ProgressIndicator> myProgressIndicatorFactory;
public void addNotFoundAction(Action _action) {
if (myNotFoundActions == null) myNotFoundActions = new ArrayList<Action>();
myNotFoundActions.add(_action);
}
public List<Action> getNotFoundActions() {
return myNotFoundActions;
}
public boolean isShowNotFoundMessage() {
return myShowNotFoundMessage;
}
public void setShowNotFoundMessage(final boolean showNotFoundMessage) {
myShowNotFoundMessage = showNotFoundMessage;
}
public boolean isShowPanelIfOnlyOneUsage() {
return myShowPanelIfOnlyOneUsage;
}
public void setShowPanelIfOnlyOneUsage(final boolean showPanelIfOnlyOneUsage) {
myShowPanelIfOnlyOneUsage = showPanelIfOnlyOneUsage;
}
public Factory<ProgressIndicator> getProgressIndicatorFactory() {
return myProgressIndicatorFactory;
}
public void setProgressIndicatorFactory(final Factory<ProgressIndicator> progressIndicatorFactory) {
myProgressIndicatorFactory = progressIndicatorFactory;
}
}
@@ -42,4 +42,6 @@ public interface UsageView extends Disposeable {
Set<Usage> getUsages();
JComponent getComponent();
int getUsagesCount();
}
@@ -2,7 +2,6 @@ package com.intellij.usages;
import com.intellij.openapi.util.Factory;
import com.intellij.openapi.progress.ProgressIndicator;
/**
* Created by IntelliJ IDEA.
@@ -28,9 +27,7 @@ public interface UsageViewManager {
void searchAndShowUsages(UsageTarget[] searchFor,
Factory<UsageSearcher> searcherFactory,
boolean showPanelIfOnlyOneUsage,
boolean showNotFoundMessage,
FindUsagesProcessPresentation processPresentation,
UsageViewPresentation presentation,
Factory<ProgressIndicator> progressIndicatorFactory,
UsageViewStateListener listener);
}
@@ -1,5 +1,9 @@
package com.intellij.usages;
import javax.swing.*;
import java.util.List;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* User: max
@@ -19,8 +23,7 @@ public class UsageViewPresentation {
private boolean myOpenInNewTab = true;
private boolean myCodeUsages = true;
public UsageViewPresentation() {
}
private List<Action> myNotFoundActions;
public String getTabText() {
return myTabText;
@@ -101,5 +104,14 @@ public class UsageViewPresentation {
public void setCodeUsages(final boolean codeUsages) {
myCodeUsages = codeUsages;
}
public void addNotFoundAction(Action _action) {
if (myNotFoundActions == null) myNotFoundActions = new ArrayList<Action>();
myNotFoundActions.add(_action);
}
public List<Action> getNotFoundActions() {
return myNotFoundActions;
}
}
@@ -99,7 +99,7 @@ class GroupNode extends Node implements Navigatable {
private void doUpdate() {
--myRecursiveUsageCount;
myTreeModel.reload(this);
myTreeModel.nodeChanged(this);
}
public UsageNode addUsage(Usage usage) {
@@ -522,6 +522,10 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
return myRootPanel;
}
public int getUsagesCount() {
return myUsageNodes.size();
}
public void setContent(Content content) {
myContent = content;
content.setDisposer(this);
@@ -17,6 +17,9 @@ import com.intellij.usages.*;
import com.intellij.util.Processor;
import javax.swing.*;
import java.util.List;
import java.util.ArrayList;
import java.awt.event.ActionEvent;
/**
* Created by IntelliJ IDEA.
@@ -65,9 +68,13 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
final UsageViewImpl[] usageView = new UsageViewImpl[]{null};
FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation();
processPresentation.setShowNotFoundMessage(showNotFoundMessage);
processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);
final Application application = ApplicationManager.getApplication();
application.runProcessWithProgressSynchronously(
createSearchRunnable(usageView, presentation, searchFor, searcherFactory, showNotFoundMessage, showPanelIfOnlyOneUsage, null),
new SearchForUsagesRunnable(usageView, presentation, searchFor, searcherFactory, processPresentation, null),
getProgressTitle(presentation),
true,
myProject
@@ -76,35 +83,25 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
return usageView[0];
}
private Runnable createSearchRunnable(final UsageViewImpl[] usageView,
final UsageViewPresentation presentation,
final UsageTarget[] searchFor,
final Factory<UsageSearcher> searcherFactory,
final boolean showNotFoundMessage,
final boolean showPanelIfOnlyOneUsage,
final UsageViewManager.UsageViewStateListener listener) {
return new SearchForUsagesRunnable(usageView, presentation, searchFor, searcherFactory, showNotFoundMessage, showPanelIfOnlyOneUsage, listener);
}
public void searchAndShowUsages(UsageTarget[] searchFor,
Factory<UsageSearcher> searcherFactory,
boolean showPanelIfOnlyOneUsage,
boolean showNotFoundMessage,
FindUsagesProcessPresentation processPresentation,
UsageViewPresentation presentation,
final Factory<ProgressIndicator> progressIndicatorFactory,
UsageViewManager.UsageViewStateListener listener
) {
final UsageViewImpl[] usageView = new UsageViewImpl[]{null};
final SearchForUsagesRunnable runnable = (SearchForUsagesRunnable)createSearchRunnable(
usageView, presentation, searchFor, searcherFactory, showNotFoundMessage, showPanelIfOnlyOneUsage, listener
);
final SearchForUsagesRunnable runnable = (SearchForUsagesRunnable)new SearchForUsagesRunnable(usageView, presentation, searchFor, searcherFactory, processPresentation, listener);
final Factory<ProgressIndicator> progressIndicatorFactory = processPresentation.getProgressIndicatorFactory();
UsageViewImplUtil.runProcessWithProgress(
progressIndicatorFactory.create(),
new Runnable() {
public void run() {
runnable.searchUsages();
if (usageView[0] != null) usageView[0].setProgressIndicatorFactory(progressIndicatorFactory);
if (usageView[0] != null) {
usageView[0].setProgressIndicatorFactory(progressIndicatorFactory);
}
}
},
new Runnable() {
@@ -153,23 +150,20 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
private final UsageViewPresentation myPresentation;
private final UsageTarget[] mySearchFor;
private final Factory<UsageSearcher> mySearcherFactory;
private final boolean myShowNotFoundMessage;
private final boolean myShowPanelIfOnlyOneUsage;
private final FindUsagesProcessPresentation myProcessPresentation;
private UsageViewManager.UsageViewStateListener myListener;
public SearchForUsagesRunnable(final UsageViewImpl[] usageView,
final UsageViewPresentation presentation,
final UsageTarget[] searchFor,
final Factory<UsageSearcher> searcherFactory,
final boolean showNotFoundMessage,
final boolean showPanelIfOnlyOneUsage,
FindUsagesProcessPresentation processPresentation,
final UsageViewManager.UsageViewStateListener listener) {
myUsageView = usageView;
myPresentation = presentation;
mySearchFor = searchFor;
mySearcherFactory = searcherFactory;
myShowNotFoundMessage = showNotFoundMessage;
myShowPanelIfOnlyOneUsage = showPanelIfOnlyOneUsage;
myProcessPresentation = processPresentation;
myListener = listener;
}
@@ -193,16 +187,16 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
}
private void searchUsages() {
if (!myShowNotFoundMessage) activateView();
if (!myProcessPresentation.isShowNotFoundMessage()) activateView();
UsageSearcher usageSearcher = mySearcherFactory.create();
usageSearcher.generate(new Processor<Usage>() {
public boolean process(final Usage usage) {
myUsageCount++;
if (myUsageCount == 1 && !myShowPanelIfOnlyOneUsage) {
if (myUsageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
myFirstUsage = usage;
}
if (myUsageCount == 2 ||
(myShowPanelIfOnlyOneUsage && myUsageCount == 1)) {
(myProcessPresentation.isShowPanelIfOnlyOneUsage() && myUsageCount == 1)) {
activateView();
if (myFirstUsage != null) {
myUsageView[0].appendUsageLater(myFirstUsage);
@@ -223,15 +217,41 @@ public class UsageViewManagerImpl implements UsageViewManager, ProjectComponent
}
private void endSearchForUsages() {
if (myUsageCount == 0 && myShowNotFoundMessage) {
if (myUsageCount == 0 && myProcessPresentation.isShowNotFoundMessage()) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
Messages.showMessageDialog(myProject, "No " + myPresentation.getUsagesString() + " found in " + myPresentation.getScopeText(), "Information",
Messages.getInformationIcon());
final List<Action> notFoundActions = myProcessPresentation.getNotFoundActions();
final String message = "No " + myPresentation.getUsagesString() + " found in " + myPresentation.getScopeText();
if (notFoundActions == null || notFoundActions.size() == 0) {
Messages.showMessageDialog(myProject, message, "Information",
Messages.getInformationIcon());
} else {
List<String> titles = new ArrayList<String>(notFoundActions.size()+1);
titles.add("OK");
for (int i = 0; i < notFoundActions.size(); i++) {
Action action = notFoundActions.get(i);
Object value = action.getValue(FindUsagesProcessPresentation.NAME_WITH_MNEMONIC_KEY);
if (value == null) value = action.getValue(Action.NAME);
titles.add((String)value);
}
int option = Messages.showDialog(myProject,
message,
"Information",
titles.toArray(new String[titles.size()]),
0,
Messages.getInformationIcon());
if (option > 0) {
notFoundActions.get(option-1).actionPerformed(new ActionEvent(this,0,titles.get(option)));
}
}
}
}, ModalityState.NON_MMODAL);
}
else if (myUsageCount == 1 && !myShowPanelIfOnlyOneUsage) {
else if (myUsageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (myFirstUsage.canNavigate()) {
@@ -2,7 +2,6 @@ package com.intellij.find.findInProject;
import com.intellij.find.FindManager;
import com.intellij.find.FindModel;
import com.intellij.find.FindProgressIndicator;
import com.intellij.find.FindSettings;
import com.intellij.find.impl.FindInProjectUtil;
import com.intellij.find.replaceInProject.ReplaceInProjectManager;
@@ -10,12 +9,10 @@ import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.actionSystem.DataContext;
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.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.util.Processor;
@@ -108,6 +105,9 @@ public class FindInProjectManager implements ProjectComponent {
findManager.getFindInProjectModel().copyFrom(findModel);
final FindModel findModelCopy = (FindModel)findModel.clone();
final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(myToOpenInNewTab, findModelCopy);
final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
manager.searchAndShowUsages(
new UsageTarget[] { new FindInProjectUtil.StringUsageTarget(findModel.getStringToFind()) },
@@ -118,34 +118,20 @@ public class FindInProjectManager implements ProjectComponent {
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;
}
});
FindInProjectUtil.findUsages(
findModelCopy,
psiDirectory,
myProject,
new FindInProjectUtil.AsyncFindUsagesProcessListener2ProcessorAdapter(processor)
);
myIsFindInProgress = false;
}
};
}
},
!FindSettings.getInstance().isSkipResultsWithOneUsage(),
true,
processPresentation,
presentation,
new Factory<ProgressIndicator>() {
public ProgressIndicator create() {
return new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(findModelCopy));
}
},
null
);
}
@@ -3,12 +3,11 @@ package com.intellij.find.impl;
import com.intellij.Patches;
import com.intellij.navigation.ItemPresentation;
import com.intellij.usages.impl.UsageViewImplUtil;
import com.intellij.usages.UsageTarget;
import com.intellij.usages.UsageViewPresentation;
import com.intellij.usages.Usage;
import com.intellij.usages.*;
import com.intellij.find.FindManager;
import com.intellij.find.FindModel;
import com.intellij.find.FindResult;
import com.intellij.find.FindProgressIndicator;
import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.ex.DataConstantsEx;
@@ -30,6 +29,7 @@ import com.intellij.openapi.roots.FileIndex;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Factory;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -38,6 +38,7 @@ import com.intellij.psi.*;
import com.intellij.usageView.AsyncFindUsagesProcessListener;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.PatternUtil;
import com.intellij.util.Processor;
import javax.swing.*;
import java.io.File;
@@ -326,6 +327,22 @@ public class FindInProjectUtil {
return false;
}
public static FindUsagesProcessPresentation setupProcessPresentation(final Project project,
final boolean showPanelIfOnlyOneUsage,
final UsageViewPresentation presentation) {
FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation();
processPresentation.setShowNotFoundMessage(true);
processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);
processPresentation.setProgressIndicatorFactory(
new Factory<ProgressIndicator>() {
public ProgressIndicator create() {
return new FindProgressIndicator(project, presentation.getScopeText());
}
}
);
return processPresentation;
}
public static class StringUsageTarget implements UsageTarget {
private String myStringToFind;
@@ -395,4 +412,25 @@ public class FindInProjectUtil {
return false;
}
}
public static class AsyncFindUsagesProcessListener2ProcessorAdapter implements AsyncFindUsagesProcessListener {
private final Processor<Usage> processor;
private int count;
public AsyncFindUsagesProcessListener2ProcessorAdapter(Processor<Usage> _processor) {
processor = _processor;
}
public void foundUsage(UsageInfo info) {
++count;
processor.process(new UsageInfo2UsageAdapter(info));
}
public void findUsagesCompleted() {
}
public int getCount() {
return count;
}
}
}
@@ -12,7 +12,6 @@ import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
@@ -105,6 +104,9 @@ public class ReplaceInProjectManager implements ProjectComponent {
if (manager!=null) {
final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(true, findModel);
final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(
myProject, true, presentation
);
final ReplaceContext context[] = new ReplaceContext[1];
@@ -117,34 +119,19 @@ public class ReplaceInProjectManager implements ProjectComponent {
public void generate(final Processor<Usage> processor) {
myIsFindInProgress = true;
FindInProjectUtil.findUsages(findModel, 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;
}
});
FindInProjectUtil.findUsages(
findModel,
psiDirectory,
myProject,
new FindInProjectUtil.AsyncFindUsagesProcessListener2ProcessorAdapter(processor)
);
myIsFindInProgress = false;
}
};
}
},
true,
true,
processPresentation,
presentation,
new Factory<ProgressIndicator>() {
public ProgressIndicator create() {
return new FindProgressIndicator(myProject, FindInProjectUtil.getTitleForScope(findModel));
}
},
new UsageViewManager.UsageViewStateListener() {
public void usageViewCreated(UsageView usageView) {
context[0] = new ReplaceContext(usageView,findModel);
@@ -383,4 +370,5 @@ public class ReplaceInProjectManager implements ProjectComponent {
public boolean isEnabled () {
return !myIsFindInProgress && !FindInProjectManager.getInstance(myProject).isWorkInProgress();
}
}