reload scopes if they were changed (IDEA-24326 ); merge events on apply

This commit is contained in:
anna
2010-01-27 15:11:59 +03:00
parent 5586e281b7
commit 37f4b655cd
12 changed files with 81 additions and 17 deletions
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeList;
@@ -81,6 +82,7 @@ public class BaseAnalysisActionDialog extends DialogWrapper {
@NotNull AnalysisUIOptions analysisUIOptions,
@Nullable PsiElement context) {
super(true);
Disposer.register(myDisposable, myScopeCombo);
myAnalysisOptions = analysisUIOptions;
myContext = context;
if (!analysisUIOptions.ANALYZE_TEST_SOURCES) {
@@ -20,6 +20,7 @@ import com.intellij.find.FindSettings;
import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.IdeBorderFactory;
@@ -269,6 +270,7 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
optionsPanel.add(label, BorderLayout.WEST);
String scope = myFindUsagesOptions.searchScope.getDisplayName();
myScopeCombo = new ScopeChooserCombo(myProject, mySearchInLibrariesAvailable, true, scope);
Disposer.register(myDisposable, myScopeCombo);
optionsPanel.add(myScopeCombo, BorderLayout.CENTER);
label.setLabelFor(myScopeCombo.getComboBox());
return optionsPanel;
@@ -38,6 +38,7 @@ import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -730,6 +731,7 @@ final class FindDialog extends DialogWrapper {
gbConstraints.gridx++;
gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
myScopeCombo = new ScopeChooserCombo(myProject, true, true, FindSettings.getInstance().getDefaultScopeName());
Disposer.register(myDisposable, myScopeCombo);
scopePanel.add(myScopeCombo, gbConstraints);
@@ -18,6 +18,7 @@ package com.intellij.ide.util.scopeChooser;
import com.intellij.ide.DataManager;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.favoritesTreeView.FavoritesManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.editor.Editor;
@@ -28,6 +29,7 @@ import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -36,6 +38,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.ComboboxWithBrowseButton;
@@ -56,11 +59,14 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ScopeChooserCombo extends ComboboxWithBrowseButton {
public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Disposable {
private Project myProject;
private boolean mySuggestSearchInLibs;
private boolean myPrevSearchFiles;
private NamedScopesHolder.ScopeListener myScopeListener;
private NamedScopeManager myNamedScopeManager;
private DependencyValidationManager myValidationManager;
public ScopeChooserCombo() {
}
@@ -78,6 +84,19 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton {
myPrevSearchFiles = prevSearchWholeFiles;
final JComboBox combo = getComboBox();
myProject = project;
myScopeListener = new NamedScopesHolder.ScopeListener() {
public void scopesChanged() {
final SearchScope selectedScope = getSelectedScope();
rebuildModel();
if (selectedScope != null) {
selectScope(selectedScope.getDisplayName());
}
}
};
myNamedScopeManager = NamedScopeManager.getInstance(project);
myNamedScopeManager.addScopeListener(myScopeListener);
myValidationManager = DependencyValidationManager.getInstance(project);
myValidationManager.addScopeListener(myScopeListener);
addActionListener(createScopeChooserListener());
combo.setRenderer(new DefaultListCellRenderer() {
@@ -95,6 +114,20 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton {
selectScope(preselect);
}
@Override
public void dispose() {
super.dispose();
if (myValidationManager != null) {
myValidationManager.removeScopeListener(myScopeListener);
myValidationManager = null;
}
if (myNamedScopeManager != null) {
myNamedScopeManager.removeScopeListener(myScopeListener);
myNamedScopeManager = null;
}
myScopeListener = null;
}
private void selectScope(String preselect) {
if (preselect != null) {
final JComboBox combo = getComboBox();
@@ -175,19 +175,21 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
}
private void processScopes() {
myLocalScopesManager.removeAllSets();
mySharedScopesManager.removeAllSets();
final List<NamedScope> localScopes = new ArrayList<NamedScope>();
final List<NamedScope> sharedScopes = new ArrayList<NamedScope>();
for (int i = 0; i < myRoot.getChildCount(); i++) {
final MyNode node = (MyNode)myRoot.getChildAt(i);
final ScopeConfigurable scopeConfigurable = (ScopeConfigurable)node.getConfigurable();
final NamedScope namedScope = scopeConfigurable.getScope();
if (scopeConfigurable.getHolder() == myLocalScopesManager) {
myLocalScopesManager.addScope(namedScope);
localScopes.add(namedScope);
}
else {
mySharedScopesManager.addScope(namedScope);
sharedScopes.add(namedScope);
}
}
myLocalScopesManager.setScopes(localScopes.toArray(new NamedScope[localScopes.size()]));
mySharedScopesManager.setScopes(sharedScopes.toArray(new NamedScope[sharedScopes.size()]));
}
private void reloadTree() {
@@ -22,6 +22,7 @@ import com.intellij.analysis.BaseAnalysisAction;
import com.intellij.analysis.BaseAnalysisActionDialog;
import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.search.SearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,12 +45,17 @@ public class BackwardDependenciesAction extends BaseAnalysisAction {
scope.setSearchInLibraries(true); //find library usages in project
final SearchScope selectedScope = myPanel.myCombo.getSelectedScope();
new BackwardDependenciesHandler(project, scope, selectedScope != null ? new AnalysisScope(selectedScope, project) : new AnalysisScope(project)).analyze();
myPanel = null;
dispose();
}
@Override
protected void canceled() {
super.canceled();
dispose();
}
private void dispose() {
Disposer.dispose(myPanel.myCombo);
myPanel = null;
}
@@ -60,4 +60,6 @@ public class EvalFormPanel extends JPanel implements InputForm {
public JCheckBox getUsageViewCheckbox() {
return myUsageViewCheckbox;
}
public void dispose() {}
}
@@ -15,17 +15,17 @@
*/
package org.intellij.plugins.xpathView.search;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import org.intellij.plugins.xpathView.Config;
import org.intellij.plugins.xpathView.HistoryElement;
import org.intellij.plugins.xpathView.ui.InputExpressionDialog;
import org.intellij.plugins.xpathView.ui.Mode;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -53,6 +53,7 @@ public class FindByExpressionDialog extends InputExpressionDialog<FindFormPanel>
myForm.getMatchEachNode().setSelected(mySettings.MATCH_RECURSIVELY);
myForm.getMatchRootNode().setSelected(!mySettings.MATCH_RECURSIVELY);
Disposer.register(myDisposable, myForm);
super.init();
}
@@ -15,11 +15,11 @@
*/
package org.intellij.plugins.xpathView.search;
import org.intellij.plugins.xpathView.ui.InputForm;
import org.intellij.plugins.xpathView.ui.InputFormPanel;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import org.intellij.plugins.xpathView.ui.InputForm;
import org.intellij.plugins.xpathView.ui.InputFormPanel;
import javax.swing.*;
@@ -85,4 +85,8 @@ public class FindFormPanel extends JPanel implements InputForm {
public JPanel getOptionsPanel() {
return myOptionsPanel;
}
public void dispose() {
Disposer.dispose(myScopePanel);
}
}
@@ -16,12 +16,14 @@
package org.intellij.plugins.xpathView.search;
import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.ComboboxWithBrowseButton;
import com.intellij.ui.DocumentAdapter;
import org.jetbrains.annotations.NotNull;
@@ -35,7 +37,7 @@ import java.awt.event.ItemListener;
import java.util.Arrays;
import java.util.Vector;
public class ScopePanel extends JPanel {
public class ScopePanel extends JPanel implements Disposable{
@SuppressWarnings({ "FieldCanBeLocal", "UnusedDeclaration" })
private JPanel myRoot;
@@ -174,4 +176,8 @@ public class ScopePanel extends JPanel {
getModuleName(),
((ScopeChooserCombo)myCustomScopeSelection).getSelectedScopeName());
}
public void dispose() {
Disposer.dispose(myCustomScopeSelection);
}
}
@@ -15,9 +15,11 @@
*/
package org.intellij.plugins.xpathView.ui;
import com.intellij.openapi.Disposable;
import javax.swing.*;
public interface InputForm {
public interface InputForm extends Disposable {
JComponent getComponent();
JLabel getIcon();
@@ -47,4 +47,6 @@ public class InputFormPanel extends JPanel implements InputForm {
public JPanel getEditorPanel() {
return myEditorPanel;
}
public void dispose() {}
}