From bc9e5a29a43e0aa0e5a869a71d63bc17e869fcba Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 29 Mar 2011 13:15:52 +0400 Subject: [PATCH] GotoRelatedFileAction for forms --- .../navigation/PsiGotoRelatedItem.java | 55 +++++++++++++++++++ plugins/ui-designer/src/META-INF/plugin.xml | 1 + .../binding/FormRelatedFilesProvider.java | 52 ++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 platform/lang-api/src/com/intellij/navigation/PsiGotoRelatedItem.java create mode 100644 plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java diff --git a/platform/lang-api/src/com/intellij/navigation/PsiGotoRelatedItem.java b/platform/lang-api/src/com/intellij/navigation/PsiGotoRelatedItem.java new file mode 100644 index 000000000000..2b3c9e75c151 --- /dev/null +++ b/platform/lang-api/src/com/intellij/navigation/PsiGotoRelatedItem.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.navigation; + +import com.intellij.psi.NavigatablePsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author Dmitry Avdeev + */ +public class PsiGotoRelatedItem extends GotoRelatedItem { + + private final NavigatablePsiElement myElement; + + public PsiGotoRelatedItem(@NotNull NavigatablePsiElement element) { + myElement = element; + } + + @Override + public void navigate() { + myElement.navigate(true); + } + + @NotNull + @Override + public String getText() { + return myElement.getName(); + } + + @Override + public Icon getIcon() { + return myElement.getIcon(0); + } + + @Override + public PsiFile getContainingFile() { + return myElement.getContainingFile(); + } +} diff --git a/plugins/ui-designer/src/META-INF/plugin.xml b/plugins/ui-designer/src/META-INF/plugin.xml index 6c1f403e23aa..c14277c05805 100644 --- a/plugins/ui-designer/src/META-INF/plugin.xml +++ b/plugins/ui-designer/src/META-INF/plugin.xml @@ -111,6 +111,7 @@ + diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java new file mode 100644 index 000000000000..46e4dd1a351a --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.uiDesigner.binding; + +import com.intellij.navigation.GotoRelatedItem; +import com.intellij.navigation.GotoRelatedProvider; +import com.intellij.navigation.PsiGotoRelatedItem; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dmitry Avdeev + */ +public class FormRelatedFilesProvider extends GotoRelatedProvider { + + @NotNull + @Override + public List getItems(PsiElement context) { + PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class, false); + if (psiClass != null) { + List forms = FormClassIndex.findFormsBoundToClass(psiClass); + return ContainerUtil.map(forms, new Function() { + @Override + public GotoRelatedItem fun(PsiFile psiFile) { + return new PsiGotoRelatedItem(psiFile); + } + }); + } + return Collections.emptyList(); + } +}