use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class GotoFileAction method gotoActionPerformed.
@Override
public void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null)
return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
final GotoFileModel gotoFileModel = new GotoFileModel(project);
GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() {
@Override
protected ChooseByNameFilter<FileType> createFilter(@NotNull ChooseByNamePopup popup) {
return new GotoFileFilter(popup, gotoFileModel, project);
}
@Override
public void elementChosen(final ChooseByNamePopup popup, final Object element) {
if (element == null)
return;
ApplicationManager.getApplication().assertIsDispatchThread();
Navigatable n = (Navigatable) element;
//this is for better cursor position
if (element instanceof PsiFile) {
VirtualFile file = ((PsiFile) element).getVirtualFile();
if (file == null)
return;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
}
if (n.canNavigate()) {
n.navigate(true);
}
}
};
GotoFileItemProvider provider = new GotoFileItemProvider(project, getPsiContext(e), gotoFileModel);
showNavigationPopup(e, gotoFileModel, callback, IdeBundle.message("go.to.file.toolwindow.title"), true, true, provider);
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class StructureViewComponent method getData.
@Override
public Object getData(String dataId) {
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
TreePath path = getSelectedUniquePath();
if (path == null)
return null;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object element = getNodeValue(node);
if (element instanceof StructureViewTreeElement) {
element = ((StructureViewTreeElement) element).getValue();
}
if (!(element instanceof PsiElement))
return null;
if (!((PsiElement) element).isValid())
return null;
return element;
}
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
return convertToPsiElementsArray(getSelectedElements());
}
if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
return myFileEditor;
}
if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
return myCopyPasteDelegator.getCutProvider();
}
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
return myCopyPasteDelegator.getCopyProvider();
}
if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
return myCopyPasteDelegator.getPasteProvider();
}
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
Object[] selectedElements = getSelectedTreeElements();
if (selectedElements == null || selectedElements.length == 0)
return null;
if (selectedElements[0] instanceof Navigatable) {
return selectedElements[0];
}
}
if (PlatformDataKeys.HELP_ID.is(dataId)) {
return getHelpID();
}
if (CommonDataKeys.PROJECT.is(dataId)) {
return myProject;
}
return super.getData(dataId);
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class SlicePanel method getNavigatables.
@NotNull
private List<Navigatable> getNavigatables() {
TreePath[] paths = myTree.getSelectionPaths();
if (paths == null)
return Collections.emptyList();
final ArrayList<Navigatable> navigatables = new ArrayList<>();
for (TreePath path : paths) {
Object lastPathComponent = path.getLastPathComponent();
if (lastPathComponent instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastPathComponent;
Object userObject = node.getUserObject();
if (userObject instanceof Navigatable) {
navigatables.add((Navigatable) userObject);
} else if (node instanceof Navigatable) {
navigatables.add((Navigatable) node);
}
}
}
return navigatables;
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class RunConfigurationNode method getNavigatable.
@Nullable
@Override
public Navigatable getNavigatable() {
return new Navigatable() {
@Override
public void navigate(boolean requestFocus) {
RunManager.getInstance(myProject).setSelectedConfiguration(mySettings);
EditConfigurationsDialog dialog = new EditConfigurationsDialog(myProject);
dialog.show();
}
@Override
public boolean canNavigate() {
return true;
}
@Override
public boolean canNavigateToSource() {
return false;
}
};
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class GotoTargetHandler method show.
private void show(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull final GotoData gotoData) {
final PsiElement[] targets = gotoData.targets;
final List<AdditionalAction> additionalActions = gotoData.additionalActions;
if (targets.length == 0 && additionalActions.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
return;
}
boolean finished = gotoData.listUpdaterTask == null || gotoData.listUpdaterTask.isFinished();
if (targets.length == 1 && additionalActions.isEmpty() && finished) {
navigateToElement(targets[0]);
return;
}
for (PsiElement eachTarget : targets) {
gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
}
final String name = ((PsiNamedElement) gotoData.source).getName();
final String title = getChooserTitle(gotoData.source, name, targets.length, finished);
if (shouldSortTargets()) {
Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
}
List<Object> allElements = new ArrayList<>(targets.length + additionalActions.size());
Collections.addAll(allElements, targets);
allElements.addAll(additionalActions);
final JBList list = new JBList(new CollectionListModel<>(allElements));
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setFont(EditorUtil.getEditorFont());
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value == null)
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof AdditionalAction) {
return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
final Runnable runnable = () -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
Object[] selectedElements = list.getSelectedValues();
for (Object element : selectedElements) {
if (element instanceof AdditionalAction) {
((AdditionalAction) element).execute();
} else {
Navigatable nav = element instanceof Navigatable ? (Navigatable) element : EditSourceUtil.getDescriptor((PsiElement) element);
try {
if (nav != null && nav.canNavigate()) {
navigateToElement(nav);
}
} catch (IndexNotReadyException e) {
DumbService.getInstance(project).showDumbModeNotification("Navigation is not available while indexing");
}
}
}
};
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setFilteringEnabled(o -> {
if (o instanceof AdditionalAction) {
return ((AdditionalAction) o).getText();
}
return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
});
final Ref<UsageView> usageView = new Ref<>();
final JBPopup popup = builder.setTitle(title).setItemChoosenCallback(runnable).setMovable(true).setCancelCallback(() -> {
HintUpdateSupply.hideHint(list);
final ListBackgroundUpdaterTask task = gotoData.listUpdaterTask;
if (task != null) {
task.cancelTask();
}
return true;
}).setCouldPin(popup1 -> {
usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), gotoData.source.getProject()));
popup1.cancel();
return false;
}).setAdText(getAdText(gotoData.source, targets.length)).createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
if (gotoData.listUpdaterTask != null) {
Alarm alarm = new Alarm(popup);
alarm.addRequest(() -> popup.showInBestPositionFor(editor), 300);
gotoData.listUpdaterTask.init((AbstractPopup) popup, list, usageView);
ProgressManager.getInstance().run(gotoData.listUpdaterTask);
} else {
popup.showInBestPositionFor(editor);
}
}
Aggregations