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_SIMPLE_DATA:
case B_REFS_RECEIVED: case B_REFS_RECEIVED:
break; 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: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -107,15 +120,29 @@ MainWindow::_BuildMenu(BMenuBar* menuBar)
void void
MainWindow::_AdoptModel() MainWindow::_AdoptModel()
{ {
PackageInfoList packages = fModel.CreatePackageList(); fVisiblePackages = fModel.CreatePackageList();
fPackageListView->Clear(); fPackageListView->Clear();
for (int32 i = 0; i < packages.CountItems(); i++) { for (int32 i = 0; i < fVisiblePackages.CountItems(); i++) {
fPackageListView->AddPackage(packages.ItemAtFast(i)); fPackageListView->AddPackage(fVisiblePackages.ItemAtFast(i));
} }
} }
void
MainWindow::_AdoptPackage(const PackageInfo& package)
{
fPackageInfoView->SetPackage(package);
}
void
MainWindow::_ClearPackage()
{
fPackageInfoView->Clear();
}
void void
MainWindow::_InitDummyModel() MainWindow::_InitDummyModel()
{ {
+4
View File
@@ -33,6 +33,9 @@ public:
private: private:
void _BuildMenu(BMenuBar* menuBar); void _BuildMenu(BMenuBar* menuBar);
void _AdoptModel(); void _AdoptModel();
void _AdoptPackage(const PackageInfo& package);
void _ClearPackage();
void _InitDummyModel(); void _InitDummyModel();
@@ -44,6 +47,7 @@ private:
BSplitView* fSplitView; BSplitView* fSplitView;
Model fModel; Model fModel;
PackageInfoList fVisiblePackages;
}; };
#endif // MAIN_WINDOW_H #endif // MAIN_WINDOW_H
+9 -1
View File
@@ -23,7 +23,7 @@ class TitleView : public BView {
public: public:
TitleView() TitleView()
: :
BView("title view", B_WILL_DRAW), BView("title view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fIcon(NULL), fIcon(NULL),
fTitle() fTitle()
{ {
@@ -47,6 +47,8 @@ public:
BPoint offset(B_ORIGIN); BPoint offset(B_ORIGIN);
BRect bounds(Bounds()); BRect bounds(Bounds());
FillRect(updateRect, B_SOLID_LOW);
if (fIcon != NULL) { if (fIcon != NULL) {
// TODO: ... // TODO: ...
} }
@@ -81,6 +83,7 @@ public:
// TODO: Fetch icon // TODO: Fetch icon
fTitle = package.Title(); fTitle = package.Title();
InvalidateLayout(); InvalidateLayout();
Invalidate();
} }
void Clear() void Clear()
@@ -88,6 +91,11 @@ public:
delete fIcon; delete fIcon;
fIcon = NULL; fIcon = NULL;
fTitle = ""; fTitle = "";
if (Parent() != NULL) {
InvalidateLayout();
Invalidate();
}
} }
private: private:
+20
View File
@@ -9,6 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Window.h>
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@@ -288,6 +289,8 @@ PackageListView::PackageListView()
B_TRUNCATE_END), kSizeColumn); B_TRUNCATE_END), kSizeColumn);
AddColumn(new PackageColumn(B_TRANSLATE("Status"), 100, 50, 500, AddColumn(new PackageColumn(B_TRANSLATE("Status"), 100, 50, 500,
B_TRUNCATE_END), kStatusColumn); 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 void
PackageListView::AddPackage(const PackageInfo& package) PackageListView::AddPackage(const PackageInfo& package)
{ {
+7
View File
@@ -14,6 +14,11 @@
class PackageRow; class PackageRow;
enum {
MSG_PACKAGE_SELECTED = 'pkgs',
};
class PackageListView : public BColumnListView { class PackageListView : public BColumnListView {
public: public:
PackageListView(); PackageListView();
@@ -22,6 +27,8 @@ public:
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void SelectionChanged();
void AddPackage(const PackageInfo& package); void AddPackage(const PackageInfo& package);
private: private: