Outliner: Tweaks for Driver Operators
authorJoshua Leung <aligorith@gmail.com>
Wed, 21 Oct 2009 05:59:51 +0000 (05:59 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 21 Oct 2009 05:59:51 +0000 (05:59 +0000)
* Driver adding/removing operators in the Outliner now work properly for arrays
* Renamed these operators so that their names are more indicative of how they work (i.e. based on the data in the Outliner that is selected)
* Added a menu labelled 'Edit' in the Datablocks view which gives access to (and includes the hotkeys for) these tools.

release/scripts/ui/space_outliner.py
source/blender/editors/space_outliner/outliner.c
source/blender/editors/space_outliner/outliner_intern.h
source/blender/editors/space_outliner/outliner_ops.c

index 87c31e1aa949db29641c9e2cd9977d6b959b7cbd..40816309e7e97fd86d0eec65a54abcd71a1d7d85 100644 (file)
@@ -17,6 +17,8 @@ class OUTLINER_HT_header(bpy.types.Header):
                if context.area.show_menus:
                        sub = row.row(align=True)
                        sub.itemM("OUTLINER_MT_view")
+                       if space.display_mode == 'DATABLOCKS':
+                               sub.itemM("OUTLINER_MT_edit_datablocks")
 
                layout.itemR(space, "display_mode", text="")
                
@@ -26,13 +28,16 @@ class OUTLINER_HT_header(bpy.types.Header):
                        row = layout.row(align=True)
                        row.itemO("outliner.keyingset_add_selected", icon='ICON_ZOOMIN', text="")
                        row.itemO("outliner.keyingset_remove_selected", icon='ICON_ZOOMOUT', text="")
+                       
                        if ks:
+                               row = layout.row(align=False)
                                row.item_pointerR(scene, "active_keying_set", scene, "keying_sets", text="")
                                
                                row = layout.row(align=True)
                                row.itemO("anim.insert_keyframe", text="", icon='ICON_KEY_HLT')
                                row.itemO("anim.delete_keyframe", text="", icon='ICON_KEY_DEHLT')
                        else:
+                               row = layout.row(align=False)
                                row.itemL(text="No Keying Set active")
 
 class OUTLINER_MT_view(bpy.types.Menu):
@@ -51,6 +56,23 @@ class OUTLINER_MT_view(bpy.types.Menu):
 
                col.itemO("outliner.show_one_level")
                col.itemO("outliner.show_hierarchy")
+               
+class OUTLINER_MT_edit_datablocks(bpy.types.Menu):
+       __label__ = "Edit"
+       
+       def draw(self, context):
+               layout = self.layout
+               
+               col = layout.column()
+
+               col.itemO("outliner.keyingset_add_selected")
+               col.itemO("outliner.keyingset_remove_selected")
+               
+               col.itemS()
+               
+               col.itemO("outliner.drivers_add_selected")
+               col.itemO("outliner.drivers_delete_selected")
 
 bpy.types.register(OUTLINER_HT_header)
 bpy.types.register(OUTLINER_MT_view)
+bpy.types.register(OUTLINER_MT_edit_datablocks)
index 2612f8a024c3f58ab1bd31c2b3796ca4bef3118b..5e67e9372fc80407122a2374f63f180fe5795461 100644 (file)
@@ -3771,21 +3771,39 @@ static void do_outliner_drivers_editop(SpaceOops *soops, ListBase *tree, short m
                        }
                        
                        /* only if ID and path were set, should we perform any actions */
+                       // FIXME: if whole array flag is set, mus add the entire array
                        if (id && path) {
-                               /* action depends on mode */
-                               switch (mode) {
-                                       case DRIVERS_EDITMODE_ADD:
-                                       {
-                                               /* add a new driver with the information obtained (only if valid) */
-                                               ANIM_add_driver(id, path, array_index, flag, DRIVER_TYPE_AVERAGE);
-                                       }
-                                               break;
-                                       case DRIVERS_EDITMODE_REMOVE:
-                                       {
-                                               /* remove driver matching the information obtained (only if valid) */
-                                               ANIM_remove_driver(id, path, array_index, flag);
+                               int arraylen, i;
+                               
+                               /* array checks */
+                               if (flag & KSP_FLAG_WHOLE_ARRAY) {
+                                       /* entire array was selected, so add drivers for all */
+                                       arraylen= RNA_property_array_length(&te->rnaptr, te->directdata);
+                               }
+                               else
+                                       arraylen= array_index;
+                               
+                               /* we should do at least one step */
+                               if (arraylen == array_index)
+                                       arraylen++;
+                               
+                               /* for each array element we should affect, add driver */
+                               for (; array_index < arraylen; array_index++) {
+                                       /* action depends on mode */
+                                       switch (mode) {
+                                               case DRIVERS_EDITMODE_ADD:
+                                               {
+                                                       /* add a new driver with the information obtained (only if valid) */
+                                                       ANIM_add_driver(id, path, array_index, flag, DRIVER_TYPE_PYTHON);
+                                               }
+                                                       break;
+                                               case DRIVERS_EDITMODE_REMOVE:
+                                               {
+                                                       /* remove driver matching the information obtained (only if valid) */
+                                                       ANIM_remove_driver(id, path, array_index, flag);
+                                               }
+                                                       break;
                                        }
-                                               break;
                                }
                                
                                /* free path, since it had to be generated */
@@ -3815,16 +3833,16 @@ static int outliner_drivers_addsel_exec(bContext *C, wmOperator *op)
        do_outliner_drivers_editop(soutliner, &soutliner->tree, DRIVERS_EDITMODE_ADD);
        
        /* send notifiers */
-       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
+       WM_event_add_notifier(C, ND_KEYS, NULL); // XXX
        
        return OPERATOR_FINISHED;
 }
 
-void OUTLINER_OT_drivers_add(wmOperatorType *ot)
+void OUTLINER_OT_drivers_add_selected(wmOperatorType *ot)
 {
        /* api callbacks */
-       ot->idname= "OUTLINER_OT_drivers_add";
-       ot->name= "Add Drivers";
+       ot->idname= "OUTLINER_OT_drivers_add_selected";
+       ot->name= "Add Drivers for Selected";
        ot->description= "Add drivers to selected items.";
        
        /* api callbacks */
@@ -3850,16 +3868,16 @@ static int outliner_drivers_deletesel_exec(bContext *C, wmOperator *op)
        do_outliner_drivers_editop(soutliner, &soutliner->tree, DRIVERS_EDITMODE_REMOVE);
        
        /* send notifiers */
-       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
+       WM_event_add_notifier(C, ND_KEYS, NULL); // XXX
        
        return OPERATOR_FINISHED;
 }
 
-void OUTLINER_OT_drivers_delete(wmOperatorType *ot)
+void OUTLINER_OT_drivers_delete_selected(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->idname= "OUTLINER_OT_drivers_delete";
-       ot->name= "Delete Drivers";
+       ot->idname= "OUTLINER_OT_drivers_delete_selected";
+       ot->name= "Delete Drivers for Selected";
        ot->description= "Delete drivers assigned to selected items.";
        
        /* api callbacks */
index c71b5181d16320a1ca76bb99bad8c8d15031c6f1..a1fc2f11bc43ce2c42e4c757d60f0ad515009727 100644 (file)
@@ -143,8 +143,8 @@ void OUTLINER_OT_visibility_toggle(struct wmOperatorType *ot);
 void OUTLINER_OT_keyingset_add_selected(struct wmOperatorType *ot);
 void OUTLINER_OT_keyingset_remove_selected(struct wmOperatorType *ot);
 
-void OUTLINER_OT_drivers_add(struct wmOperatorType *ot);
-void OUTLINER_OT_drivers_delete(struct wmOperatorType *ot);
+void OUTLINER_OT_drivers_add_selected(struct wmOperatorType *ot);
+void OUTLINER_OT_drivers_delete_selected(struct wmOperatorType *ot);
 
 #if 0
 extern void outliner_mouse_event(Scene *scene, ARegion *ar, SpaceOops *soops, short event);
index 3cdd054fe0e991107c99aef27cc406e14c4c0dc6..431801d50f2c69de554ca887766bc3c9c68f4b8e 100644 (file)
@@ -70,8 +70,8 @@ void outliner_operatortypes(void)
        WM_operatortype_append(OUTLINER_OT_keyingset_add_selected);
        WM_operatortype_append(OUTLINER_OT_keyingset_remove_selected);
        
-       WM_operatortype_append(OUTLINER_OT_drivers_add);
-       WM_operatortype_append(OUTLINER_OT_drivers_delete);
+       WM_operatortype_append(OUTLINER_OT_drivers_add_selected);
+       WM_operatortype_append(OUTLINER_OT_drivers_delete_selected);
 }
 
 void outliner_keymap(wmKeyConfig *keyconf)
@@ -110,7 +110,7 @@ void outliner_keymap(wmKeyConfig *keyconf)
        WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe", IKEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe", IKEY, KM_PRESS, KM_ALT, 0);
        
-       WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_add", DKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_delete", DKEY, KM_PRESS, KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_add_selected", DKEY, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_delete_selected", DKEY, KM_PRESS, KM_ALT, 0);
 }