Пример #1
0
int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
    QTextBlock block = cursor.block();
    const QString text = block.text().trimmed();
    if (text == "end"
            || text == "else"
            || text.startsWith("elsif")
            || text.startsWith("rescue")
            || text == "ensure") {
        Indenter indenter(const_cast<QTextDocument*>(block.document()));
        indenter.indentBlock(block, QChar(), tabSettings());
    }

    return 0;
    // This implementation is buggy
#if 0
    const QString textFromCursor = text.mid(cursor.positionInBlock()).trimmed();
    if (!textFromCursor.isEmpty())
        return 0;

    if (Language::symbolDefinition.indexIn(text) == -1
            && Language::startOfBlock.indexIn(text) == -1) {
        return 0;
    }

    int spaces = 0;
    for (const QChar c : text) {
        if (!c.isSpace())
            break;
        spaces++;
    }
    QString indent = text.left(spaces);

    QString line;
    QTextBlock nextBlock = block.next();
    while (nextBlock.isValid()) {
        line = nextBlock.text();
        if (Language::endKeyword.indexIn(line) != -1 && line.startsWith(indent))
            return 0;
        if (!line.trimmed().isEmpty())
            break;
        nextBlock = nextBlock.next();
    }

    int pos = cursor.position();
    cursor.insertBlock();
    cursor.insertText("end");
    cursor.setPosition(pos);

    return 1;
#endif
}
QWidget *NimCodeStyleSettingsPage::widget()
{
    if (!m_widget) {
        auto originalTabPreferences = qobject_cast<SimpleCodeStylePreferences *>(NimSettings::globalCodeStyle());
        m_nimCodeStylePreferences = new SimpleCodeStylePreferences(m_widget);
        m_nimCodeStylePreferences->setDelegatingPool(originalTabPreferences->delegatingPool());
        m_nimCodeStylePreferences->setTabSettings(originalTabPreferences->tabSettings());
        m_nimCodeStylePreferences->setCurrentDelegate(originalTabPreferences->currentDelegate());
        m_nimCodeStylePreferences->setId(originalTabPreferences->id());
        auto factory = TextEditorSettings::codeStyleFactory(Nim::Constants::C_NIMLANGUAGE_ID);
        m_widget = new CodeStyleEditor(factory, m_nimCodeStylePreferences);
    }
    return m_widget;
}
Пример #3
0
void TabSettingsWidget::slotSettingsChanged()
{
    emit settingsChanged(tabSettings());
}
Пример #4
0
void PlainTextDocument::updateTabSettings()
{
    if (Highlighter *highlighter = qobject_cast<Highlighter *>(syntaxHighlighter()))
        highlighter->setTabSettings(tabSettings());
}