1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 11:46:14 +02:00

Make Selector robust against an empty file list

This can happen on a directory with 0 file matches when directories are
not being shown (otherwise there is either ".." or a subdir).

Since there is nothing to be selected, the Accept button is disabled
and no cursor is shown.
This commit is contained in:
Maarten ter Huurne 2014-08-16 15:50:16 +02:00
parent 3cce71284a
commit dc39fcc01f

View File

@ -61,7 +61,9 @@ int Selector::exec(int startSelection) {
writeSubTitle(bg, link.getDescription());
int x = 5;
if (fl.size() != 0) {
x = gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], x);
}
if (showDirectories) {
x = gmenu2x->drawButton(bg, "left", "", x);
x = gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], x);
@ -96,6 +98,10 @@ int Selector::exec(int startSelection) {
bg.blit(s, 0, 0);
if (fl.size() == 0) {
gmenu2x->font->write(s, "(no items)", 4, top + lineHeight / 2,
Font::HAlignLeft, Font::VAlignMiddle);
} else {
if (selected >= firstElement + nb_elements)
firstElement = selected - nb_elements + 1;
if (selected < firstElement)
@ -137,6 +143,7 @@ int Selector::exec(int startSelection) {
}
}
s.clearClipRect();
}
gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement);
s.flip();
@ -194,6 +201,7 @@ int Selector::exec(int startSelection) {
break;
case InputManager::ACCEPT:
if (fl.size() != 0) {
if (fl.isFile(selected)) {
file = fl[selected];
close = true;
@ -207,6 +215,7 @@ int Selector::exec(int startSelection) {
firstElement = 0;
prepare(fl);
}
}
break;
default: