diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-07-30 08:38:38 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-30 08:38:38 +0000 |
| commit | ba41fa537a432210147586b1442ab67b6d400d18 (patch) | |
| tree | d65b1bb4e7d20de518b40db98fb4399f419d36be /utils/themeeditor/gui/codeeditor.cpp | |
| parent | f8dd370ff8ece4d32589767dc4a9b43398c1cf7e (diff) | |
| download | rockbox-ba41fa537a432210147586b1442ab67b6d400d18.zip rockbox-ba41fa537a432210147586b1442ab67b6d400d18.tar.gz rockbox-ba41fa537a432210147586b1442ab67b6d400d18.tar.bz2 rockbox-ba41fa537a432210147586b1442ab67b6d400d18.tar.xz | |
Theme Editor: Made auto-complete functional and enabled it by default. Added a small subset of the available tags to the tagdb file, filling it out is todo
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27625 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to '')
| -rw-r--r-- | utils/themeeditor/gui/codeeditor.cpp | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/utils/themeeditor/gui/codeeditor.cpp b/utils/themeeditor/gui/codeeditor.cpp index 44f331d..3858460 100644 --- a/utils/themeeditor/gui/codeeditor.cpp +++ b/utils/themeeditor/gui/codeeditor.cpp @@ -107,6 +107,11 @@ void CodeEditor::cursorMoved() /* Closing the completer if the cursor has moved out of its bounds */ if(completer.isVisible()) { + if(document()->toPlainText().length() > docLength) + tagEnd++; + else if(document()->toPlainText().length() < docLength) + tagEnd--; + if(textCursor().position() < tagBegin || textCursor().position() > tagEnd) { @@ -115,6 +120,24 @@ void CodeEditor::cursorMoved() } } +void CodeEditor::insertTag() +{ + /* Clearing the typed tag and inserting one from the completer */ + QTextCursor at(document()); + at.setPosition(tagBegin, QTextCursor::MoveAnchor); + while(document()->characterAt(at.position()) == QChar('%') + || document()->characterAt(at.position()) == '?') + at.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 1); + + at.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, + tagEnd - at.position()); + at.removeSelectedText(); + + at.insertText(completer.currentItem()->text(0)); + + completer.hide(); +} + //![resizeEvent] void CodeEditor::resizeEvent(QResizeEvent *e) @@ -131,7 +154,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e) void CodeEditor::keyPressEvent(QKeyEvent *event) { - if(!settings.value("completeSyntax", false).toBool()) + if(!settings.value("completeSyntax", true).toBool()) { QPlainTextEdit::keyPressEvent(event); return; @@ -154,10 +177,22 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) < completer.topLevelItemCount() - 1) QApplication::sendEvent(&completer, event); } - else if(event->key() == Qt::Key_Backspace) + else if(event->key() == Qt::Key_Backspace + || event->key() == Qt::Key_Delete) { - tagEnd--; + docLength = document()->toPlainText().length(); QPlainTextEdit::keyPressEvent(event); + + QString filterText; + + for(int i = tagBegin; i < tagEnd; i++) + { + QChar c = document()->characterAt(i); + if(c != '%' && c != '?') + filterText.append(c); + } + + completer.filter(filterText); } else if(event->key() == Qt::Key_Escape) { @@ -165,14 +200,15 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) completer.hide(); QPlainTextEdit::keyPressEvent(event); } - else if(event->key() == Qt::Key_Enter) + else if(event->key() == Qt::Key_Return) { /* The enter key inserts the currently selected tag */ + insertTag(); } else if(event->key() == Qt::Key_Question) { /* The question mark doesn't filter the list */ - tagEnd++; + docLength = document()->toPlainText().length(); QPlainTextEdit::keyPressEvent(event); } else if(event->key() == Qt::Key_Left @@ -184,10 +220,19 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) else { /* Otherwise, we have to filter the list */ - tagEnd++; + docLength = document()->toPlainText().length(); QPlainTextEdit::keyPressEvent(event); - QString filterText = ""; + QString filterText; + + for(int i = tagBegin; i < tagEnd; i++) + { + QChar c = document()->characterAt(i); + if(c != '%' && c != '?') + filterText.append(c); + } + + completer.filter(filterText); } } else |