Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Added confirm dialog when tranlation conflict occurs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob van Mourik committed Oct 4, 2016
1 parent 688101b commit d45d454
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/main/java/com/jvms/i18neditor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ public void showMessage(String title, Component component) {
showMessageDialog(title, component, JOptionPane.PLAIN_MESSAGE);
}

public boolean showConfirmation(String title, String message) {
return showConfirmDialog(title, message, JOptionPane.WARNING_MESSAGE);
}

public void showMessageDialog(String title, String message, int type) {
JOptionPane.showMessageDialog(this, message, title, type);
}
Expand All @@ -250,6 +254,10 @@ public void showMessageDialog(String title, Component component, int type) {
JOptionPane.showMessageDialog(this, component, title, type);
}

public boolean showConfirmDialog(String title, String message, int type) {
return JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION, type) == 0 ? true : false;
}

public void showImportDialog() {
String path = null;
if (resourcesDir != null) {
Expand Down Expand Up @@ -302,7 +310,18 @@ public void showRenameTranslationDialog(String key) {
if (!TranslationKeys.isValid(newKey)) {
showError(MessageBundle.get("dialogs.translation.rename.error"));
} else {
renameTranslationKey(key, newKey);
TranslationTreeNode newNode = translationTree.getNodeByKey(newKey);
TranslationTreeNode oldNode = translationTree.getNodeByKey(key);
if (newNode != null) {
boolean isReplace = newNode.isLeaf() || oldNode.isLeaf();
boolean confirm = showConfirmation(MessageBundle.get("dialogs.translation.conflict.title"),
MessageBundle.get("dialogs.translation.conflict.text." + (isReplace ? "replace" : "merge")));
if (confirm) {
renameTranslationKey(key, newKey);
}
} else {
renameTranslationKey(key, newKey);
}
}
}
}
Expand All @@ -320,7 +339,18 @@ public void showDuplicateTranslationDialog(String key) {
if (!TranslationKeys.isValid(newKey)) {
showError(MessageBundle.get("dialogs.translation.duplicate.error"));
} else {
duplicateTranslationKey(key, newKey);
TranslationTreeNode newNode = translationTree.getNodeByKey(newKey);
TranslationTreeNode oldNode = translationTree.getNodeByKey(key);
if (newNode != null) {
boolean isReplace = newNode.isLeaf() || oldNode.isLeaf();
boolean confirm = showConfirmation(MessageBundle.get("dialogs.translation.conflict.title"),
MessageBundle.get("dialogs.translation.conflict.text." + (isReplace ? "replace" : "merge")));
if (confirm) {
duplicateTranslationKey(key, newKey);
}
} else {
duplicateTranslationKey(key, newKey);
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/jvms/i18neditor/TranslationTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ private void duplicateNodeByKey(String key, String newKey, boolean keepOld) {
model.removeNodeFromParent(node);
}

if (node.isLeaf() && newNode != null) {
model.removeNodeFromParent(newNode);
newNode = null;
}
if (newNode != null) {
model.insertDescendantsInto(node, newNode);
node = newNode;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/bundles/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ dialogs.save.title = Save Translations
dialogs.translation.add.error = The translation key you entered is invalid.
dialogs.translation.add.text = Enter translation key:
dialogs.translation.add.title = Add Translation
dialogs.translation.conflict.text.replace = There already exists a translation with this key, do you want to replace it?
dialogs.translation.conflict.text.merge = There already exists a translation with this key, do you want to merge it?
dialogs.translation.conflict.title = Translation conflict
dialogs.translation.duplicate.error = The key you entered is invalid.
dialogs.translation.duplicate.text = Enter new key:
dialogs.translation.duplicate.title = Duplicate Translation
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/bundles/messages_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ dialogs.save.title = Vertalingen Opslaan
dialogs.translation.add.error = De opgegeven naam voor de vertaling is niet geldig.
dialogs.translation.add.text = Naam voor de vertaling:
dialogs.translation.add.title = Vertaling Toevoegen
dialogs.translation.conflict.text.replace = Er bestaat al een vertaling met deze naam, wilt u deze vervangen?
dialogs.translation.conflict.text.merge = Er bestaat al een vertaling met deze naam, wilt u deze samenvoegen?
dialogs.translation.conflict.title = Vertalingsconflict
dialogs.translation.duplicate.error = De opgegeven naam is niet geldig.
dialogs.translation.duplicate.text = Nieuwe naam:
dialogs.translation.duplicate.title = Vertaling Dupliceren
Expand Down

0 comments on commit d45d454

Please sign in to comment.