Skip to content

Commit

Permalink
LibraryPage: move PLAY handler code to LibraryTagListPage::HandleEnter()
Browse files Browse the repository at this point in the history
This completes mouse support for the library page, because now
TagListPage::OnMouse() can call LibraryTagListPage::HandleEnter().
  • Loading branch information
MaxKellermann committed Oct 28, 2020
1 parent 1450401 commit 0673585
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 32 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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

Expand Down
81 changes: 50 additions & 31 deletions src/LibraryPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"),
Expand 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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/TagListPage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0673585

Please sign in to comment.