From 5c26a0a0cb6adb1d6c7143408b80f6763140c149 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Wed, 11 Mar 2009 14:12:23 +0300 Subject: [PATCH] API for custom matchers in ChooseByName popup --- .../intellij/ide/util/gotoByName/ChooseByNameBase.java | 4 ++-- .../ide/util/gotoByName/CustomMatcherModel.java | 18 ++++++++++++++++++ .../intellij/ide/util/gotoByName/GotoActionModel.java | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 lang-impl/src/com/intellij/ide/util/gotoByName/CustomMatcherModel.java diff --git a/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index e53831648c..a8955fc64e 100644 --- a/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -1179,8 +1179,8 @@ patterns: throw new ProcessCanceledException(); } if (name != null) { - if (myModel instanceof GotoActionModel) { - if (((GotoActionModel)myModel).matches(name, pattern)) { + if (myModel instanceof CustomMatcherModel) { + if (((CustomMatcherModel)myModel).matches(name, pattern)) { list.add(name); } } diff --git a/lang-impl/src/com/intellij/ide/util/gotoByName/CustomMatcherModel.java b/lang-impl/src/com/intellij/ide/util/gotoByName/CustomMatcherModel.java new file mode 100644 index 0000000000..da820cba19 --- /dev/null +++ b/lang-impl/src/com/intellij/ide/util/gotoByName/CustomMatcherModel.java @@ -0,0 +1,18 @@ +package com.intellij.ide.util.gotoByName; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Roman.Chernyatchik + * @date Mar 11, 2009 + */ +public interface CustomMatcherModel { + /** + * Allows to implement custom matcher for matching itemps from ChooseByName popup + * with user pattern + * @param popupItem Item from list + * @param userPattern Pattern defined by user in Choose by name popup + * @return True if matches + */ + boolean matches(@NotNull final String popupItem, @NotNull final String userPattern); +} diff --git a/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index abcd590531..90513e0d9d 100644 --- a/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -22,7 +22,7 @@ import javax.swing.*; import java.awt.*; import java.util.*; -public class GotoActionModel implements ChooseByNameModel { +public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel { private final Project myProject; private final Component myContextComponent; @@ -204,7 +204,7 @@ public class GotoActionModel implements ChooseByNameModel { return ((AnAction)((Map.Entry)element).getKey()).getTemplatePresentation().getText(); } - public boolean matches(final String name, final String pattern) { + public boolean matches(@NotNull final String name, @NotNull final String pattern) { final AnAction anAction = myActionManager.getAction(name); if (!(anAction instanceof ActionGroup)) { final Presentation presentation = anAction.getTemplatePresentation(); -- 2.11.4.GIT