Ejemplo n.º 1
0
void SkinDocument::codeChanged()
{
    if(blockUpdate)
        return;

    if(editor->document()->isEmpty())
    {
        parseStatus = tr("Empty document");
        statusLabel->setText(parseStatus);
        return;
    }

    editor->clearErrors();
    parseStatus = model->changeTree(editor->document()->
                                    toPlainText().toAscii());
    if(skin_error_line() > 0)
        parseStatus = tr("Errors in document");
    statusLabel->setText(parseStatus);

    /* Highlighting if an error was found */
    if(skin_error_line() > 0)
    {
        editor->addError(skin_error_line());

        /* Now we're going to attempt parsing again at each line, until we find
           one that won't error out*/
        QTextDocument doc(editor->document()->toPlainText());
        int base = 0;
        while(skin_error_line() > 0 && !doc.isEmpty())
        {
            QTextCursor rest(&doc);

            for(int i = 0; i < skin_error_line(); i++)
                rest.movePosition(QTextCursor::NextBlock,
                                  QTextCursor::KeepAnchor);
            if(skin_error_line() == doc.blockCount())
                rest.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);

            rest.removeSelectedText();
            base += skin_error_line();

            skin_parse(doc.toPlainText().toAscii());

            if(skin_error_line() > 0)
                editor->addError(base + skin_error_line());

        }
    }

    if(editor->document()->toPlainText() != saved)
        emit titleChanged(titleText + QChar('*'));
    else
        emit titleChanged(titleText);

    model->render(project, &fileName);

    cursorChanged();

}
Ejemplo n.º 2
0
void SkinDocument::cursorChanged()
{
    if(editor->isError(editor->textCursor().blockNumber() + 1))
    {
        QTextCursor line = editor->textCursor();
        line.movePosition(QTextCursor::StartOfLine);
        line.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
        skin_parse(line.selectedText().toAscii());
        if(skin_error_line() > 0)
            parseStatus = tr("Error on line ") +
                          QString::number(line.blockNumber() + 1) + tr(": ") +
                          skin_error_message();
        statusLabel->setText(parseStatus);
    }
    else if(editor->hasErrors())
    {
        parseStatus = tr("Errors in document");
        statusLabel->setText(parseStatus);
    }
    else
    {
        emit lineChanged(editor->textCursor().blockNumber() + 1);
    }

}
Ejemplo n.º 3
0
QString ParseTreeModel::changeTree(const char *document)
{
    struct skin_element* test = skin_parse(document);

    if(!test)
    {
        QString error = tr("Error on line ") +
                        QString::number(skin_error_line())
                        + tr(", column ") + QString::number(skin_error_col())
                        + tr(": ") + QString(skin_error_message());
        return error;
    }

    ParseTreeNode* temp = new ParseTreeNode(test, this);

    if(root)
    {
        emit beginRemoveRows(QModelIndex(), 0, root->numChildren() - 1);
        delete root;
        emit endRemoveRows();
    }

    root = temp;

    emit beginInsertRows(QModelIndex(), 0, temp->numChildren() - 1);
    emit endInsertRows();

    return tr("Document Parses Successfully");

}