mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
todo by scopes: reuse scope chooser combo, exclude ClassHierarchy (place to clear inner cache?) (IDEA-126228)
This commit is contained in:
+6
@@ -21,11 +21,17 @@
|
||||
package com.intellij.ide.util.scopeChooser;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HierarchyScopeDescriptorProvider implements ScopeDescriptorProvider {
|
||||
@NotNull
|
||||
public ScopeDescriptor[] getScopeDescriptors(final Project project) {
|
||||
if (Comparing.strEqual(ToolWindowManager.getInstance(project).getActiveToolWindowId(), ToolWindowId.TODO_VIEW)) {
|
||||
return EMPTY;
|
||||
}
|
||||
return new ScopeDescriptor[]{new ClassHierarchyScopeDescriptor(project)};
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ package com.intellij.ide.todo;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.ide.util.scopeChooser.IgnoringComboBox;
|
||||
import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.psi.search.scope.NonProjectFilesScope;
|
||||
@@ -44,115 +45,33 @@ import java.util.List;
|
||||
public class ScopeBasedTodosPanel extends TodoPanel {
|
||||
private static final String SELECTED_SCOPE = "TODO_SCOPE";
|
||||
private final Alarm myAlarm;
|
||||
private JComboBox myScopes;
|
||||
private final NamedScopesHolder.ScopeListener myScopeListener;
|
||||
private final NamedScopeManager myNamedScopeManager;
|
||||
private final DependencyValidationManager myValidationManager;
|
||||
private ScopeChooserCombo myScopes;
|
||||
|
||||
public ScopeBasedTodosPanel(final Project project, TodoPanelSettings settings, Content content){
|
||||
super(project,settings,false,content);
|
||||
myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, project);
|
||||
final String scopeName = PropertiesComponent.getInstance(project).getValue(SELECTED_SCOPE);
|
||||
rebuildModel(project, scopeName);
|
||||
|
||||
myScopeListener = new NamedScopesHolder.ScopeListener() {
|
||||
@Override
|
||||
public void scopesChanged() {
|
||||
final ScopeWrapper scope = (ScopeWrapper)myScopes.getSelectedItem();
|
||||
rebuildModel(project, scope != null ? scope.getName() : null);
|
||||
}
|
||||
};
|
||||
|
||||
myNamedScopeManager = NamedScopeManager.getInstance(project);
|
||||
myNamedScopeManager.addScopeListener(myScopeListener);
|
||||
|
||||
myValidationManager = DependencyValidationManager.getInstance(project);
|
||||
myValidationManager.addScopeListener(myScopeListener);
|
||||
|
||||
myScopes.setRenderer(new ListCellRendererWrapper<ScopeWrapper>(){
|
||||
@Override
|
||||
public void customize(JList list, ScopeWrapper value, int index, boolean selected, boolean hasFocus) {
|
||||
setText(value.getName());
|
||||
if (value.isSeparator()) {
|
||||
setSeparator();
|
||||
}
|
||||
}
|
||||
});
|
||||
myScopes.addActionListener(new ActionListener() {
|
||||
myScopes.getChildComponent().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
rebuildWithAlarm(ScopeBasedTodosPanel.this.myAlarm);
|
||||
final ScopeWrapper selectedItem = (ScopeWrapper)myScopes.getSelectedItem();
|
||||
if (selectedItem != null) {
|
||||
PropertiesComponent.getInstance(myProject).setValue(SELECTED_SCOPE, selectedItem.getName());
|
||||
final String selectedItemName = myScopes.getSelectedScopeName();
|
||||
if (selectedItemName != null) {
|
||||
PropertiesComponent.getInstance(myProject).setValue(SELECTED_SCOPE, selectedItemName);
|
||||
}
|
||||
}
|
||||
});
|
||||
rebuildWithAlarm(myAlarm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
myNamedScopeManager.removeScopeListener(myScopeListener);
|
||||
myValidationManager.removeScopeListener(myScopeListener);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void rebuildModel(Project project, String scopeName) {
|
||||
final ArrayList<ScopeWrapper> scopes = new ArrayList<ScopeWrapper>();
|
||||
final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
|
||||
|
||||
scopes.add(new ScopeWrapper("Predefined Scopes"));
|
||||
List<NamedScope> predefinedScopesList = manager.getPredefinedScopes();
|
||||
NamedScope[] predefinedScopes = predefinedScopesList.toArray(new NamedScope[predefinedScopesList.size()]);
|
||||
predefinedScopes = NonProjectFilesScope.removeFromList(predefinedScopes);
|
||||
for (NamedScope predefinedScope : predefinedScopes) {
|
||||
scopes.add(new ScopeWrapper(predefinedScope));
|
||||
}
|
||||
|
||||
collectEditableScopes(scopes, manager, "Custom Project Scopes");
|
||||
collectEditableScopes(scopes, NamedScopeManager.getInstance(project), "Custom Local Scopes");
|
||||
|
||||
myScopes.setModel(new DefaultComboBoxModel(scopes.toArray(new ScopeWrapper[scopes.size()])));
|
||||
setSelection(scopeName, scopes);
|
||||
}
|
||||
|
||||
private void setSelection(@Nullable String scopeName, ArrayList<ScopeWrapper> scopes) {
|
||||
boolean hasNonSeparators = false;
|
||||
for (ScopeWrapper scope : scopes) {
|
||||
if (!scope.isSeparator()) {
|
||||
hasNonSeparators = true;
|
||||
if (scopeName == null || scopeName.equals(scope.getName())) {
|
||||
myScopes.setSelectedItem(scope);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert hasNonSeparators;
|
||||
setSelection(null, scopes);
|
||||
}
|
||||
|
||||
private static void collectEditableScopes(ArrayList<ScopeWrapper> scopes, NamedScopesHolder manager, String separatorTitle) {
|
||||
NamedScope[] editableScopes = manager.getEditableScopes();
|
||||
if (editableScopes.length > 0) {
|
||||
scopes.add(new ScopeWrapper(separatorTitle));
|
||||
for (NamedScope scope : editableScopes) {
|
||||
scopes.add(new ScopeWrapper(scope));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterComponent() {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
final JComponent component = super.createCenterComponent();
|
||||
panel.add(component, BorderLayout.CENTER);
|
||||
myScopes = new IgnoringComboBox() {
|
||||
@Override
|
||||
protected boolean isIgnored(Object item) {
|
||||
return item instanceof ScopeWrapper && ((ScopeWrapper)item).isSeparator();
|
||||
}
|
||||
};
|
||||
String preselect = PropertiesComponent.getInstance(myProject).getValue(SELECTED_SCOPE);
|
||||
myScopes = new ScopeChooserCombo(myProject, false, true, preselect);
|
||||
myScopes.setCurrentSelection(false);
|
||||
myScopes.setUsageView(false);
|
||||
|
||||
JPanel chooserPanel = new JPanel(new GridBagLayout());
|
||||
final JLabel scopesLabel = new JLabel("Scope:");
|
||||
@@ -177,32 +96,4 @@ public class ScopeBasedTodosPanel extends TodoPanel {
|
||||
builder.init();
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static class ScopeWrapper {
|
||||
private final String myName;
|
||||
private final boolean mySeparator;
|
||||
private NamedScope myNamedScope;
|
||||
|
||||
private ScopeWrapper(NamedScope namedScope) {
|
||||
mySeparator = false;
|
||||
myNamedScope = namedScope;
|
||||
myName = myNamedScope.getName();
|
||||
}
|
||||
private ScopeWrapper(String name) {
|
||||
mySeparator = true;
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public NamedScope getNamedScope() {
|
||||
return myNamedScope;
|
||||
}
|
||||
|
||||
public boolean isSeparator() {
|
||||
return mySeparator;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.intellij.ide.todo;
|
||||
|
||||
import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -26,9 +27,9 @@ import javax.swing.*;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
public class ScopeBasedTodosTreeBuilder extends TodoTreeBuilder{
|
||||
private final JComboBox myScopes;
|
||||
private final ScopeChooserCombo myScopes;
|
||||
|
||||
public ScopeBasedTodosTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project, JComboBox scopes){
|
||||
public ScopeBasedTodosTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project, ScopeChooserCombo scopes){
|
||||
super(tree,treeModel,project);
|
||||
myScopes = scopes;
|
||||
}
|
||||
|
||||
@@ -24,22 +24,14 @@ import com.intellij.ide.todo.nodes.ToDoRootNode;
|
||||
import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
import com.intellij.psi.search.scope.packageSet.PackageSet;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
|
||||
public class ScopeBasedTodosTreeStructure extends TodoTreeStructure {
|
||||
private final JComboBox myScopes;
|
||||
private final ScopeChooserCombo myScopes;
|
||||
|
||||
public ScopeBasedTodosTreeStructure(Project project, JComboBox scopes) {
|
||||
public ScopeBasedTodosTreeStructure(Project project, ScopeChooserCombo scopes) {
|
||||
super(project);
|
||||
myScopes = scopes;
|
||||
}
|
||||
@@ -48,12 +40,9 @@ public class ScopeBasedTodosTreeStructure extends TodoTreeStructure {
|
||||
public boolean accept(final PsiFile psiFile) {
|
||||
if (!psiFile.isValid()) return false;
|
||||
boolean isAffected = false;
|
||||
final ScopeBasedTodosPanel.ScopeWrapper scope = (ScopeBasedTodosPanel.ScopeWrapper)myScopes.getSelectedItem();
|
||||
if (scope != null) {
|
||||
final PackageSet value = scope.getNamedScope().getValue();
|
||||
if (value != null) {
|
||||
isAffected = value.contains(psiFile, NamedScopesHolder.getHolder(myProject, scope.getName(), DependencyValidationManager.getInstance(myProject)));
|
||||
}
|
||||
SearchScope scope = myScopes.getSelectedScope();
|
||||
if (scope instanceof GlobalSearchScope) {
|
||||
isAffected = ((GlobalSearchScope)scope).contains(psiFile.getVirtualFile());
|
||||
}
|
||||
return isAffected && (myTodoFilter != null && myTodoFilter.accept(mySearchHelper, psiFile) ||
|
||||
(myTodoFilter == null && mySearchHelper.getTodoItemsCount(psiFile) > 0));
|
||||
|
||||
@@ -71,6 +71,8 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
|
||||
private NamedScopesHolder.ScopeListener myScopeListener;
|
||||
private NamedScopeManager myNamedScopeManager;
|
||||
private DependencyValidationManager myValidationManager;
|
||||
private boolean myCurrentSelection = true;
|
||||
private boolean myUsageView = true;
|
||||
|
||||
public ScopeChooserCombo() {
|
||||
super(new IgnoringComboBox(){
|
||||
@@ -118,6 +120,14 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
|
||||
selectScope(preselect);
|
||||
}
|
||||
|
||||
public void setCurrentSelection(boolean currentSelection) {
|
||||
myCurrentSelection = currentSelection;
|
||||
}
|
||||
|
||||
public void setUsageView(boolean usageView) {
|
||||
myUsageView = usageView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
@@ -220,7 +230,7 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
|
||||
|
||||
private void createPredefinedScopeDescriptors(DefaultComboBoxModel model) {
|
||||
@SuppressWarnings("deprecation") final DataContext context = DataManager.getInstance().getDataContext();
|
||||
for (SearchScope scope : getPredefinedScopes(myProject, context, mySuggestSearchInLibs, myPrevSearchFiles, true, true)) {
|
||||
for (SearchScope scope : getPredefinedScopes(myProject, context, mySuggestSearchInLibs, myPrevSearchFiles, myCurrentSelection, myUsageView)) {
|
||||
model.addElement(new ScopeDescriptor(scope));
|
||||
}
|
||||
for (ScopeDescriptorProvider provider : Extensions.getExtensions(ScopeDescriptorProvider.EP_NAME)) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ScopeDescriptorProvider {
|
||||
ScopeDescriptor[] EMPTY = new ScopeDescriptor[0];
|
||||
ExtensionPointName<ScopeDescriptorProvider> EP_NAME = ExtensionPointName.create("com.intellij.scopeDescriptorProvider");
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user