Skip to content

Commit

Permalink
WTrackMenu: Group crates into sections according to their parent folder
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed Oct 16, 2024
1 parent d2b90f0 commit 7a553e1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,12 @@ void WTrackMenu::slotPopulateCrateMenu() {
->crates()
.selectCratesWithTrackCount(trackIds));

// The crates returned by selectCratesWithTrackCount are ordered
// by their parent folder's full path as well as their name.
// Based on that assumption, the following code creates sections
// for the different folders.
CrateFolderId currentFolderId;

CrateSummary crate;
while (allCrates.populateNext(&crate)) {
auto pAction = make_parented<QWidgetAction>(
Expand Down Expand Up @@ -1521,6 +1527,17 @@ void WTrackMenu::slotPopulateCrateMenu() {
pCheckBox->setCheckState(Qt::PartiallyChecked);
}

if (crate.getFolderId() != currentFolderId) {
currentFolderId = crate.getFolderId();
// Crates that are children of the root item
// have a NULL folder_path and simply come first
// in the list, without an explicit section.
if (crate.getFolderPath().isEmpty()) {
auto pSection = m_pCrateMenu->addSection(crate.getFolderPath());
pSection->setProperty("folderId", QVariant::fromValue(crate.getFolderId()));
}
}

m_pCrateMenu->addAction(pAction.get());
connect(pAction.get(), &QAction::triggered, this, [this, pCheckBox{pCheckBox.get()}] { updateSelectionCrates(pCheckBox); });
connect(pCheckBox.get(), &QCheckBox::stateChanged, this, [this, pCheckBox{pCheckBox.get()}] { updateSelectionCrates(pCheckBox); });
Expand Down

0 comments on commit 7a553e1

Please sign in to comment.