diff options
Diffstat (limited to 'enigma-swing/src/main/java/cuchaz')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java | 59 |
1 files changed, 44 insertions, 15 deletions
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 9bf5fa72..3409fc14 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 | |||
| @@ -69,6 +69,7 @@ public class EditorPanel { | |||
| 69 | private final Gui gui; | 69 | private final Gui gui; |
| 70 | 70 | ||
| 71 | private EntryReference<Entry<?>, Entry<?>> cursorReference; | 71 | private EntryReference<Entry<?>, Entry<?>> cursorReference; |
| 72 | private EntryReference<Entry<?>, Entry<?>> nextReference; | ||
| 72 | private boolean mouseIsPressed = false; | 73 | private boolean mouseIsPressed = false; |
| 73 | private boolean shouldNavigateOnClick; | 74 | private boolean shouldNavigateOnClick; |
| 74 | 75 | ||
| @@ -332,13 +333,14 @@ public class EditorPanel { | |||
| 332 | } else { | 333 | } else { |
| 333 | this.displayError(res.unwrapErr()); | 334 | this.displayError(res.unwrapErr()); |
| 334 | } | 335 | } |
| 336 | this.nextReference = null; | ||
| 335 | }); | 337 | }); |
| 336 | } | 338 | } |
| 337 | 339 | ||
| 338 | public void displayError(ClassHandleError t) { | 340 | public void displayError(ClassHandleError t) { |
| 339 | this.setDisplayMode(DisplayMode.ERRORED); | 341 | this.setDisplayMode(DisplayMode.ERRORED); |
| 340 | String str; | 342 | String str; |
| 341 | switch(t.type) { | 343 | switch (t.type) { |
| 342 | case DECOMPILE: | 344 | case DECOMPILE: |
| 343 | str = "editor.decompile_error"; | 345 | str = "editor.decompile_error"; |
| 344 | break; | 346 | break; |
| @@ -404,21 +406,13 @@ public class EditorPanel { | |||
| 404 | } | 406 | } |
| 405 | 407 | ||
| 406 | public void onCaretMove(int pos, boolean fromClick) { | 408 | public void onCaretMove(int pos, boolean fromClick) { |
| 409 | if (this.settingSource) return; | ||
| 407 | if (this.controller.project == null) return; | 410 | if (this.controller.project == null) return; |
| 408 | 411 | ||
| 409 | EntryRemapper mapper = this.controller.project.getMapper(); | 412 | EntryRemapper mapper = this.controller.project.getMapper(); |
| 410 | Token token = getToken(pos); | 413 | Token token = getToken(pos); |
| 411 | 414 | ||
| 412 | if (this.settingSource) { | 415 | setCursorReference(getReference(token)); |
| 413 | EntryReference<Entry<?>, Entry<?>> ref = getCursorReference(); | ||
| 414 | EntryReference<Entry<?>, Entry<?>> refAtCursor = getReference(token); | ||
| 415 | if (this.editor.getDocument().getLength() != 0 && ref != null && !ref.equals(refAtCursor)) { | ||
| 416 | showReference0(ref); | ||
| 417 | } | ||
| 418 | return; | ||
| 419 | } else { | ||
| 420 | setCursorReference(getReference(token)); | ||
| 421 | } | ||
| 422 | 416 | ||
| 423 | Entry<?> referenceEntry = this.cursorReference != null ? this.cursorReference.entry : null; | 417 | Entry<?> referenceEntry = this.cursorReference != null ? this.cursorReference.entry : null; |
| 424 | 418 | ||
| @@ -484,17 +478,49 @@ public class EditorPanel { | |||
| 484 | if (source == null) return; | 478 | if (source == null) return; |
| 485 | try { | 479 | try { |
| 486 | this.settingSource = true; | 480 | this.settingSource = true; |
| 481 | |||
| 482 | int newCaretPos = 0; | ||
| 483 | if (this.source != null && this.source.getEntry().equals(source.getEntry())) { | ||
| 484 | int caretPos = this.editor.getCaretPosition(); | ||
| 485 | |||
| 486 | if (this.source.getTokenStore().isCompatible(source.getTokenStore())) { | ||
| 487 | newCaretPos = this.source.getTokenStore().mapPosition(source.getTokenStore(), caretPos); | ||
| 488 | } else { | ||
| 489 | // if the class is the same but the token stores aren't | ||
| 490 | // compatible, then the user probably switched decompilers | ||
| 491 | |||
| 492 | // check if there's a selected reference we can navigate to, | ||
| 493 | // but only if there's none already queued up for being selected | ||
| 494 | if (this.getCursorReference() != null && this.nextReference == null) { | ||
| 495 | this.nextReference = this.getCursorReference(); | ||
| 496 | } | ||
| 497 | |||
| 498 | // otherwise fall back to just using the same average | ||
| 499 | // position in the file | ||
| 500 | float scale = (float) source.toString().length() / this.source.toString().length(); | ||
| 501 | newCaretPos = (int) (caretPos * scale); | ||
| 502 | } | ||
| 503 | } | ||
| 504 | |||
| 487 | this.source = source; | 505 | this.source = source; |
| 488 | this.editor.getHighlighter().removeAllHighlights(); | 506 | this.editor.getHighlighter().removeAllHighlights(); |
| 489 | this.editor.setText(source.toString()); | 507 | this.editor.setText(source.toString()); |
| 508 | if (this.source != null) { | ||
| 509 | this.editor.setCaretPosition(newCaretPos); | ||
| 510 | } | ||
| 490 | setHighlightedTokens(source.getHighlightedTokens()); | 511 | setHighlightedTokens(source.getHighlightedTokens()); |
| 512 | setCursorReference(getReference(getToken(this.editor.getCaretPosition()))); | ||
| 491 | } finally { | 513 | } finally { |
| 492 | this.settingSource = false; | 514 | this.settingSource = false; |
| 493 | } | 515 | } |
| 494 | showReference0(getCursorReference()); | 516 | |
| 517 | if (this.nextReference != null) { | ||
| 518 | this.showReference0(this.nextReference); | ||
| 519 | this.nextReference = null; | ||
| 520 | } | ||
| 495 | } | 521 | } |
| 496 | 522 | ||
| 497 | public void setHighlightedTokens(Map<RenamableTokenType, Collection<Token>> tokens) { | 523 | public void setHighlightedTokens(Map<RenamableTokenType, ? extends Collection<Token>> tokens) { |
| 498 | // remove any old highlighters | 524 | // remove any old highlighters |
| 499 | this.editor.getHighlighter().removeAllHighlights(); | 525 | this.editor.getHighlighter().removeAllHighlights(); |
| 500 | 526 | ||
| @@ -526,8 +552,11 @@ public class EditorPanel { | |||
| 526 | } | 552 | } |
| 527 | 553 | ||
| 528 | public void showReference(EntryReference<Entry<?>, Entry<?>> reference) { | 554 | public void showReference(EntryReference<Entry<?>, Entry<?>> reference) { |
| 529 | setCursorReference(reference); | 555 | if (this.mode == DisplayMode.SUCCESS) { |
| 530 | showReference0(reference); | 556 | showReference0(reference); |
| 557 | } else if (this.mode != DisplayMode.ERRORED) { | ||
| 558 | this.nextReference = reference; | ||
| 559 | } | ||
| 531 | } | 560 | } |
| 532 | 561 | ||
| 533 | /** | 562 | /** |