From 6b9f4a41190d97dae07836d6ecfec4ac22f8c0bc Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Tue, 3 Jun 2014 21:54:21 +0400 Subject: [PATCH] goto related localizations for properties files --- .../src/META-INF/PropertiesPlugin.xml | 1 + ...toResourceBundleLocalizationsProvider.java | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 plugins/properties/src/com/intellij/lang/properties/editor/GotoResourceBundleLocalizationsProvider.java diff --git a/plugins/properties/properties-psi-impl/src/META-INF/PropertiesPlugin.xml b/plugins/properties/properties-psi-impl/src/META-INF/PropertiesPlugin.xml index d4dc21ce5b02..6b2c0c71af46 100644 --- a/plugins/properties/properties-psi-impl/src/META-INF/PropertiesPlugin.xml +++ b/plugins/properties/properties-psi-impl/src/META-INF/PropertiesPlugin.xml @@ -84,6 +84,7 @@ + diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/GotoResourceBundleLocalizationsProvider.java b/plugins/properties/src/com/intellij/lang/properties/editor/GotoResourceBundleLocalizationsProvider.java new file mode 100644 index 000000000000..a092ad1f912b --- /dev/null +++ b/plugins/properties/src/com/intellij/lang/properties/editor/GotoResourceBundleLocalizationsProvider.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2014 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.lang.properties.editor; + +import com.intellij.lang.properties.ResourceBundle; +import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.navigation.GotoRelatedItem; +import com.intellij.navigation.GotoRelatedProvider; +import com.intellij.openapi.actionSystem.*; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author Dmitry Batkovich + */ +public class GotoResourceBundleLocalizationsProvider extends GotoRelatedProvider { + + @NotNull + @Override + public List getItems(@NotNull final DataContext context) { + final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(context); + if (psiFile == null || !(psiFile instanceof PropertiesFile)) { + return Collections.emptyList(); + } + final ResourceBundle resourceBundle = ((PropertiesFile)psiFile).getResourceBundle(); + final List bundlePropertiesFiles = resourceBundle.getPropertiesFiles(((PropertiesFile)psiFile).getProject()); + assert bundlePropertiesFiles.size() != 0; + if (bundlePropertiesFiles.size() != 1) { + final ArrayList propertiesFilesWithoutCurrent = ContainerUtil.newArrayList(bundlePropertiesFiles); + propertiesFilesWithoutCurrent.remove(psiFile); + return ContainerUtil.map(propertiesFilesWithoutCurrent, new Function() { + @Override + public GotoRelatedItem fun(final PropertiesFile propertiesFile) { + return new GotoRelatedItem((PsiElement) propertiesFile, "Other Localizations"); + } + }); + } else { + return Collections.emptyList(); + } + } +}