Workspace: Move engines to workspace and Properties Editor cleanup
[blender.git] / source / blender / editors / space_action / space_action.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_action/space_action.c
28  *  \ingroup spaction
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_action_types.h"
36 #include "DNA_group_types.h"
37 #include "DNA_scene_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_math.h"
43 #include "BLI_utildefines.h"
44
45 #include "BKE_context.h"
46 #include "BKE_screen.h"
47
48 #include "BIF_gl.h"
49
50 #include "WM_api.h"
51 #include "WM_types.h"
52
53 #include "UI_resources.h"
54 #include "UI_view2d.h"
55
56 #include "ED_space_api.h"
57 #include "ED_screen.h"
58 #include "ED_anim_api.h"
59 #include "ED_markers.h"
60
61 #include "action_intern.h"  /* own include */
62
63 /* ******************** manage regions ********************* */
64
65 ARegion *action_has_buttons_region(ScrArea *sa)
66 {
67         ARegion *ar, *arnew;
68         
69         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
70         if (ar) return ar;
71         
72         /* add subdiv level; after main */
73         ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
74         
75         /* is error! */
76         if (ar == NULL) return NULL;
77         
78         arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
79         
80         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
81         arnew->regiontype = RGN_TYPE_UI;
82         arnew->alignment = RGN_ALIGN_RIGHT;
83         
84         arnew->flag = RGN_FLAG_HIDDEN;
85         
86         return arnew;
87 }
88
89 /* ******************** default callbacks for action space ***************** */
90
91 static SpaceLink *action_new(const bContext *C)
92 {
93         Scene *scene = CTX_data_scene(C);
94         ScrArea *sa = CTX_wm_area(C);
95         SpaceAction *saction;
96         ARegion *ar;
97         
98         saction = MEM_callocN(sizeof(SpaceAction), "initaction");
99         saction->spacetype = SPACE_ACTION;
100         
101         saction->autosnap = SACTSNAP_FRAME;
102         saction->mode = SACTCONT_DOPESHEET;
103         
104         saction->ads.filterflag |= ADS_FILTER_SUMMARY;
105         
106         /* header */
107         ar = MEM_callocN(sizeof(ARegion), "header for action");
108         
109         BLI_addtail(&saction->regionbase, ar);
110         ar->regiontype = RGN_TYPE_HEADER;
111         ar->alignment = RGN_ALIGN_BOTTOM;
112         
113         /* channel list region */
114         ar = MEM_callocN(sizeof(ARegion), "channel region for action");
115         BLI_addtail(&saction->regionbase, ar);
116         ar->regiontype = RGN_TYPE_CHANNELS;
117         ar->alignment = RGN_ALIGN_LEFT;
118         
119         /* only need to set scroll settings, as this will use 'listview' v2d configuration */
120         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
121         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
122         
123         /* ui buttons */
124         ar = MEM_callocN(sizeof(ARegion), "buttons region for action");
125         
126         BLI_addtail(&saction->regionbase, ar);
127         ar->regiontype = RGN_TYPE_UI;
128         ar->alignment = RGN_ALIGN_RIGHT;
129         ar->flag = RGN_FLAG_HIDDEN;
130         
131         /* main region */
132         ar = MEM_callocN(sizeof(ARegion), "main region for action");
133         
134         BLI_addtail(&saction->regionbase, ar);
135         ar->regiontype = RGN_TYPE_WINDOW;
136         
137         ar->v2d.tot.xmin = (float)(SFRA - 10);
138         ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
139         ar->v2d.tot.xmax = (float)(EFRA + 10);
140         ar->v2d.tot.ymax = 0.0f;
141         
142         ar->v2d.cur = ar->v2d.tot;
143         
144         ar->v2d.min[0] = 0.0f;
145         ar->v2d.min[1] = 0.0f;
146         
147         ar->v2d.max[0] = MAXFRAMEF;
148         ar->v2d.max[1] = FLT_MAX;
149
150         ar->v2d.minzoom = 0.01f;
151         ar->v2d.maxzoom = 50;
152         ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
153         ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
154         ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
155         ar->v2d.keepofs = V2D_KEEPOFS_Y;
156         ar->v2d.align = V2D_ALIGN_NO_POS_Y;
157         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
158         
159         return (SpaceLink *)saction;
160 }
161
162 /* not spacelink itself */
163 static void action_free(SpaceLink *UNUSED(sl))
164 {       
165 //      SpaceAction *saction = (SpaceAction *) sl;
166 }
167
168
169 /* spacetype; init callback */
170 static void action_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
171 {
172         SpaceAction *saction = sa->spacedata.first;
173         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
174 }
175
176 static SpaceLink *action_duplicate(SpaceLink *sl)
177 {
178         SpaceAction *sactionn = MEM_dupallocN(sl);
179         
180         /* clear or remove stuff from old */
181         
182         return (SpaceLink *)sactionn;
183 }
184
185
186
187 /* add handlers, stuff you only do once or on area/region changes */
188 static void action_main_region_init(wmWindowManager *wm, ARegion *ar)
189 {
190         wmKeyMap *keymap;
191         
192         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
193         
194         /* own keymap */
195         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet", SPACE_ACTION, 0);
196         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
197         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
198         WM_event_add_keymap_handler(&ar->handlers, keymap);
199 }
200
201 static void action_main_region_draw(const bContext *C, ARegion *ar)
202 {
203         /* draw entirely, view changes should be handled here */
204         SpaceAction *saction = CTX_wm_space_action(C);
205         bAnimContext ac;
206         View2D *v2d = &ar->v2d;
207         View2DGrid *grid;
208         View2DScrollers *scrollers;
209         short unit = 0, flag = 0;
210         
211         /* clear and setup matrix */
212         UI_ThemeClearColor(TH_BACK);
213         glClear(GL_COLOR_BUFFER_BIT);
214         
215         UI_view2d_view_ortho(v2d);
216         
217         /* time grid */
218         unit = (saction->flag & SACTION_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
219         grid = UI_view2d_grid_calc(CTX_data_scene(C), v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
220         UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
221         UI_view2d_grid_free(grid);
222         
223         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
224
225         /* data */
226         if (ANIM_animdata_get_context(C, &ac)) {
227                 draw_channel_strips(&ac, saction, ar);
228         }
229         
230         /* current frame */
231         if (saction->flag & SACTION_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
232         if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
233         ANIM_draw_cfra(C, v2d, flag);
234         
235         /* markers */
236         UI_view2d_view_orthoSpecial(ar, v2d, 1);
237         
238         flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
239         ED_markers_draw(C, flag);
240         
241         /* preview range */
242         UI_view2d_view_ortho(v2d);
243         ANIM_draw_previewrange(C, v2d, 0);
244
245         /* callback */
246         UI_view2d_view_ortho(v2d);
247         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
248         
249         /* reset view matrix */
250         UI_view2d_view_restore(C);
251         
252         /* scrollers */
253         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
254         UI_view2d_scrollers_draw(C, v2d, scrollers);
255         UI_view2d_scrollers_free(scrollers);
256 }
257
258 /* add handlers, stuff you only do once or on area/region changes */
259 static void action_channel_region_init(wmWindowManager *wm, ARegion *ar)
260 {
261         wmKeyMap *keymap;
262         
263         /* ensure the 2d view sync works - main region has bottom scroller */
264         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
265         
266         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
267         
268         /* own keymap */
269         keymap = WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
270         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
271         
272         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
273         WM_event_add_keymap_handler(&ar->handlers, keymap);
274 }
275
276 static void action_channel_region_draw(const bContext *C, ARegion *ar)
277 {
278         /* draw entirely, view changes should be handled here */
279         bAnimContext ac;
280         View2D *v2d = &ar->v2d;
281         
282         /* clear and setup matrix */
283         UI_ThemeClearColor(TH_BACK);
284         glClear(GL_COLOR_BUFFER_BIT);
285         
286         UI_view2d_view_ortho(v2d);
287         
288         /* data */
289         if (ANIM_animdata_get_context(C, &ac)) {
290                 draw_channel_names((bContext *)C, &ac, ar);
291         }
292         
293         /* reset view matrix */
294         UI_view2d_view_restore(C);
295         
296         /* no scrollers here */
297 }
298
299
300 /* add handlers, stuff you only do once or on area/region changes */
301 static void action_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
302 {
303         ED_region_header_init(ar);
304 }
305
306 static void action_header_region_draw(const bContext *C, ARegion *ar)
307 {
308         ED_region_header(C, ar);
309 }
310
311 static void action_channel_region_listener(
312         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
313         wmNotifier *wmn, const Scene *UNUSED(scene))
314 {
315         /* context changes */
316         switch (wmn->category) {
317                 case NC_ANIMATION:
318                         ED_region_tag_redraw(ar);
319                         break;
320                 case NC_SCENE:
321                         switch (wmn->data) {
322                                 case ND_OB_ACTIVE:
323                                 case ND_FRAME:
324                                         ED_region_tag_redraw(ar);
325                                         break;
326                         }
327                         break;
328                 case NC_OBJECT:
329                         switch (wmn->data) {
330                                 case ND_BONE_ACTIVE:
331                                 case ND_BONE_SELECT:
332                                 case ND_KEYS:
333                                         ED_region_tag_redraw(ar);
334                                         break;
335                                 case ND_MODIFIER:
336                                         if (wmn->action == NA_RENAME)
337                                                 ED_region_tag_redraw(ar);
338                                         break;
339                         }
340                         break;
341                 case NC_GPENCIL:
342                         if (ELEM(wmn->action, NA_RENAME, NA_SELECTED))
343                                 ED_region_tag_redraw(ar);
344                         break;
345                 case NC_ID:
346                         if (wmn->action == NA_RENAME)
347                                 ED_region_tag_redraw(ar);
348                         break;
349                 default:
350                         if (wmn->data == ND_KEYS)
351                                 ED_region_tag_redraw(ar);
352                         break;
353         }
354 }
355
356 static void action_main_region_listener(
357         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
358         wmNotifier *wmn, const Scene *UNUSED(scene))
359 {
360         /* context changes */
361         switch (wmn->category) {
362                 case NC_ANIMATION:
363                         ED_region_tag_redraw(ar);
364                         break;
365                 case NC_SCENE:
366                         switch (wmn->data) {
367                                 case ND_RENDER_OPTIONS:
368                                 case ND_OB_ACTIVE:
369                                 case ND_FRAME:
370                                 case ND_MARKERS:
371                                         ED_region_tag_redraw(ar);
372                                         break;
373                         }
374                         break;
375                 case NC_OBJECT:
376                         switch (wmn->data) {
377                                 case ND_TRANSFORM:
378                                         /* moving object shouldn't need to redraw action */
379                                         break;
380                                 case ND_BONE_ACTIVE:
381                                 case ND_BONE_SELECT:
382                                 case ND_KEYS:
383                                         ED_region_tag_redraw(ar);
384                                         break;
385                         }
386                         break;
387                 case NC_NODE:
388                         switch (wmn->action) {
389                                 case NA_EDITED:
390                                         ED_region_tag_redraw(ar);
391                                         break;
392                         }
393                         break;
394                 case NC_ID:
395                         if (wmn->action == NA_RENAME)
396                                 ED_region_tag_redraw(ar);
397                         break;
398                 case NC_SCREEN:
399                         if (ELEM(wmn->data, ND_LAYER)) {
400                                 ED_region_tag_redraw(ar);
401                         }
402                         break;
403                 default:
404                         if (wmn->data == ND_KEYS)
405                                 ED_region_tag_redraw(ar);
406                         break;
407         }
408 }
409
410 /* editor level listener */
411 static void action_listener(
412         bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
413         WorkSpace *UNUSED(workspace))
414 {
415         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
416         
417         /* context changes */
418         switch (wmn->category) {
419                 case NC_GPENCIL:
420                         /* only handle these events in GPencil mode for performance considerations */
421                         if (saction->mode == SACTCONT_GPENCIL) {
422                                 if (wmn->action == NA_EDITED) {
423                                         ED_area_tag_redraw(sa);
424                                 }
425                                 else if (wmn->action == NA_SELECTED) {
426                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
427                                         ED_area_tag_refresh(sa);
428                                 }
429                         }
430                         break;
431                 case NC_ANIMATION:
432                         /* for NLA tweakmode enter/exit, need complete refresh */
433                         if (wmn->data == ND_NLA_ACTCHANGE) {
434                                 saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
435                                 ED_area_tag_refresh(sa);
436                         }
437                         /* autocolor only really needs to change when channels are added/removed, or previously hidden stuff appears 
438                          * (assume for now that if just adding these works, that will be fine)
439                          */
440                         else if (((wmn->data == ND_KEYFRAME) && ELEM(wmn->action, NA_ADDED, NA_REMOVED)) ||
441                                  ((wmn->data == ND_ANIMCHAN) && (wmn->action != NA_SELECTED)))
442                         {
443                                 ED_area_tag_refresh(sa);
444                         }
445                         /* for simple edits to the curve data though (or just plain selections), a simple redraw should work 
446                          * (see T39851 for an example of how this can go wrong)
447                          */
448                         else {
449                                 ED_area_tag_redraw(sa);
450                         }
451                         break;
452                 case NC_SCENE:
453                         switch (wmn->data) {
454                                 case ND_OB_ACTIVE:  /* selection changed, so force refresh to flush (needs flag set to do syncing) */
455                                 case ND_OB_SELECT:
456                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
457                                         ED_area_tag_refresh(sa);
458                                         break;
459                                         
460                                 default: /* just redrawing the view will do */
461                                         ED_area_tag_redraw(sa);
462                                         break;
463                         }
464                         break;
465                 case NC_OBJECT:
466                         switch (wmn->data) {
467                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
468                                 case ND_BONE_ACTIVE:
469                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
470                                         ED_area_tag_refresh(sa);
471                                         break;
472                                 case ND_TRANSFORM:
473                                         /* moving object shouldn't need to redraw action */
474                                         break;
475                                 default: /* just redrawing the view will do */
476                                         ED_area_tag_redraw(sa);
477                                         break;
478                         }
479                         break;
480                 case NC_MASK:
481                         if (saction->mode == SACTCONT_MASK) {
482                                 switch (wmn->data) {
483                                         case ND_DATA:
484                                                 ED_area_tag_refresh(sa);
485                                                 ED_area_tag_redraw(sa);
486                                                 break;
487                                         default: /* just redrawing the view will do */
488                                                 ED_area_tag_redraw(sa);
489                                                 break;
490                                 }
491                         }
492                         break;
493                 case NC_NODE:
494                         if (wmn->action == NA_SELECTED) {
495                                 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
496                                 saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
497                                 ED_area_tag_refresh(sa);
498                         }
499                         break;
500                 case NC_SPACE:
501                         switch (wmn->data) {
502                                 case ND_SPACE_DOPESHEET:
503                                         ED_area_tag_redraw(sa);
504                                         break;
505                                 case ND_SPACE_CHANGED:
506                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
507                                         ED_area_tag_refresh(sa);
508                                         break;
509                         }
510                         break;
511                 case NC_WINDOW:
512                         if (saction->flag & SACTION_TEMP_NEEDCHANSYNC) {
513                                 /* force redraw/refresh after undo/redo - [#28962] */
514                                 ED_area_tag_refresh(sa);
515                         }
516                         break;
517         }
518 }
519
520 static void action_header_region_listener(
521         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
522         wmNotifier *wmn, const Scene *UNUSED(scene))
523 {
524         // SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
525
526         /* context changes */
527         switch (wmn->category) {
528                 case NC_SCENE:
529                         switch (wmn->data) {
530                                 case ND_OB_ACTIVE:
531                                         ED_region_tag_redraw(ar);
532                                         break;
533                         }
534                         break;
535                 case NC_ID:
536                         if (wmn->action == NA_RENAME)
537                                 ED_region_tag_redraw(ar);
538                         break;
539                 case NC_ANIMATION:
540                         switch (wmn->data) {
541                                 case ND_ANIMCHAN: /* set of visible animchannels changed */
542                                         /* NOTE: for now, this should usually just mean that the filters changed 
543                                          *       It may be better if we had a dedicated flag for that though
544                                          */
545                                         ED_region_tag_redraw(ar);
546                                         break;
547                                         
548                                 case ND_KEYFRAME: /* new keyframed added -> active action may have changed */
549                                         //saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
550                                         ED_region_tag_redraw(ar);
551                                         break;
552                         }
553                         break;
554         }
555
556 }
557
558 /* add handlers, stuff you only do once or on area/region changes */
559 static void action_buttons_area_init(wmWindowManager *wm, ARegion *ar)
560 {
561         wmKeyMap *keymap;
562         
563         ED_region_panels_init(wm, ar);
564         
565         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
566         WM_event_add_keymap_handler(&ar->handlers, keymap);
567 }
568
569 static void action_buttons_area_draw(const bContext *C, ARegion *ar)
570 {
571         ED_region_panels(C, ar, NULL, -1, true);
572 }
573
574 static void action_region_listener(
575         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
576         wmNotifier *wmn, const Scene *UNUSED(scene))
577 {
578         /* context changes */
579         switch (wmn->category) {
580                 case NC_ANIMATION:
581                         ED_region_tag_redraw(ar);
582                         break;
583                 case NC_SCENE:
584                         switch (wmn->data) {
585                                 case ND_OB_ACTIVE:
586                                 case ND_FRAME:
587                                 case ND_MARKERS:
588                                         ED_region_tag_redraw(ar);
589                                         break;
590                         }
591                         break;
592                 case NC_OBJECT:
593                         switch (wmn->data) {
594                                 case ND_BONE_ACTIVE:
595                                 case ND_BONE_SELECT:
596                                 case ND_KEYS:
597                                         ED_region_tag_redraw(ar);
598                                         break;
599                         }
600                         break;
601                 default:
602                         if (wmn->data == ND_KEYS)
603                                 ED_region_tag_redraw(ar);
604                         break;
605         }
606 }
607
608 static void action_refresh(const bContext *C, ScrArea *sa)
609 {
610         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
611         
612         /* update the state of the animchannels in response to changes from the data they represent 
613          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
614          */
615         if (saction->flag & SACTION_TEMP_NEEDCHANSYNC) {
616                 ARegion *ar;
617                 
618                 /* Perform syncing of channel state incl. selection
619                  * Active action setting also occurs here (as part of anim channel filtering in anim_filter.c)
620                  */
621                 ANIM_sync_animchannels_to_data(C);
622                 saction->flag &= ~SACTION_TEMP_NEEDCHANSYNC;
623                 
624                 /* Tag everything for redraw
625                  * - Regions (such as header) need to be manually tagged for redraw too
626                  *   or else they don't update [#28962]
627                  */
628                 ED_area_tag_redraw(sa);
629                 for (ar = sa->regionbase.first; ar; ar = ar->next)
630                         ED_region_tag_redraw(ar);
631         }
632         
633         /* region updates? */
634         // XXX re-sizing y-extents of tot should go here?
635 }
636
637 static void action_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
638 {
639         SpaceAction *sact = (SpaceAction *)slink;
640
641         if ((ID *)sact->action == old_id) {
642                 sact->action = (bAction *)new_id;
643         }
644
645         if ((ID *)sact->ads.filter_grp == old_id) {
646                 sact->ads.filter_grp = (Group *)new_id;
647         }
648         if ((ID *)sact->ads.source == old_id) {
649                 sact->ads.source = new_id;
650         }
651
652 }
653
654 /* only called once, from space/spacetypes.c */
655 void ED_spacetype_action(void)
656 {
657         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype action");
658         ARegionType *art;
659         
660         st->spaceid = SPACE_ACTION;
661         strncpy(st->name, "Action", BKE_ST_MAXNAME);
662         
663         st->new = action_new;
664         st->free = action_free;
665         st->init = action_init;
666         st->duplicate = action_duplicate;
667         st->operatortypes = action_operatortypes;
668         st->keymap = action_keymap;
669         st->listener = action_listener;
670         st->refresh = action_refresh;
671         st->id_remap = action_id_remap;
672
673         /* regions: main window */
674         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
675         art->regionid = RGN_TYPE_WINDOW;
676         art->init = action_main_region_init;
677         art->draw = action_main_region_draw;
678         art->listener = action_main_region_listener;
679         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
680
681         BLI_addhead(&st->regiontypes, art);
682         
683         /* regions: header */
684         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
685         art->regionid = RGN_TYPE_HEADER;
686         art->prefsizey = HEADERY;
687         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
688         
689         art->init = action_header_region_init;
690         art->draw = action_header_region_draw;
691         art->listener = action_header_region_listener;
692         
693         BLI_addhead(&st->regiontypes, art);
694         
695         /* regions: channels */
696         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
697         art->regionid = RGN_TYPE_CHANNELS;
698         art->prefsizex = 200;
699         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
700         
701         art->init = action_channel_region_init;
702         art->draw = action_channel_region_draw;
703         art->listener = action_channel_region_listener;
704         
705         BLI_addhead(&st->regiontypes, art);
706         
707         /* regions: UI buttons */
708         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
709         art->regionid = RGN_TYPE_UI;
710         art->prefsizex = 200;
711         art->keymapflag = ED_KEYMAP_UI;
712         art->listener = action_region_listener;
713         art->init = action_buttons_area_init;
714         art->draw = action_buttons_area_draw;
715         
716         BLI_addhead(&st->regiontypes, art);
717         
718         action_buttons_register(art);
719         
720         BKE_spacetype_register(st);
721 }
722