summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar 2xsaiko2020-06-18 22:23:09 +0200
committerGravatar 2xsaiko2020-10-02 15:57:36 +0200
commit254e212aef43d393ca210ba529efe462adcc2f87 (patch)
tree7d55ad640994b5f70f6bd67ad81a2264207830d0
parentFix build issues (diff)
downloadenigma-fork-254e212aef43d393ca210ba529efe462adcc2f87.tar.gz
enigma-fork-254e212aef43d393ca210ba529efe462adcc2f87.tar.xz
enigma-fork-254e212aef43d393ca210ba529efe462adcc2f87.zip
Refactor PopupMenuBar -> EditorPopupMenu
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java174
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java130
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java110
3 files changed, 208 insertions, 206 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
new file mode 100644
index 0000000..86d920e
--- /dev/null
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java
@@ -0,0 +1,174 @@
1package cuchaz.enigma.gui.elements;
2
3import java.awt.event.InputEvent;
4import java.awt.event.KeyEvent;
5
6import javax.swing.JMenuItem;
7import javax.swing.JPopupMenu;
8import javax.swing.KeyStroke;
9
10import cuchaz.enigma.analysis.EntryReference;
11import cuchaz.enigma.gui.Gui;
12import cuchaz.enigma.gui.GuiController;
13import cuchaz.enigma.gui.panels.EditorPanel;
14import cuchaz.enigma.translation.representation.entry.ClassEntry;
15import cuchaz.enigma.translation.representation.entry.Entry;
16import cuchaz.enigma.translation.representation.entry.FieldEntry;
17import cuchaz.enigma.translation.representation.entry.MethodEntry;
18import cuchaz.enigma.utils.I18n;
19
20public class EditorPopupMenu {
21
22 private final JPopupMenu ui = new JPopupMenu();
23
24 private final JMenuItem renameItem = new JMenuItem(I18n.translate("popup_menu.rename"));
25 private final JMenuItem editJavadocItem = new JMenuItem(I18n.translate("popup_menu.javadoc"));
26 private final JMenuItem showInheritanceItem = new JMenuItem(I18n.translate("popup_menu.inheritance"));
27 private final JMenuItem showImplementationsItem = new JMenuItem(I18n.translate("popup_menu.implementations"));
28 private final JMenuItem showCallsItem = new JMenuItem(I18n.translate("popup_menu.calls"));
29 private final JMenuItem showCallsSpecificItem = new JMenuItem(I18n.translate("popup_menu.calls.specific"));
30 private final JMenuItem openEntryItem = new JMenuItem(I18n.translate("popup_menu.declaration"));
31 private final JMenuItem openPreviousItem = new JMenuItem(I18n.translate("popup_menu.back"));
32 private final JMenuItem openNextItem = new JMenuItem(I18n.translate("popup_menu.forward"));
33 private final JMenuItem toggleMappingItem = new JMenuItem(I18n.translate("popup_menu.mark_deobfuscated"));
34 private final JMenuItem zoomInItem = new JMenuItem(I18n.translate("popup_menu.zoom.in"));
35 private final JMenuItem zoomOutMenu = new JMenuItem(I18n.translate("popup_menu.zoom.out"));
36 private final JMenuItem resetZoomItem = new JMenuItem(I18n.translate("popup_menu.zoom.reset"));
37
38 private final EditorPanel editor;
39 private final Gui gui;
40
41 public EditorPopupMenu(EditorPanel editor, Gui gui) {
42 this.editor = editor;
43 this.gui = gui;
44
45 this.ui.add(this.renameItem);
46 this.ui.add(this.editJavadocItem);
47 this.ui.add(this.showInheritanceItem);
48 this.ui.add(this.showImplementationsItem);
49 this.ui.add(this.showCallsItem);
50 this.ui.add(this.showCallsSpecificItem);
51 this.ui.add(this.openEntryItem);
52 this.ui.add(this.openPreviousItem);
53 this.ui.add(this.openNextItem);
54 this.ui.add(this.toggleMappingItem);
55 this.ui.addSeparator();
56 this.ui.add(this.zoomInItem);
57 this.ui.add(this.zoomOutMenu);
58 this.ui.add(this.resetZoomItem);
59
60 this.renameItem.setEnabled(false);
61 this.editJavadocItem.setEnabled(false);
62 this.showInheritanceItem.setEnabled(false);
63 this.showImplementationsItem.setEnabled(false);
64 this.showCallsItem.setEnabled(false);
65 this.showCallsSpecificItem.setEnabled(false);
66 this.openEntryItem.setEnabled(false);
67 this.openPreviousItem.setEnabled(false);
68 this.openNextItem.setEnabled(false);
69 this.toggleMappingItem.setEnabled(false);
70
71 this.renameItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK));
72 this.editJavadocItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK));
73 this.showInheritanceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK));
74 this.showImplementationsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_DOWN_MASK));
75 this.showCallsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
76 this.showCallsSpecificItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK + InputEvent.SHIFT_DOWN_MASK));
77 this.openEntryItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
78 this.openPreviousItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK));
79 this.openNextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK));
80 this.toggleMappingItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK));
81 this.zoomInItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, InputEvent.CTRL_DOWN_MASK));
82 this.zoomOutMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK));
83
84 this.renameItem.addActionListener(event -> gui.startRename(editor));
85 this.editJavadocItem.addActionListener(event -> gui.startDocChange(editor));
86 this.showInheritanceItem.addActionListener(event -> gui.showInheritance(editor));
87 this.showImplementationsItem.addActionListener(event -> gui.showImplementations(editor));
88 this.showCallsItem.addActionListener(event -> gui.showCalls(editor, true));
89 this.showCallsSpecificItem.addActionListener(event -> gui.showCalls(editor, false));
90 this.openEntryItem.addActionListener(event -> gui.getController().navigateTo(editor.getCursorReference().entry));
91 this.openPreviousItem.addActionListener(event -> gui.getController().openPreviousReference());
92 this.openNextItem.addActionListener(event -> gui.getController().openNextReference());
93 this.toggleMappingItem.addActionListener(event -> gui.toggleMapping(editor));
94 this.zoomInItem.addActionListener(event -> editor.offsetEditorZoom(2));
95 this.zoomOutMenu.addActionListener(event -> editor.offsetEditorZoom(-2));
96 this.resetZoomItem.addActionListener(event -> editor.resetEditorZoom());
97 }
98
99 // TODO have editor redirect key event to menu so that the actions get
100 // triggered without having to hardcode them here, because this
101 // is a hack
102 public boolean handleKeyEvent(KeyEvent event) {
103 if (event.isControlDown()) {
104 switch (event.getKeyCode()) {
105 case KeyEvent.VK_I:
106 this.showInheritanceItem.doClick();
107 return true;
108 case KeyEvent.VK_M:
109 this.showImplementationsItem.doClick();
110 return true;
111 case KeyEvent.VK_N:
112 this.openEntryItem.doClick();
113 return true;
114 case KeyEvent.VK_P:
115 this.openPreviousItem.doClick();
116 return true;
117 case KeyEvent.VK_E:
118 this.openNextItem.doClick();
119 return true;
120 case KeyEvent.VK_C:
121 if (event.isShiftDown()) {
122 this.showCallsSpecificItem.doClick();
123 } else {
124 this.showCallsItem.doClick();
125 }
126 return true;
127 case KeyEvent.VK_O:
128 this.toggleMappingItem.doClick();
129 return true;
130 case KeyEvent.VK_R:
131 this.renameItem.doClick();
132 return true;
133 case KeyEvent.VK_D:
134 this.editJavadocItem.doClick();
135 return true;
136 }
137 }
138 return false;
139 }
140
141 public void updateUiState() {
142 EntryReference<Entry<?>, Entry<?>> ref = this.editor.getCursorReference();
143 Entry<?> referenceEntry = ref == null ? null : ref.entry;
144 GuiController controller = this.gui.getController();
145
146 boolean isClassEntry = referenceEntry instanceof ClassEntry;
147 boolean isFieldEntry = referenceEntry instanceof FieldEntry;
148 boolean isMethodEntry = referenceEntry instanceof MethodEntry && !((MethodEntry) referenceEntry).isConstructor();
149 boolean isConstructorEntry = referenceEntry instanceof MethodEntry && ((MethodEntry) referenceEntry).isConstructor();
150 boolean isRenamable = ref != null && controller.project.isRenamable(ref);
151
152 this.renameItem.setEnabled(isRenamable);
153 this.editJavadocItem.setEnabled(isRenamable);
154 this.showInheritanceItem.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry);
155 this.showImplementationsItem.setEnabled(isClassEntry || isMethodEntry);
156 this.showCallsItem.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry);
157 this.showCallsSpecificItem.setEnabled(isMethodEntry);
158 this.openEntryItem.setEnabled(isRenamable && (isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry));
159 this.openPreviousItem.setEnabled(controller.hasPreviousReference());
160 this.openNextItem.setEnabled(controller.hasNextReference());
161 this.toggleMappingItem.setEnabled(isRenamable);
162
163 if (referenceEntry != null && this.gui.getController().project.getMapper().extendedDeobfuscate(referenceEntry).isDeobfuscated()) {
164 this.toggleMappingItem.setText(I18n.translate("popup_menu.reset_obfuscated"));
165 } else {
166 this.toggleMappingItem.setText(I18n.translate("popup_menu.mark_deobfuscated"));
167 }
168 }
169
170 public JPopupMenu getUi() {
171 return ui;
172 }
173
174}
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java
deleted file mode 100644
index ad6dac6..0000000
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java
+++ /dev/null
@@ -1,130 +0,0 @@
1package cuchaz.enigma.gui.elements;
2
3import java.awt.event.InputEvent;
4import java.awt.event.KeyEvent;
5
6import javax.swing.JMenuItem;
7import javax.swing.JPopupMenu;
8import javax.swing.JSeparator;
9import javax.swing.KeyStroke;
10
11import cuchaz.enigma.gui.Gui;
12import cuchaz.enigma.gui.panels.EditorPanel;
13import cuchaz.enigma.utils.I18n;
14
15public class PopupMenuBar extends JPopupMenu {
16
17 public final JMenuItem renameMenu;
18 public final JMenuItem editJavadocMenu;
19 public final JMenuItem showInheritanceMenu;
20 public final JMenuItem showImplementationsMenu;
21 public final JMenuItem showCallsMenu;
22 public final JMenuItem showCallsSpecificMenu;
23 public final JMenuItem openEntryMenu;
24 public final JMenuItem openPreviousMenu;
25 public final JMenuItem openNextMenu;
26 public final JMenuItem toggleMappingMenu;
27
28 public PopupMenuBar(EditorPanel editor, Gui gui) {
29 {
30 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.rename"));
31 menu.addActionListener(event -> gui.startRename(editor));
32 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK));
33 menu.setEnabled(false);
34 this.add(menu);
35 this.renameMenu = menu;
36 }
37 {
38 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.javadoc"));
39 menu.addActionListener(event -> gui.startDocChange(editor));
40 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK));
41 menu.setEnabled(false);
42 this.add(menu);
43 this.editJavadocMenu = menu;
44 }
45 {
46 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.inheritance"));
47 menu.addActionListener(event -> gui.showInheritance(editor));
48 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK));
49 menu.setEnabled(false);
50 this.add(menu);
51 this.showInheritanceMenu = menu;
52 }
53 {
54 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.implementations"));
55 menu.addActionListener(event -> gui.showImplementations(editor));
56 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_DOWN_MASK));
57 menu.setEnabled(false);
58 this.add(menu);
59 this.showImplementationsMenu = menu;
60 }
61 {
62 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.calls"));
63 menu.addActionListener(event -> gui.showCalls(editor, true));
64 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
65 menu.setEnabled(false);
66 this.add(menu);
67 this.showCallsMenu = menu;
68 }
69 {
70 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.calls.specific"));
71 menu.addActionListener(event -> gui.showCalls(editor, false));
72 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK + InputEvent.SHIFT_DOWN_MASK));
73 menu.setEnabled(false);
74 this.add(menu);
75 this.showCallsSpecificMenu = menu;
76 }
77 {
78 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.declaration"));
79 menu.addActionListener(event -> gui.getController().navigateTo(editor.getCursorReference().entry));
80 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
81 menu.setEnabled(false);
82 this.add(menu);
83 this.openEntryMenu = menu;
84 }
85 {
86 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.back"));
87 menu.addActionListener(event -> gui.getController().openPreviousReference());
88 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK));
89 menu.setEnabled(false);
90 this.add(menu);
91 this.openPreviousMenu = menu;
92 }
93 {
94 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.forward"));
95 menu.addActionListener(event -> gui.getController().openNextReference());
96 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK));
97 menu.setEnabled(false);
98 this.add(menu);
99 this.openNextMenu = menu;
100 }
101 {
102 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.mark_deobfuscated"));
103 menu.addActionListener(event -> gui.toggleMapping(editor));
104 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK));
105 menu.setEnabled(false);
106 this.add(menu);
107 this.toggleMappingMenu = menu;
108 }
109 {
110 this.add(new JSeparator());
111 }
112 {
113 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.zoom.in"));
114 menu.addActionListener(event -> editor.offsetEditorZoom(2));
115 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, InputEvent.CTRL_DOWN_MASK));
116 this.add(menu);
117 }
118 {
119 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.zoom.out"));
120 menu.addActionListener(event -> editor.offsetEditorZoom(-2));
121 menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK));
122 this.add(menu);
123 }
124 {
125 JMenuItem menu = new JMenuItem(I18n.translate("popup_menu.zoom.reset"));
126 menu.addActionListener(event -> editor.resetEditorZoom());
127 this.add(menu);
128 }
129 }
130}
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java
index ab9de33..bd1fae0 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java
@@ -1,21 +1,40 @@
1package cuchaz.enigma.gui.panels; 1package cuchaz.enigma.gui.panels;
2 2
3import java.awt.*; 3import java.awt.Color;
4import java.awt.event.*; 4import java.awt.Component;
5import java.awt.Font;
6import java.awt.GridBagConstraints;
7import java.awt.GridBagLayout;
8import java.awt.GridLayout;
9import java.awt.Rectangle;
10import java.awt.event.ActionEvent;
11import java.awt.event.ActionListener;
12import java.awt.event.KeyAdapter;
13import java.awt.event.KeyEvent;
14import java.awt.event.MouseAdapter;
15import java.awt.event.MouseEvent;
5import java.util.ArrayList; 16import java.util.ArrayList;
6import java.util.Collection; 17import java.util.Collection;
7import java.util.List; 18import java.util.List;
8import java.util.Map; 19import java.util.Map;
9 20
10import javax.annotation.Nullable; 21import javax.annotation.Nullable;
11import javax.swing.*; 22import javax.swing.JButton;
23import javax.swing.JComponent;
24import javax.swing.JEditorPane;
25import javax.swing.JLabel;
26import javax.swing.JPanel;
27import javax.swing.JProgressBar;
28import javax.swing.JScrollPane;
29import javax.swing.JSeparator;
30import javax.swing.JTextArea;
31import javax.swing.SwingUtilities;
32import javax.swing.Timer;
12import javax.swing.text.BadLocationException; 33import javax.swing.text.BadLocationException;
13import javax.swing.text.Document; 34import javax.swing.text.Document;
14import javax.swing.text.Highlighter; 35import javax.swing.text.Highlighter;
15import javax.swing.text.Highlighter.HighlightPainter; 36import javax.swing.text.Highlighter.HighlightPainter;
16 37
17import de.sciss.syntaxpane.DefaultSyntaxKit;
18
19import cuchaz.enigma.EnigmaProject; 38import cuchaz.enigma.EnigmaProject;
20import cuchaz.enigma.analysis.EntryReference; 39import cuchaz.enigma.analysis.EntryReference;
21import cuchaz.enigma.classhandle.ClassHandle; 40import cuchaz.enigma.classhandle.ClassHandle;
@@ -27,7 +46,7 @@ import cuchaz.enigma.gui.GuiController;
27import cuchaz.enigma.gui.config.LookAndFeel; 46import cuchaz.enigma.gui.config.LookAndFeel;
28import cuchaz.enigma.gui.config.Themes; 47import cuchaz.enigma.gui.config.Themes;
29import cuchaz.enigma.gui.config.UiConfig; 48import cuchaz.enigma.gui.config.UiConfig;
30import cuchaz.enigma.gui.elements.PopupMenuBar; 49import cuchaz.enigma.gui.elements.EditorPopupMenu;
31import cuchaz.enigma.gui.events.EditorActionListener; 50import cuchaz.enigma.gui.events.EditorActionListener;
32import cuchaz.enigma.gui.events.ThemeChangeListener; 51import cuchaz.enigma.gui.events.ThemeChangeListener;
33import cuchaz.enigma.gui.highlight.BoxHighlightPainter; 52import cuchaz.enigma.gui.highlight.BoxHighlightPainter;
@@ -42,17 +61,16 @@ import cuchaz.enigma.translation.mapping.EntryResolver;
42import cuchaz.enigma.translation.mapping.ResolutionStrategy; 61import cuchaz.enigma.translation.mapping.ResolutionStrategy;
43import cuchaz.enigma.translation.representation.entry.ClassEntry; 62import cuchaz.enigma.translation.representation.entry.ClassEntry;
44import cuchaz.enigma.translation.representation.entry.Entry; 63import cuchaz.enigma.translation.representation.entry.Entry;
45import cuchaz.enigma.translation.representation.entry.FieldEntry;
46import cuchaz.enigma.translation.representation.entry.MethodEntry;
47import cuchaz.enigma.utils.I18n; 64import cuchaz.enigma.utils.I18n;
48import cuchaz.enigma.utils.Result; 65import cuchaz.enigma.utils.Result;
66import de.sciss.syntaxpane.DefaultSyntaxKit;
49 67
50public class EditorPanel { 68public class EditorPanel {
51 69
52 private final JPanel ui = new JPanel(); 70 private final JPanel ui = new JPanel();
53 private final JEditorPane editor = new JEditorPane(); 71 private final JEditorPane editor = new JEditorPane();
54 private final JScrollPane editorScrollPane = new JScrollPane(this.editor); 72 private final JScrollPane editorScrollPane = new JScrollPane(this.editor);
55 private final PopupMenuBar popupMenu; 73 private final EditorPopupMenu popupMenu;
56 74
57 // progress UI 75 // progress UI
58 private final JLabel decompilingLabel = new JLabel(I18n.translate("editor.decompiling"), JLabel.CENTER); 76 private final JLabel decompilingLabel = new JLabel(I18n.translate("editor.decompiling"), JLabel.CENTER);
@@ -102,8 +120,8 @@ public class EditorPanel {
102 kit.toggleComponent(this.editor, "de.sciss.syntaxpane.components.TokenMarker"); 120 kit.toggleComponent(this.editor, "de.sciss.syntaxpane.components.TokenMarker");
103 121
104 // init editor popup menu 122 // init editor popup menu
105 this.popupMenu = new PopupMenuBar(this, gui); 123 this.popupMenu = new EditorPopupMenu(this, gui);
106 this.editor.setComponentPopupMenu(this.popupMenu); 124 this.editor.setComponentPopupMenu(this.popupMenu.getUi());
107 125
108 this.decompilingLabel.setFont(ScaleUtil.getFont(this.decompilingLabel.getFont().getFontName(), Font.BOLD, 26)); 126 this.decompilingLabel.setFont(ScaleUtil.getFont(this.decompilingLabel.getFont().getFontName(), Font.BOLD, 26));
109 this.decompilingProgressBar.setIndeterminate(true); 127 this.decompilingProgressBar.setIndeterminate(true);
@@ -141,47 +159,8 @@ public class EditorPanel {
141 public void keyPressed(KeyEvent event) { 159 public void keyPressed(KeyEvent event) {
142 if (event.isControlDown()) { 160 if (event.isControlDown()) {
143 EditorPanel.this.shouldNavigateOnClick = false; 161 EditorPanel.this.shouldNavigateOnClick = false;
162 if (EditorPanel.this.popupMenu.handleKeyEvent(event)) return;
144 switch (event.getKeyCode()) { 163 switch (event.getKeyCode()) {
145 case KeyEvent.VK_I:
146 EditorPanel.this.popupMenu.showInheritanceMenu.doClick();
147 break;
148
149 case KeyEvent.VK_M:
150 EditorPanel.this.popupMenu.showImplementationsMenu.doClick();
151 break;
152
153 case KeyEvent.VK_N:
154 EditorPanel.this.popupMenu.openEntryMenu.doClick();
155 break;
156
157 case KeyEvent.VK_P:
158 EditorPanel.this.popupMenu.openPreviousMenu.doClick();
159 break;
160
161 case KeyEvent.VK_E:
162 EditorPanel.this.popupMenu.openNextMenu.doClick();
163 break;
164
165 case KeyEvent.VK_C:
166 if (event.isShiftDown()) {
167 EditorPanel.this.popupMenu.showCallsSpecificMenu.doClick();
168 } else {
169 EditorPanel.this.popupMenu.showCallsMenu.doClick();
170 }
171 break;
172
173 case KeyEvent.VK_O:
174 EditorPanel.this.popupMenu.toggleMappingMenu.doClick();
175 break;
176
177 case KeyEvent.VK_R:
178 EditorPanel.this.popupMenu.renameMenu.doClick();
179 break;
180
181 case KeyEvent.VK_D:
182 EditorPanel.this.popupMenu.editJavadocMenu.doClick();
183 break;
184
185 case KeyEvent.VK_F5: 164 case KeyEvent.VK_F5:
186 if (EditorPanel.this.classHandle != null) { 165 if (EditorPanel.this.classHandle != null) {
187 EditorPanel.this.classHandle.invalidateMapped(); 166 EditorPanel.this.classHandle.invalidateMapped();
@@ -211,7 +190,9 @@ public class EditorPanel {
211 190
212 @Override 191 @Override
213 public void keyTyped(KeyEvent event) { 192 public void keyTyped(KeyEvent event) {
214 if (!EditorPanel.this.popupMenu.renameMenu.isEnabled()) return; 193 EntryReference<Entry<?>, Entry<?>> ref = EditorPanel.this.getCursorReference();
194 if (ref == null) return;
195 if (!EditorPanel.this.controller.project.isRenamable(ref)) return;
215 196
216 if (!event.isControlDown() && !event.isAltDown() && Character.isJavaIdentifierPart(event.getKeyChar())) { 197 if (!event.isControlDown() && !event.isAltDown() && Character.isJavaIdentifierPart(event.getKeyChar())) {
217 EnigmaProject project = gui.getController().project; 198 EnigmaProject project = gui.getController().project;
@@ -431,30 +412,7 @@ public class EditorPanel {
431 private void setCursorReference(EntryReference<Entry<?>, Entry<?>> ref) { 412 private void setCursorReference(EntryReference<Entry<?>, Entry<?>> ref) {
432 this.cursorReference = ref; 413 this.cursorReference = ref;
433 414
434 Entry<?> referenceEntry = ref == null ? null : ref.entry; 415 this.popupMenu.updateUiState();
435
436 boolean isClassEntry = referenceEntry instanceof ClassEntry;
437 boolean isFieldEntry = referenceEntry instanceof FieldEntry;
438 boolean isMethodEntry = referenceEntry instanceof MethodEntry && !((MethodEntry) referenceEntry).isConstructor();
439 boolean isConstructorEntry = referenceEntry instanceof MethodEntry && ((MethodEntry) referenceEntry).isConstructor();
440 boolean isRenamable = ref != null && this.controller.project.isRenamable(ref);
441
442 this.popupMenu.renameMenu.setEnabled(isRenamable);
443 this.popupMenu.editJavadocMenu.setEnabled(isRenamable);
444 this.popupMenu.showInheritanceMenu.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry);
445 this.popupMenu.showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry);
446 this.popupMenu.showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry);
447 this.popupMenu.showCallsSpecificMenu.setEnabled(isMethodEntry);
448 this.popupMenu.openEntryMenu.setEnabled(isRenamable && (isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry));
449 this.popupMenu.openPreviousMenu.setEnabled(this.controller.hasPreviousReference());
450 this.popupMenu.openNextMenu.setEnabled(this.controller.hasNextReference());
451 this.popupMenu.toggleMappingMenu.setEnabled(isRenamable);
452
453 if (referenceEntry != null && this.controller.project.getMapper().extendedDeobfuscate(referenceEntry).isDeobfuscated()) {
454 this.popupMenu.toggleMappingMenu.setText(I18n.translate("popup_menu.reset_obfuscated"));
455 } else {
456 this.popupMenu.toggleMappingMenu.setText(I18n.translate("popup_menu.mark_deobfuscated"));
457 }
458 416
459 this.listeners.forEach(l -> l.onCursorReferenceChanged(this, ref)); 417 this.listeners.forEach(l -> l.onCursorReferenceChanged(this, ref));
460 } 418 }