Merged 38822-39182
[blender.git] / source / blender / editors / interface / interface_templates.c
index f35102e..6288898 100644 (file)
@@ -53,6 +53,7 @@
 #include "BKE_displist.h"
 
 #include "ED_screen.h"
+#include "ED_object.h"
 #include "ED_render.h"
 
 #include "RNA_access.h"
@@ -275,18 +276,28 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
                        break;
                case UI_ID_ALONE:
                        if(id) {
+                               const int do_scene_obj= (GS(id->name) == ID_OB) &&
+                                                       (template->ptr.type == &RNA_SceneObjects);
+
                                /* make copy */
-                               if(id_copy(id, &newid, 0) && newid) {
-                                       /* copy animation actions too */
-                                       BKE_copy_animdata_id_action(id);
-                                       /* us is 1 by convention, but RNA_property_pointer_set
-                                          will also incremement it, so set it to zero */
-                                       newid->us= 0;
-
-                                       /* assign copy */
-                                       RNA_id_pointer_create(newid, &idptr);
-                                       RNA_property_pointer_set(&template->ptr, template->prop, idptr);
-                                       RNA_property_update(C, &template->ptr, template->prop);
+                               if(do_scene_obj) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       ED_object_single_user(scene, (struct Object *)id);
+                                       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
+                               }
+                               else {
+                                       if(id_copy(id, &newid, 0) && newid) {
+                                               /* copy animation actions too */
+                                               BKE_copy_animdata_id_action(id);
+                                               /* us is 1 by convention, but RNA_property_pointer_set
+                                                  will also incremement it, so set it to zero */
+                                               newid->us= 0;
+
+                                               /* assign copy */
+                                               RNA_id_pointer_create(newid, &idptr);
+                                               RNA_property_pointer_set(&template->ptr, template->prop, idptr);
+                                               RNA_property_update(C, &template->ptr, template->prop);
+                                       }
                                }
                        }
                        break;
@@ -404,10 +415,7 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
 
                        sprintf(str, "%d", id->us);
 
-                       if(id->us<10)
-                               but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X,UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
-                       else
-                               but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X+10,UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
+                       but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
 
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE));
                        if(!id_copy(id, NULL, 1 /* test only */) || (idfrom && idfrom->lib) || !editable)
@@ -1884,7 +1892,7 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam
        col = uiLayoutColumn(layout, 0);
        row= uiLayoutRow(col, 1);
        
-       but= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, propname, -1, 0.0, 0.0, 0, 0, "");
+       but= uiDefButR_prop(block, HSVCIRCLE, 0, "",    0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop, -1, 0.0, 0.0, 0, 0, "");
 
        if(lock) {
                but->flag |= UI_BUT_COLOR_LOCK;
@@ -1903,7 +1911,7 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam
        uiItemS(row);
        
        if (value_slider)
-               uiDefButR(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, propname, -1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
+               uiDefButR_prop(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, prop, -1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
 }
 
 /********************* Layer Buttons Template ************************/
@@ -2034,7 +2042,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int
        return rnaicon;
 }
 
-static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, const char *activepropname)
+static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop)
 {
        uiBlock *block= uiLayoutGetBlock(layout);
        uiBut *but;
@@ -2048,7 +2056,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
        /* list item behind label & other buttons */
        sub= uiLayoutRow(overlap, 0);
 
-       but= uiDefButR(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
+       but= uiDefButR_prop(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activeprop, 0, 0, i, 0, 0, "");
        uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
 
        sub= uiLayoutRow(overlap, 0);
@@ -2207,7 +2215,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
                                        row= uiLayoutRow(col, 0);
 
                                icon= list_item_icon_get(C, &itemptr, rnaicon, 1);
-                               but= uiDefIconButR(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
+                               but= uiDefIconButR_prop(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activeprop, 0, 0, i, 0, 0, "");
                                uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
                                
 
@@ -2247,7 +2255,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
 
                /* next/prev button */
                sprintf(str, "%d :", i);
-               but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, "");
+               but= uiDefIconTextButR_prop(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, "");
                if(i == 0)
                        uiButSetFlag(but, UI_BUT_DISABLED);
        }
@@ -2286,7 +2294,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
                        /* create list items */
                        RNA_PROP_BEGIN(ptr, itemptr, prop) {
                                if(i >= pa->list_scroll && i<pa->list_scroll+items)
-                                       list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activepropname);
+                                       list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop);
 
                                i++;
                        }