diff --git a/src/main/java/com/jvms/i18neditor/editor/Editor.java b/src/main/java/com/jvms/i18neditor/editor/Editor.java index f6f11fa..c426969 100644 --- a/src/main/java/com/jvms/i18neditor/editor/Editor.java +++ b/src/main/java/com/jvms/i18neditor/editor/Editor.java @@ -7,6 +7,9 @@ import java.awt.Desktop; import java.awt.Dimension; import java.awt.KeyboardFocusManager; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -245,6 +248,16 @@ public void renameSelectedTranslation() { } } + public void copySelectedTranslationKey() { + TranslationTreeNode node = translationTree.getSelectionNode(); + if (node != null && !node.isRoot()) { + String key = node.getKey(); + StringSelection selection = new StringSelection(key); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(selection, selection); + } + } + public void duplicateSelectedTranslation() { TranslationTreeNode node = translationTree.getSelectionNode(); if (node != null && !node.isRoot()) { diff --git a/src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java b/src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java index fc77dc0..4d3e3ec 100644 --- a/src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java +++ b/src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java @@ -18,6 +18,7 @@ import com.jvms.i18neditor.editor.menu.AddLocaleMenuItem; import com.jvms.i18neditor.editor.menu.AddTranslationMenuItem; import com.jvms.i18neditor.editor.menu.CollapseTranslationsMenuItem; +import com.jvms.i18neditor.editor.menu.CopyTranslationKeyToClipboardMenuItem; import com.jvms.i18neditor.editor.menu.DuplicateTranslationMenuItem; import com.jvms.i18neditor.editor.menu.ExpandTranslationsMenuItem; import com.jvms.i18neditor.editor.menu.FindTranslationMenuItem; @@ -41,6 +42,7 @@ public class EditorMenuBar extends JMenuBar { private JMenuItem addTranslationMenuItem; private JMenuItem findTranslationMenuItem; private JMenuItem renameTranslationMenuItem; + private JMenuItem copyTranslationKeyMenuItem; private JMenuItem duplicateTranslationMenuItem; private JMenuItem removeTranslationMenuItem; private JMenuItem openContainingFolderMenuItem; @@ -173,6 +175,7 @@ private void setupUI() { removeTranslationMenuItem = new RemoveTranslationMenuItem(editor, false); duplicateTranslationMenuItem = new DuplicateTranslationMenuItem(editor, true); renameTranslationMenuItem = new RenameTranslationMenuItem(editor, false); + copyTranslationKeyMenuItem = new CopyTranslationKeyToClipboardMenuItem(editor, false); editMenu.add(new AddLocaleMenuItem(editor, true)); editMenu.addSeparator(); @@ -180,6 +183,7 @@ private void setupUI() { editMenu.add(findTranslationMenuItem); editMenu.addSeparator(); editMenu.add(renameTranslationMenuItem); + editMenu.add(copyTranslationKeyMenuItem); editMenu.add(duplicateTranslationMenuItem); editMenu.add(removeTranslationMenuItem); @@ -232,6 +236,7 @@ private void setupUI() { TranslationTreeNode node = tree.getSelectionNode(); boolean enabled = node != null && !node.isRoot(); renameTranslationMenuItem.setEnabled(enabled); + copyTranslationKeyMenuItem.setEnabled(enabled); duplicateTranslationMenuItem.setEnabled(enabled); removeTranslationMenuItem.setEnabled(enabled); }); diff --git a/src/main/java/com/jvms/i18neditor/editor/TranslationTreeNodeMenu.java b/src/main/java/com/jvms/i18neditor/editor/TranslationTreeNodeMenu.java index 94ea2fd..a8fad09 100644 --- a/src/main/java/com/jvms/i18neditor/editor/TranslationTreeNodeMenu.java +++ b/src/main/java/com/jvms/i18neditor/editor/TranslationTreeNodeMenu.java @@ -3,6 +3,7 @@ import javax.swing.JPopupMenu; import com.jvms.i18neditor.editor.menu.AddTranslationMenuItem; +import com.jvms.i18neditor.editor.menu.CopyTranslationKeyToClipboardMenuItem; import com.jvms.i18neditor.editor.menu.DuplicateTranslationMenuItem; import com.jvms.i18neditor.editor.menu.RemoveTranslationMenuItem; import com.jvms.i18neditor.editor.menu.RenameTranslationMenuItem; @@ -21,6 +22,7 @@ public TranslationTreeNodeMenu(Editor editor, TranslationTreeNode node) { if (!node.isRoot()) { addSeparator(); add(new RenameTranslationMenuItem(editor, true)); + add(new CopyTranslationKeyToClipboardMenuItem(editor, true)); add(new DuplicateTranslationMenuItem(editor, true)); add(new RemoveTranslationMenuItem(editor, true)); } diff --git a/src/main/java/com/jvms/i18neditor/editor/menu/CopyTranslationKeyToClipboardMenuItem.java b/src/main/java/com/jvms/i18neditor/editor/menu/CopyTranslationKeyToClipboardMenuItem.java new file mode 100644 index 0000000..5011bb5 --- /dev/null +++ b/src/main/java/com/jvms/i18neditor/editor/menu/CopyTranslationKeyToClipboardMenuItem.java @@ -0,0 +1,28 @@ +package com.jvms.i18neditor.editor.menu; + +import java.awt.Toolkit; +import java.awt.event.KeyEvent; + +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; + +import com.jvms.i18neditor.editor.Editor; +import com.jvms.i18neditor.util.MessageBundle; + +/** + * This class represents a menu item for copying a translations key to the system clipboard. + * + * @author Fabian Terstegen + * + */ +public class CopyTranslationKeyToClipboardMenuItem extends JMenuItem { + private static final long serialVersionUID = 6032182493888769724L; + + public CopyTranslationKeyToClipboardMenuItem(Editor editor, boolean enabled) { + super(MessageBundle.get("menu.edit.copy.key.title")); + setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + addActionListener(e -> editor.copySelectedTranslationKey()); + setEnabled(enabled); + } + +} diff --git a/src/main/resources/bundles/messages.properties b/src/main/resources/bundles/messages.properties index 2add7e0..6d26699 100644 --- a/src/main/resources/bundles/messages.properties +++ b/src/main/resources/bundles/messages.properties @@ -41,6 +41,7 @@ menu.edit.delete.title = Delete Translation menu.edit.duplicate.title = Duplicate Translation... menu.edit.find.translation.title = Find Translation... menu.edit.rename.title = Rename Translation... +menu.edit.copy.key.title = Copy Translation Key... menu.edit.title = Edit menu.edit.vk = E menu.file.exit.title = Exit diff --git a/src/main/resources/bundles/messages_nl.properties b/src/main/resources/bundles/messages_nl.properties index 6eee71d..fabea37 100644 --- a/src/main/resources/bundles/messages_nl.properties +++ b/src/main/resources/bundles/messages_nl.properties @@ -41,6 +41,7 @@ menu.edit.delete.title = Vertaling Verwijderen menu.edit.duplicate.title = Vertaling Dupliceren... menu.edit.find.translation.title = Vertaling Zoeken... menu.edit.rename.title = Vertaling Hernoemen... +menu.edit.copy.key.title = Copy Translation Key... menu.edit.title = Bewerken menu.edit.vk = W menu.file.exit.title = Sluiten diff --git a/src/main/resources/bundles/messages_pt_BR.properties b/src/main/resources/bundles/messages_pt_BR.properties index 0d1e5c2..086004d 100644 --- a/src/main/resources/bundles/messages_pt_BR.properties +++ b/src/main/resources/bundles/messages_pt_BR.properties @@ -41,6 +41,7 @@ menu.edit.delete.title = Excluir Tradu\u00e7\u00e3o menu.edit.duplicate.title = Duplicar Tradu\u00e7\u00e3o... menu.edit.find.translation.title = Localizar Tradu\u00e7\u00e3o... menu.edit.rename.title = Renomear Tradu\u00e7\u00e3o... +menu.edit.copy.key.title = Copy Translation Key... menu.edit.title = Editar menu.edit.vk = E menu.file.exit.title = Sair