From f302cc52a4258bc8606624ba3300bb2258986d24 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 5 Oct 2013 17:24:56 -0400 Subject: [PATCH] FilterView: Fix depot list. - Since the package list is built lazily in the background, the list of depots won't actually be available immediately at construction time. Defer building the menu for both that and the categority list until the model has actually been populated. --- src/apps/haiku-depot/FilterView.cpp | 64 +++++++++++++++++------------ src/apps/haiku-depot/FilterView.h | 4 +- src/apps/haiku-depot/MainWindow.cpp | 3 +- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/apps/haiku-depot/FilterView.cpp b/src/apps/haiku-depot/FilterView.cpp index 0926291be0..3ffd030b31 100644 --- a/src/apps/haiku-depot/FilterView.cpp +++ b/src/apps/haiku-depot/FilterView.cpp @@ -36,43 +36,18 @@ add_categories_to_menu(const CategoryList& categories, BMenu* menu) } -FilterView::FilterView(const Model& model) +FilterView::FilterView() : BGroupView("filter view") { // Contruct category popup BPopUpMenu* categoryMenu = new BPopUpMenu(B_TRANSLATE("Show")); - categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All packages"), - new BMessage(MSG_CATEGORY_SELECTED))); - categoryMenu->AddItem(new BSeparatorItem()); - add_categories_to_menu(model.Categories(), categoryMenu); - categoryMenu->AddItem(new BSeparatorItem()); - add_categories_to_menu(model.UserCategories(), categoryMenu); - categoryMenu->AddItem(new BSeparatorItem()); - add_categories_to_menu(model.ProgressCategories(), categoryMenu); - - categoryMenu->ItemAt(0)->SetMarked(true); fShowField = new BMenuField("category", B_TRANSLATE("Show:"), categoryMenu); // Construct repository popup BPopUpMenu* repositoryMenu = new BPopUpMenu(B_TRANSLATE("Depot")); - repositoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All depots"), - new BMessage(MSG_DEPOT_SELECTED))); - repositoryMenu->ItemAt(0)->SetMarked(true); - - repositoryMenu->AddItem(new BSeparatorItem()); - - const DepotList& depots = model.Depots(); - for (int i = 0; i < depots.CountItems(); i++) { - const DepotInfo& depot = depots.ItemAtFast(i); - BMessage* message = new BMessage(MSG_DEPOT_SELECTED); - message->AddString("name", depot.Name()); - BMenuItem* item = new BMenuItem(depot.Name(), message); - repositoryMenu->AddItem(item); - } - fRepositoryField = new BMenuField("repository", B_TRANSLATE("Depot:"), repositoryMenu); @@ -135,3 +110,40 @@ FilterView::MessageReceived(BMessage* message) break; } } + + +void +FilterView::AdoptModel(const Model& model) +{ + BMenu* repositoryMenu = fRepositoryField->Menu(); + repositoryMenu->RemoveItems(0, repositoryMenu->CountItems(), true); + + repositoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All depots"), + new BMessage(MSG_DEPOT_SELECTED))); + repositoryMenu->ItemAt(0)->SetMarked(true); + + repositoryMenu->AddItem(new BSeparatorItem()); + + const DepotList& depots = model.Depots(); + for (int i = 0; i < depots.CountItems(); i++) { + const DepotInfo& depot = depots.ItemAtFast(i); + BMessage* message = new BMessage(MSG_DEPOT_SELECTED); + message->AddString("name", depot.Name()); + BMenuItem* item = new BMenuItem(depot.Name(), message); + repositoryMenu->AddItem(item); + } + + BMenu* categoryMenu = fShowField->Menu(); + categoryMenu->RemoveItems(0, categoryMenu->CountItems(), true); + + categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All packages"), + new BMessage(MSG_CATEGORY_SELECTED))); + categoryMenu->AddItem(new BSeparatorItem()); + add_categories_to_menu(model.Categories(), categoryMenu); + categoryMenu->AddItem(new BSeparatorItem()); + add_categories_to_menu(model.UserCategories(), categoryMenu); + categoryMenu->AddItem(new BSeparatorItem()); + add_categories_to_menu(model.ProgressCategories(), categoryMenu); + + categoryMenu->ItemAt(0)->SetMarked(true); +} diff --git a/src/apps/haiku-depot/FilterView.h b/src/apps/haiku-depot/FilterView.h index 8231854d89..d6baf4eec6 100644 --- a/src/apps/haiku-depot/FilterView.h +++ b/src/apps/haiku-depot/FilterView.h @@ -22,12 +22,14 @@ enum { class FilterView : public BGroupView { public: - FilterView(const Model& model); + FilterView(); virtual ~FilterView(); virtual void AttachedToWindow(); virtual void MessageReceived(BMessage* message); + virtual void AdoptModel(const Model& model); + private: BMenuField* fShowField; BMenuField* fRepositoryField; diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index f7aacdf8ff..2e95c3352f 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -83,7 +83,7 @@ MainWindow::MainWindow(BRect frame, const BMessage& settings) BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu")); _BuildMenu(menuBar); - fFilterView = new FilterView(fModel); + fFilterView = new FilterView(); fPackageListView = new PackageListView(fModel.Lock()); fPackageInfoView = new PackageInfoView(fModel.Lock(), this); @@ -160,6 +160,7 @@ MainWindow::MessageReceived(BMessage* message) { fModelWorker = B_BAD_THREAD_ID; _AdoptModel(); + fFilterView->AdoptModel(fModel); break; } case B_SIMPLE_DATA: