HaikuDepot: Fixed selecting the right package when the list is sorted.

This commit is contained in:
Stephan Aßmus
2013-09-17 14:42:02 +02:00
committed by Rene Gollent
parent b9898c45f4
commit f7628f839d
2 changed files with 15 additions and 11 deletions
+13 -4
View File
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <Alert.h>
#include <Autolock.h>
#include <Application.h>
#include <Button.h>
#include <Catalog.h>
@@ -87,14 +88,22 @@ MainWindow::MessageReceived(BMessage* message)
switch (message->what) {
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
// TODO: ?
break;
case MSG_PACKAGE_SELECTED:
{
int32 index;
if (message->FindInt32("index", &index) == B_OK
&& index >= 0 && index < fVisiblePackages.CountItems()) {
_AdoptPackage(fVisiblePackages.ItemAtFast(index));
BString title;
if (message->FindString("title", &title) == B_OK) {
int count = fVisiblePackages.CountItems();
for (int i = 0; i < count; i++) {
const PackageInfoRef& package
= fVisiblePackages.ItemAtFast(i);
if (package.Get() != NULL && package->Title() == title) {
_AdoptPackage(package);
break;
}
}
} else {
_ClearPackage();
}
+2 -7
View File
@@ -544,14 +544,9 @@ PackageListView::SelectionChanged()
BMessage message(MSG_PACKAGE_SELECTED);
BRow* selected = CurrentSelection();
// TODO: Wrong index, its the visible one (i.e. sorted)!
// Solve by putting an ID for the package in the message instead.
int32 index = -1;
PackageRow* selected = dynamic_cast<PackageRow*>(CurrentSelection());
if (selected != NULL)
index = IndexOf(selected);
message.AddInt32("index", index);
message.AddString("title", selected->Package()->Title());
Window()->PostMessage(&message);
}