- Code: Select all
begin
etc...
etc...
end
Do you know which files or functions should I look for to make that possible?
Moderator: robert
begin
etc...
etc...
end private void possiblyCloseTokens(RSyntaxTextArea textArea,String leadingWS) {
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getCaretLineNumber();
Token t = doc.getTokenListForLine(line-1);
t = t.getLastNonCommentNonWhitespaceToken();
if (t!=null && t.getLexeme().equalsIgnoreCase("por favor")) {
if (getOpenTokenCount(doc,"por favor","obrigado")>0) {
StringBuffer sb = new StringBuffer();
if (line==textArea.getLineCount()-1) {
sb.append('\n');
}
if (leadingWS!=null) {
sb.append(leadingWS);
}
sb.append("Obrigado\n");
int dot = textArea.getCaretPosition();
int end = textArea.getLineEndOffsetOfCurrentLine();
textArea.insert(sb.toString(), end);
textArea.setCaretPosition(dot);
}
}
else if (t!=null && t.getLexeme().equalsIgnoreCase("[")) {
if (getOpenTokenCount(doc,"[","]")>0) {
StringBuffer sb = new StringBuffer();
if (line==textArea.getLineCount()-1) {
sb.append('\n');
}
if (leadingWS!=null) {
sb.append(leadingWS);
}
sb.append("]\n");
int dot = textArea.getCaretPosition();
int end = textArea.getLineEndOffsetOfCurrentLine();
textArea.insert(sb.toString(), end);
textArea.setCaretPosition(dot);
}
}
}
private static final int getOpenTokenCount(RSyntaxDocument doc, String s1, String s2) {
int openCount = 0;
int size1 = s1.length();
int size2 = s2.length();
Element root = doc.getDefaultRootElement();
int lineCount = root.getElementCount();
for (int i=0; i<lineCount; i++) {
Token t = doc.getTokenListForLine(i);
while (t!=null && t.isPaintable()) {
if (t.textCount==size1) {
String aux = t.getLexeme();
if (aux.equalsIgnoreCase(s1)) {
openCount++;
}
else if (size1==size2) {
if (aux.equalsIgnoreCase(s2))
openCount--;
}
}
else if (t.textCount==size2) {
String aux = t.getLexeme();
if (aux.equalsIgnoreCase(s2))
openCount--;
}
t = t.getNextToken();
}
}
return openCount;
}
public boolean getShouldIndentNextLineAfter(Token t) {
if (t!=null) {
if (t.textCount==1) {
char ch = t.text[t.textOffset];
return ch=='[';
}
if (t.textCount>1) {
return t.getLexeme().equalsIgnoreCase("por favor");
}
}
return false;
}Users browsing this forum: Google [Bot] and 0 guests