Cleanup: Better way to pass activate callbacks to Tree-View items
The `ui::BasicTreeViewItem` took a function-like object to execute on item activation via the constructor. This was mainly intended to be used with lambdas. However, it's confusing to just have this lambda there, with no indication of what it's for (activation). Instead, assign the function-like object via an explicit `on_activate()` function.
This commit is contained in:
parent
9a0850c8c2
commit
dbe3981b0a
|
@ -239,10 +239,11 @@ class BasicTreeViewItem : public AbstractTreeViewItem {
|
|||
using ActivateFn = std::function<void(BasicTreeViewItem &new_active)>;
|
||||
BIFIconID icon;
|
||||
|
||||
BasicTreeViewItem(StringRef label, BIFIconID icon = ICON_NONE, ActivateFn activate_fn = nullptr);
|
||||
BasicTreeViewItem(StringRef label, BIFIconID icon = ICON_NONE);
|
||||
|
||||
void build_row(uiLayout &row) override;
|
||||
void on_activate() override;
|
||||
void on_activate(ActivateFn fn);
|
||||
|
||||
protected:
|
||||
/** Created in the #build() function. */
|
||||
|
|
|
@ -278,8 +278,7 @@ uiLayout *TreeViewLayoutBuilder::current_layout() const
|
|||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
BasicTreeViewItem::BasicTreeViewItem(StringRef label, BIFIconID icon_, ActivateFn activate_fn)
|
||||
: icon(icon_), activate_fn_(activate_fn)
|
||||
BasicTreeViewItem::BasicTreeViewItem(StringRef label, BIFIconID icon_) : icon(icon_)
|
||||
{
|
||||
label_ = label;
|
||||
}
|
||||
|
@ -330,6 +329,11 @@ void BasicTreeViewItem::on_activate()
|
|||
}
|
||||
}
|
||||
|
||||
void BasicTreeViewItem::on_activate(ActivateFn fn)
|
||||
{
|
||||
activate_fn_ = fn;
|
||||
}
|
||||
|
||||
BIFIconID BasicTreeViewItem::get_draw_icon() const
|
||||
{
|
||||
if (icon) {
|
||||
|
|
|
@ -165,11 +165,12 @@ void AssetCatalogTreeView::add_all_item()
|
|||
{
|
||||
FileAssetSelectParams *params = params_;
|
||||
|
||||
ui::AbstractTreeViewItem &item = add_tree_item<AssetCatalogTreeViewAllItem>(
|
||||
IFACE_("All"), ICON_HOME, [params](ui::BasicTreeViewItem & /*item*/) {
|
||||
params->asset_catalog_visibility = FILE_SHOW_ASSETS_ALL_CATALOGS;
|
||||
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
|
||||
});
|
||||
AssetCatalogTreeViewAllItem &item = add_tree_item<AssetCatalogTreeViewAllItem>(IFACE_("All"),
|
||||
ICON_HOME);
|
||||
item.on_activate([params](ui::BasicTreeViewItem & /*item*/) {
|
||||
params->asset_catalog_visibility = FILE_SHOW_ASSETS_ALL_CATALOGS;
|
||||
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
|
||||
});
|
||||
if (params->asset_catalog_visibility == FILE_SHOW_ASSETS_ALL_CATALOGS) {
|
||||
item.activate();
|
||||
}
|
||||
|
@ -180,10 +181,13 @@ void AssetCatalogTreeView::add_unassigned_item()
|
|||
FileAssetSelectParams *params = params_;
|
||||
|
||||
AssetCatalogTreeViewUnassignedItem &item = add_tree_item<AssetCatalogTreeViewUnassignedItem>(
|
||||
IFACE_("Unassigned"), ICON_FILE_HIDDEN, [params](ui::BasicTreeViewItem & /*item*/) {
|
||||
params->asset_catalog_visibility = FILE_SHOW_ASSETS_WITHOUT_CATALOG;
|
||||
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
|
||||
});
|
||||
IFACE_("Unassigned"), ICON_FILE_HIDDEN);
|
||||
|
||||
item.on_activate([params](ui::BasicTreeViewItem & /*item*/) {
|
||||
params->asset_catalog_visibility = FILE_SHOW_ASSETS_WITHOUT_CATALOG;
|
||||
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
|
||||
});
|
||||
|
||||
if (params->asset_catalog_visibility == FILE_SHOW_ASSETS_WITHOUT_CATALOG) {
|
||||
item.activate();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue