[Bf-blender-cvs] [61466b761fd] node-add-asset-menu: Adding nodes works

Hans Goudey noreply at git.blender.org
Thu Oct 6 03:10:29 CEST 2022


Commit: 61466b761fd5d95542d75d8050944b8583aece0a
Author: Hans Goudey
Date:   Wed Oct 5 20:10:19 2022 -0500
Branches: node-add-asset-menu
https://developer.blender.org/rB61466b761fd5d95542d75d8050944b8583aece0a

Adding nodes works

===================================================================

M	source/blender/editors/space_node/add_menu_assets.cc
M	source/blender/editors/space_node/node_add.cc

===================================================================

diff --git a/source/blender/editors/space_node/add_menu_assets.cc b/source/blender/editors/space_node/add_menu_assets.cc
index 7540842d644..cf72f00bf79 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -26,7 +26,7 @@ static bool node_add_menu_poll(const bContext *C, MenuType * /*mt*/)
 }
 
 struct LibraryAsset {
-  const AssetLibraryReference &library_ref;
+  AssetLibraryReference library_ref;
   AssetHandle handle;
 };
 
@@ -63,15 +63,15 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree &node
     }
   }
 
-  /* Find assets for every catalog path. */
+  /* Find all the matching node group assets for every catalog path. */
   MultiValueMap<bke::AssetCatalogPath, LibraryAsset> assets_per_path;
-  for (const AssetLibraryReference &library : all_libraries) {
+  for (const AssetLibraryReference &library_ref : all_libraries) {
     AssetFilterSettings type_filter{};
     type_filter.id_types = FILTER_ID_NT;
 
-    ED_assetlist_storage_fetch(&library, &C);
-    ED_assetlist_ensure_previews_job(&library, &C);
-    ED_assetlist_iterate(library, [&](AssetHandle asset) {
+    ED_assetlist_storage_fetch(&library_ref, &C);
+    ED_assetlist_ensure_previews_job(&library_ref, &C);
+    ED_assetlist_iterate(library_ref, [&](AssetHandle asset) {
       if (!ED_asset_filter_matches_asset(&type_filter, &asset)) {
         return true;
       }
@@ -84,7 +84,7 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree &node
         return true;
       }
       const LibraryCatalog &library_catalog = id_to_catalog_map.lookup(meta_data.catalog_id);
-      assets_per_path.add(library_catalog.catalog->path, LibraryAsset{library, asset});
+      assets_per_path.add(library_catalog.catalog->path, LibraryAsset{library_ref, asset});
       return true;
     });
   }
@@ -141,7 +141,7 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
         &screen.id, &RNA_AssetLibraryReference, new AssetLibraryReference(item.library_ref)};
     uiLayoutSetContextPointer(row, "asset_library_ref", &library_ptr);
 
-    uiItemO(layout, ED_asset_handle_get_name(&item.handle), ICON_NONE, "NODE_OT_add_group_asset");
+    uiItemO(row, ED_asset_handle_get_name(&item.handle), ICON_NONE, "NODE_OT_add_group_asset");
   }
 
   catalog_item->foreach_child([&](bke::AssetCatalogTreeItem &child_item) {
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc
index 6d46d965a5a..bf2920ad1ed 100644
--- a/source/blender/editors/space_node/node_add.cc
+++ b/source/blender/editors/space_node/node_add.cc
@@ -371,10 +371,10 @@ void NODE_OT_add_group(wmOperatorType *ot)
 /** \name Add Node Group Asset Operator
  * \{ */
 
-static int add_node_group_asset(const bContext &C,
-                                const AssetLibraryReference &library_ref,
-                                const AssetHandle asset,
-                                ReportList &reports)
+static bool add_node_group_asset(const bContext &C,
+                                 const AssetLibraryReference &library_ref,
+                                 const AssetHandle asset,
+                                 ReportList &reports)
 {
   Main &bmain = *CTX_data_main(&C);
   SpaceNode &snode = *CTX_wm_space_node(&C);
@@ -383,13 +383,13 @@ static int add_node_group_asset(const bContext &C,
   bNodeTree *node_group = reinterpret_cast<bNodeTree *>(
       asset::get_local_id_from_asset_or_append_and_reuse(bmain, library_ref, asset));
   if (!node_group) {
-    return OPERATOR_CANCELLED;
+    return false;
   }
   if (!node_group_add_poll(edit_tree, *node_group, reports)) {
     /* Remove the node group if it was newly appended but can't be added to the tree. */
     id_us_plus(&node_group->id);
     BKE_id_free_us(&bmain, node_group);
-    return OPERATOR_CANCELLED;
+    return false;
   }
 
   ED_preview_kill_jobs(CTX_wm_manager(&C), CTX_data_main(&C));
@@ -398,8 +398,9 @@ static int add_node_group_asset(const bContext &C,
       C, ntreeTypeFind(node_group->idname)->group_idname, snode.runtime->cursor);
   if (!group_node) {
     BKE_report(&reports, RPT_WARNING, "Could not add node group");
-    return OPERATOR_CANCELLED;
+    return false;
   }
+  group_node->flag &= ~NODE_OPTIONS;
 
   group_node->id = &node_group->id;
   id_us_plus(group_node->id);
@@ -408,24 +409,9 @@ static int add_node_group_asset(const bContext &C,
   nodeSetActive(&edit_tree, group_node);
   ED_node_tree_propagate_change(&C, &bmain, nullptr);
   DEG_relations_tag_update(&bmain);
-  return OPERATOR_FINISHED;
-}
 
-// static int node_add_group_asset_exec(bContext *C, wmOperator *op)
-// {
-
-//   PointerRNA asset_ptr = RNA_pointer_get(op->ptr, "asset_handle");
-//   if (RNA_pointer_is_null(&asset_ptr)) {
-//     return OPERATOR_CANCELLED;
-//   }
-//   PointerRNA library_ptr = RNA_pointer_get(op->ptr, "library_reference");
-//   if (RNA_pointer_is_null(&library_ptr)) {
-//     return OPERATOR_CANCELLED;
-//   }
-//   const AssetHandle asset = *static_cast<AssetHandle *>(asset_ptr.data);
-//   const AssetLibraryReference &library = *static_cast<AssetLibraryReference
-//   *>(library_ptr.data);
-// }
+  return true;
+}
 
 static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
@@ -451,7 +437,16 @@ static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEven
 
   snode.runtime->cursor /= UI_DPI_FAC;
 
-  return add_node_group_asset(*C, *library_ref, handle, *op->reports);
+  const bool success = add_node_group_asset(*C, *library_ref, handle, *op->reports);
+
+  wmOperatorType *ot = WM_operatortype_find("NODE_OT_translate_attach_remove_on_cancel", true);
+  BLI_assert(ot);
+  PointerRNA ptr;
+  WM_operator_properties_create_ptr(&ptr, ot);
+  WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, nullptr);
+  WM_operator_properties_free(&ptr);
+
+  return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }
 
 void NODE_OT_add_group_asset(wmOperatorType *ot)
@@ -460,7 +455,6 @@ void NODE_OT_add_group_asset(wmOperatorType *ot)
   ot->description = "Add a node group asset to the node editor";
   ot->idname = "NODE_OT_add_group_asset";
 
-  // ot->exec = node_add_group_asset_exec;
   ot->invoke = node_add_group_asset_invoke;
   ot->poll = node_add_group_poll;



More information about the Bf-blender-cvs mailing list