diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/Gui.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index 79becf8..bf72c85 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java | |||
| @@ -63,7 +63,6 @@ import javax.swing.tree.TreeNode; | |||
| 63 | import javax.swing.tree.TreePath; | 63 | import javax.swing.tree.TreePath; |
| 64 | 64 | ||
| 65 | import jsyntaxpane.DefaultSyntaxKit; | 65 | import jsyntaxpane.DefaultSyntaxKit; |
| 66 | import jsyntaxpane.SyntaxDocument; | ||
| 67 | 66 | ||
| 68 | import com.google.common.collect.Lists; | 67 | import com.google.common.collect.Lists; |
| 69 | 68 | ||
| @@ -257,6 +256,10 @@ public class Gui | |||
| 257 | startRename(); | 256 | startRename(); |
| 258 | break; | 257 | break; |
| 259 | 258 | ||
| 259 | case KeyEvent.VK_I: | ||
| 260 | showInheritance(); | ||
| 261 | break; | ||
| 262 | |||
| 260 | case KeyEvent.VK_O: | 263 | case KeyEvent.VK_O: |
| 261 | openEntry(); | 264 | openEntry(); |
| 262 | break; | 265 | break; |
| @@ -296,10 +299,11 @@ public class Gui | |||
| 296 | } | 299 | } |
| 297 | } ); | 300 | } ); |
| 298 | popupMenu.add( menu ); | 301 | popupMenu.add( menu ); |
| 302 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_I, 0 ) ); | ||
| 299 | m_inheritanceMenu = menu; | 303 | m_inheritanceMenu = menu; |
| 300 | } | 304 | } |
| 301 | { | 305 | { |
| 302 | JMenuItem menu = new JMenuItem( "Open Class" ); | 306 | JMenuItem menu = new JMenuItem( "Go to Declaration" ); |
| 303 | menu.addActionListener( new ActionListener( ) | 307 | menu.addActionListener( new ActionListener( ) |
| 304 | { | 308 | { |
| 305 | @Override | 309 | @Override |
| @@ -598,34 +602,13 @@ public class Gui | |||
| 598 | 602 | ||
| 599 | public void setSource( String source ) | 603 | public void setSource( String source ) |
| 600 | { | 604 | { |
| 601 | setSource( source, 0 ); | 605 | m_editor.getHighlighter().removeAllHighlights(); |
| 606 | m_editor.setText( source ); | ||
| 602 | } | 607 | } |
| 603 | 608 | ||
| 604 | public void setSource( String source, int lineNum ) | 609 | public void showToken( Token token ) |
| 605 | { | 610 | { |
| 606 | // remove any old highlighters | 611 | m_editor.setCaretPosition( token.start ); |
| 607 | m_editor.getHighlighter().removeAllHighlights(); | ||
| 608 | |||
| 609 | m_editor.setText( source ); | ||
| 610 | |||
| 611 | // count the offset of the target line | ||
| 612 | String text = m_editor.getText(); | ||
| 613 | int pos = 0; | ||
| 614 | int numLines = 0; | ||
| 615 | for( ; pos < text.length(); pos++ ) | ||
| 616 | { | ||
| 617 | if( numLines == lineNum ) | ||
| 618 | { | ||
| 619 | break; | ||
| 620 | } | ||
| 621 | if( text.charAt( pos ) == '\n' ) | ||
| 622 | { | ||
| 623 | numLines++; | ||
| 624 | } | ||
| 625 | } | ||
| 626 | |||
| 627 | // put the caret at the line number | ||
| 628 | m_editor.setCaretPosition( pos ); | ||
| 629 | m_editor.grabFocus(); | 612 | m_editor.grabFocus(); |
| 630 | } | 613 | } |
| 631 | 614 | ||
| @@ -760,12 +743,13 @@ public class Gui | |||
| 760 | 743 | ||
| 761 | m_selectedEntryPair = m_controller.getEntryPair( token ); | 744 | m_selectedEntryPair = m_controller.getEntryPair( token ); |
| 762 | boolean isClassEntry = m_selectedEntryPair.obf instanceof ClassEntry; | 745 | boolean isClassEntry = m_selectedEntryPair.obf instanceof ClassEntry; |
| 746 | boolean isFieldEntry = m_selectedEntryPair.obf instanceof FieldEntry; | ||
| 763 | boolean isMethodEntry = m_selectedEntryPair.obf instanceof MethodEntry; | 747 | boolean isMethodEntry = m_selectedEntryPair.obf instanceof MethodEntry; |
| 764 | 748 | ||
| 765 | showEntryPair( m_selectedEntryPair ); | 749 | showEntryPair( m_selectedEntryPair ); |
| 766 | 750 | ||
| 767 | m_inheritanceMenu.setEnabled( isClassEntry || isMethodEntry ); | 751 | m_inheritanceMenu.setEnabled( isClassEntry || isMethodEntry ); |
| 768 | m_openEntryMenu.setEnabled( isClassEntry ); | 752 | m_openEntryMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry ); |
| 769 | } | 753 | } |
| 770 | 754 | ||
| 771 | private void startRename( ) | 755 | private void startRename( ) |
| @@ -807,12 +791,9 @@ public class Gui | |||
| 807 | String newName = text.getText(); | 791 | String newName = text.getText(); |
| 808 | if( saveName && newName != null && newName.length() > 0 ) | 792 | if( saveName && newName != null && newName.length() > 0 ) |
| 809 | { | 793 | { |
| 810 | SyntaxDocument doc = (SyntaxDocument)m_editor.getDocument(); | ||
| 811 | int lineNum = doc.getLineNumberAt( m_editor.getCaretPosition() ); | ||
| 812 | try | 794 | try |
| 813 | { | 795 | { |
| 814 | // TODO: give token to the controller so we can put the caret back there | 796 | m_controller.rename( m_selectedEntryPair.obf, newName ); |
| 815 | m_controller.rename( m_selectedEntryPair.obf, newName, lineNum ); | ||
| 816 | } | 797 | } |
| 817 | catch( IllegalNameException ex ) | 798 | catch( IllegalNameException ex ) |
| 818 | { | 799 | { |
| @@ -869,12 +850,7 @@ public class Gui | |||
| 869 | { | 850 | { |
| 870 | return; | 851 | return; |
| 871 | } | 852 | } |
| 872 | 853 | m_controller.openEntry( m_selectedEntryPair.obf ); | |
| 873 | // get the current class | ||
| 874 | if( m_selectedEntryPair.obf instanceof ClassEntry ) | ||
| 875 | { | ||
| 876 | m_controller.deobfuscateClass( new ClassFile( m_selectedEntryPair.obf.getName() ) ); | ||
| 877 | } | ||
| 878 | } | 854 | } |
| 879 | 855 | ||
| 880 | private void close( ) | 856 | private void close( ) |