mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
API to select UI elements the same way as speed search would do
This commit is contained in:
+2
-14
@@ -33,6 +33,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.speedSearch.SpeedSearchSupply;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
@@ -947,20 +948,7 @@ public class TemplateListPanel extends JPanel implements Disposable {
|
||||
}
|
||||
|
||||
void selectNode(@NotNull String searchQuery) {
|
||||
for (TemplateGroup group : myTemplateGroups) {
|
||||
for (TemplateImpl template : group.getElements()) {
|
||||
if (StringUtil.startsWithIgnoreCase(template.getKey(), searchQuery)) {
|
||||
selectTemplate(group.getName(), template.getKey());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (TemplateGroup group : myTemplateGroups) {
|
||||
if (StringUtil.startsWithIgnoreCase(group.getName(), searchQuery)) {
|
||||
selectTemplate(group.getName(), null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ObjectUtils.assertNotNull(SpeedSearchSupply.getSupply(myTree, true)).findAndSelectElement(searchQuery);
|
||||
}
|
||||
|
||||
private void selectTemplate(@Nullable final String groupName, @Nullable final String templateKey) {
|
||||
|
||||
@@ -80,4 +80,10 @@ public abstract class SpeedSearchSupply {
|
||||
|
||||
public abstract void addChangeListener(@NotNull PropertyChangeListener listener);
|
||||
public abstract void removeChangeListener(@NotNull PropertyChangeListener listener);
|
||||
|
||||
/**
|
||||
* Find an element matching the searching query in the underlying component and select it there. Speed-search popup is not affected.
|
||||
* @param searchQuery text that the selected element should match
|
||||
*/
|
||||
public abstract void findAndSelectElement(@NotNull String searchQuery);
|
||||
}
|
||||
|
||||
@@ -338,6 +338,11 @@ public abstract class SpeedSearchBase<Comp extends JComponent> extends SpeedSear
|
||||
if ( mySearchPopup != null ) mySearchPopup.refreshSelection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findAndSelectElement(@NotNull String searchQuery) {
|
||||
selectElement(findElement(searchQuery), searchQuery);
|
||||
}
|
||||
|
||||
private class SearchPopup extends JPanel {
|
||||
private final SearchField mySearchField;
|
||||
|
||||
@@ -425,7 +430,7 @@ public abstract class SpeedSearchBase<Comp extends JComponent> extends SpeedSear
|
||||
}
|
||||
|
||||
public void refreshSelection () {
|
||||
updateSelection(findElement(mySearchField.getText()));
|
||||
findAndSelectElement(mySearchField.getText());
|
||||
}
|
||||
|
||||
private void updateSelection(Object element) {
|
||||
|
||||
Reference in New Issue
Block a user