diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp index 5b8ad08492..f94c7536b1 100644 --- a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp +++ b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp @@ -61,7 +61,8 @@ public: fModel(model), fSelectedIndex(-1), fPackageListener( - new(std::nothrow) OnePackageMessagePackageListener(this)) + new(std::nothrow) OnePackageMessagePackageListener(this)), + fLowestIndexAddedOrRemoved(-1) { SetEventMask(B_POINTER_EVENTS); Clear(); @@ -260,6 +261,26 @@ public: } + void BeginAddRemove() + { + fLowestIndexAddedOrRemoved = INT32_MAX; + } + + + void EndAddRemove() + { + if (fLowestIndexAddedOrRemoved < INT32_MAX) { + if (fPackages.empty()) + Invalidate(); + else { + BRect invalidRect = Bounds(); + invalidRect.top = _YOfIndex(fLowestIndexAddedOrRemoved); + Invalidate(invalidRect); + } + } + } + + void AddPackage(const PackageInfoRef& package) { // fPackages is sorted and for this reason it is possible to find the @@ -278,9 +299,9 @@ public: if (fSelectedIndex >= insertionIndex) fSelectedIndex++; fPackages.insert(itInsertionPt, package); - Invalidate(_RectOfIndex(insertionIndex) - | _RectOfIndex(fPackages.size() - 1)); package->AddListener(fPackageListener); + if (insertionIndex < fLowestIndexAddedOrRemoved) + fLowestIndexAddedOrRemoved = insertionIndex; } } @@ -295,12 +316,8 @@ public: fSelectedIndex--; fPackages[index]->RemoveListener(fPackageListener); fPackages.erase(fPackages.begin() + index); - if (fPackages.empty()) - Invalidate(); - else { - Invalidate(_RectOfIndex(index) - | _RectOfIndex(fPackages.size() - 1)); - } + if (index < fLowestIndexAddedOrRemoved) + fLowestIndexAddedOrRemoved = index; } } @@ -630,6 +647,7 @@ private: int32 fSelectedIndex; OnePackageMessagePackageListener* fPackageListener; + int32 fLowestIndexAddedOrRemoved; }; @@ -656,6 +674,21 @@ FeaturedPackagesView::~FeaturedPackagesView() } +void +FeaturedPackagesView::BeginAddRemove() +{ + fPackagesView->BeginAddRemove(); +} + + +void +FeaturedPackagesView::EndAddRemove() +{ + fPackagesView->EndAddRemove(); + _AdjustViews(); +} + + /*! This method will add the package into the list to be displayed. The insertion will occur in alphabetical order. */ @@ -664,7 +697,6 @@ void FeaturedPackagesView::AddPackage(const PackageInfoRef& package) { fPackagesView->AddPackage(package); - _AdjustViews(); } @@ -672,7 +704,6 @@ void FeaturedPackagesView::RemovePackage(const PackageInfoRef& package) { fPackagesView->RemovePackage(package); - _AdjustViews(); } diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.h b/src/apps/haikudepot/ui/FeaturedPackagesView.h index ecc7ef19c3..13c3563c9c 100644 --- a/src/apps/haikudepot/ui/FeaturedPackagesView.h +++ b/src/apps/haikudepot/ui/FeaturedPackagesView.h @@ -1,6 +1,6 @@ /* * Copyright 2014, Stephan Aßmus . - * Copyright 2020, Andrew Lindesay . + * Copyright 2020-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef FEATURED_PACKAGES_VIEW_H @@ -24,6 +24,8 @@ public: virtual void DoLayout(); + void BeginAddRemove(); + void EndAddRemove(); void AddPackage(const PackageInfoRef& package); void RemovePackage(const PackageInfoRef& package); void Clear(); diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index 1ffa9cb608..b444055182 100644 --- a/src/apps/haikudepot/ui/MainWindow.cpp +++ b/src/apps/haikudepot/ui/MainWindow.cpp @@ -492,7 +492,11 @@ MainWindow::MessageReceived(BMessage* message) BAutolock locker(fModel.Lock()); fModel.SetPackageState(ref, ref->State()); } + + fFeaturedPackagesView->BeginAddRemove(); _AddRemovePackageFromLists(ref); + fFeaturedPackagesView->EndAddRemove(); + if ((changes & PKG_CHANGED_STATE) != 0 && !fCoordinator.IsSet()) { fWorkStatusView->PackageStatusChanged(ref); @@ -824,6 +828,9 @@ MainWindow::_AdoptModel() std::vector depots = _CreateSnapshotOfDepots(); std::vector::iterator it; + + fFeaturedPackagesView->BeginAddRemove(); + for (it = depots.begin(); it != depots.end(); it++) { DepotInfoRef depotInfoRef = *it; for (int i = 0; i < depotInfoRef->CountPackages(); i++) { @@ -832,6 +839,8 @@ MainWindow::_AdoptModel() } } + fFeaturedPackagesView->EndAddRemove(); + _AdoptModelControls(); }