Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-12-17 20:15:38 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-12-17 20:15:38 +0300
commit0af48c227bdcd1d11a0bf51b9527dcbdc6d2ba80 (patch)
tree8fd27c2a2ef97c944048627d7d51c0d7b7792519 /source/blender/editors
parent1975ee5eecc17514b441fb9ac921063c38fcabc4 (diff)
Copy To Selected
Until we have proper multi-object editing, this adds a Copy To Selected option to the right mouse button menu for Object and Bone properties, to copy the value from the active object to the selected objects. Also includes some implementation changes to reset to default operator.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/UI_interface.h2
-rw-r--r--source/blender/editors/include/UI_view2d.h2
-rw-r--r--source/blender/editors/interface/interface_handlers.c3
-rw-r--r--source/blender/editors/interface/interface_ops.c219
-rw-r--r--source/blender/editors/interface/view2d_ops.c2
-rw-r--r--source/blender/editors/space_api/spacetypes.c3
6 files changed, 127 insertions, 104 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index f0e52a13d3f..8e44d7f386e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -689,7 +689,7 @@ void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char
void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname);
/* UI Operators */
-void ui_buttons_operatortypes(void);
+void UI_buttons_operatortypes(void);
/* Helpers for Operators */
void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index);
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 8fbff25589d..e3b00c21d04 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -195,7 +195,7 @@ void UI_view2d_text_cache_rectf(struct View2D *v2d, struct rctf *rect, char *str
void UI_view2d_text_cache_draw(struct ARegion *ar);
/* operators */
-void ui_view2d_operatortypes(void);
+void UI_view2d_operatortypes(void);
void UI_view2d_keymap(struct wmKeyConfig *keyconf);
#endif /* UI_VIEW2D_H */
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 9604704dde8..88868a61592 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3506,7 +3506,8 @@ static int ui_but_menu(bContext *C, uiBut *but)
else
uiItemO(layout, "Reset to Default Value", 0, "UI_OT_reset_default_button");
- uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_clipboard_button");
+ uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_data_path_button");
+ uiItemO(layout, "Copy To Selected", 0, "UI_OT_copy_to_selected_button");
uiItemS(layout);
}
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index a5caf1c930b..d1204b41a28 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -59,18 +59,17 @@
/* ********************************************************** */
-/* Copy to Clipboard Button Operator ------------------------ */
+/* Copy Data Path Operator ------------------------ */
-static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
+static int copy_data_path_button_exec(bContext *C, wmOperator *op)
{
PointerRNA ptr;
- PropertyRNA *prop= NULL;
+ PropertyRNA *prop;
char *path;
- short success= 0;
+ int success= 0;
int index;
/* try to create driver using property retrieved from UI */
- memset(&ptr, 0, sizeof(PointerRNA));
uiAnimContextProperty(C, &ptr, &prop, &index);
if (ptr.data && prop) {
@@ -86,15 +85,15 @@ static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
}
-void UI_OT_copy_clipboard_button(wmOperatorType *ot)
+void UI_OT_copy_data_path_button(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Copy Data Path";
- ot->idname= "UI_OT_copy_clipboard_button";
+ ot->idname= "UI_OT_copy_data_path_button";
ot->description= "Copy the RNA data path for this property to the clipboard.";
/* callbacks */
- ot->exec= copy_clipboard_button_exec;
+ ot->exec= copy_data_path_button_exec;
//op->poll= ??? // TODO: need to have some valid property before this can be done
/* flags */
@@ -103,103 +102,34 @@ void UI_OT_copy_clipboard_button(wmOperatorType *ot)
/* Reset to Default Values Button Operator ------------------------ */
+static int reset_default_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ return (ptr.data && prop && RNA_property_editable(&ptr, prop));
+}
+
static int reset_default_button_exec(bContext *C, wmOperator *op)
{
PointerRNA ptr;
- PropertyRNA *prop= NULL;
- short success= 0;
- int index, len;
- int all = RNA_boolean_get(op->ptr, "all");
+ PropertyRNA *prop;
+ int success= 0;
+ int index, all = RNA_boolean_get(op->ptr, "all");
/* try to reset the nominated setting to its default value */
- memset(&ptr, 0, sizeof(PointerRNA));
uiAnimContextProperty(C, &ptr, &prop, &index);
/* if there is a valid property that is editable... */
if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
- /* get the length of the array to work with */
- len= RNA_property_array_length(&ptr, prop);
-
- /* get and set the default values as appropriate for the various types */
- switch (RNA_property_type(prop)) {
- case PROP_BOOLEAN:
- if (len) {
- if (all) {
- int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - boolean");
-
- RNA_property_boolean_get_default_array(&ptr, prop, tmparray);
- RNA_property_boolean_set_array(&ptr, prop, tmparray);
-
- MEM_freeN(tmparray);
- }
- else {
- int value= RNA_property_boolean_get_default_index(&ptr, prop, index);
- RNA_property_boolean_set_index(&ptr, prop, index, value);
- }
- }
- else {
- int value= RNA_property_boolean_get_default(&ptr, prop);
- RNA_property_boolean_set(&ptr, prop, value);
- }
- break;
- case PROP_INT:
- if (len) {
- if (all) {
- int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - int");
-
- RNA_property_int_get_default_array(&ptr, prop, tmparray);
- RNA_property_int_set_array(&ptr, prop, tmparray);
-
- MEM_freeN(tmparray);
- }
- else {
- int value= RNA_property_int_get_default_index(&ptr, prop, index);
- RNA_property_int_set_index(&ptr, prop, index, value);
- }
- }
- else {
- int value= RNA_property_int_get_default(&ptr, prop);
- RNA_property_int_set(&ptr, prop, value);
- }
- break;
- case PROP_FLOAT:
- if (len) {
- if (all) {
- float *tmparray= MEM_callocN(sizeof(float)*len, "reset_defaults - float");
-
- RNA_property_float_get_default_array(&ptr, prop, tmparray);
- RNA_property_float_set_array(&ptr, prop, tmparray);
-
- MEM_freeN(tmparray);
- }
- else {
- float value= RNA_property_float_get_default_index(&ptr, prop, index);
- RNA_property_float_set_index(&ptr, prop, index, value);
- }
- }
- else {
- float value= RNA_property_float_get_default(&ptr, prop);
- RNA_property_float_set(&ptr, prop, value);
- }
- break;
- case PROP_ENUM:
- {
- int value= RNA_property_enum_get_default(&ptr, prop);
- RNA_property_enum_set(&ptr, prop, value);
- }
- break;
-
- //case PROP_POINTER:
- //case PROP_STRING:
- default:
- // FIXME: many of the other types such as strings and pointers need this implemented too!
- break;
+ if(RNA_property_reset(&ptr, prop, (all)? -1: index)) {
+ /* perform updates required for this property */
+ RNA_property_update(C, &ptr, prop);
+ success= 1;
}
-
- /* perform updates required for this property */
- RNA_property_update(C, &ptr, prop);
-
- success= 1;
}
return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
@@ -213,12 +143,102 @@ void UI_OT_reset_default_button(wmOperatorType *ot)
ot->description= "Copy the RNA data path for this property to the clipboard.";
/* callbacks */
+ ot->poll= reset_default_button_poll;
ot->exec= reset_default_button_exec;
- //op->poll= ??? // TODO: need to have some valid property before this can be done
/* flags */
- ot->flag= OPTYPE_REGISTER;
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array.");
+}
+
+/* Copy To Selected Operator ------------------------ */
+
+static int copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb)
+{
+ if(RNA_struct_is_a(ptr->type, &RNA_Object))
+ *lb = CTX_data_collection_get(C, "selected_editable_objects");
+ else if(RNA_struct_is_a(ptr->type, &RNA_EditBone))
+ *lb = CTX_data_collection_get(C, "selected_editable_bones");
+ else if(RNA_struct_is_a(ptr->type, &RNA_PoseBone))
+ *lb = CTX_data_collection_get(C, "selected_pose_bones");
+ else
+ return 0;
+ return 1;
+}
+
+static int copy_to_selected_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index, success= 0;
+
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ if (ptr.data && prop) {
+ CollectionPointerLink *link;
+ ListBase lb;
+
+ if(copy_to_selected_list(C, &ptr, &lb)) {
+ for(link= lb.first; link; link=link->next)
+ if(link->ptr.data != ptr.data && RNA_property_editable(&link->ptr, prop))
+ success= 1;
+
+ BLI_freelistN(&lb);
+ }
+ }
+
+ return success;
+}
+
+static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int success= 0;
+ int index, all = RNA_boolean_get(op->ptr, "all");
+
+ /* try to reset the nominated setting to its default value */
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ /* if there is a valid property that is editable... */
+ if (ptr.data && prop) {
+ CollectionPointerLink *link;
+ ListBase lb;
+
+ if(copy_to_selected_list(C, &ptr, &lb)) {
+ for(link= lb.first; link; link=link->next) {
+ if(link->ptr.data != ptr.data && RNA_property_editable(&link->ptr, prop)) {
+ if(RNA_property_copy(&link->ptr, &ptr, prop, (all)? -1: index)) {
+ RNA_property_update(C, &link->ptr, prop);
+ success= 1;
+ }
+ }
+ }
+
+ BLI_freelistN(&lb);
+ }
+ }
+
+ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void UI_OT_copy_to_selected_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Copy To Selected";
+ ot->idname= "UI_OT_copy_to_selected_button";
+ ot->description= "Copy property from this object to selected objects or bones.";
+
+ /* callbacks */
+ ot->poll= copy_to_selected_button_poll;
+ ot->exec= copy_to_selected_button_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
/* properties */
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array.");
}
@@ -226,9 +246,10 @@ void UI_OT_reset_default_button(wmOperatorType *ot)
/* ********************************************************* */
/* Registration */
-void ui_buttons_operatortypes(void)
+void UI_buttons_operatortypes(void)
{
- WM_operatortype_append(UI_OT_copy_clipboard_button);
+ WM_operatortype_append(UI_OT_copy_data_path_button);
WM_operatortype_append(UI_OT_reset_default_button);
+ WM_operatortype_append(UI_OT_copy_to_selected_button);
}
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 8bd840f7e84..6742df351d1 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1403,7 +1403,7 @@ void VIEW2D_OT_reset(wmOperatorType *ot)
/* ********************************************************* */
/* Registration */
-void ui_view2d_operatortypes(void)
+void UI_view2d_operatortypes(void)
{
WM_operatortype_append(VIEW2D_OT_pan);
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index 8cf56ae3eda..90457c05fa7 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -101,7 +101,8 @@ void ED_spacetypes_init(void)
ED_operatortypes_sound();
ED_operatortypes_render();
- ui_view2d_operatortypes();
+ UI_view2d_operatortypes();
+ UI_buttons_operatortypes();
spacetypes = BKE_spacetypes_list();
for(type=spacetypes->first; type; type=type->next)