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.
This commit is contained in:
parent
cb434e1a2b
commit
f302cc52a4
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user