Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/scripttools/debugging/qscriptcompletiontask.cpp

    r2 r561  
    22**
    33** 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])
    56**
    67** This file is part of the QtSCriptTools module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4545#include "qscriptdebuggerconsolecommand_p.h"
    4646#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"
    5351
    5452#include "private/qobject_p.h"
     
    6866
    6967    void completeScriptExpression();
     68
    7069
    7170    QString contents;
    7271    int cursorPosition;
    7372    int frameIndex;
    74     QScriptDebuggerFrontend *frontend;
     73    QScriptDebuggerCommandSchedulerInterface *commandScheduler;
     74    QScriptDebuggerJobSchedulerInterface *jobScheduler;
    7575    QScriptDebuggerConsole *console;
    7676};
    7777
    7878QScriptCompletionTaskPrivate::QScriptCompletionTaskPrivate()
     79
     80
    7981{
    8082}
     
    8486}
    8587
    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 }
     88class QScriptCompleteExpressionJob : public QScriptDebuggerCommandSchedulerJob
     89{
     90public:
     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
     110private:
     111    int m_frameIndex;
     112    QStringList m_path;
     113    QScriptCompletionTaskPrivate *m_task;
     114};
    108115
    109116namespace {
     
    122129
    123130} // 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
    124162
    125163void QScriptCompletionTaskPrivate::completeScriptExpression()
     
    128166    if ((pos > 0) && contents.at(pos-1).isNumber()) {
    129167        // completion of numbers is pointless
     168
    130169        return;
    131170    }
     
    133172    while ((pos > 0) && isIdentChar(contents.at(pos-1)))
    134173        --pos;
    135     int pos2 = cursorPosition;
     174    int pos2 = cursorPosition;
    136175    while ((pos2 < contents.size()-1) && isIdentChar(contents.at(pos2+1)))
    137176        ++pos2;
     
    149188    }
    150189
    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();
    217191    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
    218225}
    219226
     
    232239            // editing command --> get command completions
    233240            d->results = d->console->commandManager()->completions(prefix);
    234             qStableSort(d->results);
    235241            d->position = cmdRx.pos(1);
    236242            d->length = prefix.length();
     
    265271            QString argType = cmd->argumentTypes().value(argNum);
    266272            if (!argType.isEmpty()) {
    267                 if (argType == QString::fromLatin1("command-or-group-name")) {
     273                if (argType == Q("command-or-group-name")) {
    268274                    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")) {
    281282                    for (int i = 0; i < cmd->subCommands().size(); ++i) {
    282283                        QString name = cmd->subCommands().at(i);
     
    284285                            d->results.append(name);
    285286                    }
    286                 } else if (argType == QString::fromLatin1("script")) {
     287                    qStableSort(d->results);
     288                } else if (argType == QLatin1String("script")) {
    287289                    d->completeScriptExpression();
     290
     291
    288292                }
    289293                if ((d->type == NoCompletion) && !d->results.isEmpty()) {
    290                     qStableSort(d->results);
    291294                    d->position = pos;
    292295                    d->length = arg.length();
    293296                    d->type = CommandArgumentCompletion;
     297
    294298                }
    295299            }
    296             emit finished();
    297300        }
    298301    } else {
    299302        // assume it's an eval expression
    300303        d->completeScriptExpression();
    301         emit finished();
    302304    }
    303305}
Note: See TracChangeset for help on using the changeset viewer.