mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
GotoRelatedFileAction for forms: reverse navigation
This commit is contained in:
@@ -43,7 +43,7 @@ public class GotoRelatedFileAction extends AnAction {
|
||||
DataContext context = e.getDataContext();
|
||||
Editor editor = PlatformDataKeys.EDITOR.getData(context);
|
||||
PsiFile psiFile = LangDataKeys.PSI_FILE.getData(context);
|
||||
if (editor == null || psiFile == null) return;
|
||||
if (psiFile == null) return;
|
||||
|
||||
List<GotoRelatedItem> items = getItems(editor, psiFile);
|
||||
if (items.isEmpty()) return;
|
||||
@@ -72,8 +72,11 @@ public class GotoRelatedFileAction extends AnAction {
|
||||
}
|
||||
|
||||
public static List<GotoRelatedItem> getItems(Editor editor, PsiFile psiFile) {
|
||||
PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
|
||||
if (psiElement == null) psiElement = psiFile;
|
||||
|
||||
PsiElement psiElement = psiFile;
|
||||
if (editor != null) {
|
||||
psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
|
||||
}
|
||||
|
||||
List<GotoRelatedItem> items = new ArrayList<GotoRelatedItem>();
|
||||
|
||||
@@ -85,8 +88,7 @@ public class GotoRelatedFileAction extends AnAction {
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(PlatformDataKeys.EDITOR.getData(e.getDataContext()) != null &&
|
||||
LangDataKeys.PSI_FILE.getData(e.getDataContext()) != null);
|
||||
e.getPresentation().setEnabled(LangDataKeys.PSI_FILE.getData(e.getDataContext()) != null);
|
||||
}
|
||||
|
||||
private static class ItemCellRenderer extends JPanel implements ListCellRenderer {
|
||||
|
||||
@@ -23,7 +23,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author yole
|
||||
*/
|
||||
public class FormFileTypeFactory extends FileTypeFactory {
|
||||
|
||||
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
|
||||
consumer.consume(new GuiFormFileType(), GuiFormFileType.DEFAULT_EXTENSION);
|
||||
consumer.consume(GuiFormFileType.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.swing.*;
|
||||
|
||||
public class GuiFormFileType implements FileType {
|
||||
|
||||
public static final GuiFormFileType INSTANCE = new GuiFormFileType();
|
||||
|
||||
@NonNls public static final String DEFAULT_EXTENSION = "form";
|
||||
@NonNls public static final String DOT_DEFAULT_EXTENSION = "." + DEFAULT_EXTENSION;
|
||||
|
||||
|
||||
@@ -18,10 +18,15 @@ package com.intellij.uiDesigner.binding;
|
||||
import com.intellij.navigation.GotoRelatedItem;
|
||||
import com.intellij.navigation.GotoRelatedProvider;
|
||||
import com.intellij.navigation.PsiGotoRelatedItem;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.uiDesigner.GuiFormFileType;
|
||||
import com.intellij.uiDesigner.compiler.Utils;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -47,6 +52,24 @@ public class FormRelatedFilesProvider extends GotoRelatedProvider {
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
PsiFile file = context.getContainingFile();
|
||||
if (file.getFileType() == GuiFormFileType.INSTANCE) {
|
||||
try {
|
||||
String className = Utils.getBoundClassName(file.getText());
|
||||
if (className != null) {
|
||||
Project project = file.getProject();
|
||||
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
|
||||
if (aClass != null) {
|
||||
return Collections.<GotoRelatedItem>singletonList(new PsiGotoRelatedItem(aClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user