mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 00:00:44 +01:00
[code] Search function in the code Toolbox.
When the user types a letter, the toolbox scrolls to the first row that begins with said letter (without considering if it is lower or upper case). If there is not such a row, the toolbox scrolls to the first row that has a letter higher than the typed letter. Change-Id: I353d23560d8a4d618d96426c393b024e7fb487af
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "toolbox.h"
|
||||
#include "../shared/toolbox_helpers.h"
|
||||
#include <assert.h>
|
||||
extern "C" {
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
}
|
||||
|
||||
namespace Code {
|
||||
|
||||
@@ -211,6 +214,17 @@ void Toolbox::setAction(Action action) {
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
bool Toolbox::handleEvent(Ion::Events::Event event) {
|
||||
if (::Toolbox::handleEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
if (event.hasText() && strlen(event.text()) == 1) {
|
||||
scrollToLetter(event.text()[0]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
KDCoordinate Toolbox::rowHeight(int j) {
|
||||
if (typeAtLocation(0, j) == ::Toolbox::LeafCellType) {
|
||||
if (m_messageTreeModel->label() != I18n::Message::IfStatementMenu) {
|
||||
@@ -260,5 +274,34 @@ int Toolbox::maxNumberOfDisplayedRows() {
|
||||
return k_maxNumberOfDisplayedRows;
|
||||
}
|
||||
|
||||
void Toolbox::scrollToLetter(char letter) {
|
||||
char lowerLetter = tolower(letter);
|
||||
// We look for a child MessageTree that starts with the wanted letter.
|
||||
for (int i = 0; i < m_messageTreeModel->numberOfChildren(); i++) {
|
||||
char currentFirstLetterLowered = tolower(I18n::translate(m_messageTreeModel->children(i)->label())[0]);
|
||||
if (currentFirstLetterLowered == lowerLetter) {
|
||||
scrollToAndSelectChild(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// We did not find a child MessageTree that starts with the wanted letter.
|
||||
// We scroll to the first child MessageTree that starts with a letter higher
|
||||
// than the wanted letter.
|
||||
for (int i = 0; i < m_messageTreeModel->numberOfChildren(); i++) {
|
||||
char currentFirstLetterLowered = tolower(I18n::translate(m_messageTreeModel->children(i)->label())[0]);
|
||||
if (currentFirstLetterLowered >= lowerLetter && currentFirstLetterLowered <= 'z') {
|
||||
scrollToAndSelectChild(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbox::scrollToAndSelectChild(int i) {
|
||||
assert(i >=0 && i<m_messageTreeModel->numberOfChildren());
|
||||
m_selectableTableView.deselectTable();
|
||||
m_selectableTableView.scrollToCell(0, i);
|
||||
m_selectableTableView.selectCellAtLocation(0, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user