Skip to content

Commit

Permalink
Address #352, the accidental jump back to page 1 on editing a categor…
Browse files Browse the repository at this point in the history
…y. This was a regression but introduced with #310 back in April 2024 with the release of 2.3.0
  • Loading branch information
christofmuc committed Oct 21, 2024
1 parent 8d9fbe6 commit c71e1f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions The-Orm/PatchButtonPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion The-Orm/PatchButtonPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<midikraft::PatchHolder> const& patches, int autoSelectTarget = -1);

Expand Down
4 changes: 2 additions & 2 deletions The-Orm/PatchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ PatchView::PatchView(midikraft::PatchDatabase &database, std::vector<midikraft::
[this](std::shared_ptr<midikraft::PatchHolder> favoritePatch) {
database_.putPatch(*favoritePatch);
int total = getTotalCount();
patchButtons_->setTotalCount(total);
patchButtons_->setTotalCount(total, false);
patchButtons_->refresh(true);
synthBank_->refreshPatch(favoritePatch);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c71e1f2

Please sign in to comment.