ASTGen: remove lastClickedWord

This commit is contained in:
Jakub Valtar
2016-04-22 10:51:26 +02:00
parent 5343a2e988
commit 8a5297b33c
3 changed files with 10 additions and 111 deletions

View File

@@ -1185,22 +1185,6 @@ public class ASTGenerator {
handleShowUsage(binding);
}
protected int lastClickedTab = 0;
protected int lastClickedOffset = 0;
protected String lastClickedWord = null;
public String getLastClickedWord() {
return lastClickedWord;
}
public void setLastClickedWord(int tabIndex, int offset, String lastClickedWord) {
Messages.log("* setLastClickedWord");
this.lastClickedTab = tabIndex;
this.lastClickedOffset = offset;
this.lastClickedWord = lastClickedWord;
log("Last clicked: " + lastClickedWord);
}
public void handleShowUsage(IBinding binding) {
PreprocessedSketch ps = errorCheckerService.latestResult;
@@ -1212,8 +1196,6 @@ public class ASTGenerator {
List<SimpleName> occurrences = findAllOccurrences(ps.compilationUnit, bindingKey);
if (occurrences == null) return;
lastClickedWord = null;
// Send to gui
EventQueue.invokeLater(() -> gui.handleShowUsage(binding, occurrences));
}
@@ -2571,11 +2553,6 @@ public class ASTGenerator {
}
private String getSelectedText() {
return editor.getTextArea().getSelectedText();
}
/// GUI ----------------------------------------------------------------------

View File

@@ -75,9 +75,6 @@ public class JavaTextArea extends JEditTextArea {
super(defaults, new JavaInputHandler(editor));
this.editor = editor;
// handle right click on a word
painter.addMouseListener(rightClickMouseAdapter);
// change cursor to pointer in the gutter area
painter.addMouseMotionListener(gutterCursorMouseAdapter);
@@ -258,77 +255,6 @@ public class JavaTextArea extends JEditTextArea {
}
/**
* Retrieves the word on which the mouse pointer is present
* @param evt - the MouseEvent which triggered this method
*/
private String fetchPhrase(MouseEvent evt) {
Messages.log("--handle Mouse Right Click--");
int off = xyToOffset(evt.getX(), evt.getY());
if (off < 0)
return null;
int line = getLineOfOffset(off);
if (line < 0)
return null;
String s = getLineText(line);
if (s == null)
return null;
else if (s.length() == 0)
return null;
else {
int x = xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
Messages.log("x=" + x);
if (x < 0 || x >= s.length())
return null;
String word = s.charAt(x) + "";
if (s.charAt(x) == ' ')
return null;
if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s
.charAt(x) == '$'))
return null;
int i = 0;
while (true) {
i++;
if (x1 >= 0 && x1 < s.length()) {
if (Character.isLetter(s.charAt(x1)) || s.charAt(x1) == '_') {
word = s.charAt(x1--) + word;
} else
x1 = -1;
} else
x1 = -1;
if (x2 >= 0 && x2 < s.length()) {
if (Character.isLetterOrDigit(s.charAt(x2)) || s.charAt(x2) == '_'
|| s.charAt(x2) == '$')
word = word + s.charAt(x2++);
else
x2 = -1;
} else
x2 = -1;
if (x1 < 0 && x2 < 0)
break;
if (i > 200) {
// time out!
break;
}
}
if (Character.isDigit(word.charAt(0))) {
return null;
}
Messages.log("Mouse click, word: " + word.trim());
ASTGenerator astGenerator = editor.getErrorChecker().getASTGenerator();
int tabIndex = editor.getSketch().getCurrentCodeIndex();
synchronized (astGenerator) {
astGenerator.setLastClickedWord(tabIndex, off, word);
}
return word.trim();
}
}
SwingWorker<Void, Void> suggestionWorker = null;
volatile boolean suggestionRunning = false;
@@ -708,20 +634,6 @@ public class JavaTextArea extends JEditTextArea {
}
/**
* Fetches word under the cursor on right click
*/
protected final MouseAdapter rightClickMouseAdapter = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
if (me.getButton() == MouseEvent.BUTTON3 &&
!editor.hasJavaTabs()) { // tooltips, etc disabled for java tabs
fetchPhrase(me);
}
}
};
/**
* Sets default cursor (instead of text cursor) in the gutter area.
*/