use of com.intellij.ide.util.gotoByName.GotoFileCellRenderer in project android by JetBrains.
the class EditMultipleSourcesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
final Navigatable[] files = e.getData(CommonDataKeys.NAVIGATABLE_ARRAY);
assert files != null && files.length > 0;
if (files.length > 1) {
DefaultListModel listModel = new DefaultListModel();
for (int i = 0; i < files.length; ++i) {
assert files[i] instanceof PsiClassNavigation;
//noinspection unchecked
listModel.add(i, ((PsiClassNavigation) files[i]).getPsiFile());
}
final JBList list = new JBList(listModel);
int width = WindowManager.getInstance().getFrame(project).getSize().width;
list.setCellRenderer(new GotoFileCellRenderer(width));
JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(new Runnable() {
@Override
public void run() {
Object selectedValue = list.getSelectedValue();
PsiClassNavigation navigationWrapper = null;
for (Navigatable file : files) {
if (selectedValue == ((PsiClassNavigation) file).getPsiFile()) {
navigationWrapper = (PsiClassNavigation) file;
break;
}
}
assert navigationWrapper != null;
if (navigationWrapper.canNavigate()) {
navigationWrapper.navigate(true);
}
}
}).createPopup();
if (e.getInputEvent().getSource() instanceof ActionButton) {
popup.showUnderneathOf((ActionButton) e.getInputEvent().getSource());
} else {
popup.showInBestPositionFor(e.getDataContext());
}
} else {
assert files[0] instanceof PsiClassNavigation;
PsiClassNavigation file = (PsiClassNavigation) files[0];
if (file.canNavigate()) {
file.navigate(true);
}
}
}
use of com.intellij.ide.util.gotoByName.GotoFileCellRenderer in project intellij-community by JetBrains.
the class MultipleFilesHyperlinkInfo method navigate.
@Override
public void navigate(@NotNull final Project project, @Nullable RelativePoint hyperlinkLocationPoint) {
List<PsiFile> currentFiles = new ArrayList<>();
AccessToken accessToken = ReadAction.start();
try {
for (VirtualFile file : myVirtualFiles) {
if (!file.isValid())
continue;
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile != null) {
// Sources may be downloaded.
PsiElement navigationElement = psiFile.getNavigationElement();
if (navigationElement instanceof PsiFile) {
currentFiles.add((PsiFile) navigationElement);
continue;
}
currentFiles.add(psiFile);
}
}
} finally {
accessToken.finish();
}
if (currentFiles.isEmpty())
return;
if (currentFiles.size() == 1) {
new OpenFileHyperlinkInfo(myProject, currentFiles.get(0).getVirtualFile(), myLineNumber).navigate(project);
} else {
final JBList list = new JBList(currentFiles);
int width = WindowManager.getInstance().getFrame(project).getSize().width;
list.setCellRenderer(new GotoFileCellRenderer(width));
JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(() -> {
VirtualFile file = ((PsiFile) list.getSelectedValue()).getVirtualFile();
new OpenFileHyperlinkInfo(myProject, file, myLineNumber).navigate(project);
}).createPopup();
if (hyperlinkLocationPoint != null) {
popup.show(hyperlinkLocationPoint);
} else {
popup.showInFocusCenter();
}
}
}
Aggregations