Skip to content

Commit

Permalink
Library track menu: show Hide action also in Playlist & Crates
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Apr 19, 2024
1 parent 82d601c commit f8f783d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ TrackModel::Capabilities PlaylistTableModel::getCapabilities() const {
Capability::LoadToSampler |
Capability::LoadToPreviewDeck |
Capability::ResetPlayed |
Capability::Hide |
Capability::Analyze;

if (m_iPlaylistId !=
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/library/trackset/crate/cratetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ TrackModel::Capabilities CrateTableModel::getCapabilities() const {
Capability::LoadToPreviewDeck |
Capability::RemoveCrate |
Capability::ResetPlayed |
Capability::Hide |
Capability::RemoveFromDisk |
Capability::Analyze;

Expand Down
11 changes: 7 additions & 4 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
27 changes: 20 additions & 7 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f8f783d

Please sign in to comment.