From f8f783ddda79054c75da2d58d0c8d167f9d149a1 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Thu, 31 Aug 2023 01:52:36 +0200 Subject: [PATCH] Library track menu: show Hide action also in Playlist & Crates --- src/library/playlisttablemodel.cpp | 6 +++-- .../trackset/crate/cratetablemodel.cpp | 1 + src/widget/wtrackmenu.cpp | 11 +++++--- src/widget/wtracktableview.cpp | 27 ++++++++++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index 7ed771c5d273..adfe44d9155d 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -359,6 +359,7 @@ TrackModel::Capabilities PlaylistTableModel::getCapabilities() const { Capability::LoadToSampler | Capability::LoadToPreviewDeck | Capability::ResetPlayed | + Capability::Hide | Capability::Analyze; if (m_iPlaylistId != @@ -373,8 +374,9 @@ TrackModel::Capabilities PlaylistTableModel::getCapabilities() const { if (m_pTrackCollectionManager->internalCollection() ->getPlaylistDAO() .getHiddenType(m_iPlaylistId) == PlaylistDAO::PLHT_SET_LOG) { - // Disable track reordering and adding tracks via drag'n'drop for history playlists - caps &= ~(Capability::ReceiveDrops | Capability::Reorder); + // Disallow reordering and hiding tracks, as well as adding tracks via + // drag'n'drop for history playlists + caps &= ~(Capability::ReceiveDrops | Capability::Reorder | Capability::Hide); } bool locked = m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().isPlaylistLocked(m_iPlaylistId); if (locked) { diff --git a/src/library/trackset/crate/cratetablemodel.cpp b/src/library/trackset/crate/cratetablemodel.cpp index 28388f4bfb15..de082679f0e4 100644 --- a/src/library/trackset/crate/cratetablemodel.cpp +++ b/src/library/trackset/crate/cratetablemodel.cpp @@ -131,6 +131,7 @@ TrackModel::Capabilities CrateTableModel::getCapabilities() const { Capability::LoadToPreviewDeck | Capability::RemoveCrate | Capability::ResetPlayed | + Capability::Hide | Capability::RemoveFromDisk | Capability::Analyze; diff --git a/src/widget/wtrackmenu.cpp b/src/widget/wtrackmenu.cpp index 77f0a41fbf8f..9e34f71ef3b6 100644 --- a/src/widget/wtrackmenu.cpp +++ b/src/widget/wtrackmenu.cpp @@ -302,7 +302,10 @@ void WTrackMenu::createActions() { m_pHideAct = new QAction(tr("Hide from Library"), this); // This is just for having the shortcut displayed next to the action in the menu. // The actual keypress is handled in WTrackTableView::keyPressEvent(). - m_pHideAct->setShortcut(hideRemoveKeySequence); + // Note: don't show the hotkey for more than one action + if (!featureIsEnabled(Feature::Remove)) { + m_pHideAct->setShortcut(hideRemoveKeySequence); + } connect(m_pHideAct, &QAction::triggered, this, &WTrackMenu::slotHide); m_pUnhideAct = new QAction(tr("Unhide from Library"), this); @@ -1001,9 +1004,9 @@ void WTrackMenu::updateMenus() { if (featureIsEnabled(Feature::HideUnhidePurge)) { bool locked = m_pTrackModel->hasCapabilities(TrackModel::Capability::Locked); - if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Hide)) { - m_pHideAct->setEnabled(!locked); - } + // Note: Hide action is enabled regardless the locked state. + // Like in Tracks, in locked playlists A confirmation dialog pops up: + // "Hiding track ... will remove it from the following playlists: ..." if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Unhide)) { m_pUnhideAct->setEnabled(!locked); } diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 0b59d3bea209..b8da5503f01d 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -905,22 +905,35 @@ void WTrackTableView::hideOrRemoveSelectedTracks() { } TrackModel::Capability cap; - // Hide is the primary action if allowed. Else we test for remove capability - if (pTrackModel->hasCapabilities(TrackModel::Capability::Hide)) { - cap = TrackModel::Capability::Hide; - } else if (pTrackModel->isLocked()) { // Locked playlists and crates - return; - } + // Remove is the primary action if allowed (playlists and crates). + // Else we test for remove capability. + // In the track menu the hotkey is shown for 'Remove ..' actions, or if there + // is no remove action, for 'Hide ..'. Hence, to match the hotkey, do Hide + // only if the track model doesn't support any Remove actions. if (pTrackModel->hasCapabilities(TrackModel::Capability::Remove)) { cap = TrackModel::Capability::Remove; } else if (pTrackModel->hasCapabilities(TrackModel::Capability::RemoveCrate)) { cap = TrackModel::Capability::RemoveCrate; } else if (pTrackModel->hasCapabilities(TrackModel::Capability::RemovePlaylist)) { cap = TrackModel::Capability::RemovePlaylist; - } else { + } else if (pTrackModel->hasCapabilities(TrackModel::Capability::Hide)) { + cap = TrackModel::Capability::Hide; + } else { // Locked playlists and crates return; } + switch (cap) { + case TrackModel::Capability::Remove: + case TrackModel::Capability::RemoveCrate: + case TrackModel::Capability::RemovePlaylist: { + if (pTrackModel->isLocked()) { + return; + } + default: + break; + } + } + if (pTrackModel->getRequireConfirmationToHideRemoveTracks()) { QString title; QString message;