API to select UI elements the same way as speed search would do

This commit is contained in:
peter
2015-01-19 17:51:12 +01:00
parent aa915b2f7d
commit a3fe80e2d1
3 changed files with 14 additions and 15 deletions
@@ -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) {