UI: deduplicate code for Copy To Selected and Alt-button tweaking

This resolves an old TODO to deduplicate code in copy_to_selected_button
& ui_selectcontext_begin.
This is also in hindsight of adding id-property support [incl. Geometry
Nodes modifier properties] for this in the next commit.
No behavior change expected here.

ref T93983 & D13573
This commit is contained in:
Philipp Oeser 2021-12-16 13:03:39 +01:00
parent 3e04d37529
commit 6da23db5e0
Notes: blender-bot 2023-02-13 16:49:09 +01:00
Referenced by issue #93983, Copy To Selected (also ALT-changing with multiple objects selected) does not work with ID properties (this includes Geometry Nodes modifier UIs)
3 changed files with 106 additions and 87 deletions

View File

@ -3007,6 +3007,13 @@ bool UI_context_copy_to_selected_list(struct bContext *C,
struct ListBase *r_lb,
bool *r_use_path_from_id,
char **r_path);
bool UI_context_copy_to_selected_check(struct PointerRNA *ptr,
struct PointerRNA *ptr_link,
struct PropertyRNA *prop,
const char *path,
bool use_path_from_id,
struct PointerRNA *r_ptr,
struct PropertyRNA **r_prop);
/* Helpers for Operators */
uiBut *UI_context_active_but_get(const struct bContext *C);

View File

@ -1787,7 +1787,7 @@ static bool ui_but_is_drag_toggle(const uiBut *but)
static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore *selctx_data)
{
PointerRNA lptr, idptr;
PointerRNA lptr;
PropertyRNA *lprop;
bool success = false;
@ -1821,68 +1821,48 @@ static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore
if (i >= selctx_data->elems_len) {
break;
}
uiSelectContextElem *other = &selctx_data->elems[i];
/* TODO: de-duplicate copy_to_selected_button. */
if (link->ptr.data != ptr.data) {
if (use_path_from_id) {
/* Path relative to ID. */
lprop = NULL;
RNA_id_pointer_create(link->ptr.owner_id, &idptr);
RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
}
else if (path) {
/* Path relative to elements from list. */
lprop = NULL;
RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
}
else {
lptr = link->ptr;
lprop = prop;
}
/* lptr might not be the same as link->ptr! */
if ((lptr.data != ptr.data) && (lprop == prop) && RNA_property_editable(&lptr, lprop)) {
other->ptr = lptr;
if (is_array) {
if (rna_type == PROP_FLOAT) {
other->val_f = RNA_property_float_get_index(&lptr, lprop, index);
}
else if (rna_type == PROP_INT) {
other->val_i = RNA_property_int_get_index(&lptr, lprop, index);
}
/* ignored for now */
# if 0
else if (rna_type == PROP_BOOLEAN) {
other->val_b = RNA_property_boolean_get_index(&lptr, lprop, index);
}
# endif
}
else {
if (rna_type == PROP_FLOAT) {
other->val_f = RNA_property_float_get(&lptr, lprop);
}
else if (rna_type == PROP_INT) {
other->val_i = RNA_property_int_get(&lptr, lprop);
}
/* ignored for now */
# if 0
else if (rna_type == PROP_BOOLEAN) {
other->val_b = RNA_property_boolean_get(&lptr, lprop);
}
else if (rna_type == PROP_ENUM) {
other->val_i = RNA_property_enum_get(&lptr, lprop);
}
# endif
}
continue;
}
if (!UI_context_copy_to_selected_check(
&ptr, &link->ptr, prop, path, use_path_from_id, &lptr, &lprop)) {
selctx_data->elems_len -= 1;
i -= 1;
continue;
}
selctx_data->elems_len -= 1;
i -= 1;
uiSelectContextElem *other = &selctx_data->elems[i];
other->ptr = lptr;
if (is_array) {
if (rna_type == PROP_FLOAT) {
other->val_f = RNA_property_float_get_index(&lptr, lprop, index);
}
else if (rna_type == PROP_INT) {
other->val_i = RNA_property_int_get_index(&lptr, lprop, index);
}
/* ignored for now */
# if 0
else if (rna_type == PROP_BOOLEAN) {
other->val_b = RNA_property_boolean_get_index(&lptr, lprop, index);
}
# endif
}
else {
if (rna_type == PROP_FLOAT) {
other->val_f = RNA_property_float_get(&lptr, lprop);
}
else if (rna_type == PROP_INT) {
other->val_i = RNA_property_int_get(&lptr, lprop);
}
/* ignored for now */
# if 0
else if (rna_type == PROP_BOOLEAN) {
other->val_b = RNA_property_boolean_get(&lptr, lprop);
}
else if (rna_type == PROP_ENUM) {
other->val_i = RNA_property_enum_get(&lptr, lprop);
}
# endif
}
}
success = (selctx_data->elems_len != 0);
}
}

View File

@ -26,7 +26,8 @@
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
#include "DNA_object_types.h" /* for OB_DATA_SUPPORT_ID */
#include "DNA_modifier_types.h" /* for handling geometry nodes properties */
#include "DNA_object_types.h" /* for OB_DATA_SUPPORT_ID */
#include "DNA_screen_types.h"
#include "DNA_text_types.h"
@ -985,6 +986,61 @@ bool UI_context_copy_to_selected_list(bContext *C,
return true;
}
bool UI_context_copy_to_selected_check(PointerRNA *ptr,
PointerRNA *ptr_link,
PropertyRNA *prop,
const char *path,
bool use_path_from_id,
PointerRNA *r_ptr,
PropertyRNA **r_prop)
{
PointerRNA idptr;
PropertyRNA *lprop;
PointerRNA lptr;
if (ptr_link->data == ptr->data) {
return false;
}
if (use_path_from_id) {
/* Path relative to ID. */
lprop = NULL;
RNA_id_pointer_create(ptr_link->owner_id, &idptr);
RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
}
else if (path) {
/* Path relative to elements from list. */
lprop = NULL;
RNA_path_resolve_property(ptr_link, path, &lptr, &lprop);
}
else {
lptr = *ptr_link;
lprop = prop;
}
if (lptr.data == ptr->data) {
/* temp_ptr might not be the same as ptr_link! */
return false;
}
if ((lprop != prop)) {
return false;
}
if (!RNA_property_editable(&lptr, lprop)) {
return false;
}
if (r_ptr) {
*r_ptr = lptr;
}
if (r_prop) {
*r_prop = lprop;
}
return true;
}
/**
* Called from both exec & poll.
*
@ -995,7 +1051,7 @@ bool UI_context_copy_to_selected_list(bContext *C,
static bool copy_to_selected_button(bContext *C, bool all, bool poll)
{
Main *bmain = CTX_data_main(C);
PointerRNA ptr, lptr, idptr;
PointerRNA ptr, lptr;
PropertyRNA *prop, *lprop;
bool success = false;
int index;
@ -1025,32 +1081,8 @@ static bool copy_to_selected_button(bContext *C, bool all, bool poll)
continue;
}
if (use_path_from_id) {
/* Path relative to ID. */
lprop = NULL;
RNA_id_pointer_create(link->ptr.owner_id, &idptr);
RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
}
else if (path) {
/* Path relative to elements from list. */
lprop = NULL;
RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
}
else {
lptr = link->ptr;
lprop = prop;
}
if (lptr.data == ptr.data) {
/* lptr might not be the same as link->ptr! */
continue;
}
if (lprop != prop) {
continue;
}
if (!RNA_property_editable(&lptr, lprop)) {
if (!UI_context_copy_to_selected_check(
&ptr, &link->ptr, prop, path, use_path_from_id, &lptr, &lprop)) {
continue;
}