diff options
author | Julian Eisel <julian@blender.org> | 2021-10-08 21:09:42 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-10-08 21:09:42 +0300 |
commit | 8f8982d57c7a022a4040169e19d1943da62c42f9 (patch) | |
tree | 6ae768c7e4b030c6517637d369b304cf42eb80fc /source | |
parent | 17c928e9752372b698a1ed27e243181873aa411e (diff) |
Asset Browser: Context menu for catalogs
The context menu is a standard way to expose operations of the clicked
item to the user. They expect it to be there, and we can make use of it
as a place to put more advanced operations in.
The menu contains:
* New Catalog
* Delete Catalog
* Rename
Also removes the 'x' icon to delete a catalog from the right side of a
row. This was just placed there temporarily until the context menu is
there. It's too easy to accidentally delete catalogs with this.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_file/asset_catalog_tree_view.cc | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc index 28d64cfca60..3407be9d8cd 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -94,6 +94,7 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem { void on_activate() override; void build_row(uiLayout &row) override; + void build_context_menu(bContext &C, uiLayout &column) const override; bool can_drop(const wmDrag &drag) const override; std::string drop_tooltip(const bContext &C, @@ -225,23 +226,47 @@ void AssetCatalogTreeViewItem::build_row(uiLayout &row) uiButTreeRow *tree_row_but = tree_row_button(); PointerRNA *props; - const CatalogID catalog_id = catalog_item_.get_catalog_id(); props = UI_but_extra_operator_icon_add( (uiBut *)tree_row_but, "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD); RNA_string_set(props, "parent_path", catalog_item_.catalog_path().c_str()); +} - /* Tree items without a catalog ID represent components of catalog paths that are not - * associated with an actual catalog. They exist merely by the presence of a child catalog, and - * thus cannot be deleted themselves. */ - if (!BLI_uuid_is_nil(catalog_id)) { - char catalog_id_str_buffer[UUID_STRING_LEN] = ""; - BLI_uuid_format(catalog_id_str_buffer, catalog_id); - - props = UI_but_extra_operator_icon_add( - (uiBut *)tree_row_but, "ASSET_OT_catalog_delete", WM_OP_INVOKE_DEFAULT, ICON_X); - RNA_string_set(props, "catalog_id", catalog_id_str_buffer); +void AssetCatalogTreeViewItem::build_context_menu(bContext &C, uiLayout &column) const +{ + PointerRNA props; + + uiItemFullO(&column, + "ASSET_OT_catalog_new", + "New Catalog", + ICON_NONE, + nullptr, + WM_OP_INVOKE_DEFAULT, + 0, + &props); + RNA_string_set(&props, "parent_path", catalog_item_.catalog_path().c_str()); + + char catalog_id_str_buffer[UUID_STRING_LEN] = ""; + BLI_uuid_format(catalog_id_str_buffer, catalog_item_.get_catalog_id()); + uiItemFullO(&column, + "ASSET_OT_catalog_delete", + "Delete Catalog", + ICON_NONE, + nullptr, + WM_OP_INVOKE_DEFAULT, + 0, + &props); + RNA_string_set(&props, "catalog_id", catalog_id_str_buffer); + uiItemO(&column, "Rename", ICON_NONE, "UI_OT_tree_view_item_rename"); + + /* Doesn't actually exist right now, but could be defined in Python. Reason that this isn't done + * in Python yet is that catalogs are not exposed in BPY, and we'd somehow pass the clicked on + * catalog to the menu draw callback (via context probably).*/ + MenuType *mt = WM_menutype_find("ASSETBROWSER_MT_catalog_context_menu", true); + if (!mt) { + return; } + UI_menutype_draw(&C, mt, &column); } bool AssetCatalogTreeViewItem::has_droppable_item(const wmDrag &drag) |