- Moved code guessing current keyword in its function

- Find-in-reference disabled in right-click popup menu unless
appropriate text is selected (#1014)
This commit is contained in:
s17t.net 2012-08-30 00:30:33 +02:00
parent 222d51e383
commit 2ca5d3e056
1 changed files with 28 additions and 23 deletions

View File

@ -1809,8 +1809,7 @@ public class Editor extends JFrame implements RunnerListener {
stopCompoundEdit();
}
protected void handleFindReference() {
protected String getCurrentKeyword() {
String text = "";
if (textarea.getSelectedText() != null)
text = textarea.getSelectedText().trim();
@ -1820,7 +1819,8 @@ public class Editor extends JFrame implements RunnerListener {
int startOffset = 0;
int endIndex = current;
String tmp = textarea.getDocument().getText(current, 1);
// TODO probably a regexp that matches Arduino lang special chars already exists.
// TODO probably a regexp that matches Arduino lang special chars
// already exists.
String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";
while (!tmp.matches(regexp)) {
@ -1836,17 +1836,23 @@ public class Editor extends JFrame implements RunnerListener {
if (current - startOffset < 0) {
tmp = textarea.getDocument().getText(0, 1);
break;
}
else
} else
tmp = textarea.getDocument().getText(current - startOffset, 1);
}
startOffset--;
int length = endIndex - current + startOffset;
text = textarea.getDocument().getText(current - startOffset, length);
} catch (BadLocationException bl) {
bl.printStackTrace();
} finally {
return text;
}
}
protected void handleFindReference() {
String text = getCurrentKeyword();
String referenceFile = PdeKeywords.getReference(text);
if (referenceFile == null) {
@ -2781,16 +2787,15 @@ public class Editor extends JFrame implements RunnerListener {
copyItem.setEnabled(true);
discourseItem.setEnabled(true);
String sel = textarea.getSelectedText().trim();
referenceFile = PdeKeywords.getReference(sel);
referenceItem.setEnabled(referenceFile != null);
} else {
cutItem.setEnabled(false);
copyItem.setEnabled(false);
discourseItem.setEnabled(false);
referenceItem.setEnabled(false);
}
referenceFile = PdeKeywords.getReference(getCurrentKeyword());
referenceItem.setEnabled(referenceFile != null);
super.show(component, x, y);
}
}