diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-11 02:33:54 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-11 02:33:54 +0400 |
commit | 6238fb4c43682f37172ddbb5a6bdac3dcd2a3aa6 (patch) | |
tree | 828ed444a8554eae63778a3dbb3cb3a7381459ca | |
parent | 7cdaf56b30381881d174e70bbb6f808470e7b74a (diff) |
UI: de-duplicate UI_OT_copy_to_selected_button poll/exec
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 83 |
1 files changed, 32 insertions, 51 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 4bbccec7f9d..cef7128cd5e 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -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_exec(bContext *C, wmOperator *op) +static int copy_to_selected_button_poll(bContext *C) { - PointerRNA ptr, lptr, idptr; - PropertyRNA *prop, *lprop; - bool success = false; - int index; - 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; - - if (!copy_to_selected_list(C, &ptr, &lb, &use_path)) - return OPERATOR_CANCELLED; + return copy_to_selected_button(C, false, true); +} - 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; - } +static int copy_to_selected_button_exec(bContext *C, wmOperator *op) +{ + bool success; - 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; - } - } - } - } - } + const bool all = RNA_boolean_get(op->ptr, "all"); - if (path) - MEM_freeN(path); - } + success = copy_to_selected_button(C, all, false); - BLI_freelistN(&lb); - } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } |