UI: de-duplicate UI_OT_copy_to_selected_button poll/exec
This commit is contained in:
@@ -283,14 +283,24 @@ static bool copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb, bo
|
||||
return true;
|
||||
}
|
||||
|
||||
static int copy_to_selected_button_poll(bContext *C)
|
||||
/**
|
||||
* called from both exec & poll
|
||||
*
|
||||
* \note: normally we wouldn't call a loop from within a poll function,
|
||||
* However this is a special case, and for regular poll calls, getting
|
||||
* the context from the button will fail early.
|
||||
*/
|
||||
static bool copy_to_selected_button(bContext *C, bool all, bool poll)
|
||||
{
|
||||
PointerRNA ptr, lptr, idptr;
|
||||
PropertyRNA *prop, *lprop;
|
||||
int index, success = 0;
|
||||
bool success = false;
|
||||
int index;
|
||||
|
||||
/* try to reset the nominated setting to its default value */
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
/* if there is a valid property that is editable... */
|
||||
if (ptr.data && prop) {
|
||||
char *path = NULL;
|
||||
bool use_path;
|
||||
@@ -314,8 +324,18 @@ static int copy_to_selected_button_poll(bContext *C)
|
||||
}
|
||||
|
||||
if (lprop == prop) {
|
||||
if (RNA_property_editable(&lptr, prop))
|
||||
success = 1;
|
||||
if (RNA_property_editable(&lptr, lprop)) {
|
||||
if (poll) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
|
||||
RNA_property_update(C, &lptr, prop);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,58 +350,19 @@ static int copy_to_selected_button_poll(bContext *C)
|
||||
return success;
|
||||
}
|
||||
|
||||
static int copy_to_selected_button_poll(bContext *C)
|
||||
{
|
||||
return copy_to_selected_button(C, false, true);
|
||||
}
|
||||
|
||||
static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
PointerRNA ptr, lptr, idptr;
|
||||
PropertyRNA *prop, *lprop;
|
||||
bool success = false;
|
||||
int index;
|
||||
bool success;
|
||||
|
||||
const bool all = RNA_boolean_get(op->ptr, "all");
|
||||
|
||||
/* try to reset the nominated setting to its default value */
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
/* if there is a valid property that is editable... */
|
||||
if (ptr.data && prop) {
|
||||
char *path = NULL;
|
||||
bool use_path;
|
||||
CollectionPointerLink *link;
|
||||
ListBase lb;
|
||||
success = copy_to_selected_button(C, all, false);
|
||||
|
||||
if (!copy_to_selected_list(C, &ptr, &lb, &use_path))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
if (!use_path || (path = RNA_path_from_ID_to_property(&ptr, prop))) {
|
||||
for (link = lb.first; link; link = link->next) {
|
||||
if (link->ptr.data != ptr.data) {
|
||||
if (use_path) {
|
||||
lprop = NULL;
|
||||
RNA_id_pointer_create(link->ptr.id.data, &idptr);
|
||||
RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
|
||||
}
|
||||
else {
|
||||
lptr = link->ptr;
|
||||
lprop = prop;
|
||||
}
|
||||
|
||||
if (lprop == prop) {
|
||||
if (RNA_property_editable(&lptr, lprop)) {
|
||||
if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
|
||||
RNA_property_update(C, &lptr, prop);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path)
|
||||
MEM_freeN(path);
|
||||
}
|
||||
|
||||
BLI_freelistN(&lb);
|
||||
}
|
||||
|
||||
return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user