|
5 | 5 | import com.intellij.notification.Notifications;
|
6 | 6 | import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
7 | 7 | import com.intellij.openapi.project.Project;
|
| 8 | +import com.intellij.openapi.ui.popup.JBPopupFactory; |
8 | 9 | import com.intellij.openapi.util.TextRange;
|
| 10 | +import com.intellij.openapi.vfs.VirtualFile; |
9 | 11 | import com.intellij.psi.PsiElement;
|
10 | 12 | import com.intellij.psi.PsiFile;
|
11 | 13 | import com.intellij.psi.PsiReferenceBase;
|
|
16 | 18 | import org.jetbrains.annotations.NotNull;
|
17 | 19 | import org.jetbrains.annotations.Nullable;
|
18 | 20 |
|
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.HashMap; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | + |
19 | 26 | public class FileInfoRef extends PsiReferenceBase<PsiElement> {
|
20 | 27 |
|
21 | 28 | public FileInfoRef(@NotNull PsiElement element, TextRange textRange) {
|
@@ -43,18 +50,29 @@ public void navigate(boolean requestFocus) {
|
43 | 50 | int line = Integer.valueOf(pos[0]) - 1;
|
44 | 51 | int column = Integer.valueOf(pos[1].replace("]", "")) - 1;
|
45 | 52 |
|
46 |
| - Project p = myElement.getProject(); |
47 |
| - PsiFile[] files = FilenameIndex.getFilesByName(p,filename, GlobalSearchScope.projectScope(p)); |
| 53 | + Project project = myElement.getProject(); |
| 54 | + PsiFile[] files = FilenameIndex.getFilesByName(project,filename, GlobalSearchScope.projectScope(project)); |
48 | 55 | int length = files.length;
|
49 | 56 | if (length != 0){
|
50 | 57 | if (length == 1) {
|
51 |
| - new OpenFileDescriptor(p, files[0].getVirtualFile(),line,column).navigate(true); |
| 58 | + new OpenFileDescriptor(project, files[0].getVirtualFile(),line,column).navigate(true); |
52 | 59 | } else {
|
53 |
| - Notifications.Bus.notify(new Notification("","",String.valueOf(length) + " " |
54 |
| - + filename + "files found!", NotificationType.INFORMATION)); |
| 60 | + List<String> list = new ArrayList<>(); |
| 61 | + final Map<String, VirtualFile> map = new HashMap<>(); |
| 62 | + for (PsiFile file : files) { |
| 63 | + VirtualFile vFile = file.getVirtualFile(); |
| 64 | + String relativePath = vFile.getCanonicalPath().replace(project.getBasePath(), "").substring(1); |
| 65 | + |
| 66 | + map.put(relativePath, vFile); |
| 67 | + list.add(relativePath); |
| 68 | + } |
| 69 | + JBPopupFactory.getInstance().createPopupChooserBuilder(list) |
| 70 | + .setTitle("File Chooser") |
| 71 | + .setItemChosenCallback((chosenFile) -> new OpenFileDescriptor(project, map.get(chosenFile),line,column).navigate(true)) |
| 72 | + .createPopup().showInFocusCenter(); |
55 | 73 | }
|
56 | 74 | } else {
|
57 |
| - Notifications.Bus.notify(new Notification("","",filename + " not found!", |
| 75 | + Notifications.Bus.notify(new Notification("FileInfo","",filename + " not found!", |
58 | 76 | NotificationType.ERROR));
|
59 | 77 | }
|
60 | 78 | }
|
|
0 commit comments