HaikuDepot: Show package in info area when selected in list

* Includes fixes along the way. Shows only package title as of
   now.
This commit is contained in:
Stephan Aßmus
2013-07-28 15:46:54 +02:00
parent cc4fa3bf29
commit 0aea921993
5 changed files with 70 additions and 4 deletions
+30 -3
View File
@@ -88,6 +88,19 @@ MainWindow::MessageReceived(BMessage* message)
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
break;
case MSG_PACKAGE_SELECTED:
{
int32 index;
if (message->FindInt32("index", &index) == B_OK
&& index >= 0 && index < fVisiblePackages.CountItems()) {
_AdoptPackage(fVisiblePackages.ItemAtFast(index));
} else {
_ClearPackage();
}
break;
}
default:
BWindow::MessageReceived(message);
break;
@@ -107,15 +120,29 @@ MainWindow::_BuildMenu(BMenuBar* menuBar)
void
MainWindow::_AdoptModel()
{
PackageInfoList packages = fModel.CreatePackageList();
fVisiblePackages = fModel.CreatePackageList();
fPackageListView->Clear();
for (int32 i = 0; i < packages.CountItems(); i++) {
fPackageListView->AddPackage(packages.ItemAtFast(i));
for (int32 i = 0; i < fVisiblePackages.CountItems(); i++) {
fPackageListView->AddPackage(fVisiblePackages.ItemAtFast(i));
}
}
void
MainWindow::_AdoptPackage(const PackageInfo& package)
{
fPackageInfoView->SetPackage(package);
}
void
MainWindow::_ClearPackage()
{
fPackageInfoView->Clear();
}
void
MainWindow::_InitDummyModel()
{
+4
View File
@@ -33,6 +33,9 @@ public:
private:
void _BuildMenu(BMenuBar* menuBar);
void _AdoptModel();
void _AdoptPackage(const PackageInfo& package);
void _ClearPackage();
void _InitDummyModel();
@@ -44,6 +47,7 @@ private:
BSplitView* fSplitView;
Model fModel;
PackageInfoList fVisiblePackages;
};
#endif // MAIN_WINDOW_H
+9 -1
View File
@@ -23,7 +23,7 @@ class TitleView : public BView {
public:
TitleView()
:
BView("title view", B_WILL_DRAW),
BView("title view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fIcon(NULL),
fTitle()
{
@@ -47,6 +47,8 @@ public:
BPoint offset(B_ORIGIN);
BRect bounds(Bounds());
FillRect(updateRect, B_SOLID_LOW);
if (fIcon != NULL) {
// TODO: ...
}
@@ -81,6 +83,7 @@ public:
// TODO: Fetch icon
fTitle = package.Title();
InvalidateLayout();
Invalidate();
}
void Clear()
@@ -88,6 +91,11 @@ public:
delete fIcon;
fIcon = NULL;
fTitle = "";
if (Parent() != NULL) {
InvalidateLayout();
Invalidate();
}
}
private:
+20
View File
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <Catalog.h>
#include <Window.h>
#undef B_TRANSLATION_CONTEXT
@@ -288,6 +289,8 @@ PackageListView::PackageListView()
B_TRUNCATE_END), kSizeColumn);
AddColumn(new PackageColumn(B_TRANSLATE("Status"), 100, 50, 500,
B_TRUNCATE_END), kStatusColumn);
SetSortingEnabled(true);
}
@@ -314,6 +317,23 @@ PackageListView::MessageReceived(BMessage* message)
}
void
PackageListView::SelectionChanged()
{
BColumnListView::SelectionChanged();
BMessage message(MSG_PACKAGE_SELECTED);
BRow* selected = CurrentSelection();
int32 index = -1;
if (selected != NULL)
index = IndexOf(selected);
message.AddInt32("index", index);
Window()->PostMessage(&message);
}
void
PackageListView::AddPackage(const PackageInfo& package)
{
+7
View File
@@ -14,6 +14,11 @@
class PackageRow;
enum {
MSG_PACKAGE_SELECTED = 'pkgs',
};
class PackageListView : public BColumnListView {
public:
PackageListView();
@@ -22,6 +27,8 @@ public:
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
virtual void SelectionChanged();
void AddPackage(const PackageInfo& package);
private: