summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/EditableType.java33
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java28
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java32
3 files changed, 61 insertions, 32 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/EditableType.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/EditableType.java
index 3dfa35ce..1e8d6cf0 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/EditableType.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/EditableType.java
@@ -1,5 +1,9 @@
1package cuchaz.enigma.gui; 1package cuchaz.enigma.gui;
2 2
3import javax.annotation.Nullable;
4
5import cuchaz.enigma.translation.representation.entry.*;
6
3public enum EditableType { 7public enum EditableType {
4 CLASS, 8 CLASS,
5 METHOD, 9 METHOD,
@@ -7,4 +11,33 @@ public enum EditableType {
7 PARAMETER, 11 PARAMETER,
8 LOCAL_VARIABLE, 12 LOCAL_VARIABLE,
9 JAVADOC, 13 JAVADOC,
14 ;
15
16 @Nullable
17 public static EditableType fromEntry(Entry<?> entry) {
18 // TODO get rid of this with Entry rework
19 EditableType type = null;
20
21 if (entry instanceof ClassEntry) {
22 type = EditableType.CLASS;
23 } else if (entry instanceof MethodEntry me) {
24 if (me.isConstructor()) {
25 // treat constructors as classes because renaming one renames
26 // the class
27 type = EditableType.CLASS;
28 } else {
29 type = EditableType.METHOD;
30 }
31 } else if (entry instanceof FieldEntry) {
32 type = EditableType.FIELD;
33 } else if (entry instanceof LocalVariableEntry lve) {
34 if (lve.isArgument()) {
35 type = EditableType.PARAMETER;
36 } else {
37 type = EditableType.LOCAL_VARIABLE;
38 }
39 }
40
41 return type;
42 }
10} 43}
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 637f6a48..2ce6ed93 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,7 +12,10 @@ import cuchaz.enigma.gui.EditableType;
12import cuchaz.enigma.gui.Gui; 12import cuchaz.enigma.gui.Gui;
13import cuchaz.enigma.gui.GuiController; 13import cuchaz.enigma.gui.GuiController;
14import cuchaz.enigma.gui.panels.EditorPanel; 14import cuchaz.enigma.gui.panels.EditorPanel;
15import cuchaz.enigma.translation.representation.entry.*; 15import cuchaz.enigma.translation.representation.entry.ClassEntry;
16import cuchaz.enigma.translation.representation.entry.Entry;
17import cuchaz.enigma.translation.representation.entry.FieldEntry;
18import cuchaz.enigma.translation.representation.entry.MethodEntry;
16import cuchaz.enigma.utils.I18n; 19import cuchaz.enigma.utils.I18n;
17 20
18public class EditorPopupMenu { 21public class EditorPopupMenu {
@@ -149,28 +152,7 @@ public class EditorPopupMenu {
149 boolean isConstructorEntry = referenceEntry instanceof MethodEntry me && me.isConstructor(); 152 boolean isConstructorEntry = referenceEntry instanceof MethodEntry me && me.isConstructor();
150 boolean isRenamable = ref != null && controller.project.isRenamable(ref); 153 boolean isRenamable = ref != null && controller.project.isRenamable(ref);
151 154
152 // TODO get rid of this with Entry rework 155 EditableType type = EditableType.fromEntry(referenceEntry);
153 EditableType type = null;
154
155 if (referenceEntry instanceof ClassEntry) {
156 type = EditableType.CLASS;
157 } else if (referenceEntry instanceof MethodEntry me) {
158 if (me.isConstructor()) {
159 // treat constructors as classes because renaming one renames
160 // the class
161 type = EditableType.CLASS;
162 } else {
163 type = EditableType.METHOD;
164 }
165 } else if (referenceEntry instanceof FieldEntry) {
166 type = EditableType.FIELD;
167 } else if (referenceEntry instanceof LocalVariableEntry lve) {
168 if (lve.isArgument()) {
169 type = EditableType.PARAMETER;
170 } else {
171 type = EditableType.LOCAL_VARIABLE;
172 }
173 }
174 156
175 this.renameItem.setEnabled(isRenamable && (type != null && this.gui.isEditable(type))); 157 this.renameItem.setEnabled(isRenamable && (type != null && this.gui.isEditable(type)));
176 this.editJavadocItem.setEnabled(isRenamable && this.gui.isEditable(EditableType.JAVADOC)); 158 this.editJavadocItem.setEnabled(isRenamable && this.gui.isEditable(EditableType.JAVADOC));
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 f6564f59..2055309c 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
@@ -11,7 +11,6 @@ import javax.annotation.Nullable;
11import javax.swing.*; 11import javax.swing.*;
12import javax.swing.text.BadLocationException; 12import javax.swing.text.BadLocationException;
13import javax.swing.text.Document; 13import javax.swing.text.Document;
14import javax.swing.text.Highlighter;
15import javax.swing.text.Highlighter.HighlightPainter; 14import javax.swing.text.Highlighter.HighlightPainter;
16 15
17import de.sciss.syntaxpane.DefaultSyntaxKit; 16import de.sciss.syntaxpane.DefaultSyntaxKit;
@@ -22,6 +21,7 @@ import cuchaz.enigma.classhandle.ClassHandle;
22import cuchaz.enigma.classhandle.ClassHandleError; 21import cuchaz.enigma.classhandle.ClassHandleError;
23import cuchaz.enigma.events.ClassHandleListener; 22import cuchaz.enigma.events.ClassHandleListener;
24import cuchaz.enigma.gui.BrowserCaret; 23import cuchaz.enigma.gui.BrowserCaret;
24import cuchaz.enigma.gui.EditableType;
25import cuchaz.enigma.gui.Gui; 25import cuchaz.enigma.gui.Gui;
26import cuchaz.enigma.gui.GuiController; 26import cuchaz.enigma.gui.GuiController;
27import cuchaz.enigma.gui.config.LookAndFeel; 27import cuchaz.enigma.gui.config.LookAndFeel;
@@ -461,10 +461,26 @@ public class EditorPanel {
461 this.editor.getHighlighter().removeAllHighlights(); 461 this.editor.getHighlighter().removeAllHighlights();
462 462
463 if (this.boxHighlightPainters != null) { 463 if (this.boxHighlightPainters != null) {
464 BoxHighlightPainter proposedPainter = this.boxHighlightPainters.get(RenamableTokenType.PROPOSED);
465
464 for (RenamableTokenType type : tokens.keySet()) { 466 for (RenamableTokenType type : tokens.keySet()) {
465 BoxHighlightPainter painter = this.boxHighlightPainters.get(type); 467 BoxHighlightPainter painter = this.boxHighlightPainters.get(type);
468
466 if (painter != null) { 469 if (painter != null) {
467 setHighlightedTokens(tokens.get(type), painter); 470 for (Token token : tokens.get(type)) {
471 EntryReference<Entry<?>, Entry<?>> reference = this.getReference(token);
472 BoxHighlightPainter tokenPainter;
473
474 if (reference != null) {
475 EditableType t = EditableType.fromEntry(reference.entry);
476 boolean editable = t == null || this.gui.isEditable(t);
477 tokenPainter = editable ? painter : proposedPainter;
478 } else {
479 tokenPainter = painter;
480 }
481
482 this.addHighlightedToken(token, tokenPainter);
483 }
468 } 484 }
469 } 485 }
470 } 486 }
@@ -473,13 +489,11 @@ public class EditorPanel {
473 this.editor.repaint(); 489 this.editor.repaint();
474 } 490 }
475 491
476 private void setHighlightedTokens(Iterable<Token> tokens, Highlighter.HighlightPainter painter) { 492 private void addHighlightedToken(Token token, HighlightPainter tokenPainter) {
477 for (Token token : tokens) { 493 try {
478 try { 494 this.editor.getHighlighter().addHighlight(token.start, token.end, tokenPainter);
479 this.editor.getHighlighter().addHighlight(token.start, token.end, painter); 495 } catch (BadLocationException ex) {
480 } catch (BadLocationException ex) { 496 throw new IllegalArgumentException(ex);
481 throw new IllegalArgumentException(ex);
482 }
483 } 497 }
484 } 498 }
485 499