From 0673585b12cbf8c8493ec190e1410ec5adbbfed2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 28 Oct 2020 21:49:24 +0100 Subject: [PATCH] LibraryPage: move PLAY handler code to LibraryTagListPage::HandleEnter() This completes mouse support for the library page, because now TagListPage::OnMouse() can call LibraryTagListPage::HandleEnter(). --- NEWS | 1 + src/LibraryPage.cxx | 81 ++++++++++++++++++++++++++++----------------- src/TagListPage.hxx | 4 ++- 3 files changed, 54 insertions(+), 32 deletions(-) diff --git a/NEWS b/NEWS index 1454d34c..3d00e689 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ncmpc 0.42 - not yet released * file page: repaint after moving cursor with mouse * file page: handle mouse click on directory +* library page: mouse support * suppor the mouse wheel * fix assertion failure on exit diff --git a/src/LibraryPage.cxx b/src/LibraryPage.cxx index 1f6b4a6a..3d8d024e 100644 --- a/src/LibraryPage.cxx +++ b/src/LibraryPage.cxx @@ -107,13 +107,23 @@ SongListPage::Update(struct mpdclient &c, unsigned events) noexcept } } +class ArtistBrowserPage; + class LibraryTagListPage final : public TagListPage { + ArtistBrowserPage &library_page; + public: - LibraryTagListPage(ScreenManager &_screen, Page *_parent, + LibraryTagListPage(ScreenManager &_screen, + ArtistBrowserPage &_library_page, + Page *_parent, const enum mpd_tag_type _tag, const char *_all_text, WINDOW *_w, Size size) noexcept - :TagListPage(_screen, _parent, _tag, _all_text, _w, size) {} + :TagListPage(_screen, _parent, _tag, _all_text, _w, size), + library_page(_library_page) {} + +protected: + bool HandleEnter(struct mpdclient &c) override; }; class ArtistBrowserPage final : public ProxyPage { @@ -131,7 +141,7 @@ class ArtistBrowserPage final : public ProxyPage { bool first = true; for (const auto &tag : options.library_page_tags) { - tag_list_pages.emplace_back(_screen, + tag_list_pages.emplace_back(_screen, *this, first ? nullptr : this, tag, first ? nullptr : _("All"), @@ -140,6 +150,8 @@ class ArtistBrowserPage final : public ProxyPage { } } + void EnterTag(struct mpdclient &c, TagFilter &&filter); + private: void OpenTagPage(struct mpdclient &c, TagFilter &&filter) noexcept; @@ -260,43 +272,50 @@ ArtistBrowserPage::Update(struct mpdclient &c, unsigned events) noexcept ProxyPage::Update(c, events); } -bool -ArtistBrowserPage::OnCommand(struct mpdclient &c, Command cmd) +inline void +ArtistBrowserPage::EnterTag(struct mpdclient &c, TagFilter &&filter) { - if (ProxyPage::OnCommand(c, cmd)) - return true; + assert(current_tag_list_page != tag_list_pages.end()); - switch (cmd) { - case Command::PLAY: - if (current_tag_list_page != tag_list_pages.end()) { - auto filter = current_tag_list_page->MakeCursorFilter(); - if (filter.empty()) + ++current_tag_list_page; + + if (current_tag_list_page != tag_list_pages.end()) { + while (true) { + OpenTagPage(c, std::move(filter)); + if (current_tag_list_page->HasMultipleValues()) break; + /* skip tags which have just + one value */ + filter = current_tag_list_page->GetFilter(); ++current_tag_list_page; - - if (current_tag_list_page != tag_list_pages.end()) { - while (true) { - OpenTagPage(c, std::move(filter)); - if (current_tag_list_page->HasMultipleValues()) - break; - - /* skip tags which have just - one value */ - filter = current_tag_list_page->GetFilter(); - ++current_tag_list_page; - if (current_tag_list_page == tag_list_pages.end()) { - OpenSongList(c, std::move(filter)); - break; - } - } - } else + if (current_tag_list_page == tag_list_pages.end()) { OpenSongList(c, std::move(filter)); - return true; + break; + } } + } else + OpenSongList(c, std::move(filter)); +} - break; +bool +LibraryTagListPage::HandleEnter(struct mpdclient &c) +{ + auto new_filter = MakeCursorFilter(); + if (new_filter.empty()) + return TagListPage::HandleEnter(c); + + library_page.EnterTag(c, std::move(new_filter)); + return true; +} +bool +ArtistBrowserPage::OnCommand(struct mpdclient &c, Command cmd) +{ + if (ProxyPage::OnCommand(c, cmd)) + return true; + + switch (cmd) { case Command::GO_ROOT_DIRECTORY: if (GetCurrentPage() != &tag_list_pages.front()) { current_tag_list_page = tag_list_pages.begin(); diff --git a/src/TagListPage.hxx b/src/TagListPage.hxx index 90f01e6d..27d3489f 100644 --- a/src/TagListPage.hxx +++ b/src/TagListPage.hxx @@ -95,8 +95,10 @@ public: : nullptr; } +protected: + virtual bool HandleEnter(struct mpdclient &c); + private: - bool HandleEnter(struct mpdclient &c); bool HandleSelect(struct mpdclient &c); void LoadValues(struct mpdclient &c) noexcept;