UI: action editor header now also uses template for browsing action
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 16 Sep 2009 18:32:10 +0000 (18:32 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 16 Sep 2009 18:32:10 +0000 (18:32 +0000)
datablocks, was last place using deprecated uiDefIDPoinButs.

source/blender/editors/space_action/action_edit.c
source/blender/editors/space_action/action_header.c
source/blender/editors/space_action/action_intern.h
source/blender/editors/space_action/action_ops.c
source/blender/makesrna/intern/rna_space.c

index 89633d0cdfea3cb44856b9d62e88cae042ed19c7..9e05c482ecbce46abd78fc8276ddb333de98fe3a 100644 (file)
@@ -1331,4 +1331,38 @@ void ACT_OT_mirror (wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", prop_actkeys_mirror_types, 0, "Type", "");
 }
 
+/* ******************** New Action Operator *********************** */
+
+static int act_new_exec(bContext *C, wmOperator *op)
+{
+       bAction *action;
+
+       // XXX need to restore behaviour to copy old actions...
+       action= add_empty_action("Action");
+
+       /* combined with RNA property, this will assign & increase user,
+          so decrease here to compensate for that */
+       action->id.us--;
+       
+       /* set notifier that keyframes have changed */
+       WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+void ACT_OT_new (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "New";
+       ot->idname= "ACT_OT_new";
+       ot->description= "Create new action.";
+       
+       /* api callbacks */
+       ot->exec= act_new_exec;
+       ot->poll= ED_operator_action_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /* ************************************************************************** */
index 8674f481a1871c324a041251f75befe998d95152..57546d440b004993a46dd94d49557afeab3c571b 100644 (file)
@@ -260,61 +260,6 @@ static void do_action_buttons(bContext *C, void *arg, int event)
        }
 }
 
-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;
-                               adt->action->id.us++;
-                       }
-                       
-                       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");
-                       if (saction->pin == 0) {
-                               AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
-                               
-                               /* set new action */
-                               // XXX need to restore behaviour to copy old actions...
-                               printf("\tset new action \n");
-                               adt->action= saction->action= add_empty_action("Action");
-                       }
-                       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;
-       }
-}
-
 void action_header_buttons(const bContext *C, ARegion *ar)
 {
        ScrArea *sa= CTX_wm_area(C);
@@ -409,9 +354,15 @@ void action_header_buttons(const bContext *C, ARegion *ar)
                        xco += 30;
                }
                else if (saction->mode == SACTCONT_ACTION) {
-                       /* 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);
+                       uiLayout *layout;
+                       bScreen *sc= CTX_wm_screen(C);
+                       PointerRNA ptr;
+
+                       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", "ACT_OT_new", NULL, NULL);
+                       uiBlockLayoutResolve(C, block, &xco, NULL);
                        
                        xco += 8;
                }
index e5f0ab8994e4893b72b2f32485a2f5c85350a59e..4326bed62d3928ac1b498e186b6d82655bb2e7cb 100644 (file)
@@ -99,6 +99,8 @@ void ACT_OT_frame_jump(struct wmOperatorType *ot);
 void ACT_OT_snap(struct wmOperatorType *ot);
 void ACT_OT_mirror(struct wmOperatorType *ot);
 
+void ACT_OT_new(struct wmOperatorType *ot);
+
 /* defines for snap keyframes 
  * NOTE: keep in sync with eEditKeyframes_Snap (in ED_keyframes_edit.h)
  */
index 42b033040b1f5b07db7b767aace693c9f5f7c8ed..cd4a7b30efffc68a484fc860a12bd00796df6e8d 100644 (file)
@@ -83,6 +83,7 @@ void action_operatortypes(void)
        WM_operatortype_append(ACT_OT_insert_keyframe);
        WM_operatortype_append(ACT_OT_copy);
        WM_operatortype_append(ACT_OT_paste);
+       WM_operatortype_append(ACT_OT_new);
        
        WM_operatortype_append(ACT_OT_previewrange_set);
        WM_operatortype_append(ACT_OT_view_all);
index c2f565e49126dd63ff766da2fee507cd063b8637..6b6e8b5b98eb1094354ce95529cf0fd51b59b2a6 100644 (file)
@@ -38,8 +38,7 @@
 #include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
 
-#include "BKE_paint.h"
-
+#include "WM_api.h"
 #include "WM_types.h"
 
 EnumPropertyItem space_type_items[] = {
@@ -80,11 +79,15 @@ static EnumPropertyItem dc_all_items[] = {DC_RGB, DC_RGBA, DC_ALPHA, DC_Z, DC_LC
 
 #ifdef RNA_RUNTIME
 
+#include "DNA_anim_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 
+#include "BKE_animsys.h"
 #include "BKE_brush.h"
+#include "BKE_colortools.h"
 #include "BKE_context.h"
+#include "BKE_paint.h"
 
 #include "ED_image.h"
 #include "ED_screen.h"
@@ -227,13 +230,6 @@ static void rna_SpaceTextEditor_text_set(PointerRNA *ptr, PointerRNA value)
        st->top= 0;
 }
 
-static void rna_SpaceFileBrowser_params_set(PointerRNA *ptr, PointerRNA value)
-{
-       SpaceFile *sfile= (SpaceFile*)(ptr->data);
-
-       sfile->params= value.data;
-}
-
 /* Space Properties */
 
 static StructRNA *rna_SpaceProperties_pin_id_typef(PointerRNA *ptr)
@@ -311,12 +307,36 @@ static void rna_View3D_display_background_image_set(PointerRNA *ptr, int value)
 }
 
 /* Space Time */
+
 static void rna_SpaceTime_redraw_update(bContext *C, PointerRNA *ptr)
 {
        SpaceTime *st= (SpaceTime*)ptr->data;
        ED_screen_animation_timer_update(C, st->redraws);
 }
 
+/* Space Dopesheet */
+
+static void rna_SpaceDopeSheetEditor_action_set(PointerRNA *ptr, PointerRNA value)
+{
+       SpaceAction *saction= (SpaceAction*)(ptr->data);
+       saction->action= value.data;
+}
+
+static void rna_SpaceDopeSheetEditor_action_update(bContext *C, PointerRNA *ptr)
+{
+       SpaceAction *saction= (SpaceAction*)(ptr->data);
+       Object *obact= CTX_data_active_object(C);
+
+       /* we must set this action to be the one used by active object (if not pinned) */
+       if(obact && saction->pin == 0) {
+               AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
+               
+               /* set action */
+               adt->action= saction->action;
+               id_us_plus(&adt->action->id);
+       }
+}
+
 #else
 
 static void rna_def_space(BlenderRNA *brna)
@@ -1039,6 +1059,13 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
        srna= RNA_def_struct(brna, "SpaceDopeSheetEditor", "Space");
        RNA_def_struct_sdna(srna, "SpaceAction");
        RNA_def_struct_ui_text(srna, "Space DopeSheet Editor", "DopeSheet space data.");
+
+       /* data */
+       prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceDopeSheetEditor_action_set", NULL);
+       RNA_def_property_ui_text(prop, "Action", "Action displayed and edited in this space.");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_DOPESHEET, "rna_SpaceDopeSheetEditor_action_update");
        
        /* mode */
        prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
@@ -1425,7 +1452,6 @@ static void rna_def_space_filebrowser(BlenderRNA *brna)
 
        prop= RNA_def_property(srna, "params", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "params");
-       RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceFileBrowser_params_set", NULL);
        RNA_def_property_ui_text(prop, "Filebrowser Parameter", "Parameters and Settings for the Filebrowser.");
 }