summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/GuiController.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/GuiController.java')
-rw-r--r--src/main/java/cuchaz/enigma/gui/GuiController.java69
1 files changed, 57 insertions, 12 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java
index 4155062..5610233 100644
--- a/src/main/java/cuchaz/enigma/gui/GuiController.java
+++ b/src/main/java/cuchaz/enigma/gui/GuiController.java
@@ -12,7 +12,6 @@
12package cuchaz.enigma.gui; 12package cuchaz.enigma.gui;
13 13
14import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
15import com.google.common.collect.Queues;
16import com.google.common.util.concurrent.ThreadFactoryBuilder; 15import com.google.common.util.concurrent.ThreadFactoryBuilder;
17import com.strobel.decompiler.languages.java.ast.CompilationUnit; 16import com.strobel.decompiler.languages.java.ast.CompilationUnit;
18import cuchaz.enigma.Deobfuscator; 17import cuchaz.enigma.Deobfuscator;
@@ -20,6 +19,7 @@ import cuchaz.enigma.SourceProvider;
20import cuchaz.enigma.analysis.*; 19import cuchaz.enigma.analysis.*;
21import cuchaz.enigma.config.Config; 20import cuchaz.enigma.config.Config;
22import cuchaz.enigma.gui.dialog.ProgressDialog; 21import cuchaz.enigma.gui.dialog.ProgressDialog;
22import cuchaz.enigma.gui.util.History;
23import cuchaz.enigma.throwables.MappingParseException; 23import cuchaz.enigma.throwables.MappingParseException;
24import cuchaz.enigma.translation.Translator; 24import cuchaz.enigma.translation.Translator;
25import cuchaz.enigma.translation.mapping.*; 25import cuchaz.enigma.translation.mapping.*;
@@ -40,7 +40,6 @@ import java.io.PrintWriter;
40import java.io.StringWriter; 40import java.io.StringWriter;
41import java.nio.file.Path; 41import java.nio.file.Path;
42import java.util.Collection; 42import java.util.Collection;
43import java.util.Deque;
44import java.util.List; 43import java.util.List;
45import java.util.concurrent.ExecutorService; 44import java.util.concurrent.ExecutorService;
46import java.util.concurrent.Executors; 45import java.util.concurrent.Executors;
@@ -53,14 +52,13 @@ public class GuiController {
53 private final Gui gui; 52 private final Gui gui;
54 private Deobfuscator deobfuscator; 53 private Deobfuscator deobfuscator;
55 private DecompiledClassSource currentSource; 54 private DecompiledClassSource currentSource;
56 private Deque<EntryReference<Entry<?>, Entry<?>>> referenceStack; 55
57 56
58 private Path loadedMappingPath; 57 private Path loadedMappingPath;
59 private MappingFormat loadedMappingFormat; 58 private MappingFormat loadedMappingFormat;
60 59
61 public GuiController(Gui gui) { 60 public GuiController(Gui gui) {
62 this.gui = gui; 61 this.gui = gui;
63 this.referenceStack = Queues.newArrayDeque();
64 } 62 }
65 63
66 public boolean isDirty() { 64 public boolean isDirty() {
@@ -246,6 +244,10 @@ public class GuiController {
246 refreshCurrentClass(reference); 244 refreshCurrentClass(reference);
247 } 245 }
248 246
247 /**
248 * Navigates to the declaration with respect to navigation history
249 * @param entry the entry whose declaration will be navigated to
250 */
249 public void openDeclaration(Entry<?> entry) { 251 public void openDeclaration(Entry<?> entry) {
250 if (entry == null) { 252 if (entry == null) {
251 throw new IllegalArgumentException("Entry cannot be null!"); 253 throw new IllegalArgumentException("Entry cannot be null!");
@@ -253,11 +255,29 @@ public class GuiController {
253 openReference(new EntryReference<>(entry, entry.getName())); 255 openReference(new EntryReference<>(entry, entry.getName()));
254 } 256 }
255 257
258 /**
259 * Navigates to the reference with respect to navigation history
260 * @param reference the reference
261 */
256 public void openReference(EntryReference<Entry<?>, Entry<?>> reference) { 262 public void openReference(EntryReference<Entry<?>, Entry<?>> reference) {
257 if (reference == null) { 263 if (reference == null) {
258 throw new IllegalArgumentException("Reference cannot be null!"); 264 throw new IllegalArgumentException("Reference cannot be null!");
259 } 265 }
266 if (this.gui.referenceHistory == null) {
267 this.gui.referenceHistory = new History<>(reference);
268 } else {
269 if (!reference.equals(this.gui.referenceHistory.getCurrent())) {
270 this.gui.referenceHistory.push(reference);
271 }
272 }
273 setReference(reference);
274 }
260 275
276 /**
277 * Navigates to the reference without modifying history. If the class is not currently loaded, it will be loaded.
278 * @param reference the reference
279 */
280 private void setReference(EntryReference<Entry<?>, Entry<?>> reference) {
261 // get the reference target class 281 // get the reference target class
262 ClassEntry classEntry = reference.getLocationClassEntry(); 282 ClassEntry classEntry = reference.getLocationClassEntry();
263 if (!this.deobfuscator.isRenamable(classEntry)) { 283 if (!this.deobfuscator.isRenamable(classEntry)) {
@@ -272,6 +292,10 @@ public class GuiController {
272 } 292 }
273 } 293 }
274 294
295 /**
296 * Navigates to the reference without modifying history. Assumes the class is loaded.
297 * @param reference
298 */
275 private void showReference(EntryReference<Entry<?>, Entry<?>> reference) { 299 private void showReference(EntryReference<Entry<?>, Entry<?>> reference) {
276 EntryRemapper mapper = this.deobfuscator.getMapper(); 300 EntryRemapper mapper = this.deobfuscator.getMapper();
277 301
@@ -289,18 +313,39 @@ public class GuiController {
289 } 313 }
290 } 314 }
291 315
292 public void savePreviousReference(EntryReference<Entry<?>, Entry<?>> reference) { 316 public void openPreviousReference() {
293 this.referenceStack.push(reference); 317 if (hasPreviousReference()) {
318 setReference(gui.referenceHistory.goBack());
319 }
294 } 320 }
295 321
296 public void openPreviousReference() { 322 public boolean hasPreviousReference() {
297 if (hasPreviousLocation()) { 323 return gui.referenceHistory != null && gui.referenceHistory.canGoBack();
298 openReference(this.referenceStack.pop()); 324 }
325
326 public void openNextReference() {
327 if (hasNextReference()) {
328 setReference(gui.referenceHistory.goForward());
299 } 329 }
300 } 330 }
301 331
302 public boolean hasPreviousLocation() { 332 public boolean hasNextReference() {
303 return !this.referenceStack.isEmpty(); 333 return gui.referenceHistory != null && gui.referenceHistory.canGoForward();
334 }
335
336 public void navigateTo(Entry<?> entry) {
337 if (!entryIsInJar(entry)) {
338 // entry is not in the jar. Ignore it
339 return;
340 }
341 openDeclaration(entry);
342 }
343
344 public void navigateTo(EntryReference<Entry<?>, Entry<?>> reference) {
345 if (!entryIsInJar(reference.getLocationClassEntry())) {
346 return;
347 }
348 openReference(reference);
304 } 349 }
305 350
306 private void refreshClasses() { 351 private void refreshClasses() {
@@ -390,7 +435,7 @@ public class GuiController {
390 435
391 public void modifierChange(ItemEvent event) { 436 public void modifierChange(ItemEvent event) {
392 if (event.getStateChange() == ItemEvent.SELECTED) { 437 if (event.getStateChange() == ItemEvent.SELECTED) {
393 deobfuscator.changeModifier(gui.reference.entry, (AccessModifier) event.getItem()); 438 deobfuscator.changeModifier(gui.cursorReference.entry, (AccessModifier) event.getItem());
394 refreshCurrentClass(); 439 refreshCurrentClass();
395 } 440 }
396 } 441 }