diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java')
-rw-r--r-- | platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java | 129 |
1 files changed, 10 insertions, 119 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 97b3f8720f60..057082105eeb 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/ScopeBasedTodosPanel.java @@ -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,47 +45,18 @@ 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); } } }); @@ -92,67 +64,14 @@ public class ScopeBasedTodosPanel extends TodoPanel { } @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; - } - } }
\ No newline at end of file |