2
// C++ Implementation: jscodecompletion
7
// Author: ian reinhart geiser <geiseri@kde.org>, (C) 2004
9
// Copyright: See COPYING file that comes with this distribution
12
#include "jscodecompletion.h"
13
#include <qwhatsthis.h>
15
#include <qfileinfo.h>
16
#include <qstringlist.h>
17
#include <qtextstream.h>
19
#include <kapplication.h>
22
#include <kiconloader.h>
27
#include <kparts/part.h>
28
#include <kdialogbase.h>
31
#include <kdevelop/kdevcore.h>
32
#include <kdevelop/kdevmainwindow.h>
33
#include <kdevelop/kdevlanguagesupport.h>
34
#include <kdevelop/kdevpartcontroller.h>
35
#include <kdevelop/kdevproject.h>
36
#include <kdevelop/kdevappfrontend.h>
37
#include <kdevelop/domutil.h>
38
#include <kdevelop/codemodel.h>
40
JSCodeCompletion::JSCodeCompletion(QObject *parent, const char *name)
41
: QObject(parent, name)
43
m_argWidgetShow = false;
44
m_completionBoxShow=false;
48
JSCodeCompletion::~JSCodeCompletion()
51
void JSCodeCompletion::setActiveEditorPart( KParts::Part * part )
53
if (!part || !part->widget())
56
kdDebug() << "JSCodeCompletion::setActiveEditorPart" << endl;
58
// We need to think about this
59
// if(!(m_config->getCodeCompletion() || m_config->getCodeHinting())){
63
m_editInterface = dynamic_cast<KTextEditor::EditInterface*>(part);
66
kdDebug() << "editor doesn't support the EditDocumentIface" << endl;
70
m_cursorInterface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget());
71
if (!m_cursorInterface)
73
kdDebug() << "editor does not support the ViewCursorInterface" << endl;
77
m_codeInterface = dynamic_cast<KTextEditor::CodeCompletionInterface*>(part->widget());
79
{ // no CodeCompletionDocument available
80
kdDebug() << "editor doesn't support the CodeCompletionDocumentIface" << endl;
84
disconnect(part->widget(), 0, this, 0 ); // to make sure that it is't connected twice
85
connect(part->widget(), SIGNAL(cursorPositionChanged()),
86
this, SLOT(cursorPositionChanged()));
87
connect(part->widget(), SIGNAL(argHintHidden()), this, SLOT(argHintHidden()));
88
connect(part->widget(), SIGNAL(completionAborted()), this, SLOT(completionBoxAbort()));
89
connect(part->widget(), SIGNAL(completionDone()), this, SLOT(completionBoxHidden()));
92
QValueList< KTextEditor::CompletionEntry > JSCodeCompletion::getVars( const QString & startText )
94
kdDebug() << "getVars for " << startText << endl;
95
QValueList<KTextEditor::CompletionEntry> varList;
97
QValueList<QString>::ConstIterator it;
98
for (it = m_vars.begin(); it != m_vars.end(); ++it)
100
QString var = "$" + (*it);
101
kdDebug() << "Compair " << var << endl;
102
if( var.startsWith( startText ))
104
KTextEditor::CompletionEntry e;
108
kdDebug() << "getVar: " << var << endl;
116
void JSCodeCompletion::cursorPositionChanged( )
119
m_cursorInterface->cursorPositionReal(&line, &col);
120
kdDebug() << "JSCodeCompletion::cursorPositionChanged:" << line << ":" << col << endl;
122
QString lineStr = m_editInterface->textLine(line);
123
if(lineStr.isNull() || lineStr.isEmpty())
125
kdDebug() << "No Text..." << endl;
126
return; // nothing to do
128
// if(m_config->getCodeCompletion())
130
QString restLine = lineStr.mid(col);
131
QString prevText = lineStr.mid(0,col);
133
if(restLine.left(1) != " " && restLine.left(1) != "\t" && !restLine.isNull())
135
kdDebug() << "no codecompletion because no empty character after cursor:" << restLine << ":" << endl;
139
QRegExp prevReg("([\\d\\w]*)[.]$");
141
if (prevReg.search( prevText ) != -1 )
143
// We are in completion mode
144
QString startMatch = prevReg.cap(0);
145
kdDebug() << "Matching: " << startMatch << endl;
146
m_completionBoxShow=true;
147
m_codeInterface->showCompletionBox(getVars(startMatch),2);
151
kdDebug() << "no vars in: " << prevText << endl;
160
void JSCodeCompletion::completionBoxHidden( )
162
kdDebug() << "Complete..." << endl;
163
m_completionBoxShow=false;
166
void JSCodeCompletion::completionBoxAbort( )
168
kdDebug() << "aborted..." << endl;
169
m_completionBoxShow=false;
174
#include "jscodecompletion.moc"