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

Commit

Permalink
Merge pull request #37 from FabianTe/feature/translationKeyToClipboard
Browse files Browse the repository at this point in the history
Added "Copy Translation Key" Option to Edit menus
  • Loading branch information
jcbvm authored Jun 19, 2018
2 parents 84c64ab + f0fc872 commit a6e2e10
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/jvms/i18neditor/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -173,13 +175,15 @@ 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();
editMenu.add(addTranslationMenuItem);
editMenu.add(findTranslationMenuItem);
editMenu.addSeparator();
editMenu.add(renameTranslationMenuItem);
editMenu.add(copyTranslationKeyMenuItem);
editMenu.add(duplicateTranslationMenuItem);
editMenu.add(removeTranslationMenuItem);

Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
1 change: 1 addition & 0 deletions src/main/resources/bundles/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/bundles/messages_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/bundles/messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a6e2e10

Please sign in to comment.