From 0b9d6c036983de36c76714d4398951852d224d8e Mon Sep 17 00:00:00 2001 From: marhali Date: Thu, 13 Jan 2022 11:31:15 +0100 Subject: [PATCH] consider children nodes on marking paths with empty translation values --- CHANGELOG.md | 1 + .../easyi18n/tabs/mapper/TreeModelMapper.java | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf58c2..763d02b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Support for dots within key nodes in YAML files ### Changed +- Improve marking nodes with missing values in tree-view - Key completion inside editor suggests all keys without any logic - Translation file pattern uses wildcard matcher instead of regex - Improve exception handling on IO operations diff --git a/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java b/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java index 4049e10..16753d6 100644 --- a/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java +++ b/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java @@ -71,7 +71,15 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList 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 entry : translationNode.getChildren().entrySet()) { String key = entry.getKey(); TranslationNode childTranslationNode = entry.getValue(); @@ -79,8 +87,15 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList if(!childTranslationNode.isLeaf()) { // Nested node - run recursively 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); + } else { String previewLocale = this.state.getPreviewLocale(); 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()) { data.setForcedTextForeground(JBColor.RED); + foundMissing = true; } 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) { List nodes = new ArrayList<>();