Added new NO_SELECTION constant to ListWindow, and use it to help set and reset default state.

This commit is contained in:
casey 2016-05-17 22:57:18 -07:00
parent 2d65ab480a
commit e8b9c873db
4 changed files with 21 additions and 6 deletions

View File

@ -40,10 +40,9 @@
using namespace musik::core;
MetadataValue::MetadataValue(const DBID newId, const char *value)
: id(newId)
{
if(value) {
this->value = value;
: id(newId) {
if (value) {
this->value = value;
}
}

View File

@ -35,7 +35,7 @@ void CategoryListView::Requery() {
DBID CategoryListView::GetSelectedId() {
size_t index = this->GetSelectedIndex();
if (this->metadata && index < this->metadata->size()) {
if (index != NO_SELECTION && this->metadata && index < this->metadata->size()) {
return this->metadata->at(index)->id;
}
return -1;

View File

@ -3,9 +3,11 @@
typedef IScrollAdapter::ScrollPosition ScrollPos;
size_t ListWindow::NO_SELECTION = (size_t) -1;
ListWindow::ListWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->selectedIndex = 0;
this->selectedIndex = (size_t) -1;
}
ListWindow::~ListWindow() {
@ -130,6 +132,18 @@ size_t ListWindow::GetSelectedIndex() {
void ListWindow::OnAdapterChanged() {
IScrollAdapter *adapter = &GetScrollAdapter();
size_t count = adapter->GetEntryCount();
/* update initial state... */
if (selectedIndex == NO_SELECTION) {
if (adapter->GetEntryCount()) {
this->SetSelectedIndex(0);
}
}
else if (count == 0) {
this->SetSelectedIndex(NO_SELECTION);
}
GetScrollAdapter().DrawPage(
this->GetContent(),
this->scrollPosition.firstVisibleEntryIndex,

View File

@ -7,6 +7,8 @@
class ListWindow : public ScrollableWindow {
public:
static size_t NO_SELECTION;
sigslot::signal3<ListWindow*, size_t, size_t> SelectionChanged;
ListWindow(IWindow *parent = NULL);