mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
f8dd370ff8
commit
ba41fa537a
8 changed files with 174 additions and 27 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue