diff options
Diffstat (limited to 'enigma-swing/src/main/java')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java | 11 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java | 10 |
2 files changed, 21 insertions, 0 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java index d128bf5c..28822189 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java | |||
| @@ -12,6 +12,7 @@ import cuchaz.enigma.gui.EditableType; | |||
| 12 | import cuchaz.enigma.gui.Gui; | 12 | import cuchaz.enigma.gui.Gui; |
| 13 | import cuchaz.enigma.gui.GuiController; | 13 | import cuchaz.enigma.gui.GuiController; |
| 14 | import cuchaz.enigma.gui.panels.EditorPanel; | 14 | import cuchaz.enigma.gui.panels.EditorPanel; |
| 15 | import cuchaz.enigma.gui.util.GuiUtil; | ||
| 15 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 16 | import cuchaz.enigma.translation.representation.entry.Entry; | 17 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 17 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | 18 | import cuchaz.enigma.translation.representation.entry.FieldEntry; |
| @@ -22,6 +23,7 @@ public class EditorPopupMenu { | |||
| 22 | private final JPopupMenu ui = new JPopupMenu(); | 23 | private final JPopupMenu ui = new JPopupMenu(); |
| 23 | 24 | ||
| 24 | private final JMenuItem renameItem = new JMenuItem(); | 25 | private final JMenuItem renameItem = new JMenuItem(); |
| 26 | private final JMenuItem pasteItem = new JMenuItem(); | ||
| 25 | private final JMenuItem editJavadocItem = new JMenuItem(); | 27 | private final JMenuItem editJavadocItem = new JMenuItem(); |
| 26 | private final JMenuItem showInheritanceItem = new JMenuItem(); | 28 | private final JMenuItem showInheritanceItem = new JMenuItem(); |
| 27 | private final JMenuItem showImplementationsItem = new JMenuItem(); | 29 | private final JMenuItem showImplementationsItem = new JMenuItem(); |
| @@ -45,6 +47,7 @@ public class EditorPopupMenu { | |||
| 45 | this.retranslateUi(); | 47 | this.retranslateUi(); |
| 46 | 48 | ||
| 47 | this.ui.add(this.renameItem); | 49 | this.ui.add(this.renameItem); |
| 50 | this.ui.add(this.pasteItem); | ||
| 48 | this.ui.add(this.editJavadocItem); | 51 | this.ui.add(this.editJavadocItem); |
| 49 | this.ui.add(this.showInheritanceItem); | 52 | this.ui.add(this.showInheritanceItem); |
| 50 | this.ui.add(this.showImplementationsItem); | 53 | this.ui.add(this.showImplementationsItem); |
| @@ -60,6 +63,7 @@ public class EditorPopupMenu { | |||
| 60 | this.ui.add(this.resetZoomItem); | 63 | this.ui.add(this.resetZoomItem); |
| 61 | 64 | ||
| 62 | this.renameItem.setEnabled(false); | 65 | this.renameItem.setEnabled(false); |
| 66 | this.pasteItem.setEnabled(false); | ||
| 63 | this.editJavadocItem.setEnabled(false); | 67 | this.editJavadocItem.setEnabled(false); |
| 64 | this.showInheritanceItem.setEnabled(false); | 68 | this.showInheritanceItem.setEnabled(false); |
| 65 | this.showImplementationsItem.setEnabled(false); | 69 | this.showImplementationsItem.setEnabled(false); |
| @@ -71,6 +75,7 @@ public class EditorPopupMenu { | |||
| 71 | this.toggleMappingItem.setEnabled(false); | 75 | this.toggleMappingItem.setEnabled(false); |
| 72 | 76 | ||
| 73 | this.renameItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)); | 77 | this.renameItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)); |
| 78 | this.pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK)); | ||
| 74 | this.editJavadocItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)); | 79 | this.editJavadocItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)); |
| 75 | this.showInheritanceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK)); | 80 | this.showInheritanceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK)); |
| 76 | this.showImplementationsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_DOWN_MASK)); | 81 | this.showImplementationsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_DOWN_MASK)); |
| @@ -84,6 +89,7 @@ public class EditorPopupMenu { | |||
| 84 | this.zoomOutMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK)); | 89 | this.zoomOutMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK)); |
| 85 | 90 | ||
| 86 | this.renameItem.addActionListener(event -> gui.startRename(editor)); | 91 | this.renameItem.addActionListener(event -> gui.startRename(editor)); |
| 92 | this.pasteItem.addActionListener(event -> gui.startRename(editor, GuiUtil.getClipboard())); | ||
| 87 | this.editJavadocItem.addActionListener(event -> gui.startDocChange(editor)); | 93 | this.editJavadocItem.addActionListener(event -> gui.startDocChange(editor)); |
| 88 | this.showInheritanceItem.addActionListener(event -> gui.showInheritance(editor)); | 94 | this.showInheritanceItem.addActionListener(event -> gui.showInheritance(editor)); |
| 89 | this.showImplementationsItem.addActionListener(event -> gui.showImplementations(editor)); | 95 | this.showImplementationsItem.addActionListener(event -> gui.showImplementations(editor)); |
| @@ -136,6 +142,9 @@ public class EditorPopupMenu { | |||
| 136 | case KeyEvent.VK_D: | 142 | case KeyEvent.VK_D: |
| 137 | this.editJavadocItem.doClick(); | 143 | this.editJavadocItem.doClick(); |
| 138 | return true; | 144 | return true; |
| 145 | case KeyEvent.VK_V: | ||
| 146 | this.pasteItem.doClick(); | ||
| 147 | return true; | ||
| 139 | } | 148 | } |
| 140 | } | 149 | } |
| 141 | 150 | ||
| @@ -156,6 +165,7 @@ public class EditorPopupMenu { | |||
| 156 | EditableType type = EditableType.fromEntry(referenceEntry); | 165 | EditableType type = EditableType.fromEntry(referenceEntry); |
| 157 | 166 | ||
| 158 | this.renameItem.setEnabled(isRenamable && (type != null && this.gui.isEditable(type))); | 167 | this.renameItem.setEnabled(isRenamable && (type != null && this.gui.isEditable(type))); |
| 168 | this.pasteItem.setEnabled(isRenamable && (type != null && this.gui.isEditable(type)) && !GuiUtil.getClipboard().equals("")); | ||
| 159 | this.editJavadocItem.setEnabled(isRenamable && this.gui.isEditable(EditableType.JAVADOC)); | 169 | this.editJavadocItem.setEnabled(isRenamable && this.gui.isEditable(EditableType.JAVADOC)); |
| 160 | this.showInheritanceItem.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry); | 170 | this.showInheritanceItem.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry); |
| 161 | this.showImplementationsItem.setEnabled(isClassEntry || isMethodEntry); | 171 | this.showImplementationsItem.setEnabled(isClassEntry || isMethodEntry); |
| @@ -175,6 +185,7 @@ public class EditorPopupMenu { | |||
| 175 | 185 | ||
| 176 | public void retranslateUi() { | 186 | public void retranslateUi() { |
| 177 | this.renameItem.setText(I18n.translate("popup_menu.rename")); | 187 | this.renameItem.setText(I18n.translate("popup_menu.rename")); |
| 188 | this.pasteItem.setText(I18n.translate("popup_menu.paste")); | ||
| 178 | this.editJavadocItem.setText(I18n.translate("popup_menu.javadoc")); | 189 | this.editJavadocItem.setText(I18n.translate("popup_menu.javadoc")); |
| 179 | this.showInheritanceItem.setText(I18n.translate("popup_menu.inheritance")); | 190 | this.showInheritanceItem.setText(I18n.translate("popup_menu.inheritance")); |
| 180 | this.showImplementationsItem.setText(I18n.translate("popup_menu.implementations")); | 191 | this.showImplementationsItem.setText(I18n.translate("popup_menu.implementations")); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java index d0784243..106859cc 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java | |||
| @@ -12,6 +12,8 @@ import java.awt.event.MouseListener; | |||
| 12 | import java.awt.event.WindowAdapter; | 12 | import java.awt.event.WindowAdapter; |
| 13 | import java.awt.event.WindowEvent; | 13 | import java.awt.event.WindowEvent; |
| 14 | import java.awt.event.WindowListener; | 14 | import java.awt.event.WindowListener; |
| 15 | import java.awt.datatransfer.DataFlavor; | ||
| 16 | import java.awt.datatransfer.UnsupportedFlavorException; | ||
| 15 | import java.awt.font.TextAttribute; | 17 | import java.awt.font.TextAttribute; |
| 16 | import java.io.IOException; | 18 | import java.io.IOException; |
| 17 | import java.net.URI; | 19 | import java.net.URI; |
| @@ -85,6 +87,14 @@ public class GuiUtil { | |||
| 85 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null); | 87 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null); |
| 86 | } | 88 | } |
| 87 | 89 | ||
| 90 | public static String getClipboard() { | ||
| 91 | try { | ||
| 92 | return (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); | ||
| 93 | } catch (UnsupportedFlavorException | IOException e) { | ||
| 94 | return ""; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 88 | public static void showPopup(JComponent component, String text, int x, int y) { | 98 | public static void showPopup(JComponent component, String text, int x, int y) { |
| 89 | // from https://stackoverflow.com/questions/39955015/java-swing-show-tooltip-as-a-message-dialog | 99 | // from https://stackoverflow.com/questions/39955015/java-swing-show-tooltip-as-a-message-dialog |
| 90 | JToolTip tooltip = new JToolTip(); | 100 | JToolTip tooltip = new JToolTip(); |