diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 836660ea0..deb33e013 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,8 +4,8 @@ options * added the ability to click transport metadata to display a context menu with a list of actions for the current track/artist/album -* added the ability to search/filter in browse view; focus the category list - and press `Shift+F`. +* added the ability to search/filter in browse view; press `^F` to toggle the + feature on and off. * fixed a bug that could cause tracks to sort incorrectly if some tracks in the album have a disc number specified and others don't. * added the ability to use `libelogind` or `basu` instead of `libsystemd` for diff --git a/src/musikcube/app/layout/BrowseLayout.cpp b/src/musikcube/app/layout/BrowseLayout.cpp index a63e1e259..ff425ab6f 100755 --- a/src/musikcube/app/layout/BrowseLayout.cpp +++ b/src/musikcube/app/layout/BrowseLayout.cpp @@ -153,7 +153,7 @@ void BrowseLayout::OnLayout() { this->categoryList->MoveAndResize(x, y, categoryWidth, cy - categoryListBottomMargin); if (showFilter) { - bool refocusFilter = !this->categoryListFilter->IsVisible(); + const bool refocusFilter = !this->categoryListFilter->IsVisible(); this->categoryListFilter->Show(); this->categoryListFilter->MoveAndResize( x + kFilterPadding, @@ -227,6 +227,13 @@ void BrowseLayout::LoadLastSession() { this->SwitchCategory(field); this->ScrollTo(field, id); } + this->showCategoryListFilter = session->GetBool(keys::LastBrowseFilterVisible, false); + if (this->showCategoryListFilter) { + const std::string filter = session->GetString(keys::LastBrowseFilter); + if (filter != this->currentFilter) { + this->categoryListFilter->SetText(filter); + } + } } void BrowseLayout::SaveSession() { @@ -235,6 +242,8 @@ void BrowseLayout::SaveSession() { const double id = static_cast(this->categoryList->GetSelectedId()); session->SetString(keys::LastBrowseCategoryType, type.c_str()); session->SetDouble(keys::LastBrowseCategoryId, id); + session->SetBool(keys::LastBrowseFilterVisible, this->showCategoryListFilter); + session->SetString(keys::LastBrowseFilter, this->currentFilter.c_str()); } void BrowseLayout::ProcessMessage(musik::core::runtime::IMessage &message) { @@ -271,7 +280,7 @@ void BrowseLayout::ProcessMessage(musik::core::runtime::IMessage &message) { } case cube::message::RequeryCategoryList: { - this->categoryList->Requery(this->currentFilter); + this->categoryList->Requery(this->currentFilter, 0); break; } @@ -391,16 +400,7 @@ void BrowseLayout::ShowTrackSortOverlay() { } bool BrowseLayout::KeyPress(const std::string& key) { - if (key == "^[" && this->showCategoryListFilter) { - if (this->GetFocus() == this->categoryList || - this->GetFocus() == this->categoryListFilter) - { - this->showCategoryListFilter = false; - this->Layout(); - return true; - } - } - else if (key == "KEY_ENTER") { + if (key == "KEY_ENTER") { /* if the tracklist is NOT focused (i.e. the focus is on a category window), start playback from the top. */ if (this->GetFocus() != this->trackList) { @@ -412,21 +412,10 @@ bool BrowseLayout::KeyPress(const std::string& key) { } } else if (Hotkeys::Is(Hotkeys::BrowseCategoryFilter, key)) { - if (this->GetFocus() == this->categoryList || - this->GetFocus() == this->categoryListFilter) - { - /* if the filter is visible but the list is focused, focus the filter */ - if (this->GetFocus() == this->categoryList && this->showCategoryListFilter) { - this->SetFocus(this->categoryListFilter); - } - /* otherwise, toggle the filter visibility */ - else { - this->showCategoryListFilter = !this->showCategoryListFilter; - this->Layout(); - } - return true; - } - } + this->showCategoryListFilter = !this->showCategoryListFilter; + this->Layout(); + return true; + } else if (Hotkeys::Is(Hotkeys::TrackListChangeSortOrder, key)) { this->ShowTrackSortOverlay(); return true; diff --git a/src/musikcube/app/util/Hotkeys.cpp b/src/musikcube/app/util/Hotkeys.cpp index 69c979528..aaee4fbbe 100755 --- a/src/musikcube/app/util/Hotkeys.cpp +++ b/src/musikcube/app/util/Hotkeys.cpp @@ -189,7 +189,7 @@ static std::unordered_map ID_TO_DEFAULT = { { Id::PlayQueueHotSwap, "M-a" }, { Id::PlayQueueClear, "X" }, - { Id::BrowseCategoryFilter, "F" }, + { Id::BrowseCategoryFilter, "^F" }, { Id::BrowsePlaylistsSave, "M-s" }, { Id::BrowsePlaylistsNew, "M-n" }, diff --git a/src/musikcube/app/util/PreferenceKeys.cpp b/src/musikcube/app/util/PreferenceKeys.cpp index 64042ac70..7c1a5054c 100644 --- a/src/musikcube/app/util/PreferenceKeys.cpp +++ b/src/musikcube/app/util/PreferenceKeys.cpp @@ -50,6 +50,8 @@ namespace musik { namespace cube { namespace prefs { const std::string keys::LastBrowseCategoryType = "LastBrowseCategoryType"; const std::string keys::LastBrowseCategoryId = "LastBrowseCategoryId"; const std::string keys::LastBrowseDirectoryRoot = "LastBrowseDirectoryRoot"; + const std::string keys::LastBrowseFilterVisible = "LastBrowseFilterVisible"; + const std::string keys::LastBrowseFilter = "LastBrowseFilter"; const std::string keys::LastCategoryFilter = "LastCategoryFilter"; const std::string keys::LastCategoryFilterMatchType = "LastCategoryFilterMatchType"; const std::string keys::LastTrackFilter = "LastTrackFilter"; diff --git a/src/musikcube/app/util/PreferenceKeys.h b/src/musikcube/app/util/PreferenceKeys.h index d25e7d74c..15aefe2fb 100644 --- a/src/musikcube/app/util/PreferenceKeys.h +++ b/src/musikcube/app/util/PreferenceKeys.h @@ -52,6 +52,8 @@ namespace musik { namespace cube { namespace prefs { extern const std::string LastBrowseCategoryType; extern const std::string LastBrowseCategoryId; extern const std::string LastBrowseDirectoryRoot; + extern const std::string LastBrowseFilterVisible; + extern const std::string LastBrowseFilter; extern const std::string LastCategoryFilter; extern const std::string LastCategoryFilterMatchType; extern const std::string LastTrackFilter; diff --git a/src/musikcube/app/window/CategoryListView.cpp b/src/musikcube/app/window/CategoryListView.cpp index 06966791a..8ec175d74 100755 --- a/src/musikcube/app/window/CategoryListView.cpp +++ b/src/musikcube/app/window/CategoryListView.cpp @@ -266,6 +266,9 @@ void CategoryListView::OnQueryCompleted(IQuery* query) { int selectedIndex = -1; if (this->selectAfterQuery != -1LL) { selectedIndex = active->GetIndexOf(this->selectAfterQuery); + if (selectedIndex == -1) { + selectedIndex = 0; + } } if (this->activeQuery &&