mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-86919 navigate to the next incomplete property in resource bundle
This commit is contained in:
+33
-28
@@ -60,10 +60,40 @@ public class ResourceBundleFileStructureViewElement implements StructureViewTree
|
||||
return myResourceBundle;
|
||||
}
|
||||
|
||||
private Map<String, IProperty> getChildrenIdShowOnlyIncomplete() {
|
||||
@NotNull
|
||||
public StructureViewTreeElement[] getChildren() {
|
||||
final Map<String, IProperty> propertyNames = getPropertiesMap(myResourceBundle, myShowOnlyIncomplete);
|
||||
List<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>(propertyNames.size());
|
||||
for (IProperty property : propertyNames.values()) {
|
||||
result.add(new ResourceBundlePropertyStructureViewElement(myResourceBundle, property));
|
||||
}
|
||||
return result.toArray(new StructureViewTreeElement[result.size()]);
|
||||
}
|
||||
|
||||
public static Map<String, IProperty> getPropertiesMap(ResourceBundle resourceBundle, boolean onlyIncomplete) {
|
||||
List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
|
||||
final Map<String, IProperty> propertyNames;
|
||||
if (onlyIncomplete) {
|
||||
propertyNames = getChildrenIdShowOnlyIncomplete(resourceBundle);
|
||||
} else {
|
||||
propertyNames = new LinkedHashMap<String, IProperty>();
|
||||
for (PropertiesFile propertiesFile : propertiesFiles) {
|
||||
List<IProperty> properties = propertiesFile.getProperties();
|
||||
for (IProperty property : properties) {
|
||||
String name = property.getKey();
|
||||
if (!propertyNames.containsKey(name)) {
|
||||
propertyNames.put(name, property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertyNames;
|
||||
}
|
||||
|
||||
private static Map<String, IProperty> getChildrenIdShowOnlyIncomplete(ResourceBundle resourceBundle) {
|
||||
final Map<String, IProperty> propertyNames = new LinkedHashMap<String, IProperty>();
|
||||
TObjectIntHashMap<String> occurrences = new TObjectIntHashMap<String>();
|
||||
for (PropertiesFile file : myResourceBundle.getPropertiesFiles()) {
|
||||
for (PropertiesFile file : resourceBundle.getPropertiesFiles()) {
|
||||
Map<String, IProperty> currentFilePropertyNames = new LinkedHashMap<String, IProperty>();
|
||||
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<String>() {
|
||||
@Override
|
||||
public boolean execute(String propertyName, int occurrences) {
|
||||
@@ -93,31 +123,6 @@ public class ResourceBundleFileStructureViewElement implements StructureViewTree
|
||||
return propertyNames;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StructureViewTreeElement[] getChildren() {
|
||||
List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles();
|
||||
final Map<String, IProperty> propertyNames;
|
||||
if (myShowOnlyIncomplete) {
|
||||
propertyNames = getChildrenIdShowOnlyIncomplete();
|
||||
} else {
|
||||
propertyNames = new LinkedHashMap<String, IProperty>();
|
||||
for (PropertiesFile propertiesFile : propertiesFiles) {
|
||||
List<IProperty> properties = propertiesFile.getProperties();
|
||||
for (IProperty property : properties) {
|
||||
String name = property.getKey();
|
||||
if (!propertyNames.containsKey(name)) {
|
||||
propertyNames.put(name, property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>(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() {
|
||||
|
||||
@@ -134,5 +134,9 @@
|
||||
description="Add Property to Resource Bundle">
|
||||
<add-to-group group-id="NewGroup" anchor="first"/>
|
||||
</action>
|
||||
<action id="GotoNextIncompletePropertyAction"
|
||||
class="com.intellij.lang.properties.editor.GotoNextIncompletePropertyAction"
|
||||
text="Go to next incomplete property"
|
||||
use-shortcut-of="GotoNextError"/>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
||||
+40
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<String, IProperty> propertiesMap =
|
||||
ResourceBundleFileStructureViewElement.getPropertiesMap(myResourceBundle, root.isShowOnlyIncomplete());
|
||||
final boolean isAlphaSorted = myStructureViewComponent.isActionActive(Sorter.ALPHA_SORTER_ID);
|
||||
final List<String> keysOrder = new ArrayList<String>(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() {
|
||||
|
||||
Reference in New Issue
Block a user