diff options
| author | 2021-07-08 16:30:39 +0200 | |
|---|---|---|
| committer | 2021-07-08 16:30:39 +0200 | |
| commit | 8efb62490ec153246d467a1a72c513781db887bf (patch) | |
| tree | 0f2eedd97d9c0d95544ff7d24f2b479cf10271fe /enigma-swing/src/main | |
| parent | Add --single-class-tree argument that puts all classes into deobf panel & hid... (diff) | |
| download | enigma-8efb62490ec153246d467a1a72c513781db887bf.tar.gz enigma-8efb62490ec153246d467a1a72c513781db887bf.tar.xz enigma-8efb62490ec153246d467a1a72c513781db887bf.zip | |
Entry Changes (#364)
* Initial refactor: Allow EntryMapping to have null targetName, add EntryChange in favor of entry changing methods in GuiController
* Fix resetting name not actually removing it, and renaming a class causing name collisions with itself
Closes #246.
* Use name proposer for setting default deobf name
Closes #314
* Make network protocol use EntryChange directly
* Handle writing other data correctly when the deobf name is null
* b
* Add some new abstraction stuff
* Use pattern matching instanceof
* Move classes out of newabstraction package
* Make EntryChange final
* Regenerate equals and hashCode
* Convert EntryMapping to record
* Make TristateChange final
* Safety guard null accessModifier initialization
Diffstat (limited to 'enigma-swing/src/main')
7 files changed, 81 insertions, 107 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index a657d171..cddedad7 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -49,11 +49,9 @@ import cuchaz.enigma.gui.renderer.InheritanceTreeCellRenderer; | |||
| 49 | import cuchaz.enigma.gui.renderer.MessageListCellRenderer; | 49 | import cuchaz.enigma.gui.renderer.MessageListCellRenderer; |
| 50 | import cuchaz.enigma.gui.util.*; | 50 | import cuchaz.enigma.gui.util.*; |
| 51 | import cuchaz.enigma.network.Message; | 51 | import cuchaz.enigma.network.Message; |
| 52 | import cuchaz.enigma.network.packet.MarkDeobfuscatedC2SPacket; | ||
| 53 | import cuchaz.enigma.network.packet.MessageC2SPacket; | 52 | import cuchaz.enigma.network.packet.MessageC2SPacket; |
| 54 | import cuchaz.enigma.network.packet.RemoveMappingC2SPacket; | ||
| 55 | import cuchaz.enigma.network.packet.RenameC2SPacket; | ||
| 56 | import cuchaz.enigma.source.Token; | 53 | import cuchaz.enigma.source.Token; |
| 54 | import cuchaz.enigma.translation.mapping.EntryChange; | ||
| 57 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 55 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 58 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 56 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 59 | import cuchaz.enigma.translation.representation.entry.Entry; | 57 | import cuchaz.enigma.translation.representation.entry.Entry; |
| @@ -740,12 +738,10 @@ public class Gui implements LanguageChangeListener { | |||
| 740 | 738 | ||
| 741 | Entry<?> obfEntry = cursorReference.entry; | 739 | Entry<?> obfEntry = cursorReference.entry; |
| 742 | 740 | ||
| 743 | if (controller.project.getMapper().extendedDeobfuscate(obfEntry).isDeobfuscated()) { | 741 | if (this.controller.project.getMapper().getDeobfMapping(obfEntry).targetName() != null) { |
| 744 | if (!validateImmediateAction(vc -> this.controller.removeMapping(vc, cursorReference))) return; | 742 | validateImmediateAction(vc -> this.controller.applyChange(vc, EntryChange.modify(obfEntry).clearDeobfName())); |
| 745 | this.controller.sendPacket(new RemoveMappingC2SPacket(cursorReference.getNameableEntry())); | ||
| 746 | } else { | 743 | } else { |
| 747 | if (!validateImmediateAction(vc -> this.controller.markAsDeobfuscated(vc, cursorReference))) return; | 744 | validateImmediateAction(vc -> this.controller.applyChange(vc, EntryChange.modify(obfEntry).withDefaultDeobfName(this.getController().project))); |
| 748 | this.controller.sendPacket(new MarkDeobfuscatedC2SPacket(cursorReference.getNameableEntry())); | ||
| 749 | } | 745 | } |
| 750 | } | 746 | } |
| 751 | 747 | ||
| @@ -813,7 +809,7 @@ public class Gui implements LanguageChangeListener { | |||
| 813 | this.frame.repaint(); | 809 | this.frame.repaint(); |
| 814 | } | 810 | } |
| 815 | 811 | ||
| 816 | public void onPanelRename(ValidationContext vc, Object prevData, Object data, DefaultMutableTreeNode node) { | 812 | public void onRenameFromClassTree(ValidationContext vc, Object prevData, Object data, DefaultMutableTreeNode node) { |
| 817 | if (data instanceof String) { | 813 | if (data instanceof String) { |
| 818 | // package rename | 814 | // package rename |
| 819 | for (int i = 0; i < node.getChildCount(); i++) { | 815 | for (int i = 0; i < node.getChildCount(); i++) { |
| @@ -821,7 +817,7 @@ public class Gui implements LanguageChangeListener { | |||
| 821 | ClassEntry prevDataChild = (ClassEntry) childNode.getUserObject(); | 817 | ClassEntry prevDataChild = (ClassEntry) childNode.getUserObject(); |
| 822 | ClassEntry dataChild = new ClassEntry(data + "/" + prevDataChild.getSimpleName()); | 818 | ClassEntry dataChild = new ClassEntry(data + "/" + prevDataChild.getSimpleName()); |
| 823 | 819 | ||
| 824 | onPanelRename(vc, prevDataChild, dataChild, node); | 820 | onRenameFromClassTree(vc, prevDataChild, dataChild, node); |
| 825 | } | 821 | } |
| 826 | node.setUserObject(data); | 822 | node.setUserObject(data); |
| 827 | // Ob package will never be modified, just reload deob view | 823 | // Ob package will never be modified, just reload deob view |
| @@ -839,9 +835,9 @@ public class Gui implements LanguageChangeListener { | |||
| 839 | .filter(e -> mapper.deobfuscate(e).equals(deobf)) | 835 | .filter(e -> mapper.deobfuscate(e).equals(deobf)) |
| 840 | .findAny().orElse(deobf); | 836 | .findAny().orElse(deobf); |
| 841 | 837 | ||
| 842 | this.controller.rename(vc, new EntryReference<>(obf, obf.getFullName()), ((ClassEntry) data).getFullName(), false); | 838 | this.controller.applyChange(vc, EntryChange.modify(obf).withDeobfName(((ClassEntry) data).getFullName())); |
| 843 | if (!vc.canProceed()) return; | 839 | } else { |
| 844 | this.controller.sendPacket(new RenameC2SPacket(obf, ((ClassEntry) data).getFullName(), false)); | 840 | throw new IllegalStateException(String.format("unhandled rename object data: '%s'", data)); |
| 845 | } | 841 | } |
| 846 | } | 842 | } |
| 847 | 843 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index 2b75655a..4a15b418 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -18,6 +18,7 @@ import java.io.IOException; | |||
| 18 | import java.nio.file.Path; | 18 | import java.nio.file.Path; |
| 19 | import java.util.Collection; | 19 | import java.util.Collection; |
| 20 | import java.util.List; | 20 | import java.util.List; |
| 21 | import java.util.Objects; | ||
| 21 | import java.util.Set; | 22 | import java.util.Set; |
| 22 | import java.util.concurrent.CompletableFuture; | 23 | import java.util.concurrent.CompletableFuture; |
| 23 | import java.util.concurrent.ExecutionException; | 24 | import java.util.concurrent.ExecutionException; |
| @@ -39,10 +40,12 @@ import cuchaz.enigma.classprovider.ClasspathClassProvider; | |||
| 39 | import cuchaz.enigma.gui.config.NetConfig; | 40 | import cuchaz.enigma.gui.config.NetConfig; |
| 40 | import cuchaz.enigma.gui.config.UiConfig; | 41 | import cuchaz.enigma.gui.config.UiConfig; |
| 41 | import cuchaz.enigma.gui.dialog.ProgressDialog; | 42 | import cuchaz.enigma.gui.dialog.ProgressDialog; |
| 43 | import cuchaz.enigma.gui.newabstraction.EntryValidation; | ||
| 42 | import cuchaz.enigma.gui.stats.StatsGenerator; | 44 | import cuchaz.enigma.gui.stats.StatsGenerator; |
| 43 | import cuchaz.enigma.gui.stats.StatsMember; | 45 | import cuchaz.enigma.gui.stats.StatsMember; |
| 44 | import cuchaz.enigma.gui.util.History; | 46 | import cuchaz.enigma.gui.util.History; |
| 45 | import cuchaz.enigma.network.*; | 47 | import cuchaz.enigma.network.*; |
| 48 | import cuchaz.enigma.network.packet.EntryChangeC2SPacket; | ||
| 46 | import cuchaz.enigma.network.packet.LoginC2SPacket; | 49 | import cuchaz.enigma.network.packet.LoginC2SPacket; |
| 47 | import cuchaz.enigma.network.packet.Packet; | 50 | import cuchaz.enigma.network.packet.Packet; |
| 48 | import cuchaz.enigma.source.DecompiledClassSource; | 51 | import cuchaz.enigma.source.DecompiledClassSource; |
| @@ -62,6 +65,7 @@ import cuchaz.enigma.translation.representation.entry.FieldEntry; | |||
| 62 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 65 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 63 | import cuchaz.enigma.utils.I18n; | 66 | import cuchaz.enigma.utils.I18n; |
| 64 | import cuchaz.enigma.utils.Utils; | 67 | import cuchaz.enigma.utils.Utils; |
| 68 | import cuchaz.enigma.utils.validation.PrintValidatable; | ||
| 65 | import cuchaz.enigma.utils.validation.ValidationContext; | 69 | import cuchaz.enigma.utils.validation.ValidationContext; |
| 66 | 70 | ||
| 67 | public class GuiController implements ClientPacketHandler { | 71 | public class GuiController implements ClientPacketHandler { |
| @@ -401,19 +405,6 @@ public class GuiController implements ClientPacketHandler { | |||
| 401 | }); | 405 | }); |
| 402 | } | 406 | } |
| 403 | 407 | ||
| 404 | public void onModifierChanged(ValidationContext vc, Entry<?> entry, AccessModifier modifier) { | ||
| 405 | EntryRemapper mapper = project.getMapper(); | ||
| 406 | |||
| 407 | EntryMapping mapping = mapper.getDeobfMapping(entry); | ||
| 408 | if (mapping != null) { | ||
| 409 | mapper.mapFromObf(vc, entry, new EntryMapping(mapping.getTargetName(), modifier)); | ||
| 410 | } else { | ||
| 411 | mapper.mapFromObf(vc, entry, new EntryMapping(entry.getName(), modifier)); | ||
| 412 | } | ||
| 413 | |||
| 414 | chp.invalidateMapped(); | ||
| 415 | } | ||
| 416 | |||
| 417 | public StructureTreeNode getClassStructure(ClassEntry entry, StructureTreeOptions options) { | 408 | public StructureTreeNode getClassStructure(ClassEntry entry, StructureTreeOptions options) { |
| 418 | StructureTreeNode rootNode = new StructureTreeNode(this.project, entry, entry); | 409 | StructureTreeNode rootNode = new StructureTreeNode(this.project, entry, entry); |
| 419 | rootNode.load(this.project, options); | 410 | rootNode.load(this.project, options); |
| @@ -471,74 +462,54 @@ public class GuiController implements ClientPacketHandler { | |||
| 471 | } | 462 | } |
| 472 | 463 | ||
| 473 | @Override | 464 | @Override |
| 474 | public void rename(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference, String newName, boolean refreshClassTree) { | 465 | public boolean applyChangeFromServer(EntryChange<?> change) { |
| 475 | rename(vc, reference, newName, refreshClassTree, false); | 466 | ValidationContext vc = new ValidationContext(); |
| 476 | } | 467 | vc.setActiveElement(PrintValidatable.INSTANCE); |
| 477 | 468 | this.applyChange0(vc, change); | |
| 478 | public void rename(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference, String newName, boolean refreshClassTree, boolean validateOnly) { | ||
| 479 | Entry<?> entry = reference.getNameableEntry(); | ||
| 480 | EntryMapping previous = project.getMapper().getDeobfMapping(entry); | ||
| 481 | project.getMapper().mapFromObf(vc, entry, previous != null ? previous.withName(newName) : new EntryMapping(newName), true, validateOnly); | ||
| 482 | gui.showStructure(gui.getActiveEditor()); | 469 | gui.showStructure(gui.getActiveEditor()); |
| 483 | 470 | ||
| 484 | if (validateOnly || !vc.canProceed()) return; | 471 | return vc.canProceed(); |
| 472 | } | ||
| 485 | 473 | ||
| 486 | if (refreshClassTree && reference.entry instanceof ClassEntry && !((ClassEntry) reference.entry).isInnerClass()) | 474 | public void validateChange(ValidationContext vc, EntryChange<?> change) { |
| 487 | this.gui.moveClassTree(reference.entry, newName); | 475 | if (change.getDeobfName().isSet()) { |
| 476 | EntryValidation.validateRename(vc, this.project, change.getTarget(), change.getDeobfName().getNewValue()); | ||
| 477 | } | ||
| 488 | 478 | ||
| 489 | chp.invalidateMapped(); | 479 | if (change.getJavadoc().isSet()) { |
| 480 | EntryValidation.validateJavadoc(vc, change.getJavadoc().getNewValue()); | ||
| 481 | } | ||
| 490 | } | 482 | } |
| 491 | 483 | ||
| 492 | @Override | 484 | public void applyChange(ValidationContext vc, EntryChange<?> change) { |
| 493 | public void removeMapping(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference) { | 485 | this.applyChange0(vc, change); |
| 494 | project.getMapper().removeByObf(vc, reference.getNameableEntry()); | ||
| 495 | gui.showStructure(gui.getActiveEditor()); | 486 | gui.showStructure(gui.getActiveEditor()); |
| 496 | |||
| 497 | if (!vc.canProceed()) return; | 487 | if (!vc.canProceed()) return; |
| 498 | 488 | this.sendPacket(new EntryChangeC2SPacket(change)); | |
| 499 | if (reference.entry instanceof ClassEntry) | ||
| 500 | this.gui.moveClassTree(reference.entry, false, true); | ||
| 501 | |||
| 502 | chp.invalidateMapped(); | ||
| 503 | } | 489 | } |
| 504 | 490 | ||
| 505 | @Override | 491 | private void applyChange0(ValidationContext vc, EntryChange<?> change) { |
| 506 | public void changeDocs(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference, String updatedDocs) { | 492 | validateChange(vc, change); |
| 507 | changeDocs(vc, reference, updatedDocs, false); | 493 | if (!vc.canProceed()) return; |
| 508 | } | ||
| 509 | |||
| 510 | public void changeDocs(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference, String updatedDocs, boolean validateOnly) { | ||
| 511 | changeDoc(vc, reference.entry, updatedDocs, validateOnly); | ||
| 512 | |||
| 513 | if (validateOnly || !vc.canProceed()) return; | ||
| 514 | 494 | ||
| 515 | chp.invalidateJavadoc(reference.getLocationClassEntry()); | 495 | Entry<?> target = change.getTarget(); |
| 516 | } | 496 | EntryMapping prev = this.project.getMapper().getDeobfMapping(target); |
| 497 | EntryMapping mapping = EntryUtil.applyChange(vc, this.project.getMapper(), change); | ||
| 517 | 498 | ||
| 518 | private void changeDoc(ValidationContext vc, Entry<?> obfEntry, String newDoc, boolean validateOnly) { | 499 | boolean renamed = !change.getDeobfName().isUnchanged(); |
| 519 | EntryRemapper mapper = project.getMapper(); | ||
| 520 | 500 | ||
| 521 | EntryMapping deobfMapping = mapper.getDeobfMapping(obfEntry); | 501 | if (renamed && target instanceof ClassEntry && !((ClassEntry) target).isInnerClass()) { |
| 522 | if (deobfMapping == null) { | 502 | this.gui.moveClassTree(target, prev.targetName() == null, mapping.targetName() == null); |
| 523 | deobfMapping = new EntryMapping(mapper.deobfuscate(obfEntry).getName()); | ||
| 524 | } | 503 | } |
| 525 | 504 | ||
| 526 | mapper.mapFromObf(vc, obfEntry, deobfMapping.withDocs(newDoc), false, validateOnly); | 505 | if (!Objects.equals(prev.targetName(), mapping.targetName())) { |
| 527 | } | 506 | this.chp.invalidateMapped(); |
| 507 | } | ||
| 528 | 508 | ||
| 529 | @Override | 509 | if (!Objects.equals(prev.javadoc(), mapping.javadoc())) { |
| 530 | public void markAsDeobfuscated(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference) { | 510 | this.chp.invalidateJavadoc(target.getTopLevelClass()); |
| 531 | EntryRemapper mapper = project.getMapper(); | 511 | } |
| 532 | Entry<?> entry = reference.getNameableEntry(); | ||
| 533 | mapper.mapFromObf(vc, entry, new EntryMapping(mapper.deobfuscate(entry).getName())); | ||
| 534 | gui.showStructure(gui.getActiveEditor()); | 512 | gui.showStructure(gui.getActiveEditor()); |
| 535 | |||
| 536 | if (!vc.canProceed()) return; | ||
| 537 | |||
| 538 | if (reference.entry instanceof ClassEntry && !((ClassEntry) reference.entry).isInnerClass()) | ||
| 539 | this.gui.moveClassTree(reference.entry, true, false); | ||
| 540 | |||
| 541 | chp.invalidateMapped(); | ||
| 542 | } | 513 | } |
| 543 | 514 | ||
| 544 | public void openStats(Set<StatsMember> includedMembers, String topLevelPackage, boolean includeSynthetic) { | 515 | public void openStats(Set<StatsMember> includedMembers, String topLevelPackage, boolean includeSynthetic) { |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java index 2fc67476..9470e11c 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java | |||
| @@ -29,23 +29,22 @@ import cuchaz.enigma.gui.config.UiConfig; | |||
| 29 | import cuchaz.enigma.gui.elements.ValidatableTextArea; | 29 | import cuchaz.enigma.gui.elements.ValidatableTextArea; |
| 30 | import cuchaz.enigma.gui.util.GuiUtil; | 30 | import cuchaz.enigma.gui.util.GuiUtil; |
| 31 | import cuchaz.enigma.gui.util.ScaleUtil; | 31 | import cuchaz.enigma.gui.util.ScaleUtil; |
| 32 | import cuchaz.enigma.network.packet.ChangeDocsC2SPacket; | 32 | import cuchaz.enigma.translation.mapping.EntryChange; |
| 33 | import cuchaz.enigma.translation.representation.entry.Entry; | 33 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 34 | import cuchaz.enigma.utils.I18n; | 34 | import cuchaz.enigma.utils.I18n; |
| 35 | import cuchaz.enigma.utils.validation.Message; | ||
| 36 | import cuchaz.enigma.utils.validation.ValidationContext; | 35 | import cuchaz.enigma.utils.validation.ValidationContext; |
| 37 | 36 | ||
| 38 | public class JavadocDialog { | 37 | public class JavadocDialog { |
| 39 | 38 | ||
| 40 | private final JDialog ui; | 39 | private final JDialog ui; |
| 41 | private final GuiController controller; | 40 | private final GuiController controller; |
| 42 | private final EntryReference<Entry<?>, Entry<?>> entry; | 41 | private final Entry<?> entry; |
| 43 | 42 | ||
| 44 | private final ValidatableTextArea text; | 43 | private final ValidatableTextArea text; |
| 45 | 44 | ||
| 46 | private final ValidationContext vc = new ValidationContext(); | 45 | private final ValidationContext vc = new ValidationContext(); |
| 47 | 46 | ||
| 48 | private JavadocDialog(JFrame parent, GuiController controller, EntryReference<Entry<?>, Entry<?>> entry, String preset) { | 47 | private JavadocDialog(JFrame parent, GuiController controller, Entry<?> entry, String preset) { |
| 49 | this.ui = new JDialog(parent, I18n.translate("javadocs.edit")); | 48 | this.ui = new JDialog(parent, I18n.translate("javadocs.edit")); |
| 50 | this.controller = controller; | 49 | this.controller = controller; |
| 51 | this.entry = entry; | 50 | this.entry = entry; |
| @@ -161,28 +160,21 @@ public class JavadocDialog { | |||
| 161 | public void validate() { | 160 | public void validate() { |
| 162 | vc.setActiveElement(text); | 161 | vc.setActiveElement(text); |
| 163 | 162 | ||
| 164 | if (text.getText().contains("*/")) { | 163 | controller.validateChange(vc, EntryChange.modify(entry).withJavadoc(text.getText())); |
| 165 | vc.raise(Message.ILLEGAL_DOC_COMMENT_END); | ||
| 166 | } | ||
| 167 | |||
| 168 | controller.changeDocs(vc, entry, text.getText(), true); | ||
| 169 | } | 164 | } |
| 170 | 165 | ||
| 171 | public void save() { | 166 | public void save() { |
| 172 | vc.setActiveElement(text); | 167 | vc.setActiveElement(text); |
| 173 | controller.changeDocs(vc, entry, text.getText().trim().isEmpty() ? null : text.getText()); | ||
| 174 | |||
| 175 | if (!vc.canProceed()) return; | ||
| 176 | 168 | ||
| 177 | controller.sendPacket(new ChangeDocsC2SPacket(entry.getNameableEntry(), text.getText())); | 169 | controller.applyChange(vc, EntryChange.modify(entry).withJavadoc(text.getText())); |
| 178 | } | 170 | } |
| 179 | 171 | ||
| 180 | public static void show(JFrame parent, GuiController controller, EntryReference<Entry<?>, Entry<?>> entry) { | 172 | public static void show(JFrame parent, GuiController controller, EntryReference<Entry<?>, Entry<?>> entry) { |
| 181 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.project.getMapper().deobfuscate(entry); | 173 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.project.getMapper().deobfuscate(entry); |
| 182 | String text = Strings.nullToEmpty(translatedReference.entry.getJavadocs()); | 174 | String text = Strings.nullToEmpty(translatedReference.entry.getJavadocs()); |
| 183 | 175 | ||
| 184 | JavadocDialog dialog = new JavadocDialog(parent, controller, entry, text); | 176 | JavadocDialog dialog = new JavadocDialog(parent, controller, entry.getNameableEntry(), text); |
| 185 | dialog.ui.doLayout(); | 177 | //dialog.ui.doLayout(); |
| 186 | dialog.ui.setVisible(true); | 178 | dialog.ui.setVisible(true); |
| 187 | dialog.text.grabFocus(); | 179 | dialog.text.grabFocus(); |
| 188 | } | 180 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/newabstraction/EntryValidation.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/newabstraction/EntryValidation.java new file mode 100644 index 00000000..898529a4 --- /dev/null +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/newabstraction/EntryValidation.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | package cuchaz.enigma.gui.newabstraction; | ||
| 2 | |||
| 3 | import cuchaz.enigma.EnigmaProject; | ||
| 4 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 5 | import cuchaz.enigma.utils.validation.Message; | ||
| 6 | import cuchaz.enigma.utils.validation.ValidationContext; | ||
| 7 | |||
| 8 | public class EntryValidation { | ||
| 9 | |||
| 10 | public static boolean validateJavadoc(ValidationContext vc, String javadoc) { | ||
| 11 | if (javadoc.contains("*/")) { | ||
| 12 | vc.raise(Message.ILLEGAL_DOC_COMMENT_END); | ||
| 13 | return false; | ||
| 14 | } | ||
| 15 | return true; | ||
| 16 | } | ||
| 17 | |||
| 18 | public static boolean validateRename(ValidationContext vc, EnigmaProject p, Entry<?> entry, String newName) { | ||
| 19 | return p.getMapper().getValidator().validateRename(vc, entry, newName); | ||
| 20 | } | ||
| 21 | |||
| 22 | } | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/DeobfPanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/DeobfPanel.java index 5b7882b0..cd09c1a1 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/DeobfPanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/DeobfPanel.java | |||
| @@ -22,7 +22,7 @@ public class DeobfPanel extends JPanel { | |||
| 22 | 22 | ||
| 23 | this.deobfClasses = new ClassSelector(gui, ClassSelector.DEOBF_CLASS_COMPARATOR, true); | 23 | this.deobfClasses = new ClassSelector(gui, ClassSelector.DEOBF_CLASS_COMPARATOR, true); |
| 24 | this.deobfClasses.setSelectionListener(gui.getController()::navigateTo); | 24 | this.deobfClasses.setSelectionListener(gui.getController()::navigateTo); |
| 25 | this.deobfClasses.setRenameSelectionListener(gui::onPanelRename); | 25 | this.deobfClasses.setRenameSelectionListener(gui::onRenameFromClassTree); |
| 26 | 26 | ||
| 27 | this.setLayout(new BorderLayout()); | 27 | this.setLayout(new BorderLayout()); |
| 28 | this.add(this.title, BorderLayout.NORTH); | 28 | this.add(this.title, BorderLayout.NORTH); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/IdentifierPanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/IdentifierPanel.java index 3bae94c3..4ae0b7be 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/IdentifierPanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/IdentifierPanel.java | |||
| @@ -15,7 +15,6 @@ import javax.swing.JLabel; | |||
| 15 | import javax.swing.JPanel; | 15 | import javax.swing.JPanel; |
| 16 | 16 | ||
| 17 | import cuchaz.enigma.EnigmaProject; | 17 | import cuchaz.enigma.EnigmaProject; |
| 18 | import cuchaz.enigma.analysis.EntryReference; | ||
| 19 | import cuchaz.enigma.gui.EditableType; | 18 | import cuchaz.enigma.gui.EditableType; |
| 20 | import cuchaz.enigma.gui.Gui; | 19 | import cuchaz.enigma.gui.Gui; |
| 21 | import cuchaz.enigma.gui.elements.ConvertingTextField; | 20 | import cuchaz.enigma.gui.elements.ConvertingTextField; |
| @@ -23,8 +22,8 @@ import cuchaz.enigma.gui.events.ConvertingTextFieldListener; | |||
| 23 | import cuchaz.enigma.gui.util.GridBagConstraintsBuilder; | 22 | import cuchaz.enigma.gui.util.GridBagConstraintsBuilder; |
| 24 | import cuchaz.enigma.gui.util.GuiUtil; | 23 | import cuchaz.enigma.gui.util.GuiUtil; |
| 25 | import cuchaz.enigma.gui.util.ScaleUtil; | 24 | import cuchaz.enigma.gui.util.ScaleUtil; |
| 26 | import cuchaz.enigma.network.packet.RenameC2SPacket; | ||
| 27 | import cuchaz.enigma.translation.mapping.AccessModifier; | 25 | import cuchaz.enigma.translation.mapping.AccessModifier; |
| 26 | import cuchaz.enigma.translation.mapping.EntryChange; | ||
| 28 | import cuchaz.enigma.translation.mapping.EntryMapping; | 27 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 29 | import cuchaz.enigma.translation.representation.entry.*; | 28 | import cuchaz.enigma.translation.representation.entry.*; |
| 30 | import cuchaz.enigma.utils.I18n; | 29 | import cuchaz.enigma.utils.I18n; |
| @@ -76,7 +75,7 @@ public class IdentifierPanel { | |||
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | private void onModifierChanged(AccessModifier modifier) { | 77 | private void onModifierChanged(AccessModifier modifier) { |
| 79 | gui.validateImmediateAction(vc -> this.gui.getController().onModifierChanged(vc, entry, modifier)); | 78 | gui.validateImmediateAction(vc -> this.gui.getController().applyChange(vc, EntryChange.modify(entry).withAccess(modifier))); |
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | public void refreshReference() { | 81 | public void refreshReference() { |
| @@ -176,13 +175,12 @@ public class IdentifierPanel { | |||
| 176 | } | 175 | } |
| 177 | 176 | ||
| 178 | private void validateRename(String newName) { | 177 | private void validateRename(String newName) { |
| 179 | gui.getController().rename(vc, new EntryReference<>(entry, deobfEntry.getName()), newName, true, true); | 178 | gui.getController().validateChange(vc, EntryChange.modify(entry).withDeobfName(newName)); |
| 180 | } | 179 | } |
| 181 | 180 | ||
| 182 | private void doRename(String newName) { | 181 | private void doRename(String newName) { |
| 183 | gui.getController().rename(vc, new EntryReference<>(entry, deobfEntry.getName()), newName, true); | 182 | EntryChange<? extends Entry<?>> change = EntryChange.modify(entry).withDeobfName(newName); |
| 184 | if (!vc.canProceed()) return; | 183 | gui.getController().applyChange(vc, change); |
| 185 | gui.getController().sendPacket(new RenameC2SPacket(entry, newName, true)); | ||
| 186 | } | 184 | } |
| 187 | 185 | ||
| 188 | public void retranslateUi() { | 186 | public void retranslateUi() { |
| @@ -277,12 +275,7 @@ public class IdentifierPanel { | |||
| 277 | 275 | ||
| 278 | JComboBox<AccessModifier> combo = new JComboBox<>(AccessModifier.values()); | 276 | JComboBox<AccessModifier> combo = new JComboBox<>(AccessModifier.values()); |
| 279 | EntryMapping mapping = project.getMapper().getDeobfMapping(e); | 277 | EntryMapping mapping = project.getMapper().getDeobfMapping(e); |
| 280 | 278 | combo.setSelectedIndex(mapping.accessModifier().ordinal()); | |
| 281 | if (mapping != null) { | ||
| 282 | combo.setSelectedIndex(mapping.getAccessModifier().ordinal()); | ||
| 283 | } else { | ||
| 284 | combo.setSelectedIndex(AccessModifier.UNCHANGED.ordinal()); | ||
| 285 | } | ||
| 286 | 279 | ||
| 287 | if (this.gui.isEditable(type)) { | 280 | if (this.gui.isEditable(type)) { |
| 288 | combo.addItemListener(event -> { | 281 | combo.addItemListener(event -> { |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/ObfPanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/ObfPanel.java index b384968d..7783843d 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/ObfPanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/ObfPanel.java | |||
| @@ -33,7 +33,7 @@ public class ObfPanel extends JPanel { | |||
| 33 | 33 | ||
| 34 | this.obfClasses = new ClassSelector(gui, obfClassComparator, false); | 34 | this.obfClasses = new ClassSelector(gui, obfClassComparator, false); |
| 35 | this.obfClasses.setSelectionListener(gui.getController()::navigateTo); | 35 | this.obfClasses.setSelectionListener(gui.getController()::navigateTo); |
| 36 | this.obfClasses.setRenameSelectionListener(gui::onPanelRename); | 36 | this.obfClasses.setRenameSelectionListener(gui::onRenameFromClassTree); |
| 37 | 37 | ||
| 38 | this.setLayout(new BorderLayout()); | 38 | this.setLayout(new BorderLayout()); |
| 39 | this.add(this.title, BorderLayout.NORTH); | 39 | this.add(this.title, BorderLayout.NORTH); |