11package club .bytecode .the .jda .gui .fileviewer ;
22
3- import club .bytecode .the .jda .FileContainer ;
43import club .bytecode .the .jda .JDA ;
4+ import club .bytecode .the .jda .gui .search .SearchDialog ;
55import club .bytecode .the .jda .settings .Settings ;
6- import net .miginfocom .swing .MigLayout ;
76import org .fife .ui .rsyntaxtextarea .RSyntaxTextArea ;
87import org .fife .ui .rsyntaxtextarea .Token ;
98import org .fife .ui .rsyntaxtextarea .TokenTypes ;
10- import org .mapleir .stdlib .util .Pair ;
119
1210import javax .swing .*;
1311import javax .swing .event .CaretEvent ;
@@ -33,7 +31,7 @@ public JDATextArea(String text) {
3331
3432 setText (text );
3533 setCaretPosition (0 );
36- setFont (new Font ( Settings .FONT_FAMILY . getString (), Settings . FONT_OPTIONS . getInt (), Settings . FONT_SIZE . getInt () ));
34+ setFont (Settings .getCodeFont ( ));
3735
3836 setEditable (false );
3937 addFocusListener (new FocusListener () {
@@ -127,46 +125,6 @@ private void setComment(int line, String comment) {
127125 resetLine (line );
128126 }
129127
130- private void search (String needle ) {
131- List <ViewerFile > matches = new ArrayList <>();
132- for (FileContainer fc : JDA .getOpenFiles ()) {
133- for (Map .Entry <String , byte []> e : fc .getFiles ().entrySet ()) {
134- if (e .getKey ().endsWith (".class" )) {
135- try {
136- // ClassNode cn = fc.loadClassFile(e.getKey());
137- String fileBytes = new String (e .getValue ());
138- if (fileBytes .contains (needle )) {
139- matches .add (new ViewerFile (fc , e .getKey ()));
140- }
141- } catch (Exception ex ) {
142- ex .printStackTrace ();
143- }
144- }
145- }
146- }
147- final JDialog frame = new JDialog (new JFrame (), "Search Results" , true );
148- Container pane = frame .getContentPane ();
149- pane .setLayout (new MigLayout ());
150- pane .add (new JLabel (needle + "found in:" ), "spanx, grow, wrap, align center" );
151- JList <Pair <FileContainer , String >> list = new JList (matches .toArray ());
152- list .setSelectionMode (ListSelectionModel .SINGLE_INTERVAL_SELECTION );
153- list .setLayoutOrientation (JList .VERTICAL );
154- list .addMouseListener (new MouseAdapter () {
155- public void mouseClicked (MouseEvent evt ) {
156- JList list = (JList )evt .getSource ();
157- if (evt .getClickCount () == 2 ) {
158- int index = list .locationToIndex (evt .getPoint ());
159- ViewerFile vf = matches .get (index );
160- JDA .viewer .navigator .openClassFileToWorkSpace (vf );
161- }
162- }
163- });
164- JScrollPane listScroller = new JScrollPane (list );
165- pane .add (listScroller );
166- frame .pack ();
167- frame .setVisible (true );
168- }
169-
170128 private void resetLine (int line ) {
171129 if (line > lines .size ())
172130 return ;
@@ -185,12 +143,23 @@ private boolean isIdentifierSelected() {
185143 return currentlySelectedToken != null && currentlySelectedToken .getType () == TokenTypes .IDENTIFIER ;
186144 }
187145
146+ private boolean isStringSelected () {
147+ return currentlySelectedToken != null && currentlySelectedToken .getType () == TokenTypes .LITERAL_STRING_DOUBLE_QUOTE ;
148+ }
149+
188150 private void doXrefDialog () {
189- if (!isIdentifierSelected ())
151+ String tokenName ;
152+ if (getSelectedText () != null )
153+ tokenName = getSelectedText ();
154+ else if (isIdentifierSelected ())
155+ tokenName = currentlySelectedToken .getLexeme ();
156+ else if (isStringSelected ()) {
157+ tokenName = currentlySelectedToken .getLexeme ();
158+ tokenName = tokenName .substring (1 , tokenName .length () - 1 );
159+ } else
190160 return ;
191- String oldName = currentlySelectedToken .getLexeme ();
192- search (oldName );
193- // JOptionPane.showMessageDialog(this, "Not implemented");
161+
162+ new SearchDialog (tokenName , JDA .search (tokenName )).setVisible (true );
194163 }
195164
196165 private void doRenameDialog () {
0 commit comments