Skip to content

Commit

Permalink
WIP Library sidebar: select renamed or neighbour of deleted playlist/…
Browse files Browse the repository at this point in the history
…crate only if it was selected previously
  • Loading branch information
ronso0 committed Jan 16, 2023
1 parent c54a0c9 commit 6a6a2c3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
28 changes: 15 additions & 13 deletions src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,6 @@ void BasePlaylistFeature::slotDeletePlaylist() {
return;
}

// we will switch to the sibling if the deleted playlist is currently active
bool wasActive = m_pPlaylistTableModel->getPlaylist() == playlistId;
// TODO 'active' doesn't mean it was visible, e.g. while the playlist feuture
// root view or another feature model is currently loaded in the tracks view
qWarning() << " wasActive:" << wasActive;

VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) {
return;
}
Expand All @@ -437,7 +431,17 @@ void BasePlaylistFeature::slotDeletePlaylist() {
return;
}

int siblingId = getSiblingPlaylistIdOf(m_lastRightClickedIndex);
int siblingId = kInvalidPlaylistId;
// If the playlist is currently loaded and shown in the tracks table we will
// select a sibling playlist after deletion.
// TODO find a better way to detect 'active' than isChildIndexSelected()
if (playlistId == m_pPlaylistTableModel->getPlaylist() &&
m_pSidebarWidget != nullptr &&
// m_pSidebarWidget->isChildIndexSelected(m_lastRightClickedIndex);
m_pSidebarWidget->isChildIndexSelected(indexFromPlaylistId(playlistId))) {
siblingId = getSiblingPlaylistIdOf(m_lastRightClickedIndex);
qWarning() << " wasActive, get sibling id:" << siblingId;
}

QMessageBox::StandardButton btn = QMessageBox::question(nullptr,
tr("Confirm Deletion"),
Expand All @@ -451,13 +455,11 @@ void BasePlaylistFeature::slotDeletePlaylist() {

m_playlistDao.deletePlaylist(playlistId);

if (siblingId == kInvalidPlaylistId) {
return;
}
if (wasActive) {
if (siblingId != kInvalidPlaylistId) {
qWarning() << ".";
qWarning() << " Pl delete: was active, activate sibling";
qWarning() << ".";
activatePlaylist(siblingId);
} else if (m_pSidebarWidget) {
m_pSidebarWidget->selectChildIndex(indexFromPlaylistId(siblingId), false);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/library/trackset/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,13 @@ void CrateFeature::slotDeleteCrate() {
CrateId crateId = crate.getId();
// Store sibling id to restore selection after crate was deleted
// to avoid the scroll position being reset to Crate root item.
storePrevSiblingCrateId(crateId);
m_prevSiblingCrate = CrateId();
if (crateId == m_crateTableModel.selectedCrate() &&
m_pSidebarWidget &&
m_pSidebarWidget->isChildIndexSelected(m_lastRightClickedIndex)) {
storePrevSiblingCrateId(crateId);
}

QMessageBox::StandardButton btn = QMessageBox::question(nullptr,
tr("Confirm Deletion"),
tr("Do you really want to delete crate <b>%1</b>?")
Expand Down
13 changes: 12 additions & 1 deletion src/library/trackset/playlistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,19 @@ void PlaylistFeature::slotPlaylistTableRenamed(
type == PlaylistDAO::PLHT_UNKNOWN) { // In case of a deleted Playlist
clearChildModel();
m_lastRightClickedIndex = constructChildModel(playlistId);
if (type != PlaylistDAO::PLHT_UNKNOWN) {
if (type == PlaylistDAO::PLHT_UNKNOWN) {
return;
}

// reselect playlist if it was selected previously, i.e. don't activate
// if another sidebar item was selected
if (playlistId == m_pPlaylistTableModel->getPlaylist() &&
m_pSidebarWidget &&
m_pSidebarWidget->isChildIndexSelected(
indexFromPlaylistId(playlistId))) {
activatePlaylist(playlistId);
} else {
selectPlaylistInSidebar(playlistId, false);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/library/trackset/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,14 @@ void SetlogFeature::slotPlaylistTableRenamed(int playlistId, const QString& newN
clearChildModel();
m_lastRightClickedIndex = constructChildModel(playlistId);
if (type != PlaylistDAO::PLHT_UNKNOWN) {
if (playlistId == m_pPlaylistTableModel->getPlaylist()) {
if (playlistId == m_pPlaylistTableModel->getPlaylist() &&
m_pSidebarWidget &&
m_pSidebarWidget->isChildIndexSelected(
indexFromPlaylistId(playlistId))) {
activatePlaylist(playlistId);
} else if (m_pSidebarWidget) {
m_pSidebarWidget->selectChildIndex(indexFromPlaylistId(playlistId), false);
// m_pSidebarWidget->selectChildIndex(indexFromPlaylistId(playlistId), false);
slotPlaylistTableChangedAndScrollTo(playlistId);
}
}
}
Expand Down

0 comments on commit 6a6a2c3

Please sign in to comment.