From 13d8b3b6c4b1f6e6d12a04ef631e310b12c69ec1 Mon Sep 17 00:00:00 2001 From: casey langen Date: Wed, 21 Oct 2020 11:36:21 -0700 Subject: [PATCH] CategoryListView widgets can now requery themselves automatically using visibility events, instead of relying on their parent. This fixes bugs related to "JumpTo". --- src/musikcube/app/layout/BrowseLayout.cpp | 11 ++--------- src/musikcube/app/layout/BrowseLayout.h | 1 - src/musikcube/app/overlay/PlayQueueOverlays.cpp | 10 ++++++---- src/musikcube/app/window/CategoryListView.cpp | 8 ++++++++ src/musikcube/app/window/CategoryListView.h | 2 ++ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/musikcube/app/layout/BrowseLayout.cpp b/src/musikcube/app/layout/BrowseLayout.cpp index 6f6396665..c3a04a5f5 100755 --- a/src/musikcube/app/layout/BrowseLayout.cpp +++ b/src/musikcube/app/layout/BrowseLayout.cpp @@ -228,15 +228,6 @@ void BrowseLayout::ScrollTo(const std::string& fieldType, int64_t fieldId) { this->categoryList->SetFrameTitle(getTitleForCategory(fieldType)); } -void BrowseLayout::OnVisibilityChanged(bool visible) { - LayoutBase::OnVisibilityChanged(visible); - - if (visible) { - this->categoryList->Requery( - this->categoryList->GetSelectedId()); - } -} - void BrowseLayout::OnIndexerProgress(int count) { this->Post(message::IndexerProgress); } @@ -370,6 +361,7 @@ bool BrowseLayout::ProcessPlaylistOperation(const std::string& key) { this->categoryList->Requery(this->categoryList->GetFilter(), id); }); } + return true; } else if (Hotkeys::Is(Hotkeys::BrowsePlaylistsDelete, key)) { if (this->GetFocus() == this->categoryList) { @@ -382,6 +374,7 @@ bool BrowseLayout::ProcessPlaylistOperation(const std::string& key) { }); } } + return true; } } diff --git a/src/musikcube/app/layout/BrowseLayout.h b/src/musikcube/app/layout/BrowseLayout.h index f96fc29e4..f042edcd9 100755 --- a/src/musikcube/app/layout/BrowseLayout.h +++ b/src/musikcube/app/layout/BrowseLayout.h @@ -58,7 +58,6 @@ namespace musik { virtual ~BrowseLayout(); - virtual void OnVisibilityChanged(bool visible) override; virtual bool KeyPress(const std::string& key) override; virtual void ProcessMessage(musik::core::runtime::IMessage &message) override; diff --git a/src/musikcube/app/overlay/PlayQueueOverlays.cpp b/src/musikcube/app/overlay/PlayQueueOverlays.cpp index 45d48fca1..6d992f61c 100644 --- a/src/musikcube/app/overlay/PlayQueueOverlays.cpp +++ b/src/musikcube/app/overlay/PlayQueueOverlays.cpp @@ -334,8 +334,8 @@ static void handleJumpTo( IMessageQueue& messageQueue, TrackPtr track) { - int64_t type; - int64_t id; + int64_t type = -1LL; + int64_t id = -1LL; if (index == 0) { type = cube::message::category::Album; @@ -350,8 +350,10 @@ static void handleJumpTo( id = track->GetInt64(library::constants::Track::GENRE_ID); } - messageQueue.Broadcast(runtime::Message::Create( - nullptr, cube::message::JumpToCategory, type, id)); + if (type != -1LL && id != -1LL) { + messageQueue.Broadcast(runtime::Message::Create( + nullptr, cube::message::JumpToCategory, type, id)); + } } static void showAddCategorySelectionToPlaylistOverlay( diff --git a/src/musikcube/app/window/CategoryListView.cpp b/src/musikcube/app/window/CategoryListView.cpp index 19abec976..e314ec8b6 100755 --- a/src/musikcube/app/window/CategoryListView.cpp +++ b/src/musikcube/app/window/CategoryListView.cpp @@ -92,6 +92,14 @@ CategoryListView::~CategoryListView() { delete adapter; } +void CategoryListView::OnVisibilityChanged(bool visible) { + ListWindow::OnVisibilityChanged(visible); + + if (visible && !this->activeQuery) { + this->Requery(this->GetSelectedId()); + } +} + void CategoryListView::RequeryWithField( const std::string& fieldName, const std::string& filter, diff --git a/src/musikcube/app/window/CategoryListView.h b/src/musikcube/app/window/CategoryListView.h index e2ac276e7..ff31e75a6 100755 --- a/src/musikcube/app/window/CategoryListView.h +++ b/src/musikcube/app/window/CategoryListView.h @@ -83,6 +83,8 @@ namespace musik { std::string GetFieldName(); void SetFieldName(const std::string& fieldName); + virtual void OnVisibilityChanged(bool visible) override; + protected: virtual cursespp::IScrollAdapter& GetScrollAdapter(); virtual bool OnEntryContextMenu(size_t index);