Java源码示例:com.intellij.ide.util.gotoByName.ChooseByNamePopup
示例1
private List<Object> calcPopupElements(ChooseByNamePopup popup, String text, boolean checkboxState) {
List<Object> elements = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(1);
//noinspection KotlinInternalInJava
SwingUtilities.invokeLater(() ->
popup.scheduleCalcElements(text, checkboxState, ModalityState.NON_MODAL, SelectMostRelevant.INSTANCE,
set -> {
elements.addAll(set);
latch.countDown();
}));
try {
if (!latch.await(10, TimeUnit.SECONDS)) {
Assert.fail();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return elements;
}
示例2
CurrentInputText(Project project) {
ChooseByNamePopup chooseByNamePopup =
project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
if (chooseByNamePopup == null) {
buildDir = null;
hasBuildRule = false;
return;
}
String currentText =
chooseByNamePopup
.getEnteredText()
// Remove the begining //
.replaceFirst("^/*", "");
// check if we have as input a proper target
int targetSeparatorIndex = currentText.lastIndexOf(TARGET_NAME_SEPARATOR);
if (targetSeparatorIndex != -1) {
hasBuildRule = true;
buildDir = currentText.substring(0, targetSeparatorIndex);
} else {
hasBuildRule = false;
buildDir = currentText;
}
}
示例3
@Override
public void gotoActionPerformed(@Nonnull AnActionEvent e) {
Project project = e.getProject();
Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
Editor editor = e.getData(CommonDataKeys.EDITOR);
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.action");
GotoActionModel model = new GotoActionModel(project, component, editor);
GotoActionCallback<Object> callback = new GotoActionCallback<Object>() {
@Override
public void elementChosen(@Nonnull ChooseByNamePopup popup, @Nonnull Object element) {
if (project != null) {
// if the chosen action displays another popup, don't populate it automatically with the text from this popup
project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, null);
}
String enteredText = popup.getTrimmedText();
int modifiers = popup.isClosedByShiftEnter() ? InputEvent.SHIFT_MASK : 0;
openOptionOrPerformAction(((GotoActionModel.MatchedValue)element).value, enteredText, project, component, modifiers);
}
};
Pair<String, Integer> start = getInitialText(false, e);
showNavigationPopup(callback, null, createPopup(project, model, start.first, start.second, component, e), false);
}
示例4
private static boolean processOptionInplace(Object value, ChooseByNamePopup popup, Component component, AnActionEvent e) {
if (value instanceof BooleanOptionDescription) {
BooleanOptionDescription option = (BooleanOptionDescription)value;
option.setOptionState(!option.isOptionEnabled());
repaint(popup);
return true;
}
else if (value instanceof GotoActionModel.ActionWrapper) {
AnAction action = ((GotoActionModel.ActionWrapper)value).getAction();
if (action instanceof ToggleAction) {
performAction(action, component, e, 0, () -> repaint(popup));
return true;
}
}
return false;
}
示例5
protected void gotoActionPerformed(AnActionEvent anActionEvent) {
final Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT);
final ChooseByNamePopup byNamePopup = ChooseByNamePopup.createPopup(
project,
new MyContributorsBasedGotoByModel(project, getNameContributor()),
(PsiElement)null
);
byNamePopup.invoke(new ChooseByNamePopupComponent.Callback() {
public void elementChosen(Object element) {
((NavigationItem)element).navigate(true);
}
public void onClose() {
if (GotoBaseAction.this.getClass().equals(myInAction)) myInAction = null;
}
}, ModalityState.current(), false);
}
示例6
@Override
public void processNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope globalSearchScope, @Nullable IdFilter idFilter) {
String queryString = Optional.ofNullable(globalSearchScope.getProject())
.map(p -> p.getUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN)).orElse("");
workspaceSymbolProvider.workspaceSymbols(queryString, globalSearchScope.getProject()).stream()
.filter(ni -> globalSearchScope.accept(ni.getFile()))
.map(NavigationItem::getName)
.forEach(processor::process);
}
示例7
@Override public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object o) {
if (o != null && o instanceof PsiFile) {
PsiFile file = (PsiFile)o;
VirtualFile vf = file.getVirtualFile();
if (vf != null) {
File f = new File(vf.getCanonicalPath());
if (f.exists()) {
console.sendFile(f.getAbsolutePath());
} else {
console.send(vf.getCanonicalPath());
}
}
}
}
示例8
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
if (element instanceof AtMappingNavigationItem) {
AtMappingNavigationItem el = (AtMappingNavigationItem) element;
if (el.canNavigate()) {
el.navigate(true);
}
}
}
示例9
@Override
protected void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return;
}
final ChooseTargetModel model = new ChooseTargetModel(project);
GotoActionCallback<BuckBuildTarget> callback = new GotoActionCallback<BuckBuildTarget>() {
@Override
public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object element) {
if (element == null) {
return;
}
BuckSettingsProvider buckSettingsProvider = BuckSettingsProvider.getInstance();
if (buckSettingsProvider == null || buckSettingsProvider.getState() == null) {
return;
}
ChooseTargetItem item = (ChooseTargetItem) element;
if (buckSettingsProvider.getState().lastAlias != null) {
buckSettingsProvider.getState().lastAlias.put(
project.getBasePath(), item.getBuildTarget());
}
BuckToolWindowFactory.updateBuckToolWindowTitle(project);
}
};
DefaultChooseByNameItemProvider provider =
new DefaultChooseByNameItemProvider(getPsiContext(e));
showNavigationPopup(e, model, callback, "Choose Build Target", true, false, provider);
}
示例10
private List<String> getBuildTargetFromBuildProjectFile(Project project, String buildDir) {
List<String> names = new ArrayList<>();
names.add(getAllBuildTargetsInSameDirectory(buildDir));
names.addAll(
BuckQueryAction.customExecuteForTargetCompletion(
project,
"//" + buildDir + TARGET_NAME_SEPARATOR,
new Function<List<String>, Void>() {
@Nullable
@Override
public Void apply(@Nullable List<String> strings) {
ApplicationManager.getApplication()
.invokeLater(
new Runnable() {
@Override
public void run() {
ChooseByNamePopup chooseByNamePopup =
project.getUserData(
ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
// the user might have closed the window
if (chooseByNamePopup != null) {
// if we don't have them, just refresh the view when we do, if the
// window is still open
chooseByNamePopup.rebuildList(true);
}
}
});
return null;
}
}));
return names;
}
示例11
public SearchStringFilter create(ChooseByNamePopup popup, SearchStringModel model) {
return new SearchStringFilter(popup, model, project);
}
示例12
private SearchStringFilter(ChooseByNamePopup popup, SearchStringModel model, Project project) {
super(popup, model, SearchStringConfiguration.getInstance(project), project);
}
示例13
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
if(element instanceof NavigationItem) {
((NavigationItem) element).navigate(true);
}
}
示例14
GotoFileFilter(final ChooseByNamePopup popup, GotoFileModel model, final Project project) {
super(popup, model, GotoFileConfiguration.getInstance(project), project);
}
示例15
private static void repaint(@Nullable ChooseByNamePopup popup) {
if (popup != null) {
popup.repaintListImmediate();
}
}
示例16
/**
* A constructor
*
* @param popup a parent popup
* @param model a model for popup
* @param filterConfiguration storage for selected filter values
* @param project a context project
*/
public ChooseByRouteNameFilter(@NotNull ChooseByNamePopup popup,
@NotNull FilteringGotoByModel<RequestMethod> model,
@NotNull ChooseByNameFilterConfiguration<RequestMethod> filterConfiguration,
@NotNull Project project) {
super(popup, model, filterConfiguration, project);
}