consider children nodes on marking paths with empty translation values

This commit is contained in:
marhali 2022-01-13 11:31:15 +01:00
parent c0e385000a
commit 0b9d6c0369
2 changed files with 26 additions and 2 deletions

View File

@ -12,6 +12,7 @@
- Support for dots within key nodes in YAML files - Support for dots within key nodes in YAML files
### Changed ### Changed
- Improve marking nodes with missing values in tree-view
- Key completion inside editor suggests all keys without any logic - Key completion inside editor suggests all keys without any logic
- Translation file pattern uses wildcard matcher instead of regex - Translation file pattern uses wildcard matcher instead of regex
- Improve exception handling on IO operations - Improve exception handling on IO operations

View File

@ -71,7 +71,15 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList
super.setRoot(rootNode); super.setRoot(rootNode);
} }
private void generateNodes(@NotNull DefaultMutableTreeNode parent, @NotNull TranslationNode translationNode) { /**
*
* @param parent Parent tree node
* @param translationNode Layer of translation node to write to tree
* @return true if children nodes misses any translation values
*/
private boolean generateNodes(@NotNull DefaultMutableTreeNode parent, @NotNull TranslationNode translationNode) {
boolean foundMissing = false;
for(Map.Entry<String, TranslationNode> entry : translationNode.getChildren().entrySet()) { for(Map.Entry<String, TranslationNode> entry : translationNode.getChildren().entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
TranslationNode childTranslationNode = entry.getValue(); TranslationNode childTranslationNode = entry.getValue();
@ -79,8 +87,15 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList
if(!childTranslationNode.isLeaf()) { if(!childTranslationNode.isLeaf()) {
// Nested node - run recursively // Nested node - run recursively
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(key); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(key);
this.generateNodes(childNode, childTranslationNode);
if(this.generateNodes(childNode, childTranslationNode)) { // Mark red if any children misses translations
PresentationData data = new PresentationData(key, null, null, null);
data.setForcedTextForeground(JBColor.RED);
childNode.setUserObject(data);
}
parent.add(childNode); parent.add(childNode);
} else { } else {
String previewLocale = this.state.getPreviewLocale(); String previewLocale = this.state.getPreviewLocale();
String sub = "(" + previewLocale + ": " + childTranslationNode.getValue().get(previewLocale) + ")"; String sub = "(" + previewLocale + ": " + childTranslationNode.getValue().get(previewLocale) + ")";
@ -91,13 +106,21 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList
if(childTranslationNode.getValue().size() != this.data.getLocales().size()) { if(childTranslationNode.getValue().size() != this.data.getLocales().size()) {
data.setForcedTextForeground(JBColor.RED); data.setForcedTextForeground(JBColor.RED);
foundMissing = true;
} }
parent.add(new DefaultMutableTreeNode(data)); parent.add(new DefaultMutableTreeNode(data));
} }
} }
return foundMissing;
} }
/**
* Converts KeyPath to TreePath
* @param fullPath Absolute translation key path
* @return Converted TreePath
*/
public @NotNull TreePath findTreePath(@NotNull KeyPath fullPath) { public @NotNull TreePath findTreePath(@NotNull KeyPath fullPath) {
List<Object> nodes = new ArrayList<>(); List<Object> nodes = new ArrayList<>();