diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundleFileStructureViewElement.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundleFileStructureViewElement.java index a158a0b2a5db..dde89d00cdca 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundleFileStructureViewElement.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundleFileStructureViewElement.java @@ -60,10 +60,40 @@ public class ResourceBundleFileStructureViewElement implements StructureViewTree return myResourceBundle; } - private Map getChildrenIdShowOnlyIncomplete() { + @NotNull + public StructureViewTreeElement[] getChildren() { + final Map propertyNames = getPropertiesMap(myResourceBundle, myShowOnlyIncomplete); + List result = new ArrayList(propertyNames.size()); + for (IProperty property : propertyNames.values()) { + result.add(new ResourceBundlePropertyStructureViewElement(myResourceBundle, property)); + } + return result.toArray(new StructureViewTreeElement[result.size()]); + } + + public static Map getPropertiesMap(ResourceBundle resourceBundle, boolean onlyIncomplete) { + List propertiesFiles = resourceBundle.getPropertiesFiles(); + final Map propertyNames; + if (onlyIncomplete) { + propertyNames = getChildrenIdShowOnlyIncomplete(resourceBundle); + } else { + propertyNames = new LinkedHashMap(); + for (PropertiesFile propertiesFile : propertiesFiles) { + List properties = propertiesFile.getProperties(); + for (IProperty property : properties) { + String name = property.getKey(); + if (!propertyNames.containsKey(name)) { + propertyNames.put(name, property); + } + } + } + } + return propertyNames; + } + + private static Map getChildrenIdShowOnlyIncomplete(ResourceBundle resourceBundle) { final Map propertyNames = new LinkedHashMap(); TObjectIntHashMap occurrences = new TObjectIntHashMap(); - for (PropertiesFile file : myResourceBundle.getPropertiesFiles()) { + for (PropertiesFile file : resourceBundle.getPropertiesFiles()) { Map currentFilePropertyNames = new LinkedHashMap(); for (IProperty property : file.getProperties()) { String name = property.getKey(); @@ -80,7 +110,7 @@ public class ResourceBundleFileStructureViewElement implements StructureViewTree } } } - final int targetOccurrences = myResourceBundle.getPropertiesFiles().size(); + final int targetOccurrences = resourceBundle.getPropertiesFiles().size(); occurrences.forEachEntry(new TObjectIntProcedure() { @Override public boolean execute(String propertyName, int occurrences) { @@ -93,31 +123,6 @@ public class ResourceBundleFileStructureViewElement implements StructureViewTree return propertyNames; } - @NotNull - public StructureViewTreeElement[] getChildren() { - List propertiesFiles = myResourceBundle.getPropertiesFiles(); - final Map propertyNames; - if (myShowOnlyIncomplete) { - propertyNames = getChildrenIdShowOnlyIncomplete(); - } else { - propertyNames = new LinkedHashMap(); - for (PropertiesFile propertiesFile : propertiesFiles) { - List properties = propertiesFile.getProperties(); - for (IProperty property : properties) { - String name = property.getKey(); - if (!propertyNames.containsKey(name)) { - propertyNames.put(name, property); - } - } - } - } - List result = new ArrayList(propertyNames.size()); - for (IProperty property : propertyNames.values()) { - result.add(new ResourceBundlePropertyStructureViewElement(myResourceBundle, property)); - } - return result.toArray(new StructureViewTreeElement[result.size()]); - } - @NotNull public ItemPresentation getPresentation() { return new ItemPresentation() { diff --git a/plugins/properties/src/META-INF/plugin.xml b/plugins/properties/src/META-INF/plugin.xml index 2a0cfe4623e1..782f31acd4c2 100644 --- a/plugins/properties/src/META-INF/plugin.xml +++ b/plugins/properties/src/META-INF/plugin.xml @@ -134,5 +134,9 @@ description="Add Property to Resource Bundle"> + diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/GotoNextIncompletePropertyAction.java b/plugins/properties/src/com/intellij/lang/properties/editor/GotoNextIncompletePropertyAction.java new file mode 100644 index 000000000000..b7937f1b84ac --- /dev/null +++ b/plugins/properties/src/com/intellij/lang/properties/editor/GotoNextIncompletePropertyAction.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2015 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.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.diagnostic.Logger; + +/** + * @author Dmitry Batkovich + */ +public class GotoNextIncompletePropertyAction extends AnAction { + private final static Logger LOG = Logger.getInstance(GotoNextIncompletePropertyAction.class); + + @Override + public void actionPerformed(AnActionEvent e) { + final ResourceBundleEditor editor = (ResourceBundleEditor)PlatformDataKeys.FILE_EDITOR.getData(e.getDataContext()); + LOG.assertTrue(editor != null); + editor.selectNextIncompleteProperty(); + } + + @Override + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(PlatformDataKeys.FILE_EDITOR.getData(e.getDataContext()) instanceof ResourceBundleEditor); + } +} 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 e21f79d5a3d9..60f4a9939742 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java @@ -27,9 +27,11 @@ import com.intellij.ide.structureView.newStructureView.StructureViewComponent; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.AbstractTreeUi; import com.intellij.ide.util.treeView.smartTree.CachingChildrenTreeNode; +import com.intellij.ide.util.treeView.smartTree.Sorter; import com.intellij.ide.util.treeView.smartTree.TreeElement; import com.intellij.lang.properties.IProperty; 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.lang.properties.psi.PropertiesResourceBundleUtil; @@ -682,6 +684,38 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit return selectedElements.size() == 1 ? ContainerUtil.getFirstItem(selectedElements) : null; } + public void selectNextIncompleteProperty() { + if (getSelectedNodes().size() != 1) { + return; + } + final IProperty selectedProperty = getSelectedProperty(); + if (selectedProperty == null) { + return; + } + + final ResourceBundleFileStructureViewElement root = + (ResourceBundleFileStructureViewElement)myStructureViewComponent.getTreeModel().getRoot(); + final Map propertiesMap = + ResourceBundleFileStructureViewElement.getPropertiesMap(myResourceBundle, root.isShowOnlyIncomplete()); + final boolean isAlphaSorted = myStructureViewComponent.isActionActive(Sorter.ALPHA_SORTER_ID); + final List keysOrder = new ArrayList(propertiesMap.keySet()); + if (isAlphaSorted) { + Collections.sort(keysOrder); + } + + final String currentKey = selectedProperty.getKey(); + final int idx = keysOrder.indexOf(currentKey); + LOG.assertTrue(idx != -1); + for (int i = 1; i < keysOrder.size(); i++) { + int trimmedIndex = (i + idx) % keysOrder.size(); + final String key = keysOrder.get(trimmedIndex); + if (!PropertiesUtil.isPropertyComplete(myResourceBundle, key)) { + selectProperty(key); + return; + } + } + } + @Override @NotNull public JComponent getComponent() {