Changeset 561 for trunk/src/scripttools/debugging/qscriptcompletiontask.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/scripttools/debugging/qscriptcompletiontask.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtSCriptTools module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 45 45 #include "qscriptdebuggerconsolecommand_p.h" 46 46 #include "qscriptdebuggerconsolecommandmanager_p.h" 47 48 #include "qscriptenginedebuggerfrontend_p.h" // ### kill 49 #include "qscriptdebuggerbackend_p.h" // ### kill 50 #include <QtScript/qscriptcontext.h> 51 #include <QtScript/qscriptvalue.h> 52 #include <QtScript/qscriptvalueiterator.h> 47 #include "qscriptdebuggercommandschedulerjob_p.h" 48 #include "qscriptdebuggercommandschedulerfrontend_p.h" 49 #include "qscriptdebuggerjobschedulerinterface_p.h" 50 #include "qscriptdebuggerresponse_p.h" 53 51 54 52 #include "private/qobject_p.h" … … 68 66 69 67 void completeScriptExpression(); 68 70 69 71 70 QString contents; 72 71 int cursorPosition; 73 72 int frameIndex; 74 QScriptDebuggerFrontend *frontend; 73 QScriptDebuggerCommandSchedulerInterface *commandScheduler; 74 QScriptDebuggerJobSchedulerInterface *jobScheduler; 75 75 QScriptDebuggerConsole *console; 76 76 }; 77 77 78 78 QScriptCompletionTaskPrivate::QScriptCompletionTaskPrivate() 79 80 79 81 { 80 82 } … … 84 86 } 85 87 86 QScriptCompletionTask::QScriptCompletionTask( 87 const QString &contents, int cursorPosition, 88 int frameIndex, QScriptDebuggerFrontend *frontend, 89 QScriptDebuggerConsole *console, 90 QObject *parent) 91 : QScriptCompletionTaskInterface( 92 *new QScriptCompletionTaskPrivate, parent) 93 { 94 Q_D(QScriptCompletionTask); 95 d->contents = contents; 96 d->cursorPosition = cursorPosition; 97 if ((frameIndex == -1) && console) 98 d->frameIndex = console->currentFrameIndex(); 99 else 100 d->frameIndex = frameIndex; 101 d->frontend = frontend; 102 d->console = console; 103 } 104 105 QScriptCompletionTask::~QScriptCompletionTask() 106 { 107 } 88 class QScriptCompleteExpressionJob : public QScriptDebuggerCommandSchedulerJob 89 { 90 public: 91 QScriptCompleteExpressionJob(int frameIndex, const QStringList &path, 92 QScriptCompletionTaskPrivate *task, 93 QScriptDebuggerCommandSchedulerInterface *scheduler) 94 : QScriptDebuggerCommandSchedulerJob(scheduler), 95 m_frameIndex(frameIndex), m_path(path), m_task(task) 96 {} 97 98 void start() 99 { 100 QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); 101 frontend.scheduleGetCompletions(m_frameIndex, m_path); 102 } 103 void handleResponse(const QScriptDebuggerResponse &response, int /*commandId*/) 104 { 105 m_task->results = response.result().toStringList(); 106 m_task->emitFinished(); 107 finish(); 108 } 109 110 private: 111 int m_frameIndex; 112 QStringList m_path; 113 QScriptCompletionTaskPrivate *m_task; 114 }; 108 115 109 116 namespace { … … 122 129 123 130 } // namespace 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 124 162 125 163 void QScriptCompletionTaskPrivate::completeScriptExpression() … … 128 166 if ((pos > 0) && contents.at(pos-1).isNumber()) { 129 167 // completion of numbers is pointless 168 130 169 return; 131 170 } … … 133 172 while ((pos > 0) && isIdentChar(contents.at(pos-1))) 134 173 --pos; 135 int pos2 = cursorPosition ;174 int pos2 = cursorPosition; 136 175 while ((pos2 < contents.size()-1) && isIdentChar(contents.at(pos2+1))) 137 176 ++pos2; … … 149 188 } 150 189 151 // ### super-cheating for now; have to use the async API 152 QScriptEngineDebuggerFrontend *edf = static_cast<QScriptEngineDebuggerFrontend*>(frontend); 153 QScriptDebuggerBackend *backend = edf->backend(); 154 QScriptContext *ctx = backend->context(frameIndex); 155 QScriptValueList objects; 156 QString prefix = path.last(); 157 QSet<QString> matches; 158 if (path.size() > 1) { 159 const QString &topLevelIdent = path.at(0); 160 QScriptValue obj; 161 if (topLevelIdent == QString::fromLatin1("this")) { 162 obj = ctx->thisObject(); 163 } else { 164 QScriptValueList scopeChain; 165 #if QT_VERSION >= 0x040500 166 scopeChain = ctx->scopeChain(); 167 #else 168 scopeChain.append(ctx->activationObject()); 169 #endif 170 for (int i = 0; i < scopeChain.size(); ++i) { 171 QScriptValue oo = scopeChain.at(i).property(topLevelIdent); 172 if (oo.isObject()) { 173 obj = oo; 174 break; 175 } 176 } 177 } 178 for (int i = 1; obj.isObject() && (i < path.size()-1); ++i) 179 obj = obj.property(path.at(i)); 180 if (obj.isValid()) 181 objects.append(obj); 182 } else { 183 #if QT_VERSION >= 0x040500 184 objects << ctx->scopeChain(); 185 #else 186 objects.append(ctx->activationObject()); 187 #endif 188 QStringList keywords; 189 keywords.append(QString::fromLatin1("this")); 190 keywords.append(QString::fromLatin1("true")); 191 keywords.append(QString::fromLatin1("false")); 192 keywords.append(QString::fromLatin1("null")); 193 for (int i = 0; i < keywords.size(); ++i) { 194 const QString &kwd = keywords.at(i); 195 if (isPrefixOf(prefix, kwd)) 196 matches.insert(kwd); 197 } 198 } 199 200 for (int i = 0; i < objects.size(); ++i) { 201 QScriptValue obj = objects.at(i); 202 while (obj.isObject()) { 203 QScriptValueIterator it(obj); 204 while (it.hasNext()) { 205 it.next(); 206 QString propertyName = it.name(); 207 if (isPrefixOf(prefix, propertyName)) 208 matches.insert(propertyName); 209 } 210 obj = obj.prototype(); 211 } 212 } 213 results = matches.toList(); 214 qStableSort(results); 215 216 length = prefix.length(); 190 length = path.last().length(); 217 191 type = QScriptCompletionTask::ScriptIdentifierCompletion; 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 218 225 } 219 226 … … 232 239 // editing command --> get command completions 233 240 d->results = d->console->commandManager()->completions(prefix); 234 qStableSort(d->results);235 241 d->position = cmdRx.pos(1); 236 242 d->length = prefix.length(); … … 265 271 QString argType = cmd->argumentTypes().value(argNum); 266 272 if (!argType.isEmpty()) { 267 if (argType == Q String::fromLatin1("command-or-group-name")) {273 if (argType == Q("command-or-group-name")) { 268 274 d->results = d->console->commandManager()->completions(arg); 269 } else if (argType == QString::fromLatin1("script-filename")) { 270 // ### super-cheating for now; have to use the async API 271 QScriptEngineDebuggerFrontend *edf = static_cast<QScriptEngineDebuggerFrontend*>(d->frontend); 272 QScriptDebuggerBackend *backend = edf->backend(); 273 QScriptScriptMap scripts = backend->scripts(); 274 QScriptScriptMap::const_iterator it; 275 for (it = scripts.constBegin(); it != scripts.constEnd(); ++it) { 276 QString fileName = it.value().fileName(); 277 if (isPrefixOf(arg, fileName)) 278 d->results.append(fileName); 279 } 280 } else if (argType == QString::fromLatin1("subcommand-name")) { 275 } else if (argType == QLatin1String("script-filename")) { 276 d->position = pos; 277 d->length = arg.length(); 278 d->type = CommandArgumentCompletion; 279 QScriptDebuggerJob *job = new QScriptCompleteScriptsJob(arg, d, d->commandScheduler); 280 d->jobScheduler->scheduleJob(job); 281 } else if (argType == QLatin1String("subcommand-name")) { 281 282 for (int i = 0; i < cmd->subCommands().size(); ++i) { 282 283 QString name = cmd->subCommands().at(i); … … 284 285 d->results.append(name); 285 286 } 286 } else if (argType == QString::fromLatin1("script")) { 287 qStableSort(d->results); 288 } else if (argType == QLatin1String("script")) { 287 289 d->completeScriptExpression(); 290 291 288 292 } 289 293 if ((d->type == NoCompletion) && !d->results.isEmpty()) { 290 qStableSort(d->results);291 294 d->position = pos; 292 295 d->length = arg.length(); 293 296 d->type = CommandArgumentCompletion; 297 294 298 } 295 299 } 296 emit finished();297 300 } 298 301 } else { 299 302 // assume it's an eval expression 300 303 d->completeScriptExpression(); 301 emit finished();302 304 } 303 305 }
Note:
See TracChangeset
for help on using the changeset viewer.