Пример #1
0
// Add auto-completion words for a particular word (defined by where it appears
// in the APIs) and depending on whether the word was complete (when it's
// actually the next word in the API entry that is of interest) or not.
void QsciAPIs::addAPIEntries(const WordIndexList &wl, bool complete,
        QStringList &with_context, bool &unambig)
{
    QStringList wseps = lexer()->autoCompletionWordSeparators();

    for (int w = 0; w < wl.count(); ++w)
    {
        const WordIndex &wi = wl[w];

        QStringList api_words = prep->apiWords(wi.first, wseps, false);

        int idx = wi.second;

        if (complete)
        {
            // Skip if this is the last word.
            if (++idx >= api_words.count())
                continue;
        }

        QString api_word;

        if (idx == 0)
            api_word = api_words[0] + ' ';
        else
        {
            QStringList orgl;
    
            for (int i = 0; i < idx; ++i)
                orgl.append(api_words[i]);

            QString org = orgl.join(wseps.first());

            api_word = QString("%1 (%2)").arg(api_words[idx]).arg(org);

            // See if the origin has been used before.
            if (unambig)
                if (unambiguous_context.isEmpty())
                    unambiguous_context = org;
                else if (unambiguous_context != org)
                {
                    unambiguous_context.truncate(0);
                    unambig = false;
                }
        }

        if (!with_context.contains(api_word))
            with_context.append(api_word);
    }
}
Пример #2
0
// Add auto-completion words for a particular word (defined by where it appears
// in the APIs) and depending on whether the word was complete (when it's
// actually the next word in the API entry that is of interest) or not.
void QsciAPIs::addAPIEntries(const WordIndexList &wl, bool complete,
        QStringList &with_context, bool &unambig)
{
    QStringList wseps = lexer()->autoCompletionWordSeparators();

    for (int w = 0; w < wl.count(); ++w)
    {
        const WordIndex &wi = wl[w];

        QStringList api_words = prep->apiWords(wi.first, wseps, false);

        int idx = wi.second;

        if (complete)
        {
            // Skip if this is the last word.
            if (++idx >= api_words.count())
                continue;
        }

        QString api_word, org;

        if (idx == 0)
        {
            api_word = api_words[0] + ' ';
            org = QString::fromLatin1("");
        }
        else
        {
            QStringList orgl = api_words.mid(0, idx);
            org = orgl.join(wseps.first());

            // Add the context (allowing for a possible image identifier).
            QString w = api_words[idx];
            QString type;
            int type_idx = w.indexOf(QLatin1String("?"));

            if (type_idx >= 0)
            {
                type = w.mid(type_idx);
                w.truncate(type_idx);
            }

            api_word = QString("%1 (%2)%3").arg(w).arg(org).arg(type);
        }

        // If the origin is different to the context then the context is
        // ambiguous.
        if (unambig)
        {
            if (unambiguous_context.isNull())
            {
                unambiguous_context = org;
            }
            else if (unambiguous_context != org)
            {
                unambiguous_context.truncate(0);
                unambig = false;
            }
        }

        if (!with_context.contains(api_word))
            with_context.append(api_word);
    }
}