diff options
| author | 2019-05-12 09:47:41 +0200 | |
|---|---|---|
| committer | 2019-05-12 09:47:41 +0200 | |
| commit | 65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039 (patch) | |
| tree | ae282f190a8e86a3f0be75ca168f2660d89c56f3 /src/main/java/cuchaz/enigma/gui/GuiController.java | |
| parent | Support navigation to declaration on ctrl+click (diff) | |
| download | enigma-fork-65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039.tar.gz enigma-fork-65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039.tar.xz enigma-fork-65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039.zip | |
Add forward and backward reference history with mouse navigation (#132)
* Add History
* Add forward and backward reference history
* Update PopupMenuBar text for history
* Fix indentation
* Fix more indentation
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/GuiController.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/GuiController.java | 69 |
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 @@ | |||
| 12 | package cuchaz.enigma.gui; | 12 | package cuchaz.enigma.gui; |
| 13 | 13 | ||
| 14 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| 15 | import com.google.common.collect.Queues; | ||
| 16 | import com.google.common.util.concurrent.ThreadFactoryBuilder; | 15 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 17 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | 16 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; |
| 18 | import cuchaz.enigma.Deobfuscator; | 17 | import cuchaz.enigma.Deobfuscator; |
| @@ -20,6 +19,7 @@ import cuchaz.enigma.SourceProvider; | |||
| 20 | import cuchaz.enigma.analysis.*; | 19 | import cuchaz.enigma.analysis.*; |
| 21 | import cuchaz.enigma.config.Config; | 20 | import cuchaz.enigma.config.Config; |
| 22 | import cuchaz.enigma.gui.dialog.ProgressDialog; | 21 | import cuchaz.enigma.gui.dialog.ProgressDialog; |
| 22 | import cuchaz.enigma.gui.util.History; | ||
| 23 | import cuchaz.enigma.throwables.MappingParseException; | 23 | import cuchaz.enigma.throwables.MappingParseException; |
| 24 | import cuchaz.enigma.translation.Translator; | 24 | import cuchaz.enigma.translation.Translator; |
| 25 | import cuchaz.enigma.translation.mapping.*; | 25 | import cuchaz.enigma.translation.mapping.*; |
| @@ -40,7 +40,6 @@ import java.io.PrintWriter; | |||
| 40 | import java.io.StringWriter; | 40 | import java.io.StringWriter; |
| 41 | import java.nio.file.Path; | 41 | import java.nio.file.Path; |
| 42 | import java.util.Collection; | 42 | import java.util.Collection; |
| 43 | import java.util.Deque; | ||
| 44 | import java.util.List; | 43 | import java.util.List; |
| 45 | import java.util.concurrent.ExecutorService; | 44 | import java.util.concurrent.ExecutorService; |
| 46 | import java.util.concurrent.Executors; | 45 | import 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 | } |