HaikuDepot: selection on filter
This change corrects the selection of a package so that if it could not have been in the filtered list of packages then it becomes unselected. Also fix a problem where `StackedFeaturedPackagesView` is getting pointer events and so getting `MouseDown(..)` all the time. Also remove some disused code. Fixes #20195 Change-Id: I4e30a79d1bfe9cd59bca10113376e8fa87f37ec6 Reviewed-on: https://review.haiku-os.org/c/haiku/+/11318 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]> Haiku-Format: Haiku-format Bot <[email protected]> (cherry picked from commit a2cb86260ce9e1898ed31d9a45f8f76e718c0a1b) Reviewed-on: https://review.haiku-os.org/c/haiku/+/11319
This commit is contained in:
committed by
waddlesplash
parent
b5a3401119
commit
bc55e4974a
@@ -199,8 +199,6 @@ public:
|
|||||||
fModel(model),
|
fModel(model),
|
||||||
fSelectedIndex(-1)
|
fSelectedIndex(-1)
|
||||||
{
|
{
|
||||||
SetEventMask(B_POINTER_EVENTS);
|
|
||||||
|
|
||||||
fTitleFont = StackedFeaturedPackagesView::CreateTitleFont();
|
fTitleFont = StackedFeaturedPackagesView::CreateTitleFont();
|
||||||
fMetadataFont = StackedFeaturedPackagesView::CreateMetadataFont();
|
fMetadataFont = StackedFeaturedPackagesView::CreateMetadataFont();
|
||||||
fSummaryFont = StackedFeaturedPackagesView::CreateSummaryFont();
|
fSummaryFont = StackedFeaturedPackagesView::CreateSummaryFont();
|
||||||
@@ -387,20 +385,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int _CmpProminences(int64 a, int64 b)
|
|
||||||
{
|
|
||||||
if (a <= 0)
|
|
||||||
a = PROMINANCE_ORDERING_MAX;
|
|
||||||
if (b <= 0)
|
|
||||||
b = PROMINANCE_ORDERING_MAX;
|
|
||||||
if (a == b)
|
|
||||||
return 0;
|
|
||||||
if (a > b)
|
|
||||||
return 1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*! This method will return true if the packageA is ordered before
|
/*! This method will return true if the packageA is ordered before
|
||||||
packageB.
|
packageB.
|
||||||
*/
|
*/
|
||||||
@@ -477,9 +461,16 @@ public:
|
|||||||
|
|
||||||
void RetainPackages(const std::vector<PackageInfoRef>& packages)
|
void RetainPackages(const std::vector<PackageInfoRef>& packages)
|
||||||
{
|
{
|
||||||
|
PackageInfoRef selectedPackage;
|
||||||
|
|
||||||
|
if (-1 != fSelectedIndex && fSelectedIndex < static_cast<int32>(fPackages.size()))
|
||||||
|
selectedPackage = fPackages[fSelectedIndex];
|
||||||
|
|
||||||
int32 lowestIndexAddedOrRemoved = _IndexOfFirstDifference(packages);
|
int32 lowestIndexAddedOrRemoved = _IndexOfFirstDifference(packages);
|
||||||
fPackages = packages;
|
fPackages = packages;
|
||||||
_InvalidateFromIndex(lowestIndexAddedOrRemoved);
|
_InvalidateFromIndex(lowestIndexAddedOrRemoved);
|
||||||
|
|
||||||
|
SelectPackage(selectedPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -567,6 +558,9 @@ public:
|
|||||||
|
|
||||||
int32 _IndexOfPackage(PackageInfoRef package) const
|
int32 _IndexOfPackage(PackageInfoRef package) const
|
||||||
{
|
{
|
||||||
|
if (!package.IsSet())
|
||||||
|
return -1;
|
||||||
|
|
||||||
std::vector<PackageInfoRef>::const_iterator it
|
std::vector<PackageInfoRef>::const_iterator it
|
||||||
= std::lower_bound(fPackages.begin(), fPackages.end(), package, &_IsPackageBefore);
|
= std::lower_bound(fPackages.begin(), fPackages.end(), package, &_IsPackageBefore);
|
||||||
|
|
||||||
@@ -577,19 +571,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32 _IndexOfName(const BString& name) const
|
|
||||||
{
|
|
||||||
// TODO; slow linear search.
|
|
||||||
// the fPackages is not sorted on name and for this reason it is not
|
|
||||||
// possible to do a binary search.
|
|
||||||
for (uint32 i = 0; i < fPackages.size(); i++) {
|
|
||||||
if (fPackages[i]->Name() == name)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - drawing and rendering
|
// #pragma mark - drawing and rendering
|
||||||
|
|
||||||
|
|
||||||
@@ -846,7 +827,7 @@ public:
|
|||||||
|
|
||||||
void _EnsureIndexVisible(int32 index)
|
void _EnsureIndexVisible(int32 index)
|
||||||
{
|
{
|
||||||
if (!_IsIndexEntirelyVisible(index)) {
|
if (index >= 0 && !_IsIndexEntirelyVisible(index)) {
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
int32 indexOfCentreVisible = _IndexOfY(bounds.top + bounds.Height() / 2);
|
int32 indexOfCentreVisible = _IndexOfY(bounds.top + bounds.Height() / 2);
|
||||||
if (index < indexOfCentreVisible) {
|
if (index < indexOfCentreVisible) {
|
||||||
|
|||||||
@@ -1227,6 +1227,10 @@ MainWindow::_AdoptModelControls()
|
|||||||
switch (fModel.PackageListViewMode()) {
|
switch (fModel.PackageListViewMode()) {
|
||||||
case PROMINENT:
|
case PROMINENT:
|
||||||
fListTabs->Select(TAB_PROMINENT_PACKAGES);
|
fListTabs->Select(TAB_PROMINENT_PACKAGES);
|
||||||
|
// if the currently selected package is not in the prominent list then it should
|
||||||
|
// be removed.
|
||||||
|
if (!PackageUtils::IsProminent(fModel.SelectedPackage()))
|
||||||
|
fModel.ClearSelectedPackage();
|
||||||
break;
|
break;
|
||||||
case ALL:
|
case ALL:
|
||||||
fListTabs->Select(TAB_ALL_PACKAGES);
|
fListTabs->Select(TAB_ALL_PACKAGES);
|
||||||
@@ -1285,7 +1289,10 @@ MainWindow::_AdoptModel()
|
|||||||
if (fSinglePackageMode)
|
if (fSinglePackageMode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// This list will contain all of the packages that are under consideration.
|
bool retainSelectedPackage = false;
|
||||||
|
PackageInfoRef selectedPackage = fModel.SelectedPackage();
|
||||||
|
|
||||||
|
// This list will contain all the packages that are under consideration.
|
||||||
// Create a new list which only contains the featured packages.
|
// Create a new list which only contains the featured packages.
|
||||||
|
|
||||||
const std::vector<PackageInfoRef> packages = _CreateSnapshotOfFilteredPackages();
|
const std::vector<PackageInfoRef> packages = _CreateSnapshotOfFilteredPackages();
|
||||||
@@ -1294,8 +1301,26 @@ MainWindow::_AdoptModel()
|
|||||||
|
|
||||||
for (it = packages.begin(); it != packages.end(); it++) {
|
for (it = packages.begin(); it != packages.end(); it++) {
|
||||||
PackageInfoRef package = *it;
|
PackageInfoRef package = *it;
|
||||||
|
|
||||||
if (PackageUtils::IsProminent(package))
|
if (PackageUtils::IsProminent(package))
|
||||||
featuredPackages.push_back(package);
|
featuredPackages.push_back(package);
|
||||||
|
|
||||||
|
// The fact that it is prominent or not also determines if it should
|
||||||
|
// remain selected, but this is handled in _AdoptModelControls() rather
|
||||||
|
// than here.
|
||||||
|
|
||||||
|
if (!retainSelectedPackage && selectedPackage.IsSet()
|
||||||
|
&& selectedPackage->Name() == package->Name()) {
|
||||||
|
retainSelectedPackage = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the selected package is not in the filtered packages then drop the
|
||||||
|
// selection.
|
||||||
|
|
||||||
|
if (!retainSelectedPackage && selectedPackage.IsSet()) {
|
||||||
|
HDINFO("selected package not in filtered list; will unset.");
|
||||||
|
fModel.ClearSelectedPackage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now get the UI elements which display those packages to only remain the
|
// Now get the UI elements which display those packages to only remain the
|
||||||
|
|||||||
@@ -349,6 +349,9 @@ public:
|
|||||||
case MSG_MOUSE_EXITED_RATING:
|
case MSG_MOUSE_EXITED_RATING:
|
||||||
fRatingLayout->SetVisibleItem((int32)0);
|
fRatingLayout->SetVisibleItem((int32)0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BGroupView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user