From 43ad5cc88e609555087d18053b84e8351df5d7bb Mon Sep 17 00:00:00 2001 From: Angus Stanton Date: Mon, 1 Aug 2022 16:03:38 +0100 Subject: [PATCH 1/5] Asset Browser: Add selected_ids to filebrowser context Adds selected_ids member to the filebrowser context. This allows the 'Clear Asset' context menu operator to clear multiple assets. Updates the asset_ops.c logic to use 'selected_ids' if available, and fallback to 'id' if it is not. Differential Revision: https://developer.blender.org/D15593 --- .../blender/editors/asset/intern/asset_ops.cc | 17 +++++++++-------- source/blender/editors/space_file/space_file.c | 13 +++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index 05d0b7d0af4..0ef19176431 100644 --- a/source/blender/editors/asset/intern/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc @@ -51,19 +51,20 @@ static PointerRNAVec asset_operation_get_ids_from_context(const bContext *C) { PointerRNAVec ids; + ListBase ids_list; + /* First check if there is a selected_ids list to use. */ + if (CTX_data_selected_ids(C, &ids_list)) { + LISTBASE_FOREACH (CollectionPointerLink *, link, &ids_list) { + ids.append(link->ptr); + } + BLI_freelistN(&ids_list); + return ids; + } PointerRNA idptr = CTX_data_pointer_get_type(C, "id", &RNA_ID); if (idptr.data) { /* Single ID. */ ids.append(idptr); } - else { - ListBase list; - CTX_data_selected_ids(C, &list); - LISTBASE_FOREACH (CollectionPointerLink *, link, &list) { - ids.append(link->ptr); - } - BLI_freelistN(&list); - } return ids; } diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index a462476aae0..4f3631a6a94 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -957,6 +957,19 @@ static int /*eContextResult*/ file_context(const bContext *C, CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); return CTX_RESULT_OK; } + if (CTX_data_equals(member, "selected_ids")) { + const int num_files_filtered = filelist_files_ensure(sfile->files); + + for (int file_index = 0; file_index < num_files_filtered; file_index++) { + if (filelist_entry_is_selected(sfile->files, file_index)) { + FileDirEntry *entry = filelist_file(sfile->files, file_index); + ID *id = filelist_file_get_id(entry); + CTX_data_id_list_add(result, id); + } + } + CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); + return CTX_RESULT_OK; + } if (CTX_data_equals(member, "id")) { const FileDirEntry *file = filelist_file(sfile->files, params->active_file); if (file == NULL) { -- 2.30.2 From e43c976ee044e9b7e7120ac91d3ad54755971658 Mon Sep 17 00:00:00 2001 From: Angus Stanton Date: Mon, 1 Aug 2022 16:07:32 +0100 Subject: [PATCH 2/5] Formatting --- source/blender/editors/space_file/space_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 4f3631a6a94..69cff1f412c 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -967,7 +967,7 @@ static int /*eContextResult*/ file_context(const bContext *C, CTX_data_id_list_add(result, id); } } - CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); + CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); return CTX_RESULT_OK; } if (CTX_data_equals(member, "id")) { -- 2.30.2 From b6e42ef562d7d5d942db790a75ab24f6c86cd2cb Mon Sep 17 00:00:00 2001 From: Angus Stanton Date: Thu, 25 Aug 2022 11:50:45 +0100 Subject: [PATCH 3/5] Add null check to selected_ids retrieval --- source/blender/editors/space_file/space_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 69cff1f412c..79584ad9e98 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -964,6 +964,9 @@ static int /*eContextResult*/ file_context(const bContext *C, if (filelist_entry_is_selected(sfile->files, file_index)) { FileDirEntry *entry = filelist_file(sfile->files, file_index); ID *id = filelist_file_get_id(entry); + if (id == NULL) { + continue; + } CTX_data_id_list_add(result, id); } } -- 2.30.2 From 3f0afa4cc838918284301259241c52ce1f83d9d9 Mon Sep 17 00:00:00 2001 From: Angus Stanton Date: Mon, 13 Feb 2023 12:11:35 +0000 Subject: [PATCH 4/5] Temp commit --- .../scripts/modules/node_add_menu_notes.txt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 release/scripts/modules/node_add_menu_notes.txt diff --git a/release/scripts/modules/node_add_menu_notes.txt b/release/scripts/modules/node_add_menu_notes.txt new file mode 100644 index 00000000000..3acf24097d7 --- /dev/null +++ b/release/scripts/modules/node_add_menu_notes.txt @@ -0,0 +1,24 @@ +To draw node add menu: + +Call NODE_MT_add. +This calls operator to add the search. +A seperator is then added. +Finally, nodeitems_utils.draw_node_categories_menu +What does that do? +Well, before this, + +for, say, geo nodes. +Geo nodes are registered, with a list of categories (submenus). +Then, for each category, if the category fits the context, use +dynamic layout.menu("NODE_MT_category_<>>"). +This then calls draw_node_item, which calls item.draw for every item +in the category + +draw_node_catgoeries_menu +-> For each node category: draw_add_menu() +-> poll context for suitability: poll() +-> layout.menu("NODE_MT_category_%s" % category) +-> This MT operator draws each item in its category: draw_node_item() +-> For each item in category: item.draw(item, col, context) +-> item.draw = layout.operator("node.add_node") +-> node type determined by nodeitem type, surely this can be decoupled? \ No newline at end of file -- 2.30.2 From 45f198a2e5afd40b99655adba77161fc81e492e5 Mon Sep 17 00:00:00 2001 From: Angus Stanton Date: Mon, 13 Feb 2023 12:12:03 +0000 Subject: [PATCH 5/5] Remove file --- .../scripts/modules/node_add_menu_notes.txt | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 release/scripts/modules/node_add_menu_notes.txt diff --git a/release/scripts/modules/node_add_menu_notes.txt b/release/scripts/modules/node_add_menu_notes.txt deleted file mode 100644 index 3acf24097d7..00000000000 --- a/release/scripts/modules/node_add_menu_notes.txt +++ /dev/null @@ -1,24 +0,0 @@ -To draw node add menu: - -Call NODE_MT_add. -This calls operator to add the search. -A seperator is then added. -Finally, nodeitems_utils.draw_node_categories_menu -What does that do? -Well, before this, - -for, say, geo nodes. -Geo nodes are registered, with a list of categories (submenus). -Then, for each category, if the category fits the context, use -dynamic layout.menu("NODE_MT_category_<>>"). -This then calls draw_node_item, which calls item.draw for every item -in the category - -draw_node_catgoeries_menu --> For each node category: draw_add_menu() --> poll context for suitability: poll() --> layout.menu("NODE_MT_category_%s" % category) --> This MT operator draws each item in its category: draw_node_item() --> For each item in category: item.draw(item, col, context) --> item.draw = layout.operator("node.add_node") --> node type determined by nodeitem type, surely this can be decoupled? \ No newline at end of file -- 2.30.2