提交 7fe46fb6 编写于 作者: S Skylot

gui: highlight words on double click (#210)

上级 2cb94856
......@@ -5,7 +5,7 @@ mainClassName = 'jadx.gui.JadxGUI'
dependencies {
compile(project(":jadx-core"))
compile(project(":jadx-cli"))
compile 'com.fifesoft:rsyntaxtextarea:2.5.8'
compile 'com.fifesoft:rsyntaxtextarea:2.6.1'
compile 'com.google.code.gson:gson:2.3.1'
compile files('libs/jfontchooser-1.0.5.jar')
compile 'hu.kazocsaba:image-viewer:1.2.3'
......
......@@ -10,6 +10,8 @@ import javax.swing.text.Caret;
import javax.swing.text.DefaultCaret;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import org.fife.ui.rsyntaxtextarea.LinkGenerator;
import org.fife.ui.rsyntaxtextarea.LinkGeneratorResult;
......@@ -17,6 +19,9 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenTypes;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -66,9 +71,38 @@ class CodeArea extends RSyntaxTextArea {
addMenuItems(this, (JClass) node);
}
registerWordHighlighter();
setText(node.getContent());
}
private void registerWordHighlighter() {
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() % 2 == 0 && !evt.isConsumed()) {
evt.consume();
String str = getSelectedText();
if (str != null) {
highlightAllMatches(str);
}
} else {
highlightAllMatches(null);
}
}
});
}
/**
* @param str - if null -> reset current highlights
*/
private void highlightAllMatches(@Nullable String str) {
SearchContext context = new SearchContext(str);
context.setMarkAll(true);
context.setMatchCase(true);
context.setWholeWord(true);
SearchEngine.markAll(this, context);
}
private void addMenuItems(CodeArea codeArea, JClass jCls) {
Action findUsage = new FindUsageAction(codeArea, jCls);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册