HaikuDepot: Fix Redraw Featured Pkgs
The invalidation logic for when packages are added or removed from this view was broken. The new approach involves demarcating the mutation of the data with a begin operation and terminating it with an end operation with the view invalidation happening in the end operation. Resolves #16260 Change-Id: I012610c72714323cc2f7471ad05cc758d9127ef0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3764 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
a44af2ec16
commit
0b69420bc8
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* 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();
|
||||
|
@ -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<DepotInfoRef> depots = _CreateSnapshotOfDepots();
|
||||
std::vector<DepotInfoRef>::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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user