From c71e1f23ed87dfae5a5b69210d8fece249fb5fa4 Mon Sep 17 00:00:00 2001 From: Christof Date: Tue, 22 Oct 2024 00:15:19 +0200 Subject: [PATCH] Address #352, the accidental jump back to page 1 on editing a category. This was a regression but introduced with #310 back in April 2024 with the release of 2.3.0 --- The-Orm/PatchButtonPanel.cpp | 7 +++++-- The-Orm/PatchButtonPanel.h | 2 +- The-Orm/PatchView.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/The-Orm/PatchButtonPanel.cpp b/The-Orm/PatchButtonPanel.cpp index 2ef4dcbd..018591fa 100644 --- a/The-Orm/PatchButtonPanel.cpp +++ b/The-Orm/PatchButtonPanel.cpp @@ -161,12 +161,15 @@ void PatchButtonPanel::setPatchLoader(TPageLoader pageGetter) pageLoader_ = pageGetter; } -void PatchButtonPanel::setTotalCount(int totalCount) +void PatchButtonPanel::setTotalCount(int totalCount, bool resetToPageOne /* = true */) { - pageBase_ = pageNumber_ = 0; totalSize_ = totalCount; numPages_ = totalCount / pageSize_; if (totalCount % pageSize_ != 0) numPages_++; + if (resetToPageOne || pageBase_ >= totalCount) { + // Either we want to jump back to page 1, or the current page is no longer possible as the totalCount is smaller than the current's page first element index + pageBase_ = pageNumber_ = 0; + } } void PatchButtonPanel::changeGridSize(int newWidth, int newHeight) { diff --git a/The-Orm/PatchButtonPanel.h b/The-Orm/PatchButtonPanel.h index 80a178b9..e4bb6203 100644 --- a/The-Orm/PatchButtonPanel.h +++ b/The-Orm/PatchButtonPanel.h @@ -24,7 +24,7 @@ class PatchButtonPanel : public Component, virtual ~PatchButtonPanel() override; void setPatchLoader(TPageLoader pageGetter); - void setTotalCount(int totalCount); + void setTotalCount(int totalCount, bool resetToPageOne = true); void changeGridSize(int newWidth, int newHeight); void setPatches(std::vector const& patches, int autoSelectTarget = -1); diff --git a/The-Orm/PatchView.cpp b/The-Orm/PatchView.cpp index 685d614f..378df6ed 100644 --- a/The-Orm/PatchView.cpp +++ b/The-Orm/PatchView.cpp @@ -89,7 +89,7 @@ PatchView::PatchView(midikraft::PatchDatabase &database, std::vector favoritePatch) { database_.putPatch(*favoritePatch); int total = getTotalCount(); - patchButtons_->setTotalCount(total); + patchButtons_->setTotalCount(total, false); patchButtons_->refresh(true); synthBank_->refreshPatch(favoritePatch); } @@ -193,7 +193,7 @@ int PatchView::getTotalCount() { void PatchView::retrieveFirstPageFromDatabase() { // First, we need to find out how many patches there are (for the paging control) int total = getTotalCount(); - patchButtons_->setTotalCount(total); + patchButtons_->setTotalCount(total, true); patchButtons_->refresh(true); // This kicks of loading the first page Data::instance().getEphemeral().setProperty(EPROPERTY_LIBRARY_PATCH_LIST, juce::Uuid().toString(), nullptr); }