operator renaming for more consistent word ordering (_add/_remmove shold be last...
[blender-staging.git] / source / blender / editors / space_action / action_header.c
index 43e91ea6bb59cac4e9f266392376ed6ffc61ef33..d2dbb5fe3b07628f457d3166362c3cfc69776086 100644 (file)
@@ -43,6 +43,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_animsys.h"
+#include "BKE_action.h"
 #include "BKE_context.h"
 #include "BKE_screen.h"
 
@@ -67,7 +68,8 @@
 #include "action_intern.h"
 
 enum {
-       B_REDR= 0,
+       B_REDR= 1,
+       B_MODECHANGE,
 } eActHeader_Events;
 
 /* ********************************************************* */
@@ -84,13 +86,13 @@ static void act_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
        RNA_pointer_create(&sc->id, &RNA_SpaceDopeSheetEditor, sact, &spaceptr);
        
        /* create menu */
-       //uiItemO(layout, NULL, ICON_MENU_PANEL, "ACT_OT_properties");
+       //uiItemO(layout, NULL, ICON_MENU_PANEL, "ACTION_OT_properties");
        
        //uiItemS(layout);
        
-       uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0);
-       uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0, 0, 0);
-       uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0, 0, 0);
+       uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0);
+       uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0);
+       uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0);
        
        if (sact->flag & SACTION_DRAWTIME)
                uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle");
@@ -102,13 +104,13 @@ static void act_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
        uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_set");
        uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_clear");
        
-       uiItemO(layout, NULL, 0, "ACT_OT_previewrange_set");
+       uiItemO(layout, NULL, 0, "ACTION_OT_previewrange_set");
        
        uiItemS(layout);
        
-       uiItemO(layout, NULL, 0, "ACT_OT_frame_jump");
+       uiItemO(layout, NULL, 0, "ACTION_OT_frame_jump");
        
-       uiItemO(layout, NULL, 0, "ACT_OT_view_all");
+       uiItemO(layout, NULL, 0, "ACTION_OT_view_all");
        
        if (sa->full) 
                uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
@@ -118,21 +120,21 @@ static void act_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
 
 static void act_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       uiItemO(layout, NULL, 0, "ACT_OT_select_all_toggle");
-       uiItemBooleanO(layout, "Invert All", 0, "ACT_OT_select_all_toggle", "invert", 1);
+       uiItemO(layout, NULL, 0, "ACTION_OT_select_all_toggle");
+       uiItemBooleanO(layout, "Invert All", 0, "ACTION_OT_select_all_toggle", "invert", 1);
        
        uiItemS(layout);
        
-       uiItemO(layout, NULL, 0, "ACT_OT_select_border");
-       uiItemBooleanO(layout, "Border Axis Range", 0, "ACT_OT_select_border", "axis_range", 1);
+       uiItemO(layout, NULL, 0, "ACTION_OT_select_border");
+       uiItemBooleanO(layout, "Border Axis Range", 0, "ACTION_OT_select_border", "axis_range", 1);
        
        uiItemS(layout);
        
-       uiItemEnumO(layout, "Columns on Selected Keys", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_KEYS);
-       uiItemEnumO(layout, "Column on Current Frame", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_CFRA);
+       uiItemEnumO(layout, "Columns on Selected Keys", 0, "ACTION_OT_select_column", "mode", ACTKEYS_COLUMNSEL_KEYS);
+       uiItemEnumO(layout, "Column on Current Frame", 0, "ACTION_OT_select_column", "mode", ACTKEYS_COLUMNSEL_CFRA);
        
-       uiItemEnumO(layout, "Columns on Selected Markers", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
-       uiItemEnumO(layout, "Between Selected Markers", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
+       uiItemEnumO(layout, "Columns on Selected Markers", 0, "ACTION_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
+       uiItemEnumO(layout, "Between Selected Markers", 0, "ACTION_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
 }
 
 static void act_channelmenu(bContext *C, uiLayout *layout, void *arg_unused)
@@ -153,7 +155,7 @@ static void act_channelmenu(bContext *C, uiLayout *layout, void *arg_unused)
 
 static void act_gplayermenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       //uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu);
+       //uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu, NULL, NULL);
        //uiItemS(layout);
        //uiItemO(layout, NULL, 0, "NLAEDIT_OT_duplicate");
 }
@@ -165,132 +167,54 @@ static void act_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unus
        uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
 }
 
-static void act_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_CFRA);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_FRAME);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_SECOND);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_MARKER);
-}
-
-static void act_edit_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_CFRA);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_YAXIS);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_XAXIS);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_MARKER);
-}
-
-static void act_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_FREE);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_VECT);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_ALIGN);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
-}
-
-static void act_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_CONST);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_LIN);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_BEZ);
-}
-
-static void act_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
-       uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
-}
-
 static void act_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       uiItemMenuF(layout, "Transform", 0, act_edit_transformmenu);
-       uiItemMenuF(layout, "Snap", 0, act_edit_snapmenu);
-       uiItemMenuF(layout, "Mirror", 0, act_edit_mirrormenu);
+       uiItemMenuF(layout, "Transform", 0, act_edit_transformmenu, NULL);
+       uiItemMenuEnumO(layout, "Snap", 0, "ACTION_OT_snap", "type");
+       uiItemMenuEnumO(layout, "Mirror", 0, "ACTION_OT_mirror", "type");
        
        uiItemS(layout);
        
-       uiItemO(layout, NULL, 0, "ACT_OT_insert_keyframe");
+       uiItemO(layout, NULL, 0, "ACT_OT_keyframe_insert");
        
        uiItemS(layout);
        
-       uiItemO(layout, NULL, 0, "ACT_OT_duplicate");
-       uiItemO(layout, NULL, 0, "ACT_OT_delete");
+       uiItemO(layout, NULL, 0, "ACTION_OT_duplicate");
+       uiItemO(layout, NULL, 0, "ACTION_OT_delete");
        
        uiItemS(layout);
        
-       uiItemMenuF(layout, "Handle Type", 0, act_edit_handlesmenu);
-       uiItemMenuF(layout, "Interpolation Mode", 0, act_edit_ipomenu);
-       uiItemMenuF(layout, "Extrapolation Mode", 0, act_edit_expomenu);
+       uiItemMenuEnumO(layout, "Keyframe Type", 0, "ACTION_OT_keyframe_type", "type");
+       uiItemMenuEnumO(layout, "Handle Type", 0, "ACTION_OT_handle_type", "type");
+       uiItemMenuEnumO(layout, "Interpolation Type", 0, "ACTION_OT_interpolation_type", "type");
+       uiItemMenuEnumO(layout, "Extrapolation Type", 0, "ACTION_OT_extrapolation_type", "type");
        
        uiItemS(layout);
        
-       uiItemO(layout, NULL, 0, "ACT_OT_clean");
-       uiItemO(layout, NULL, 0, "ACT_OT_sample");
+       uiItemO(layout, NULL, 0, "ACTION_OT_clean");
+       uiItemO(layout, NULL, 0, "ACTION_OT_sample");
        
        uiItemS(layout);
        
-       uiItemO(layout, NULL, 0, "ACT_OT_copy");
-       uiItemO(layout, NULL, 0, "ACT_OT_paste");
+       uiItemO(layout, NULL, 0, "ACTION_OT_copy");
+       uiItemO(layout, NULL, 0, "ACTION_OT_paste");
 }
 
 /* ************************ header area region *********************** */
 
 static void do_action_buttons(bContext *C, void *arg, int event)
 {
-       switch (event) {
-               case B_REDR:
-                       ED_area_tag_redraw(CTX_wm_area(C));
-                       break;
+       /* special exception for mode changing - enable custom settings? */
+       if (event == B_MODECHANGE) {
+               SpaceAction *saction= CTX_wm_space_action(C);
+               
+               /* if the new mode is ShapeKeys editor, enable sliders */
+               if (saction->mode == SACTCONT_SHAPEKEY)
+                       saction->flag |= SACTION_SLIDERS;
        }
-}
-
-static void saction_idpoin_handle(bContext *C, ID *id, int event)
-{
-       SpaceAction *saction= CTX_wm_space_action(C);
-       Object *obact= CTX_data_active_object(C);
        
-       printf("actedit do id: \n");
-       
-       switch (event) {
-               case UI_ID_BROWSE:
-                       printf("browse \n");
-               case UI_ID_DELETE:
-                       printf("browse or delete \n");
-                       saction->action= (bAction*)id;
-                       
-                       /* we must set this action to be the one used by active object (if not pinned) */
-                       if (saction->pin == 0) {
-                               AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
-                               
-                               /* set action */
-                               printf("\tset action \n");
-                               adt->action= saction->action;
-                       }
-                       
-                       ED_area_tag_redraw(CTX_wm_area(C));
-                       ED_undo_push(C, "Assign Action");
-                       break;
-               case UI_ID_RENAME:
-                       printf("actedit rename \n");
-                       break;
-               case UI_ID_ADD_NEW:
-                       printf("actedit addnew \n");
-                       /* XXX not implemented */
-                       break;
-               case UI_ID_OPEN:
-                       printf("actedit open \n");
-                       /* XXX not implemented */
-                       break;
-               case UI_ID_ALONE:
-                       printf("actedit alone \n");
-                       /* XXX not implemented */
-                       break;
-               case UI_ID_PIN:
-                       printf("actedit pin \n");
-                       break;
-       }
+       ED_area_tag_refresh(CTX_wm_area(C));
+       ED_area_tag_redraw(CTX_wm_area(C));
 }
 
 void action_header_buttons(const bContext *C, ARegion *ar)
@@ -353,7 +277,7 @@ void action_header_buttons(const bContext *C, ARegion *ar)
        uiBlockSetEmboss(block, UI_EMBOSS);
        
        /* MODE SELECTOR */
-       uiDefButC(block, MENU, B_REDR
+       uiDefButC(block, MENU, B_MODECHANGE
                        "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
                        xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
                        "Editing modes for this editor");
@@ -361,76 +285,60 @@ void action_header_buttons(const bContext *C, ARegion *ar)
        
        xco += (90 + 8);
        
+       /* SUMMARY CHANNEL */
+       uiDefIconTextButBitI(block, TOG, ADS_FILTER_SUMMARY, B_REDR, ICON_BORDERMOVE, "Summary", xco,yco,XIC*4,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Include DopeSheet summary row"); // TODO: needs a better icon
+       xco += (XIC*4.5);
+       
        /*if (ac.data)*/ 
        {
                /* MODE-DEPENDENT DRAWING */
                if (saction->mode == SACTCONT_DOPESHEET) {
                        /* FILTERING OPTIONS */
-                       xco -= 10;
-                       
-                       //uiBlockBeginAlign(block);
-                               uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Only display selected Objects");
-                       //uiBlockEndAlign(block);
-                       xco += 5;
-                       
-                       uiBlockBeginAlign(block);
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSCE, B_REDR, ICON_SCENE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Scene Animation");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOWOR, B_REDR, ICON_WORLD_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display World Animation");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_SHAPEKEY_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display ShapeKeys");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL_DATA,     (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Materials");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Lamps");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Cameras");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Curves");
-                               uiDefIconButBitI(block, TOGN, ADS_FILTER_NOPART, B_REDR, ICON_PARTICLE_DATA,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Particles");
-                       uiBlockEndAlign(block);
-                       xco += 30;
+                       xco -= XIC; // XXX first button incurs this offset...
+                       xco= ANIM_headerUI_standard_buttons(C, &saction->ads, block, xco, yco);
                }
-               else if (saction->mode == SACTCONT_ACTION) { // not too appropriate for shapekeys atm...
-                       /* NAME ETC */
-                       //uiClearButLock();
+               else if (saction->mode == SACTCONT_ACTION) {
+                       uiLayout *layout;
+                       bScreen *sc= CTX_wm_screen(C);
+                       PointerRNA ptr;
                        
-                       /* NAME ETC  */
-                       xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)saction->action, ID_AC, &saction->pin, xco, yco,
-                               saction_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE|UI_ID_FAKE_USER|UI_ID_ALONE|UI_ID_PIN);
+                       RNA_pointer_create(&sc->id, &RNA_SpaceDopeSheetEditor, saction, &ptr);
+                       
+                       layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, 20+3, 20, 1, U.uistyles.first);
+                       uiTemplateID(layout, (bContext*)C, &ptr, "action", "ACTION_OT_new", NULL, NULL);
+                       uiBlockLayoutResolve(block, &xco, NULL);
                        
                        xco += 8;
                }
                
-               /* COPY PASTE */
-               uiBlockBeginAlign(block);
-                       uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer.");
-                       xco += XIC;
-                       uiDefIconButO(block, BUT, "ACT_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco,yco,XIC,YIC, "Pastes the keyframes from the buffer into the selected channels.");
-               uiBlockEndAlign(block);
-               xco += (XIC + 8);
-               
                /* draw AUTOSNAP */
                if (saction->mode != SACTCONT_GPENCIL) {
                        if (saction->flag & SACTION_DRAWTIME) {
                                uiDefButC(block, MENU, B_REDR,
                                                "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
-                                               xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
+                                               xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, 
                                                "Auto-snapping mode for keyframes when transforming");
                        }
                        else {
                                uiDefButC(block, MENU, B_REDR, 
                                                "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
-                                               xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
+                                               xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, 
                                                "Auto-snapping mode for keyframes when transforming");
                        }
                        
-                       xco += (70 + 8);
+                       xco += (90 + 8);
                }
                
-               /* draw LOCK */
-                       // XXX this feature is probably not relevant anymore!
-               //uiDefIconButS(block, ICONTOG, B_LOCK, ICON_UNLOCKED,  xco, yco, XIC, YIC, 
-               //                        &(saction->lock), 0, 0, 0, 0, 
-               //                        "Updates other affected window spaces automatically "
-               //                        "to reflect changes in real time");
+               /* COPY PASTE */
+               uiBlockBeginAlign(block);
+                       uiDefIconButO(block, BUT, "ACTION_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer.");
+                       xco += XIC;
+                       uiDefIconButO(block, BUT, "ACTION_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco,yco,XIC,YIC, "Pastes the keyframes from the buffer into the selected channels.");
+               uiBlockEndAlign(block);
+               xco += (XIC + 8);
        }
 
-       /* always as last  */
+       /* always as last */
        UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
        
        uiEndBlock(C, block);