From 1d5fa7211bbb6167e72591fbeec32d21689a0662 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 12 Sep 2012 13:38:33 +0400 Subject: [PATCH] separate predefined scopes (IDEA-91275) --- .../ide/todo/ScopeBasedTodosPanel.java | 73 ++++++++++++++++--- .../todo/ScopeBasedTodosTreeStructure.java | 4 +- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java b/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java index 16e21740d9e9..5b5f404f79c9 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java @@ -31,13 +31,14 @@ import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; import com.intellij.ui.ListCellRendererWrapper; import com.intellij.ui.content.Content; import com.intellij.util.Alarm; -import com.intellij.util.ArrayUtil; import javax.swing.*; import javax.swing.tree.DefaultTreeModel; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.*; +import java.util.List; public class ScopeBasedTodosPanel extends TodoPanel { private static final String SELECTED_SCOPE = "TODO_SCOPE"; @@ -56,7 +57,7 @@ public class ScopeBasedTodosPanel extends TodoPanel { myScopeListener = new NamedScopesHolder.ScopeListener() { @Override public void scopesChanged() { - final NamedScope scope = (NamedScope)myScopes.getSelectedItem(); + final ScopeWrapper scope = (ScopeWrapper)myScopes.getSelectedItem(); rebuildModel(project, scope != null ? scope.getName() : null); } }; @@ -67,17 +68,20 @@ public class ScopeBasedTodosPanel extends TodoPanel { myValidationManager = DependencyValidationManager.getInstance(project); myValidationManager.addScopeListener(myScopeListener); - myScopes.setRenderer(new ListCellRendererWrapper(){ + myScopes.setRenderer(new ListCellRendererWrapper(){ @Override - public void customize(JList list, NamedScope value, int index, boolean selected, boolean hasFocus) { + public void customize(JList list, ScopeWrapper value, int index, boolean selected, boolean hasFocus) { setText(value.getName()); + if (value.isSeparator()) { + setSeparator(); + } } }); myScopes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { rebuildWithAlarm(ScopeBasedTodosPanel.this.myAlarm); - final NamedScope selectedItem = (NamedScope)myScopes.getSelectedItem(); + final ScopeWrapper selectedItem = (ScopeWrapper)myScopes.getSelectedItem(); if (selectedItem != null) { PropertiesComponent.getInstance(myProject).setValue(SELECTED_SCOPE, selectedItem.getName()); } @@ -94,12 +98,23 @@ public class ScopeBasedTodosPanel extends TodoPanel { } private void rebuildModel(Project project, String scopeName) { - NamedScope[] scopes = DependencyValidationManager.getInstance(project).getScopes(); - scopes = ArrayUtil.mergeArrays(scopes, NamedScopeManager.getInstance(project).getScopes()); - scopes = NonProjectFilesScope.removeFromList(scopes); - myScopes.setModel(new DefaultComboBoxModel(scopes)); + final ArrayList scopes = new ArrayList(); + final DependencyValidationManager manager = DependencyValidationManager.getInstance(project); + + scopes.add(new ScopeWrapper("Predefined Scopes", true)); + List predefinedScopesList = manager.getPredefinedScopes(); + NamedScope[] predefinedScopes = predefinedScopesList.toArray(new NamedScope[predefinedScopesList.size()]); + predefinedScopes = NonProjectFilesScope.removeFromList(predefinedScopes); + for (NamedScope predefinedScope : predefinedScopes) { + scopes.add(new ScopeWrapper(predefinedScope, false)); + } + + collectEditableScopes(scopes, manager, "Custom Project Scopes"); + collectEditableScopes(scopes, NamedScopeManager.getInstance(project), "Custom Local Scopes"); + + myScopes.setModel(new DefaultComboBoxModel(scopes.toArray(new ScopeWrapper[scopes.size()]))); if (scopeName != null) { - for (NamedScope scope : scopes) { + for (ScopeWrapper scope : scopes) { if (Comparing.strEqual(scopeName, scope.getName())) { myScopes.setSelectedItem(scope); break; @@ -108,6 +123,16 @@ public class ScopeBasedTodosPanel extends TodoPanel { } } + private static void collectEditableScopes(ArrayList scopes, NamedScopesHolder manager, String separatorTitle) { + NamedScope[] editableScopes = manager.getEditableScopes(); + if (editableScopes.length > 0) { + scopes.add(new ScopeWrapper(separatorTitle, true)); + for (NamedScope scope : editableScopes) { + scopes.add(new ScopeWrapper(scope, false)); + } + } + } + @Override protected JComponent createCenterComponent() { JPanel panel = new JPanel(new BorderLayout()); @@ -137,4 +162,32 @@ 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, boolean separator) { + myNamedScope = namedScope; + mySeparator = separator; + myName = myNamedScope.getName(); + } + private ScopeWrapper(String name, boolean separator) { + mySeparator = separator; + myName = name; + } + + public String getName() { + return myName; + } + + public NamedScope getNamedScope() { + return myNamedScope; + } + + public boolean isSeparator() { + return mySeparator; + } + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosTreeStructure.java index 9a1c4d09e446..12a8b885c61e 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosTreeStructure.java @@ -47,9 +47,9 @@ public class ScopeBasedTodosTreeStructure extends TodoTreeStructure { public boolean accept(final PsiFile psiFile) { if (!psiFile.isValid()) return false; boolean isAffected = false; - final NamedScope scope = (NamedScope)myScopes.getSelectedItem(); + final ScopeBasedTodosPanel.ScopeWrapper scope = (ScopeBasedTodosPanel.ScopeWrapper)myScopes.getSelectedItem(); if (scope != null) { - final PackageSet value = scope.getValue(); + final PackageSet value = scope.getNamedScope().getValue(); if (value != null) { isAffected = value.contains(psiFile, NamedScopesHolder.getHolder(myProject, scope.getName(), DependencyValidationManager.getInstance(myProject))); }