From: Francesco D. <da...@us...> - 2006-01-29 15:26:52
|
Update of /cvsroot/tora/tora In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30305 Modified Files: NEWS tohighlightedtext.cpp tohighlightedtext.h Log Message: first half working and incomplete attempt of completion Index: NEWS =================================================================== RCS file: /cvsroot/tora/tora/NEWS,v retrieving revision 1.999 retrieving revision 1.1000 diff -C2 -d -r1.999 -r1.1000 *** NEWS 21 Jan 2006 12:57:33 -0000 1.999 --- NEWS 29 Jan 2006 15:26:42 -0000 1.1000 *************** *** 11,14 **** --- 11,16 ---- 2006-01-20: Fix for bug 957911 2006-01-21: Patch #1245301 from Mike Fleetwood (Charts in Server Tuning with 10g) + 2006-01-27: turned autoindent on + 2006-01-29: first (incomplete) implementation of the autocompletion API 1.3.19: Index: tohighlightedtext.cpp =================================================================== RCS file: /cvsroot/tora/tora/tohighlightedtext.cpp,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -d -r1.98 -r1.99 *** tohighlightedtext.cpp 30 Dec 2005 21:43:53 -0000 1.98 --- tohighlightedtext.cpp 29 Jan 2006 15:26:42 -0000 1.99 *************** *** 53,56 **** --- 53,59 ---- #include <qstylesheet.h> #include <qtimer.h> + #include <qkeysequence.h> + #include <qextscintillaapis.h> + #include <qnamespace.h> #include <qextscintillalexersql.h> *************** *** 290,299 **** setMarkerBackgroundColor(Qt::red,errorMarker); setMarginMarkerMask(1,0); connect(this,SIGNAL(cursorPositionChanged(int,int)),this,SLOT(setStatusMessage(void ))); } toHighlightedText::~toHighlightedText() { ! } --- 293,425 ---- setMarkerBackgroundColor(Qt::red,errorMarker); setMarginMarkerMask(1,0); + setAutoIndent(true); connect(this,SIGNAL(cursorPositionChanged(int,int)),this,SLOT(setStatusMessage(void ))); + complAPI=new QextScintillaAPIs(); + connect (this,SIGNAL(cursorPositionChanged(int,int)),this,SLOT(positionChanged(int,int))); + this->SendScintilla(QextScintillaBase::SCI_AUTOCSETSEPARATOR,'!'); } toHighlightedText::~toHighlightedText() { ! if(complAPI) ! delete complAPI; ! } ! ! void toHighlightedText::positionChanged(int row, int col){ ! if (col>0 && this->text(row)[col-1]=='.'){ ! this->autoCompleteFromAPIs(); ! } ! } ! ! static QString UpperIdent(const QString &str){ ! if (str.length() > 0 && str[0] == '\"') ! return str; ! else ! return str.upper(); ! } ! ! void toHighlightedText::autoCompleteFromAPIs(){ ! complAPI->clear(); ! int curline, curcol; ! getCursorPosition (&curline, &curcol); ! ! QString line = text(curline); ! ! if (!isReadOnly() && curcol >= 0 && line[curcol-1] == '.'){ ! //if (!hasSelectedText()) ! // return ; ! if (toTool::globalConfig(CONF_CODE_COMPLETION, "Yes").isEmpty()) ! return ; ! ! toSQLParse::editorTokenizer tokens(this, curcol, curline); ! QString name = tokens.getToken(false); ! QString owner; ! if (name == ".") ! name = tokens.getToken(false); ! ! QString token = tokens.getToken(false); ! if (token == ".") ! owner = tokens.getToken(false); ! else{ ! QString cmp = UpperIdent(name); ! QString lastToken; ! while ((invalidToken(tokens.line(), tokens.offset() + token.length()) || UpperIdent(token) != cmp || lastToken == ".") && token != ";" && !token.isEmpty()){ ! lastToken = token; ! token = tokens.getToken(false); ! } ! ! if(token == ";" || token.isEmpty()){ ! tokens.setLine(curline); ! tokens.setOffset(curcol); ! token = tokens.getToken(); ! while ((invalidToken(tokens.line(), tokens.offset()) || UpperIdent(token) != cmp && lastToken != ".") && token != ";" && !token.isEmpty()) ! token = tokens.getToken(); ! lastToken = token; ! tokens.getToken(false); ! } ! if(token != ";" && !token.isEmpty()){ ! token = tokens.getToken(false); ! if (token != "TABLE" && token != "UPDATE" && token != "FROM" && token != "INTO" && (toIsIdent(token[0]) || token[0] == '\"')){ ! name = token; ! token = tokens.getToken(false); ! if (token == ".") ! owner = tokens.getToken(false); ! }else if (token == ")"){ ! return ; ! } ! } ! } ! if (!owner.isEmpty()){ ! name = owner + QString::fromLatin1(".") + name; ! } ! if (!name.isEmpty()){ ! try{ ! toConnection &conn = toCurrentConnection(this); ! toQDescList &desc = conn.columns(conn.realName(name, false)); ! for (toQDescList::iterator i = desc.begin();i != desc.end();i++){ ! QString t; ! int ind = (*i).Name.find("("); ! if (ind < 0) ! ind = (*i).Name.find("RETURNING") - 1; //it could be a function or procedure without parameters. -1 to remove the space ! if (ind >= 0) ! t = conn.quote((*i).Name.mid(0, ind)) + (*i).Name.mid(ind); ! else ! t = conn.quote((*i).Name); ! /*if (!(*i).Comment.isEmpty()){ ! t += QString::fromLatin1(" - "); ! t += (*i).Comment; ! } ! t+="!";*/ ! complAPI->add(t); ! } ! this->setAutoCompletionAPIs(complAPI); ! this->setCallTipsAPIs(complAPI); ! QextScintilla::autoCompleteFromAPIs(); ! }catch (...){} ! } ! } ! } ! ! bool toHighlightedText::invalidToken(int line, int col) ! { ! bool ident = true; ! if (line < 0){ ! line = 0; ! col = 0; ! } ! while (line < lines()){ ! QString cl = text(line); ! while (col < int(cl.length())){ ! QChar c = cl[col]; ! if (!toIsIdent(c)) ! ident = false; ! if (!ident && !c.isSpace()) ! return c == '.'; ! col++; ! } ! line++; ! col = 0; ! } ! return false; } Index: tohighlightedtext.h =================================================================== RCS file: /cvsroot/tora/tora/tohighlightedtext.h,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** tohighlightedtext.h 30 Dec 2005 21:43:53 -0000 1.42 --- tohighlightedtext.h 29 Jan 2006 15:26:42 -0000 1.43 *************** *** 44,47 **** --- 44,48 ---- #include <qextscintillalexer.h> + #include <qextscintillaapis.h> #include <list> *************** *** 230,233 **** --- 231,235 ---- */ std::map<int, QString> Errors; + QextScintillaAPIs* complAPI; protected: int debugMarker; *************** *** 343,346 **** --- 345,351 ---- void tableAtCursor(QString &owner, QString &table, bool highlight = false); + private: + bool invalidToken(int line, int col); + // ------------------ END OF API used by TOra classes ---------------------- *************** *** 354,357 **** --- 359,366 ---- void previousError(void); + virtual void autoCompleteFromAPIs(); + + void positionChanged(int row, int col); + private slots: void setStatusMessage(void); |