Refactoring TreeSpeedSearch to avoid constructors with side effects

GitOrigin-RevId: 8a7362a937bcb95b07c5c1649076a67c3f4389bd
This commit is contained in:
Alex Plate
2023-03-01 17:40:02 +00:00
committed by intellij-monorepo-bot
parent f0e7e884d9
commit 917d7b0137
54 changed files with 174 additions and 80 deletions
@@ -68,7 +68,7 @@ public class FrameworksTree extends CheckboxTree {
@Override
protected void installSpeedSearch() {
new TreeSpeedSearch(this, false, path -> {
TreeSpeedSearch.installOn(this, false, path -> {
Object node = path.getLastPathComponent();
if (node instanceof FrameworkSupportNodeBase) {
return ((FrameworkSupportNodeBase<?>)node).getTitle();
@@ -57,7 +57,7 @@ class DependencyExclusionEditor {
}, myRootNode, policy) {
@Override
protected void installSpeedSearch() {
new TreeSpeedSearch(this, false, treePath -> {
TreeSpeedSearch.installOn(this, false, treePath -> {
Object node = treePath.getLastPathComponent();
if (!(node instanceof CheckedTreeNode)) return "";
Object data = ((CheckedTreeNode)node).getUserObject();
@@ -58,7 +58,7 @@ public final class ProjectJdksConfigurable extends MasterDetailsComponent {
@Override
protected void initTree() {
super.initTree();
new TreeSpeedSearch(myTree, true, treePath -> ((MyNode)treePath.getLastPathComponent()).getDisplayName());
TreeSpeedSearch.installOn(myTree, true, treePath -> ((MyNode)treePath.getLastPathComponent()).getDisplayName());
myTree.setRootVisible(false);
}
@@ -63,7 +63,7 @@ public class LayoutTree extends SimpleDnDAwareTree implements AdvancedDnDSource
}
return "";
};
new TreeSpeedSearch(this, true, f);
TreeSpeedSearch.installOn(this, true, f);
}
private List<PackagingElementNode<?>> getNodesToDrag() {
@@ -126,7 +126,7 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
myWasTreeInitialized = true;
super.initTree();
new TreeSpeedSearch(myTree, true, treePath -> getTextForSpeedSearch((MyNode)treePath.getLastPathComponent()));
TreeSpeedSearch.installOn(myTree, true, treePath -> getTextForSpeedSearch((MyNode)treePath.getLastPathComponent()));
ToolTipManager.sharedInstance().registerComponent(myTree);
myTree.setCellRenderer(new ProjectStructureElementRenderer(myContext));
}
@@ -240,7 +240,7 @@ public final class MigrationPanel extends JPanel implements Disposable {
TreeUtil.expandAll(tree);
SmartExpander.installOn(tree);
EditSourceOnDoubleClickHandler.install(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
PopupHandler.installPopupMenu(tree, createTreePopupActions(), "MigrationPanelPopup");
}
@@ -204,7 +204,7 @@ public final class CyclicDependenciesPanel extends JPanel implements Disposable,
TreeUtil.installActions(tree);
SmartExpander.installOn(tree);
EditSourceOnDoubleClickHandler.install(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
PopupHandler.installPopupMenu(tree, createTreePopupActions(), "CyclicDependenciesPopup");
}
@@ -117,7 +117,7 @@ public class PackageChooserDialog extends PackageChooser {
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
new TreeSpeedSearch(myTree, false, path -> {
TreeSpeedSearch.installOn(myTree, false, path -> {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
Object object = node.getUserObject();
if (object instanceof PsiPackage) return ((PsiPackage)object).getName();
@@ -146,7 +146,7 @@ public final class PushLog extends JPanel implements Disposable, DataProvider {
@Override
protected void installSpeedSearch() {
new TreeSpeedSearch(this, false, path -> {
TreeSpeedSearch.installOn(this, false, path -> {
Object pathComponent = path.getLastPathComponent();
if (pathComponent instanceof RepositoryNode) {
return ((RepositoryNode)pathComponent).getRepositoryName();
@@ -12,7 +12,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.SmartList;
import com.intellij.util.containers.CollectionFactory;
@@ -64,7 +64,7 @@ public abstract class BaseExecuteBeforeRunDialog<T extends BeforeRunTask<?>> ext
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
TreeUtil.installActions(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
tree.addMouseListener(new MouseAdapter() {
@Override
@@ -6,7 +6,7 @@ import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExe
import com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo;
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
import com.intellij.openapi.project.Project;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.Alarm;
import com.intellij.util.ui.tree.TreeModelAdapter;
@@ -74,7 +74,7 @@ public class ExternalSystemTasksTree extends Tree implements Supplier<ExternalTa
scheduleCollapseStateAppliance(e.getTreePath());
}
});
new TreeSpeedSearch(this);
TreeUIHelper.getInstance().installTreeSpeedSearch(this);
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
getActionMap().put("Enter", new AbstractAction() {
@@ -23,7 +23,7 @@ import com.intellij.pom.Navigatable;
import com.intellij.ui.ExperimentalUI;
import com.intellij.ui.OnePixelSplitter;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
@@ -209,7 +209,7 @@ public class ProblemsViewPanel extends OnePixelSplitter implements Disposable, D
myTree.getSelectionModel().setSelectionMode(SINGLE_TREE_SELECTION);
myTree.addTreeSelectionListener(new RestoreSelectionListener());
myTree.addTreeSelectionListener(event -> mySelectionAlarm.cancelAndRequest());
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
EditSourceOnDoubleClickHandler.install(myTree);
EditSourceOnEnterKeyHandler.install(myTree);
PopupHandler.installPopupMenu(myTree, getPopupHandlerGroupId(), "ProblemsView.ToolWindow.TreePopup");
@@ -145,7 +145,7 @@ public abstract class FormatOnSaveActionInfoBase<Options extends FormatOnSaveOpt
CheckboxTree tree = new CheckboxTree(createFileTypesRenderer(), root) {
@Override
protected void installSpeedSearch() {
new TreeSpeedSearch(this, false, path -> {
TreeSpeedSearch.installOn(this, false, path -> {
final CheckedTreeNode node = (CheckedTreeNode)path.getLastPathComponent();
final Object userObject = node.getUserObject();
if (userObject instanceof FileType) {
@@ -101,7 +101,7 @@ public class InspectionTree extends Tree {
EditSourceOnEnterKeyHandler.install(this);
TreeUtil.installActions(this);
PopupHandler.installPopupMenu(this, IdeActions.INSPECTION_TOOL_WINDOW_TREE_POPUP, ActionPlaces.CODE_INSPECTION);
new TreeSpeedSearch(this, false, o -> InspectionsConfigTreeComparator.getDisplayTextToSort(o.getLastPathComponent().toString()));
TreeSpeedSearch.installOn(this, false, o -> InspectionsConfigTreeComparator.getDisplayTextToSort(o.getLastPathComponent().toString()));
}
getModel().addTreeModelListener(new TreeModelAdapter() {
@@ -5,10 +5,7 @@ import com.intellij.execution.services.ServiceModel.ServiceViewItem;
import com.intellij.ide.DataManager;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.Disposable;
import com.intellij.ui.ComponentUtil;
import com.intellij.ui.DoubleClickListener;
import com.intellij.ui.LoadingNode;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.*;
import com.intellij.ui.tree.AsyncTreeModel;
import com.intellij.ui.treeStructure.Tree;
import org.jetbrains.annotations.NotNull;
@@ -48,7 +45,7 @@ class ServiceViewTree extends Tree {
ComponentUtil.putClientProperty(this, ANIMATION_IN_RENDERER_ALLOWED, true);
// listeners
new TreeSpeedSearch(this, true, DISPLAY_NAME_CONVERTER);
TreeSpeedSearch.installOn(this, true, DISPLAY_NAME_CONVERTER);
ServiceViewTreeLinkMouseListener mouseListener = new ServiceViewTreeLinkMouseListener(this);
mouseListener.installOn(this);
new DoubleClickListener() {
@@ -25,7 +25,7 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.OnePixelSplitter
import com.intellij.ui.PopupHandler
import com.intellij.ui.ScrollPaneFactory.createScrollPane
import com.intellij.ui.TreeSpeedSearch
import com.intellij.ui.TreeUIHelper
import com.intellij.ui.preview.DescriptorPreview
import com.intellij.ui.tree.AsyncTreeModel
import com.intellij.ui.tree.RestoreSelectionListener
@@ -237,7 +237,7 @@ class BookmarksView(val project: Project, showToolbar: Boolean?)
override fun focusGained(event: FocusEvent?) = selectionAlarm.cancelAndRequest()
})
TreeSpeedSearch(tree)
TreeUIHelper.getInstance().installTreeSpeedSearch(tree)
TreeUtil.promiseSelectFirstLeaf(tree)
tree.registerNavigateOnEnterAction { editSourceListeners.forEach { it.onEditSource() } }
EditSourceOnDoubleClickHandler.install(tree) { editSourceListeners.forEach { it.onEditSource() } }
@@ -6,7 +6,7 @@ import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
@@ -43,7 +43,7 @@ abstract class FileTemplateTabAsTree extends FileTemplateTab {
onTemplateSelected();
}
});
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
}
protected abstract FileTemplateNode initModel();
@@ -13,7 +13,7 @@ import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.ui.AutoScrollToSourceHandler;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.tabs.PinToolwindowTabAction;
import com.intellij.ui.tree.StructureTreeModel;
@@ -262,7 +262,7 @@ public abstract class HierarchyBrowserBase extends SimpleToolWindowPanel impleme
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
tree.setToggleClickCount(-1);
tree.setCellRenderer(new HierarchyNodeRenderer());
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
TreeUtil.installActions(tree);
myAutoScrollToSourceHandler.install(tree);
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.stripe.ErrorStripe;
import com.intellij.ui.stripe.ErrorStripePainter;
import com.intellij.ui.stripe.TreeUpdater;
@@ -160,7 +161,7 @@ public abstract class AbstractProjectViewPaneWithAsyncSupport extends AbstractPr
ToolTipManager.sharedInstance().registerComponent(myTree);
TreeUtil.installActions(myTree);
new MySpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTree.addKeyListener(new PsiCopyPasteManager.EscapeHandler());
CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
@@ -27,7 +27,7 @@ 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.ui.ScrollPaneFactory;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.stripe.ErrorStripePainter;
import com.intellij.ui.stripe.TreeUpdater;
import com.intellij.ui.tree.AsyncTreeModel;
@@ -182,7 +182,7 @@ public final class ScopeViewPane extends AbstractProjectViewPane {
EditSourceOnDoubleClickHandler.install(myTree);
EditSourceOnEnterKeyHandler.install(myTree);
CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_SCOPE_VIEW_POPUP, ActionPlaces.SCOPE_VIEW_POPUP);
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
enableDnD();
myTree.getEmptyText()
.setText(IdeBundle.message("scope.view.empty.text"))
@@ -228,7 +228,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre
TreeUtil.installActions(getTree());
new TreeSpeedSearch(getTree(), false, treePath -> {
TreeSpeedSearch.installOn(getTree(), false, treePath -> {
Object userObject = TreeUtil.getLastUserObject(treePath);
return userObject != null ? FileStructurePopup.getSpeedSearchText(userObject) : null;
});
@@ -177,7 +177,7 @@ public abstract class TodoPanel extends SimpleToolWindowPanel implements Occuren
myTree.setCellRenderer(new TodoCompositeRenderer());
EditSourceOnDoubleClickHandler.install(myTree);
EditSourceOnEnterKeyHandler.install(myTree);
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
DefaultActionGroup group = new DefaultActionGroup();
group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
@@ -174,7 +174,7 @@ public abstract class AbstractTreeClassChooserDialog<T extends PsiNamedElement>
myTree.addTreeSelectionListener(__ -> handleSelectionChanged());
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTabbedPane = new TabbedPaneWrapper(getDisposable());
@@ -77,7 +77,7 @@ public class DirectoryChooserModuleTreeView implements DirectoryChooserView {
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.setCellRenderer(new MyTreeCellRenderer());
new TreeSpeedSearch(myTree, true, o -> {
TreeSpeedSearch.installOn(myTree, true, o -> {
final Object userObject = ((DefaultMutableTreeNode)o.getLastPathComponent()).getUserObject();
if (userObject instanceof Module) {
return ((Module)userObject).getName();
@@ -29,10 +29,7 @@ import com.intellij.psi.PsiManager;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.DoubleClickListener;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TabbedPaneWrapper;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.*;
import com.intellij.ui.tree.AsyncTreeModel;
import com.intellij.ui.tree.StructureTreeModel;
import com.intellij.ui.treeStructure.Tree;
@@ -168,7 +165,7 @@ public final class TreeFileChooserDialog extends DialogWrapper implements TreeFi
}
);
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTabbedPane = new TabbedPaneWrapper(getDisposable());
@@ -240,7 +240,7 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
});
super.initTree();
myTree.setShowsRootHandles(false);
new TreeSpeedSearch(myTree, true, treePath -> ((MyNode)treePath.getLastPathComponent()).getDisplayName());
TreeSpeedSearch.installOn(myTree, true, treePath -> ((MyNode)treePath.getLastPathComponent()).getDisplayName());
myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}
@@ -504,7 +504,7 @@ public final class ScopeEditorPanel implements Disposable {
TreeUtil.installActions(tree);
SmartExpander.installOn(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) {
@@ -213,7 +213,7 @@ public class ModulesDependenciesPanel extends JPanel implements Disposable {
TreeUtil.installActions(tree);
new TreeSpeedSearch(tree, true, o -> o.getLastPathComponent().toString());
TreeSpeedSearch.installOn(tree, true, o -> o.getLastPathComponent().toString());
DefaultActionGroup group = new DefaultActionGroup();
CommonActionsManager commonActionManager = CommonActionsManager.getInstance();
@@ -27,7 +27,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.ui.treeStructure.Tree;
@@ -41,7 +41,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.tree.*;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
@@ -72,7 +72,7 @@ public class ContentEntryTreeEditor {
myEditingActionsGroup = new DefaultActionGroup();
TreeUtil.installActions(myTree);
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
JPanel excludePatternsPanel = new JPanel(new GridBagLayout());
excludePatternsPanel.setBorder(JBUI.Borders.empty(5));
@@ -332,7 +332,7 @@ public final class DependenciesPanel extends JPanel implements Disposable, DataP
TreeUtil.installActions(tree);
SmartExpander.installOn(tree);
EditSourceOnDoubleClickHandler.install(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
PopupHandler.installPopupMenu(tree, createTreePopupActions(isRightTree), "DependenciesPopup");
}
@@ -607,7 +607,7 @@ public class SingleInspectionProfilePanel extends JPanel {
}
});
new TreeSpeedSearch(tree, false, o -> {
TreeSpeedSearch.installOn(tree, false, o -> {
final InspectionConfigTreeNode node = (InspectionConfigTreeNode)o.getLastPathComponent();
return InspectionsConfigTreeComparator.getDisplayTextToSort(node.getText());
});
@@ -216,7 +216,7 @@ public abstract class SlicePanel extends JPanel implements DataProvider, Disposa
tree.setSelectionPath(new TreePath(root.getPath()));
EditSourceOnDoubleClickHandler.install(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
TreeUtil.installActions(tree);
ToolTipManager.sharedInstance().registerComponent(tree);
@@ -38,7 +38,7 @@ public class ColorOptionsTree extends Tree {
setRootVisible(false);
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myCategoryName = categoryName;
new TreeSpeedSearch(this, true, TreeSpeedSearch.NODE_PRESENTATION_FUNCTION);
TreeSpeedSearch.installOn(this, true, TreeSpeedSearch.NODE_PRESENTATION_FUNCTION);
}
public void fillOptions(@NotNull ColorAndFontOptions options) {
@@ -47,7 +47,7 @@ public abstract class HierarchyTree extends JTree implements TreeSelectionListen
setModel(buildModel(c));
setCellRenderer(new ComponentTreeCellRenderer(c));
getSelectionModel().addTreeSelectionListener(this);
new TreeSpeedSearch(this);
TreeUIHelper.getInstance().installTreeSpeedSearch(this);
if (c instanceof JComponent && ClientProperty.get(c, UiInspectorAction.CLICK_INFO) != null) {
SwingUtilities.invokeLater(() -> getSelectionModel().setSelectionPath(getPathForRow(getLeadSelectionRow() + 1)));
}
@@ -93,10 +93,10 @@ public class FileSystemTreeImpl implements FileSystemTree {
});
if (speedSearchConverter != null) {
new TreeSpeedSearch(myTree, false, speedSearchConverter.asFunction());
TreeSpeedSearch.installOn(myTree, false, speedSearchConverter.asFunction());
}
else {
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
}
TreeUtil.installActions(myTree);
@@ -47,6 +47,6 @@ public class CheckboxTree extends CheckboxTreeBase {
}
protected void installSpeedSearch() {
new TreeSpeedSearch(this);
TreeUIHelper.getInstance().installTreeSpeedSearch(this);
}
}
@@ -81,9 +81,25 @@ public abstract class SpeedSearchBase<Comp extends JComponent> extends SpeedSear
private Disposable myListenerDisposable;
/**
* @param sig parameter is used to avoid clash with the deprecated constructor
*/
protected SpeedSearchBase(Comp component, @SuppressWarnings("unused") Void sig) {
myComponent = component;
}
/**
* @deprecated Please use non-deprecated constructor with combination with "setup listeners" method
* to get the behaviour of this constructor
*/
@Deprecated
public SpeedSearchBase(@NotNull Comp component) {
myComponent = component;
setupListeners();
}
protected void setupListeners() {
myComponent.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent event) {
@@ -153,7 +169,7 @@ public abstract class SpeedSearchBase<Comp extends JComponent> extends SpeedSear
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString(SystemInfo.isMac ? "meta BACK_SPACE" : "control BACK_SPACE"), myComponent);
installSupplyTo(component);
installSupplyTo(myComponent);
}
protected boolean isStickySearch() {
@@ -52,11 +52,70 @@ public class TreeSpeedSearch extends SpeedSearchBase<JTree> {
return descriptor != null ? descriptor.toString() : TO_STRING.apply(path);
};
/**
* @param sig parameter is used to avoid clash with the deprecated constructor
*/
protected TreeSpeedSearch(@NotNull JTree tree,
boolean canExpand,
Void sig,
@NotNull Function<? super TreePath, String> presentableStringFunction) {
super(tree, sig);
setComparator(new SpeedSearchComparator(false, true));
myPresentableStringFunction = presentableStringFunction;
myCanExpand = canExpand;
}
/**
* Prefer {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)} as it located in the API module
*/
public static @NotNull TreeSpeedSearch installOn(@NotNull JTree tree,
boolean canExpand,
@NotNull Function<? super TreePath, String> presentableStringFunction) {
TreeSpeedSearch search = new TreeSpeedSearch(tree, canExpand, null, presentableStringFunction);
search.setupListeners();
return search;
}
/**
* Prefer {@link TreeUIHelper#installTreeSpeedSearch(JTree)} as it located in the API module
*/
public static @NotNull TreeSpeedSearch installOn(@NotNull JTree tree) {
return installOn(tree, false, TO_STRING);
}
@Override
public void setupListeners() {
super.setupListeners();
new MySelectAllAction(myComponent, this).registerCustomShortcutSet(myComponent, null);
}
/**
* @deprecated Use {@link TreeUIHelper#installTreeSpeedSearch(JTree)}
* or the static method {@link TreeSpeedSearch#installOn(JTree)} to install a speed search on tree.
* The {@link TreeUIHelper#installTreeSpeedSearch(JTree)} is preferable over the static call as it located in the API module
* <p>
* For inheritance use the non-deprecated constructor.
* <p>
* Also, note that non-deprecated constructor is side effect free, and you should call for {@link TreeSpeedSearch#setupListeners()}
* method to enable speed search
*/
@Deprecated
public TreeSpeedSearch(JTree tree) {
this(tree, false, TO_STRING);
}
/**
* @deprecated Use {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)}
* or the static method {@link TreeSpeedSearch#installOn(JTree, boolean, Function)} to install a speed search on tree.
* The {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)} is preferable over the static call as it located in the API module
* <p>
* For inheritance use the non-deprecated constructor.
* <p>
* Also, note that non-deprecated constructor is side effect free, and you should call for {@link TreeSpeedSearch#setupListeners()}
* method to enable speed search
*/
@Deprecated
public TreeSpeedSearch(@NotNull JTree tree, boolean canExpand, @NotNull Function<? super TreePath, String> presentableStringFunction) {
super(tree);
setComparator(new SpeedSearchComparator(false, true));
@@ -66,9 +125,15 @@ public class TreeSpeedSearch extends SpeedSearchBase<JTree> {
new MySelectAllAction(tree, this).registerCustomShortcutSet(tree, null);
}
/**
* @deprecated use the constructor with Function.
* @deprecated Use {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)}
* or the static method {@link TreeSpeedSearch#installOn(JTree, boolean, Function)} to install a speed search on tree.
* The {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)} is preferable over the static call as it located in the API module
* <p>
* For inheritance use the non-deprecated constructor.
* <p>
* Also, note that non-deprecated constructor is side effect free, and you should call for {@link TreeSpeedSearch#setupListeners()}
* method to enable speed search
*/
@Deprecated
public TreeSpeedSearch(JTree tree, Convertor<? super TreePath, String> toString) {
@@ -76,7 +141,14 @@ public class TreeSpeedSearch extends SpeedSearchBase<JTree> {
}
/**
* @deprecated use the constructor with Function.
* @deprecated Use {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)}
* or the static method {@link TreeSpeedSearch#installOn(JTree, boolean, Function)} to install a speed search on tree.
* The {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)} is preferable over the static call as it located in the API module
* <p>
* For inheritance use the non-deprecated constructor.
* <p>
* Also, note that non-deprecated constructor is side effect free, and you should call for {@link TreeSpeedSearch#setupListeners()}
* method to enable speed search
*/
@Deprecated
public TreeSpeedSearch(Tree tree, Convertor<? super TreePath, String> toString) {
@@ -84,7 +156,14 @@ public class TreeSpeedSearch extends SpeedSearchBase<JTree> {
}
/**
* @deprecated use the constructor with Function.
* @deprecated Use {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)}
* or the static method {@link TreeSpeedSearch#installOn(JTree, boolean, Function)} to install a speed search on tree.
* The {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)} is preferable over the static call as it located in the API module
* <p>
* For inheritance use the non-deprecated constructor.
* <p>
* Also, note that non-deprecated constructor is side effect free, and you should call for {@link TreeSpeedSearch#setupListeners()}
* method to enable speed search
*/
@Deprecated
public TreeSpeedSearch(Tree tree, Convertor<? super TreePath, String> toString, boolean canExpand) {
@@ -92,7 +171,14 @@ public class TreeSpeedSearch extends SpeedSearchBase<JTree> {
}
/**
* @deprecated use the constructor with Function.
* @deprecated Use {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)}
* or the static method {@link TreeSpeedSearch#installOn(JTree, boolean, Function)} to install a speed search on tree.
* The {@link TreeUIHelper#installTreeSpeedSearch(JTree, Convertor, boolean)} is preferable over the static call as it located in the API module
* <p>
* For inheritance use the non-deprecated constructor.
* <p>
* Also, note that non-deprecated constructor is side effect free, and you should call for {@link TreeSpeedSearch#setupListeners()}
* method to enable speed search
*/
@Deprecated
public TreeSpeedSearch(JTree tree, Convertor<? super TreePath, String> toString, boolean canExpand) {
@@ -31,7 +31,7 @@ final class TreeUIHelperImpl extends TreeUIHelper {
@Override
public void installTreeSpeedSearch(JTree tree, Convertor<? super TreePath, String> convertor, boolean canExpand) {
new TreeSpeedSearch(tree, canExpand, convertor.asFunction());
TreeSpeedSearch.installOn(tree, canExpand, convertor.asFunction());
}
@Override
@@ -144,7 +144,7 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
@Override
protected void initTree() {
super.initTree();
new TreeSpeedSearch(myTree, true, treePath -> ((MyNode)treePath.getLastPathComponent()).getDisplayName());
TreeSpeedSearch.installOn(myTree, true, treePath -> ((MyNode)treePath.getLastPathComponent()).getDisplayName());
}
@Override
@@ -186,7 +186,7 @@ public abstract class TestTreeView extends Tree implements DataProvider, CopyPro
EditSourceOnDoubleClickHandler.install(this);
EditSourceOnEnterKeyHandler.install(this);
boolean canExpand = Registry.is("tests.view.node.expanding.search");
new TreeSpeedSearch(this, canExpand, path -> {
TreeSpeedSearch.installOn(this, canExpand, path -> {
final AbstractTestProxy testProxy = getSelectedTest(path);
if (testProxy == null) return null;
return getPresentableName(testProxy);
@@ -44,10 +44,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.pom.Navigatable;
import com.intellij.pom.NavigatableAdapter;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.*;
import com.intellij.ui.awt.RelativeRectangle;
import com.intellij.ui.content.Content;
import com.intellij.util.Consumer;
@@ -367,7 +364,7 @@ public class ShelvedChangesViewManager implements Disposable {
private ShelfTree(@NotNull Project project) {
super(project, false, false, false);
new TreeSpeedSearch(this, true, ChangesBrowserNode.TO_TEXT_CONVERTER.asFunction());
TreeSpeedSearch.installOn(this, true, ChangesBrowserNode.TO_TEXT_CONVERTER.asFunction());
setKeepTreeState(true);
setDoubleClickHandler(e -> showShelvedChangesDiff());
setEnterKeyHandler(e -> showShelvedChangesDiff());
@@ -116,7 +116,7 @@ public abstract class ChangesTree extends Tree implements DataProvider {
setShowsRootHandles(true);
setOpaque(false);
if (withSpeedSearch) {
new TreeSpeedSearch(this, false, ChangesBrowserNode.TO_TEXT_CONVERTER.asFunction());
TreeSpeedSearch.installOn(this, false, ChangesBrowserNode.TO_TEXT_CONVERTER.asFunction());
}
final ChangesBrowserNodeRenderer nodeRenderer = new ChangesBrowserNodeRenderer(myProject, this::isShowFlatten, highlightProblems);
@@ -165,7 +165,7 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton {
myTree.setCellRenderer(new UpdateTreeCellRenderer());
TreeUtil.installActions(myTree);
new TreeSpeedSearch(myTree, true, path -> {
TreeSpeedSearch.installOn(myTree, true, path -> {
Object last = path.getLastPathComponent();
if (last instanceof AbstractTreeNode) {
return ((AbstractTreeNode)last).getText();
@@ -58,7 +58,7 @@ public class BreakpointsCheckboxTree extends CheckboxTree {
@Override
protected void installSpeedSearch() {
new TreeSpeedSearch(this, true, path -> {
TreeSpeedSearch.installOn(this, true, path -> {
Object node = path.getLastPathComponent();
if (node instanceof BreakpointItemNode) {
return ((BreakpointItemNode)node).getBreakpointItem().speedSearchText();
@@ -250,7 +250,7 @@ public class XDebuggerTree extends DnDAwareTree implements DataProvider, Disposa
new XDebuggerTreeSpeedSearch(this, SPEED_SEARCH_CONVERTER);
}
else {
new TreeSpeedSearch(this, false, SPEED_SEARCH_CONVERTER.asFunction());
TreeSpeedSearch.installOn(this, false, SPEED_SEARCH_CONVERTER.asFunction());
}
}
@@ -136,7 +136,7 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
});
TreeUtil.installActions(myTree);
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTree.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(final Component comp, final int x, final int y) {
@@ -91,7 +91,7 @@ public class TargetChooserDialog extends DialogWrapper {
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
TreeUtil.installActions(tree);
new TreeSpeedSearch(tree, false, path -> {
TreeSpeedSearch.installOn(tree, false, path -> {
final Object userObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
if (userObject instanceof AntTargetNodeDescriptor) {
final AntBuildTarget target = ((AntTargetNodeDescriptor)userObject).getAntTarget();
@@ -58,7 +58,7 @@ final class CopyrightProfilesPanel extends MasterDetailsComponent implements Sea
@Override
protected void initTree() {
super.initTree();
new TreeSpeedSearch(myTree, true, treePath -> {
TreeSpeedSearch.installOn(myTree, true, treePath -> {
MasterDetailsComponent.MyNode obj = (MyNode)treePath.getLastPathComponent();
return obj == null ? null : obj.getDisplayName();
});
@@ -52,7 +52,7 @@ public class CoverageSuiteChooserDialog extends DialogWrapper {
mySuitesTree = new CheckboxTree(new SuitesRenderer(), myRootNode) {
@Override
protected void installSpeedSearch() {
new TreeSpeedSearch(this, false, path -> {
TreeSpeedSearch.installOn(this, false, path -> {
final DefaultMutableTreeNode component = (DefaultMutableTreeNode)path.getLastPathComponent();
final Object userObject = component.getUserObject();
if (userObject instanceof CoverageSuite) {
@@ -425,7 +425,7 @@ public class PsiViewerDialog extends DialogWrapper implements DataProvider {
tree.updateUI();
ToolTipManager.sharedInstance().registerComponent(tree);
TreeUtil.installActions(tree);
new TreeSpeedSearch(tree);
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
}
@Override
@@ -100,7 +100,7 @@ public final class MavenSelectProjectPopup {
}
});
new TreeSpeedSearch(projectTree, false, o -> {
TreeSpeedSearch.installOn(projectTree, false, o -> {
Object lastPathComponent = o.getLastPathComponent();
if (!(lastPathComponent instanceof DefaultMutableTreeNode)) return null;
@@ -67,7 +67,7 @@ final class AssociationsEditor implements Disposable {
myTree.setModel(new AsyncTreeModel(myModel, this));
myTree.setCellRenderer(new MyNodeRenderer(myManager));
new TreeSpeedSearch(myTree);
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
if (!project.isDefault()) {
SwingUtilities.invokeLater(() -> ApplicationManager.getApplication().invokeLater(() -> {
@@ -187,7 +187,7 @@ public class ConfigFilesTreeBuilder {
}
public static void installSearch(JTree tree) {
new TreeSpeedSearch(tree, false, treePath -> {
TreeSpeedSearch.installOn(tree, false, treePath -> {
final Object object = ((DefaultMutableTreeNode)treePath.getLastPathComponent()).getUserObject();
if (object instanceof Module) {
return ((Module)object).getName();