summaryrefslogtreecommitdiff
path: root/plugins/properties/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/properties/src')
-rw-r--r--plugins/properties/src/META-INF/plugin.xml7
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/PropertiesFilesManager.java9
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java4
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/customizeActions/CombinePropertiesFilesAction.java155
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/customizeActions/DissociateResourceBundleAction.java80
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java32
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java4
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorProvider.java2
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java2
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleUtil.java2
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/projectView/CustomResourceBundlePropertiesFileNode.java56
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleGrouper.java5
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleNode.java2
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/refactoring/rename/RenamePropertyProcessor.java2
-rw-r--r--plugins/properties/src/com/intellij/lang/properties/refactoring/rename/ResourceBundleRenamer.java9
15 files changed, 334 insertions, 37 deletions
diff --git a/plugins/properties/src/META-INF/plugin.xml b/plugins/properties/src/META-INF/plugin.xml
index 513678dcbf72..672add1a002d 100644
--- a/plugins/properties/src/META-INF/plugin.xml
+++ b/plugins/properties/src/META-INF/plugin.xml
@@ -34,6 +34,7 @@
implementationClass="com.intellij.lang.properties.PropertyManipulator"/>
<projectService serviceInterface="com.intellij.lang.properties.structureView.PropertiesSeparatorManager"
serviceImplementation="com.intellij.lang.properties.structureView.PropertiesSeparatorManager"/>
+ <projectService serviceImplementation="com.intellij.lang.properties.ResourceBundleManager"/>
<codeInsight.wordCompletionFilter language="Properties"
implementationClass="com.intellij.lang.properties.PropertiesWordCompletionFilter"/>
<lang.psiStructureViewFactory language="Properties"
@@ -98,6 +99,12 @@
</project-components>
<actions>
+ <action id="DissociateResourceBundleAction" class="com.intellij.lang.properties.customizeActions.DissociateResourceBundleAction">
+ <add-to-group group-id="ProjectViewPopupMenu"/>
+ </action>
+ <action id="CombinePropertiesFilesAction" class="com.intellij.lang.properties.customizeActions.CombinePropertiesFilesAction">
+ <add-to-group group-id="ProjectViewPopupMenu"/>
+ </action>
<action id="ChooseNextSubsequentPropertyValueEditorAction"
class="com.intellij.lang.properties.editor.ChooseSubsequentPropertyValueEditorAction$Next"
text="Choose Next Property Value Editor"
diff --git a/plugins/properties/src/com/intellij/lang/properties/PropertiesFilesManager.java b/plugins/properties/src/com/intellij/lang/properties/PropertiesFilesManager.java
index 60d337681a31..5477c137021e 100644
--- a/plugins/properties/src/com/intellij/lang/properties/PropertiesFilesManager.java
+++ b/plugins/properties/src/com/intellij/lang/properties/PropertiesFilesManager.java
@@ -20,7 +20,7 @@ import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.psi.search.FileTypeIndex;
@@ -44,20 +44,24 @@ public class PropertiesFilesManager extends AbstractProjectComponent {
super(project);
}
+ @Override
public void projectOpened() {
final PropertyChangeListener myListener = new PropertyChangeListener() {
+ @Override
public void propertyChange(final PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if (EncodingManager.PROP_NATIVE2ASCII_SWITCH.equals(propertyName) ||
EncodingManager.PROP_PROPERTIES_FILES_ENCODING.equals(propertyName)
) {
DumbService.getInstance(myProject).smartInvokeLater(new Runnable(){
+ @Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable(){
+ @Override
public void run() {
Collection<VirtualFile> filesToRefresh = FileBasedIndex.getInstance()
.getContainingFiles(FileTypeIndex.NAME, PropertiesFileType.INSTANCE, GlobalSearchScope.allScope(myProject));
- VirtualFile[] virtualFiles = VfsUtil.toVirtualFileArray(filesToRefresh);
+ VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(filesToRefresh);
FileDocumentManager.getInstance().saveAllDocuments();
//force to re-detect encoding
@@ -75,6 +79,7 @@ public class PropertiesFilesManager extends AbstractProjectComponent {
EncodingManager.getInstance().addPropertyChangeListener(myListener,myProject);
}
+ @Override
@NotNull
public String getComponentName() {
return "PropertiesFileManager";
diff --git a/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java b/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java
index 5f708c3eda61..14ac858d9917 100644
--- a/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java
+++ b/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java
@@ -97,14 +97,14 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement> implem
if (!(element instanceof PropertiesFile)) {
throw new IncorrectOperationException();
}
- final String name = PropertiesUtil.getFullName((PropertiesFile)element);
+ final String name = ResourceBundleManager.getInstance(element.getProject()).getFullName((PropertiesFile)element);
return super.handleElementRename(name);
}
public boolean isReferenceTo(PsiElement element) {
if (element instanceof PropertiesFile) {
- final String name = PropertiesUtil.getFullName((PropertiesFile)element);
+ final String name = ResourceBundleManager.getInstance(element.getProject()).getFullName((PropertiesFile)element);
if (name != null && name.equals(myBundleName)) {
return true;
}
diff --git a/plugins/properties/src/com/intellij/lang/properties/customizeActions/CombinePropertiesFilesAction.java b/plugins/properties/src/com/intellij/lang/properties/customizeActions/CombinePropertiesFilesAction.java
new file mode 100644
index 000000000000..b90e74a2c767
--- /dev/null
+++ b/plugins/properties/src/com/intellij/lang/properties/customizeActions/CombinePropertiesFilesAction.java
@@ -0,0 +1,155 @@
+/*
+ * 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.customizeActions;
+
+import com.intellij.icons.AllIcons;
+import com.intellij.ide.projectView.ProjectView;
+import com.intellij.lang.properties.PropertiesBundle;
+import com.intellij.lang.properties.PropertiesImplUtil;
+import com.intellij.lang.properties.PropertiesUtil;
+import com.intellij.lang.properties.ResourceBundle;
+import com.intellij.lang.properties.ResourceBundleManager;
+import com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile;
+import com.intellij.lang.properties.psi.PropertiesFile;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.InputValidatorEx;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class CombinePropertiesFilesAction extends AnAction {
+
+ public CombinePropertiesFilesAction() {
+ super(PropertiesBundle.message("combine.properties.files.title"), null, AllIcons.FileTypes.Properties);
+ }
+
+ @Override
+ public void actionPerformed(final AnActionEvent e) {
+ final List<PropertiesFile> propertiesFiles = getPropertiesFiles(e);
+ final String newBaseName = Messages.showInputDialog(propertiesFiles.get(0).getProject(),
+ PropertiesBundle.message("combine.properties.files.prompt.text"),
+ PropertiesBundle.message("combine.properties.files.title"),
+ Messages.getQuestionIcon(),
+ PropertiesUtil.getDefaultBaseName(propertiesFiles),
+ new MyInputValidator(propertiesFiles));
+ if (newBaseName != null) {
+ final Project project = propertiesFiles.get(0).getProject();
+ ResourceBundleManager.getInstance(project).combineToResourceBundle(propertiesFiles, newBaseName);
+ final ResourceBundle resourceBundle = propertiesFiles.get(0).getResourceBundle();
+ FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(resourceBundle), true);
+ ProjectView.getInstance(project).refresh();
+ }
+ }
+
+ @Override
+ public void update(final AnActionEvent e) {
+ final List<PropertiesFile> propertiesFiles = getPropertiesFiles(e);
+ boolean isAvailable = propertiesFiles != null && propertiesFiles.size() > 1;
+ if (isAvailable) {
+ for (PropertiesFile propertiesFile : propertiesFiles) {
+ if (propertiesFile.getResourceBundle().getPropertiesFiles().size() != 1) {
+ isAvailable = false;
+ break;
+ }
+ }
+ }
+ e.getPresentation().setVisible(isAvailable);
+ }
+
+ @Nullable
+ private static List<PropertiesFile> getPropertiesFiles(AnActionEvent e) {
+ final PsiElement[] psiElements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
+ if (psiElements == null || psiElements.length == 0) {
+ return null;
+ }
+ final List<PropertiesFile> files = new ArrayList<PropertiesFile>(psiElements.length);
+ for (PsiElement psiElement : psiElements) {
+ if (!(psiElement instanceof PsiFile)) {
+ return null;
+ }
+ final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile((PsiFile)psiElement);
+ if (propertiesFile == null) {
+ return null;
+ }
+ files.add(propertiesFile);
+ }
+ return files;
+ }
+
+ @Override
+ public boolean isDumbAware() {
+ return true;
+ }
+
+ private static class MyInputValidator implements InputValidatorEx {
+ private final List<PropertiesFile> myPropertiesFiles;
+
+ private MyInputValidator(final List<PropertiesFile> propertiesFiles) {
+ myPropertiesFiles = propertiesFiles;
+ }
+
+ @Override
+ public boolean checkInput(final String newBaseName) {
+ return !newBaseName.isEmpty() && checkBaseName(newBaseName) == null;
+ }
+
+ @Override
+ public boolean canClose(final String newBaseName) {
+ return true;
+ }
+
+ @Nullable
+ @Override
+ public String getErrorText(String inputString) {
+ return checkInput(inputString) ? null : String.format("Base name must be valid for file \'%s\'", checkBaseName(inputString).getFailedFile());
+ }
+
+ @Nullable
+ private BaseNameError checkBaseName(final String baseNameCandidate) {
+ for (PropertiesFile propertiesFile : myPropertiesFiles) {
+ final String name = propertiesFile.getVirtualFile().getName();
+ if (!name.startsWith(baseNameCandidate) || !PropertiesUtil.BASE_NAME_BORDER_CHAR.contains(name.charAt(baseNameCandidate.length()))) {
+ return new BaseNameError(name);
+ }
+ }
+ return null;
+ }
+
+ private static class BaseNameError {
+
+ private final String myFailedFile;
+
+ private BaseNameError(String failedFile) {
+ myFailedFile = failedFile;
+ }
+
+ public String getFailedFile() {
+ return myFailedFile;
+ }
+ }
+ }
+}
diff --git a/plugins/properties/src/com/intellij/lang/properties/customizeActions/DissociateResourceBundleAction.java b/plugins/properties/src/com/intellij/lang/properties/customizeActions/DissociateResourceBundleAction.java
new file mode 100644
index 000000000000..10041448d97c
--- /dev/null
+++ b/plugins/properties/src/com/intellij/lang/properties/customizeActions/DissociateResourceBundleAction.java
@@ -0,0 +1,80 @@
+/*
+ * 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.customizeActions;
+
+import com.intellij.icons.AllIcons;
+import com.intellij.ide.projectView.ProjectView;
+import com.intellij.lang.properties.PropertiesImplUtil;
+import com.intellij.lang.properties.ResourceBundle;
+import com.intellij.lang.properties.ResourceBundleManager;
+import com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile;
+import com.intellij.lang.properties.psi.PropertiesFile;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class DissociateResourceBundleAction extends AnAction {
+ private static final String PRESENTATION_TEXT_TEMPLATE = "Dissociate Resource Bundle '%s'";
+
+ public DissociateResourceBundleAction() {
+ super(null, null, AllIcons.FileTypes.Properties);
+ }
+
+ @Override
+ public void actionPerformed(final AnActionEvent e) {
+ final ResourceBundle resourceBundle = extractResourceBundle(e);
+ assert resourceBundle != null;
+ final Project project = resourceBundle.getProject();
+ final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
+ fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
+ for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
+ fileEditorManager.closeFile(propertiesFile.getVirtualFile());
+ }
+ ResourceBundleManager.getInstance(e.getProject()).dissociateResourceBundle(resourceBundle);
+ ProjectView.getInstance(project).refresh();
+ }
+
+ @Override
+ public void update(final AnActionEvent e) {
+ final ResourceBundle resourceBundle = extractResourceBundle(e);
+ if (resourceBundle != null) {
+ e.getPresentation().setText(String.format(PRESENTATION_TEXT_TEMPLATE, resourceBundle.getBaseName()), false);
+ e.getPresentation().setVisible(true);
+ } else {
+ e.getPresentation().setVisible(false);
+ }
+ }
+
+ @Nullable
+ private static ResourceBundle extractResourceBundle(final AnActionEvent event) {
+ final ResourceBundle[] data = event.getData(ResourceBundle.ARRAY_DATA_KEY);
+ if (data != null && data.length == 1 && data[0].getPropertiesFiles().size() > 1) {
+ return data[0];
+ }
+ final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(event.getData(PlatformDataKeys.PSI_FILE));
+ if (propertiesFile == null) {
+ return null;
+ }
+ final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
+ return resourceBundle.getPropertiesFiles().size() > 1 ? resourceBundle : null;
+ }
+}
diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java
index 36915e7e6962..bae39bd9f2d0 100644
--- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java
+++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java
@@ -23,14 +23,10 @@ import com.intellij.ide.presentation.Presentation;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.ResourceBundle;
-import com.intellij.lang.properties.psi.PropertiesFile;
-import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
-import com.intellij.psi.PsiManager;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
@@ -38,25 +34,15 @@ import java.io.OutputStream;
@Presentation(icon = "AllIcons.Nodes.ResourceBundle")
public class ResourceBundleAsVirtualFile extends VirtualFile {
- private final VirtualFile myBasePropertiesFile;
+ private final ResourceBundle myResourceBundle;
- private ResourceBundleAsVirtualFile(@NotNull final VirtualFile basePropertiesFile) {
- myBasePropertiesFile = basePropertiesFile;
+ public ResourceBundleAsVirtualFile(@NotNull final ResourceBundle resourceBundle) {
+ myResourceBundle = resourceBundle;
}
@NotNull
- public static ResourceBundleAsVirtualFile fromResourceBundle(final @NotNull ResourceBundle resourceBundle) {
- return new ResourceBundleAsVirtualFile(resourceBundle.getDefaultPropertiesFile().getVirtualFile());
- }
-
- @Nullable
- public ResourceBundle getResourceBundle(final Project project) {
- final PsiManager psiManager = PsiManager.getInstance(project);
- final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(psiManager.findFile(myBasePropertiesFile));
- if (file == null) {
- return null;
- }
- return PropertiesImplUtil.getResourceBundle(file);
+ public ResourceBundle getResourceBundle() {
+ return myResourceBundle;
}
@Override
@@ -74,7 +60,7 @@ public class ResourceBundleAsVirtualFile extends VirtualFile {
@Override
@NotNull
public String getName() {
- return PropertiesUtil.getBaseName(myBasePropertiesFile);
+ return myResourceBundle.getBaseName();
}
public boolean equals(final Object o) {
@@ -83,13 +69,13 @@ public class ResourceBundleAsVirtualFile extends VirtualFile {
final ResourceBundleAsVirtualFile resourceBundleAsVirtualFile = (ResourceBundleAsVirtualFile)o;
- if (!myBasePropertiesFile.equals(resourceBundleAsVirtualFile.myBasePropertiesFile)) return false;
+ if (!myResourceBundle.equals(resourceBundleAsVirtualFile.myResourceBundle)) return false;
return true;
}
public int hashCode() {
- return myBasePropertiesFile.hashCode();
+ return myResourceBundle.hashCode();
}
@Override
@@ -114,7 +100,7 @@ public class ResourceBundleAsVirtualFile extends VirtualFile {
@Override
public VirtualFile getParent() {
- return myBasePropertiesFile.getParent();
+ return myResourceBundle.getBaseDirectory();
}
@Override
diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java
index 39e9ed67e7b2..27deebbff2af 100644
--- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java
+++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java
@@ -170,7 +170,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
TreeElement[] children = myStructureViewComponent.getTreeModel().getRoot().getChildren();
if (children.length != 0) {
TreeElement child = children[0];
- String propName = ((ResourceBundlePropertyStructureViewElement)child).getValue().getUnescapedKey();
+ String propName = ((ResourceBundlePropertyStructureViewElement)child).getProperty().getUnescapedKey();
setState(new ResourceBundleEditorState(propName));
}
myDataProviderPanel = new DataProviderPanel(splitPanel);
@@ -248,7 +248,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
DefaultMutableTreeNode node = toCheck.pop();
final ResourceBundleEditorViewElement element = getSelectedElement(node);
String value = element instanceof ResourceBundlePropertyStructureViewElement
- ? ((ResourceBundlePropertyStructureViewElement)element).getValue().getUnescapedKey()
+ ? ((ResourceBundlePropertyStructureViewElement)element).getProperty().getUnescapedKey()
: null;
if (propertyName.equals(value)) {
nodeToSelect = node;
diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorProvider.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorProvider.java
index fdbc2c0c5e59..d70dd358a9a9 100644
--- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorProvider.java
+++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorProvider.java
@@ -50,7 +50,7 @@ public class ResourceBundleEditorProvider extends FileTypeFactory implements Fil
public FileEditor createEditor(@NotNull Project project, @NotNull final VirtualFile file){
ResourceBundle resourceBundle;
if (file instanceof ResourceBundleAsVirtualFile) {
- resourceBundle = ((ResourceBundleAsVirtualFile)file).getResourceBundle(project);
+ resourceBundle = ((ResourceBundleAsVirtualFile)file).getResourceBundle();
}
else {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java
index da376abe05b2..f950f613ecb9 100644
--- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java
+++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java
@@ -72,7 +72,7 @@ class ResourceBundleStructureViewComponent extends PropertiesGroupingStructureVi
public Object getData(final String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
- return ResourceBundleAsVirtualFile.fromResourceBundle(myResourceBundle);
+ return new ResourceBundleAsVirtualFile(myResourceBundle);
} else if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
return getFileEditor();
} else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleUtil.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleUtil.java
index e4a35e7e677c..51c3764b7f2e 100644
--- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleUtil.java
+++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleUtil.java
@@ -56,7 +56,7 @@ public class ResourceBundleUtil {
}
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFile instanceof ResourceBundleAsVirtualFile && project != null) {
- return ((ResourceBundleAsVirtualFile)virtualFile).getResourceBundle(project);
+ return ((ResourceBundleAsVirtualFile)virtualFile).getResourceBundle();
}
if (project != null) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
diff --git a/plugins/properties/src/com/intellij/lang/properties/projectView/CustomResourceBundlePropertiesFileNode.java b/plugins/properties/src/com/intellij/lang/properties/projectView/CustomResourceBundlePropertiesFileNode.java
new file mode 100644
index 000000000000..605b8c843a47
--- /dev/null
+++ b/plugins/properties/src/com/intellij/lang/properties/projectView/CustomResourceBundlePropertiesFileNode.java
@@ -0,0 +1,56 @@
+/*
+ * 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.projectView;
+
+import com.intellij.ide.projectView.PresentationData;
+import com.intellij.ide.projectView.ViewSettings;
+import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
+import com.intellij.lang.properties.PropertiesBundle;
+import com.intellij.lang.properties.PropertiesImplUtil;
+import com.intellij.lang.properties.ResourceBundle;
+import com.intellij.lang.properties.psi.PropertiesFile;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Comparing;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiManager;
+import com.intellij.ui.SimpleTextAttributes;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class CustomResourceBundlePropertiesFileNode extends PsiFileNode {
+ public CustomResourceBundlePropertiesFileNode(Project project, PsiFile value, ViewSettings viewSettings) {
+ super(project, value, viewSettings);
+ setUpdateCount(-1);
+ }
+
+ @Override
+ public void update(PresentationData data) {
+ super.update(data);
+ final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(getValue());
+ assert propertiesFile != null;
+ final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
+ data.setLocationString(PropertiesBundle.message("project.view.resource.bundle.tree.node.text", resourceBundle.getBaseName()));
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof CustomResourceBundlePropertiesFileNode)) {
+ return false;
+ }
+ return Comparing.equal(getValue(), ((CustomResourceBundlePropertiesFileNode)object).getValue());
+ }
+}
diff --git a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleGrouper.java b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleGrouper.java
index 0ac072c062c2..f6f268df3597 100644
--- a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleGrouper.java
+++ b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleGrouper.java
@@ -18,6 +18,7 @@ package com.intellij.lang.properties.projectView;
import com.intellij.ide.projectView.TreeStructureProvider;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.util.treeView.AbstractTreeNode;
+import com.intellij.lang.properties.CustomResourceBundle;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
@@ -83,6 +84,10 @@ public class ResourceBundleGrouper implements TreeStructureProvider, DumbAware {
ResourceBundle bundle = propertiesFile.getResourceBundle();
if (childBundles.get(bundle).size() != 1) {
continue;
+ } else if (bundle instanceof CustomResourceBundle) {
+ final CustomResourceBundlePropertiesFileNode node =
+ new CustomResourceBundlePropertiesFileNode(myProject, (PsiFile)f, settings);
+ result.add(node);
}
}
}
diff --git a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleNode.java b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleNode.java
index a415e4544aa0..b9f61643095d 100644
--- a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleNode.java
+++ b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleNode.java
@@ -86,7 +86,7 @@ public class ResourceBundleNode extends ProjectViewNode<ResourceBundle>{
}
public void navigate(final boolean requestFocus) {
- OpenFileDescriptor descriptor = new OpenFileDescriptor(getProject(), ResourceBundleAsVirtualFile.fromResourceBundle(getValue()));
+ OpenFileDescriptor descriptor = new OpenFileDescriptor(getProject(), new ResourceBundleAsVirtualFile(getValue()));
FileEditorManager.getInstance(getProject()).openTextEditor(descriptor, requestFocus);
}
diff --git a/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/RenamePropertyProcessor.java b/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/RenamePropertyProcessor.java
index f3c81736673f..6f0d52f1c294 100644
--- a/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/RenamePropertyProcessor.java
+++ b/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/RenamePropertyProcessor.java
@@ -46,7 +46,7 @@ public class RenamePropertyProcessor extends RenamePsiElementProcessor {
allRenames.clear();
for (final Map.Entry<PsiElement, String> e : allRenamesCopy.entrySet()) {
final IProperty property = (IProperty) e.getKey();
- final List<IProperty> properties = PropertiesUtil.findAllProperties(project, resourceBundle, property.getUnescapedKey());
+ final List<IProperty> properties = PropertiesUtil.findAllProperties(resourceBundle, property.getUnescapedKey());
for (final IProperty toRename : properties) {
allRenames.put(toRename.getPsiElement(), e.getValue());
}
diff --git a/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/ResourceBundleRenamer.java b/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/ResourceBundleRenamer.java
index ab1b4391b0f6..000f72ef5ae3 100644
--- a/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/ResourceBundleRenamer.java
+++ b/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/ResourceBundleRenamer.java
@@ -16,7 +16,7 @@
package com.intellij.lang.properties.refactoring.rename;
import com.intellij.lang.properties.PropertiesBundle;
-import com.intellij.lang.properties.PropertiesUtil;
+import com.intellij.lang.properties.ResourceBundleManager;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNamedElement;
@@ -28,7 +28,10 @@ import org.jetbrains.annotations.NonNls;
*/
public class ResourceBundleRenamer extends AutomaticRenamer {
+ private final ResourceBundleManager myResourceBundleManager;
+
public ResourceBundleRenamer(final PropertiesFile propertiesFile, final String newName) {
+ myResourceBundleManager = ResourceBundleManager.getInstance(propertiesFile.getProject());
for (final PropertiesFile file : propertiesFile.getResourceBundle().getPropertiesFiles()) {
if (file.equals(propertiesFile)) {
continue;
@@ -41,12 +44,12 @@ public class ResourceBundleRenamer extends AutomaticRenamer {
@Override
protected String nameToCanonicalName(@NonNls final String name, final PsiNamedElement element) {
- return PropertiesUtil.getBaseName((PsiFile)element);
+ return myResourceBundleManager.getBaseName((PsiFile)element);
}
@Override
protected String canonicalNameToName(@NonNls final String canonicalName, final PsiNamedElement element) {
- final String oldCanonicalName = PropertiesUtil.getBaseName((PsiFile)element);
+ final String oldCanonicalName = myResourceBundleManager.getBaseName((PsiFile)element);
final String oldName = element.getName();
assert oldName != null;
return canonicalName + oldName.substring(oldCanonicalName.length());