From 608058338bbf3492041928b9cab38b601b052a02 Mon Sep 17 00:00:00 2001 From: bieber Date: Fri, 11 Jun 2010 19:51:34 +0000 Subject: [PATCH] Theme Editor: Fixed bug in parser handling empty lines and made ParseTreeModel handle the new VIEWPORT element properly git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26792 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/codeeditor.cpp | 2 +- utils/themeeditor/codeeditor.h | 2 ++ utils/themeeditor/parsetreenode.cpp | 6 +++++- utils/themeeditor/skin_parser.c | 14 ++++++++++++-- utils/themeeditor/skindocument.cpp | 21 ++++++++++++++------- utils/themeeditor/skindocument.h | 2 -- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/utils/themeeditor/codeeditor.cpp b/utils/themeeditor/codeeditor.cpp index d4b46ac52..49f441057 100644 --- a/utils/themeeditor/codeeditor.cpp +++ b/utils/themeeditor/codeeditor.cpp @@ -132,7 +132,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) if(errors.contains(blockNumber + 1)) { painter.fillRect(QRect(0, top, lineNumberArea->width(), - fontMetrics().height()), Qt::red); + fontMetrics().height()), errorColor); } painter.setPen(Qt::black); painter.drawText(0, top, lineNumberArea->width(), diff --git a/utils/themeeditor/codeeditor.h b/utils/themeeditor/codeeditor.h index ec36d50c2..5df5b423d 100644 --- a/utils/themeeditor/codeeditor.h +++ b/utils/themeeditor/codeeditor.h @@ -61,6 +61,7 @@ public: int lineNumberAreaWidth(); void addError(int line){ errors.append(line); } void clearErrors(){ errors.clear(); } + void setErrorColor(QColor color){ errorColor = color; } protected: void resizeEvent(QResizeEvent *event); @@ -72,6 +73,7 @@ private slots: private: QWidget *lineNumberArea; QList errors; + QColor errorColor; }; //![codeeditordefinition] diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp index df4e770f9..d3a1a71c9 100644 --- a/utils/themeeditor/parsetreenode.cpp +++ b/utils/themeeditor/parsetreenode.cpp @@ -56,7 +56,6 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) } break; - case VIEWPORT: case CONDITIONAL: for(int i = 0; i < element->params_count; i++) children.append(new ParseTreeNode(&data->params[i], this)); @@ -71,6 +70,11 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) } break; +case VIEWPORT: + for(int i = 0; i < element->params_count; i++) + children.append(new ParseTreeNode(&data->params[i], this)); + /* Deliberate fall-through here */ + case LINE: for(int i = 0; i < data->children_count; i++) { diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c index e6a6350d1..bf7ca8d7f 100644 --- a/utils/themeeditor/skin_parser.c +++ b/utils/themeeditor/skin_parser.c @@ -249,9 +249,19 @@ static struct skin_element* skin_parse_line_optional(char** document, retval = skin_alloc_element(); retval->type = LINE; retval->line = skin_line; - if(*cursor != '\0') + if(*cursor != '\0' && *cursor != '\n' + && !(conditional && (*cursor == ARGLISTSEPERATESYM + || *cursor == ARGLISTCLOSESYM + || *cursor == ENUMLISTSEPERATESYM + || *cursor == ENUMLISTCLOSESYM))) + { retval->children_count = 1; - else retval->children_count = 0; + } + else + { + retval->children_count = 0; + } + if(retval->children_count > 0) retval->children = skin_alloc_children(1); diff --git a/utils/themeeditor/skindocument.cpp b/utils/themeeditor/skindocument.cpp index b67c70db6..8547aafa1 100644 --- a/utils/themeeditor/skindocument.cpp +++ b/utils/themeeditor/skindocument.cpp @@ -146,10 +146,8 @@ void SkinDocument::settingsChanged() palette.setColor(QPalette::All, QPalette::Text, fg); editor->setPalette(palette); - errorColor = QTextCharFormat(); QColor highlight = settings.value("errorColor", Qt::red).value(); - errorColor.setBackground(highlight); - errorColor.setProperty(QTextFormat::FullWidthSelection, true); + editor->setErrorColor(highlight); /* Setting the font */ QFont def("Monospace"); @@ -175,10 +173,19 @@ void SkinDocument::codeChanged() if(skin_error_line() > 0) { editor->addError(skin_error_line()); - } - else - { - editor->setExtraSelections(QList()); + + /* 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()); + if(skin_error_line() > 0) + { + QTextCursor rest(&doc); + + for(int i = 0; i < skin_error_line(); i++) + rest.movePosition(QTextCursor::NextBlock, + QTextCursor::KeepAnchor); + rest.clearSelection(); + }*/ } if(editor->document()->toPlainText() != saved) diff --git a/utils/themeeditor/skindocument.h b/utils/themeeditor/skindocument.h index e8bd27067..741359b7a 100644 --- a/utils/themeeditor/skindocument.h +++ b/utils/themeeditor/skindocument.h @@ -79,8 +79,6 @@ private: QString saved; QString parseStatus; - QTextCharFormat errorColor; - QLayout* layout; CodeEditor* editor; -- 2.11.4.GIT