From 2db104f2e1a05c93e2204305188160c405c4eb1c Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 28 Dec 2008 21:13:04 +0100 Subject: [PATCH] do not attempt to get/select/whatever item from an empty menu --- src/menu.h | 5 ++++- src/ncmpcpp.cpp | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/menu.h b/src/menu.h index f2175de3..b41fc2a0 100644 --- a/src/menu.h +++ b/src/menu.h @@ -38,6 +38,7 @@ class List virtual ~List() { }; virtual void Select(int, bool) = 0; virtual void Static(int, bool) = 0; + virtual bool Empty() const = 0; virtual bool isSelected(int = -1) const = 0; virtual bool isStatic(int = -1) const = 0; virtual bool hasSelected() const = 0; @@ -108,7 +109,7 @@ template class Menu : public Window, public List void HighlightColor(Color col) { itsHighlightColor = col; } void Highlighting(bool hl) { highlightEnabled = hl; } - bool Empty() const { return itsOptions.empty(); } + virtual bool Empty() const { return itsOptions.empty(); } T &Back(); const T &Back() const; @@ -311,6 +312,8 @@ template void Menu::Refresh() template void Menu::Scroll(Where where) { + if (itsOptions.empty()) + return; int MaxHighlight = itsOptions.size()-1; int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight; int MaxCurrentHighlight = itsBeginning+itsHeight-1; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 093db039..2db65df5 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -487,10 +487,8 @@ int main(int argc, char *argv[]) sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (TagList::iterator it = list.begin(); it != list.end(); it++) { - if ((mLibArtists->Empty() || mLibArtists->Back() != *it) && !it->empty()) - { + if (!it->empty()) mLibArtists->AddOption(*it); - } } mLibArtists->Window::Clear(); mLibArtists->Refresh(); @@ -953,6 +951,9 @@ int main(int argc, char *argv[]) { ENTER_BROWSER_SCREEN: + if (mBrowser->Empty()) + continue; + const Item &item = mBrowser->Current(); switch (item.type) { @@ -1312,7 +1313,7 @@ int main(int argc, char *argv[]) SongList list; - if (wCurrent == mLibArtists) + if (!mLibArtists->Empty() && wCurrent == mLibArtists) { const string &tag = mLibArtists->Current(); Mpd->StartSearch(1); @@ -1421,7 +1422,7 @@ int main(int argc, char *argv[]) SongList list; - if (wCurrent == mPlaylistList) + if (wCurrent == mPlaylistList && !mPlaylistList->Empty()) { const string &playlist = mPlaylistList->Current(); Mpd->GetPlaylistContent(playlist, list); @@ -1698,6 +1699,8 @@ int main(int argc, char *argv[]) if (wCurrent == mPlaylist || wCurrent == mEditorTags || (wCurrent == mBrowser && ((Menu *)wCurrent)->Choice() >= (browsed_dir != "/" ? 1 : 0)) || (wCurrent == mSearcher && !mSearcher->Current().first) || wCurrent == mLibSongs || wCurrent == mPlaylistEditor) { List *mList = (Menu *)wCurrent; + if (mList->Empty()) + continue; size_t i = mList->Choice(); mList->Select(i, !mList->isSelected(i)); wCurrent->Scroll(wDown); @@ -1705,7 +1708,7 @@ int main(int argc, char *argv[]) } else { - if (current_screen == csBrowser) + if (current_screen == csBrowser && !mBrowser->Empty()) { const Item &item = mBrowser->Current(); switch (item.type)