How to add alternative items for showNavigationPopup

here is my code, I don't how to add alternative items for popup, and popup always show "no matches found"

package ro.idea

import com.intellij.ide.actions.GotoActionAction
import com.intellij.ide.actions.GotoActionBase
import com.intellij.ide.util.gotoByName.ChooseByNamePopup
import com.intellij.ide.util.gotoByName.ContributorsBasedGotoByModel
import com.intellij.navigation.ChooseByNameContributor
import com.intellij.navigation.ChooseByNameContributorEx
import com.intellij.navigation.NavigationItem
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.Processor
import com.intellij.util.indexing.FindSymbolParameters
import com.intellij.util.indexing.IdFilter
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

/**
* Created by roroco on 1/19/16.
* like "navigate > symbol"
*/

class PopupSchDialog extends Act {
@Override
void actionPerformed(AnActionEvent e) {
super.actionPerformed(e)
Model model = new Model(pj, new Contributor())
Callback c = new Callback()

GotoActionAction gotoAct = new GotoActionAction()
gotoAct.myInAction = GotoActionAction.class
gotoAct.showNavigationPopup(e, model, c)
}

class Callback extends GotoActionBase.GotoActionCallback {
@Override
void elementChosen(ChooseByNamePopup popup, Object element) {

}
}

class Contributor implements ChooseByNameContributorEx {

@Override
void processNames(
@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
null
}

@Override
void processElementsWithName(
@NotNull String name,
@NotNull Processor<NavigationItem> processor, @NotNull FindSymbolParameters parameters) {
null
}

@Override
String[] getNames(Project project, boolean b) {
return new String[0]
}

@Override
NavigationItem[] getItemsByName(String s, String s1, Project project, boolean b) {
return new NavigationItem[0]
}
}

class Model extends ContributorsBasedGotoByModel {

protected Model(
@NotNull Project project,
@NotNull ChooseByNameContributor[] contributors) {
super(project, contributors)
}

@Override
String getPromptText() {
return null
}

@Override
String getNotInMessage() {
return null
}

@Override
String getNotFoundMessage() {
return null
}

@Override
String getCheckBoxName() {
return null
}

@Override
char getCheckBoxMnemonic() {
return 0
}

@Override
boolean loadInitialCheckBoxState() {
return false
}

@Override
void saveInitialCheckBoxState(boolean b) {

}

@Override
String[] getSeparators() {
return new String[0]
}

@Override
String getFullName(Object o) {
return null
}

@Override
boolean willOpenEditor() {
return false
}
}
}
1 comment
Comment actions Permalink

I find the solution:

class PopupSchDialog extends Act {
@Override
void actionPerformed(AnActionEvent e) {
super.actionPerformed(e)
ChooseByNamePopup popup = ChooseByNamePopup.createPopup(pj, new ChooseByNameM(), new Provider());
popup.setShowListForEmptyPattern(true)
popup.setAdText("ad text")
popup.invoke(new ChooseByNamePopupComponent.Callback() {
@Override
void elementChosen(Object o) {

}
}, ModalityState.defaultModalityState(), false)
}

class Provider implements ChooseByNameItemProvider {

@Override
List<String> filterNames(@NotNull ChooseByNameBase base, @NotNull String[] names, @NotNull String pattern) {
return ["a", "b"]
}

@Override
boolean filterElements(
@NotNull ChooseByNameBase base,
@NotNull String pattern, boolean everywhere,
@NotNull ProgressIndicator cancelled, @NotNull Processor<Object> consumer) {
List l = ['a', 'b'];
return ContainerUtil.process(l, consumer);
}
}

class ChooseByNameM implements ChooseByNameModel {

@Override
String getPromptText() {
return null
}

@Override
String getNotInMessage() {
return null
}

@Override
String getNotFoundMessage() {
return null
}

@Override
String getCheckBoxName() {
return null
}

@Override
char getCheckBoxMnemonic() {
return 0
}

@Override
boolean loadInitialCheckBoxState() {
return false
}

@Override
void saveInitialCheckBoxState(boolean state) {

}

@Override
ListCellRenderer getListCellRenderer() {
return new NavigationItemListCellRenderer()
}

@Override
String[] getNames(boolean checkBoxState) {
return new String[0]
}

@Override
Object[] getElementsByName(String name, boolean checkBoxState, String pattern) {
return new Object[0]
}

@Override
String getElementName(Object element) {
return null
}

@Override
String[] getSeparators() {
return new String[0]
}

@Override
String getFullName(Object element) {
return null
}

@Override
String getHelpId() {
return null
}

@Override
boolean willOpenEditor() {
return false
}

@Override
boolean useMiddleMatching() {
return false
}
}
}
0

Please sign in to leave a comment.