Made minor revisions (no functional changes).
[blender.git] / source / blender / editors / space_outliner / outliner_tools.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) 2004 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): Joshua Leung
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/space_outliner/outliner_tools.c
29  *  \ingroup spoutliner
30  */
31
32 #include <math.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <stddef.h>
36
37 #include "MEM_guardedalloc.h"
38
39 #include "DNA_anim_types.h"
40 #include "DNA_armature_types.h"
41 #include "DNA_constraint_types.h"
42 #include "DNA_camera_types.h"
43 #include "DNA_group_types.h"
44 #include "DNA_key_types.h"
45 #include "DNA_lamp_types.h"
46 #include "DNA_material_types.h"
47 #include "DNA_mesh_types.h"
48 #include "DNA_meta_types.h"
49 #include "DNA_particle_types.h"
50 #include "DNA_scene_types.h"
51 #include "DNA_world_types.h"
52 #include "DNA_sequence_types.h"
53 #include "DNA_object_types.h"
54
55 #include "BLI_blenlib.h"
56 #include "BLI_utildefines.h"
57 #include "BLI_math_base.h"
58
59 #if defined WIN32 && !defined _LIBC
60 # include "BLI_fnmatch.h" /* use fnmatch included in blenlib */
61 #else
62 #  ifndef _GNU_SOURCE
63 #    define _GNU_SOURCE
64 #  endif
65 # include <fnmatch.h>
66 #endif
67
68
69 #include "BKE_animsys.h"
70 #include "BKE_context.h"
71 #include "BKE_deform.h"
72 #include "BKE_depsgraph.h"
73 #include "BKE_fcurve.h"
74 #include "BKE_global.h"
75 #include "BKE_group.h"
76 #include "BKE_library.h"
77 #include "BKE_main.h"
78 #include "BKE_modifier.h"
79 #include "BKE_report.h"
80 #include "BKE_scene.h"
81 #include "BKE_sequencer.h"
82
83 #include "ED_armature.h"
84 #include "ED_object.h"
85 #include "ED_screen.h"
86 #include "ED_util.h"
87
88 #include "WM_api.h"
89 #include "WM_types.h"
90
91 #include "BIF_gl.h"
92 #include "BIF_glutil.h"
93
94 #include "UI_interface.h"
95 #include "UI_interface_icons.h"
96 #include "UI_resources.h"
97 #include "UI_view2d.h"
98
99 #include "RNA_access.h"
100 #include "RNA_define.h"
101 #include "RNA_enum_types.h"
102
103 #include "outliner_intern.h"
104
105 /* ****************************************************** */
106
107 /* ************ SELECTION OPERATIONS ********* */
108
109 static void set_operation_types(SpaceOops *soops, ListBase *lb,
110                                 int *scenelevel,
111                                 int *objectlevel,
112                                 int *idlevel,
113                                 int *datalevel)
114 {
115         TreeElement *te;
116         TreeStoreElem *tselem;
117         
118         for(te= lb->first; te; te= te->next) {
119                 tselem= TREESTORE(te);
120                 if(tselem->flag & TSE_SELECTED) {
121                         if(tselem->type) {
122                                 if(*datalevel==0) 
123                                         *datalevel= tselem->type;
124                                 else if(*datalevel!=tselem->type) 
125                                         *datalevel= -1;
126                         }
127                         else {
128                                 int idcode= GS(tselem->id->name);
129                                 switch(idcode) {
130                                         case ID_SCE:
131                                                 *scenelevel= 1;
132                                                 break;
133                                         case ID_OB:
134                                                 *objectlevel= 1;
135                                                 break;
136                                                 
137                                         case ID_ME: case ID_CU: case ID_MB: case ID_LT:
138                                         case ID_LA: case ID_AR: case ID_CA: case ID_SPK:
139                                         case ID_MA: case ID_TE: case ID_IP: case ID_IM:
140                                         case ID_SO: case ID_KE: case ID_WO: case ID_AC:
141                                         case ID_NLA: case ID_TXT: case ID_GR:
142                                                 if(*idlevel==0) *idlevel= idcode;
143                                                 else if(*idlevel!=idcode) *idlevel= -1;
144                                                         break;
145                                 }
146                         }
147                 }
148                 if(TSELEM_OPEN(tselem,soops)) {
149                         set_operation_types(soops, &te->subtree,
150                                                                 scenelevel, objectlevel, idlevel, datalevel);
151                 }
152         }
153 }
154
155 static void unlink_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
156 {
157         /* just set action to NULL */
158         BKE_animdata_set_action(CTX_wm_reports(C), tsep->id, NULL);
159 }
160
161 static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
162 {
163         Material **matar=NULL;
164         int a, totcol=0;
165         
166         if( GS(tsep->id->name)==ID_OB) {
167                 Object *ob= (Object *)tsep->id;
168                 totcol= ob->totcol;
169                 matar= ob->mat;
170         }
171         else if( GS(tsep->id->name)==ID_ME) {
172                 Mesh *me= (Mesh *)tsep->id;
173                 totcol= me->totcol;
174                 matar= me->mat;
175         }
176         else if( GS(tsep->id->name)==ID_CU) {
177                 Curve *cu= (Curve *)tsep->id;
178                 totcol= cu->totcol;
179                 matar= cu->mat;
180         }
181         else if( GS(tsep->id->name)==ID_MB) {
182                 MetaBall *mb= (MetaBall *)tsep->id;
183                 totcol= mb->totcol;
184                 matar= mb->mat;
185         }
186
187         for(a=0; a<totcol; a++) {
188                 if(a==te->index && matar[a]) {
189                         matar[a]->id.us--;
190                         matar[a]= NULL;
191                 }
192         }
193 }
194
195 static void unlink_texture_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
196 {
197         MTex **mtex= NULL;
198         int a;
199         
200         if( GS(tsep->id->name)==ID_MA) {
201                 Material *ma= (Material *)tsep->id;
202                 mtex= ma->mtex;
203         }
204         else if( GS(tsep->id->name)==ID_LA) {
205                 Lamp *la= (Lamp *)tsep->id;
206                 mtex= la->mtex;
207         }
208         else if( GS(tsep->id->name)==ID_WO) {
209                 World *wrld= (World *)tsep->id;
210                 mtex= wrld->mtex;
211         }
212         else return;
213         
214         for(a=0; a<MAX_MTEX; a++) {
215                 if(a==te->index && mtex[a]) {
216                         if(mtex[a]->tex) {
217                                 mtex[a]->tex->id.us--;
218                                 mtex[a]->tex= NULL;
219                         }
220                 }
221         }
222 }
223
224 static void unlink_group_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem)
225 {
226         Group *group= (Group *)tselem->id;
227         
228         if(tsep) {
229                 if( GS(tsep->id->name)==ID_OB) {
230                         Object *ob= (Object *)tsep->id;
231                         ob->dup_group= NULL;
232                 }
233         }
234         else {
235                 unlink_group(group);
236         }
237 }
238
239 static void unlink_world_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem)
240 {
241         Scene *parscene = (Scene *)tsep->id;
242         World *wo = (World *)tselem->id;
243         
244         /* need to use parent scene not just scene, otherwise may end up getting wrong one */
245         id_us_min(&wo->id);
246         parscene->world = NULL;
247 }
248
249 static void outliner_do_libdata_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
250                                                                                  void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *))
251 {
252         TreeElement *te;
253         TreeStoreElem *tselem;
254         
255         for(te=lb->first; te; te= te->next) {
256                 tselem= TREESTORE(te);
257                 if(tselem->flag & TSE_SELECTED) {
258                         if(tselem->type==0) {
259                                 TreeStoreElem *tsep= TREESTORE(te->parent);
260                                 operation_cb(C, scene, te, tsep, tselem);
261                         }
262                 }
263                 if(TSELEM_OPEN(tselem,soops)) {
264                         outliner_do_libdata_operation(C, scene, soops, &te->subtree, operation_cb);
265                 }
266         }
267 }
268
269 /* */
270
271 static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
272 {
273         Base *base= (Base *)te->directdata;
274         
275         if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
276         if(base && ((base->object->restrictflag & OB_RESTRICT_VIEW)==0)) {
277                 base->flag |= SELECT;
278                 base->object->flag |= SELECT;
279         }
280 }
281
282 static void object_deselect_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
283 {
284         Base *base= (Base *)te->directdata;
285         
286         if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
287         if(base) {
288                 base->flag &= ~SELECT;
289                 base->object->flag &= ~SELECT;
290         }
291 }
292
293 static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
294 {
295         Base *base= (Base *)te->directdata;
296         
297         if(base==NULL) 
298                 base= object_in_scene((Object *)tselem->id, scene);
299         if(base) {
300                 SpaceOops *soops= CTX_wm_space_outliner(C);
301
302                 // check also library later
303                 if(scene->obedit==base->object) 
304                         ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
305                 
306                 ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
307                 te->directdata= NULL;
308                 tselem->id= NULL;
309
310                 /* XXX: tree management normally happens from draw_outliner(), but when
311                         you're clicking to fast on Delete object from context menu in
312                         outliner several mouse events can be handled in one cycle without
313                         handling notifiers/redraw which leads to deleting the same object twice.
314                         cleanup tree here to prevent such cases. */
315                 outliner_cleanup_tree(soops);
316         }
317
318 }
319
320 static void id_local_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
321 {
322         if (tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
323                 id_clear_lib_data(NULL, tselem->id);
324         }
325 }
326
327 static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
328 {
329         ID *id = tselem->id;
330         
331         if ((id) && ((id->flag & LIB_FAKEUSER) == 0)) {
332                 id->flag |= LIB_FAKEUSER;
333                 id_us_plus(id);
334         }
335 }
336
337 static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
338 {
339         ID *id = tselem->id;
340         
341         if ((id) && (id->flag & LIB_FAKEUSER)) {
342                 id->flag &= ~LIB_FAKEUSER;
343                 id_us_min(id);
344         }
345 }
346
347 static void singleuser_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem)
348 {
349         ID *id = tselem->id;
350         
351         if (id) {
352                 IdAdtTemplate *iat = (IdAdtTemplate *)tsep->id;
353                 PointerRNA ptr = {{NULL}};
354                 PropertyRNA *prop;
355                 
356                 RNA_pointer_create(&iat->id, &RNA_AnimData, iat->adt, &ptr);
357                 prop = RNA_struct_find_property(&ptr, "action");
358                 
359                 id_single_user(C, id, &ptr, prop);
360         }
361 }
362
363 static void singleuser_world_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem)
364 {
365         ID *id = tselem->id;
366         
367         /* need to use parent scene not just scene, otherwise may end up getting wrong one */
368         if (id) {
369                 Scene *parscene = (Scene *)tsep->id;
370                 PointerRNA ptr = {{NULL}};
371                 PropertyRNA *prop;
372                 
373                 RNA_id_pointer_create(&parscene->id, &ptr);
374                 prop = RNA_struct_find_property(&ptr, "world");
375                 
376                 id_single_user(C, id, &ptr, prop);
377         }
378 }
379
380 static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
381 {
382         Group *group= (Group *)tselem->id;
383         GroupObject *gob;
384         Base *base;
385         
386         for(gob=group->gobject.first; gob; gob=gob->next) {
387                 base= object_in_scene(gob->ob, scene);
388                 if (base) {
389                         base->object->flag |= SELECT;
390                         base->flag |= SELECT;
391                 } else {
392                         /* link to scene */
393                         base= MEM_callocN( sizeof(Base), "add_base");
394                         BLI_addhead(&scene->base, base);
395                         base->lay= (1<<20)-1; /*v3d->lay;*/ /* would be nice to use the 3d layer but the include's not here */
396                         gob->ob->flag |= SELECT;
397                         base->flag = gob->ob->flag;
398                         base->object= gob->ob;
399                         id_lib_extern((ID *)gob->ob); /* incase these are from a linked group */
400                 }
401         }
402 }
403
404 void outliner_do_object_operation(bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb, 
405                                                                   void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *))
406 {
407         TreeElement *te;
408         TreeStoreElem *tselem;
409         
410         for(te=lb->first; te; te= te->next) {
411                 tselem= TREESTORE(te);
412                 if(tselem->flag & TSE_SELECTED) {
413                         if(tselem->type==0 && te->idcode==ID_OB) {
414                                 // when objects selected in other scenes... dunno if that should be allowed
415                                 Scene *scene_owner= (Scene *)outliner_search_back(soops, te, ID_SCE);
416                                 if(scene_owner && scene_act != scene_owner) {
417                                         ED_screen_set_scene(C, scene_owner);
418                                 }
419                                 /* important to use 'scene_owner' not scene_act else deleting objects can crash.
420                                  * only use 'scene_act' when 'scene_owner' is NULL, which can happen when the
421                                  * outliner isnt showing scenes: Visible Layer draw mode for eg. */
422                                 operation_cb(C, scene_owner ? scene_owner : scene_act, te, NULL, tselem);
423                         }
424                 }
425                 if(TSELEM_OPEN(tselem,soops)) {
426                         outliner_do_object_operation(C, scene_act, soops, &te->subtree, operation_cb);
427                 }
428         }
429 }
430
431 /* ******************************************** */
432
433 static void unlinkact_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te), TreeStoreElem *tselem)
434 {
435         /* just set action to NULL */
436         BKE_animdata_set_action(NULL, tselem->id, NULL);
437 }
438
439 static void cleardrivers_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te), TreeStoreElem *tselem)
440 {
441         IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id;
442         
443         /* just free drivers - stored as a list of F-Curves */
444         free_fcurves(&iat->adt->drivers);
445 }
446
447 static void refreshdrivers_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te), TreeStoreElem *tselem)
448 {
449         IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id;
450         FCurve *fcu;
451         
452         /* loop over drivers, performing refresh (i.e. check graph_buttons.c and rna_fcurve.c for details) */
453         for (fcu = iat->adt->drivers.first; fcu; fcu= fcu->next) {
454                 fcu->flag &= ~FCURVE_DISABLED;
455                 
456                 if (fcu->driver)
457                         fcu->driver->flag &= ~DRIVER_FLAG_INVALID;
458         }
459 }
460
461 /* --------------------------------- */
462
463 static void pchan_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem))
464 {
465         bPoseChannel *pchan= (bPoseChannel *)te->directdata;
466         
467         if(event==1)
468                 pchan->bone->flag |= BONE_SELECTED;
469         else if(event==2)
470                 pchan->bone->flag &= ~BONE_SELECTED;
471         else if(event==3) {
472                 pchan->bone->flag |= BONE_HIDDEN_P;
473                 pchan->bone->flag &= ~BONE_SELECTED;
474         }
475         else if(event==4)
476                 pchan->bone->flag &= ~BONE_HIDDEN_P;
477 }
478
479 static void bone_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem))
480 {
481         Bone *bone= (Bone *)te->directdata;
482         
483         if(event==1)
484                 bone->flag |= BONE_SELECTED;
485         else if(event==2)
486                 bone->flag &= ~BONE_SELECTED;
487         else if(event==3) {
488                 bone->flag |= BONE_HIDDEN_P;
489                 bone->flag &= ~BONE_SELECTED;
490         }
491         else if(event==4)
492                 bone->flag &= ~BONE_HIDDEN_P;
493 }
494
495 static void ebone_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem))
496 {
497         EditBone *ebone= (EditBone *)te->directdata;
498         
499         if(event==1)
500                 ebone->flag |= BONE_SELECTED;
501         else if(event==2)
502                 ebone->flag &= ~BONE_SELECTED;
503         else if(event==3) {
504                 ebone->flag |= BONE_HIDDEN_A;
505                 ebone->flag &= ~BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
506         }
507         else if(event==4)
508                 ebone->flag &= ~BONE_HIDDEN_A;
509 }
510
511 static void sequence_cb(int event, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tselem))
512 {
513 //      Sequence *seq= (Sequence*) te->directdata;
514         if(event==1) {
515 // XXX          select_single_seq(seq, 1);
516         }
517 }
518
519 static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb, 
520                                                                                  void (*operation_cb)(int, TreeElement *, TreeStoreElem *))
521 {
522         TreeElement *te;
523         TreeStoreElem *tselem;
524         
525         for(te=lb->first; te; te= te->next) {
526                 tselem= TREESTORE(te);
527                 if(tselem->flag & TSE_SELECTED) {
528                         if(tselem->type==type) {
529                                 operation_cb(event, te, tselem);
530                         }
531                 }
532                 if(TSELEM_OPEN(tselem,soops)) {
533                         outliner_do_data_operation(soops, type, event, &te->subtree, operation_cb);
534                 }
535         }
536 }
537
538 /* **************************************** */
539
540 static EnumPropertyItem prop_object_op_types[] = {
541         {1, "SELECT", 0, "Select", ""},
542         {2, "DESELECT", 0, "Deselect", ""},
543         {4, "DELETE", 0, "Delete", ""},
544         {6, "TOGVIS", 0, "Toggle Visible", ""},
545         {7, "TOGSEL", 0, "Toggle Selectable", ""},
546         {8, "TOGREN", 0, "Toggle Renderable", ""},
547         {9, "RENAME", 0, "Rename", ""},
548         {0, NULL, 0, NULL, NULL}
549 };
550
551 static int outliner_object_operation_exec(bContext *C, wmOperator *op)
552 {
553         Main *bmain= CTX_data_main(C);
554         Scene *scene= CTX_data_scene(C);
555         SpaceOops *soops= CTX_wm_space_outliner(C);
556         int event;
557         const char *str= NULL;
558         
559         /* check for invalid states */
560         if (soops == NULL)
561                 return OPERATOR_CANCELLED;
562         
563         event= RNA_enum_get(op->ptr, "type");
564
565         if(event==1) {
566                 Scene *sce= scene;      // to be able to delete, scenes are set...
567                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_cb);
568                 if(scene != sce) {
569                         ED_screen_set_scene(C, sce);
570                 }
571                 
572                 str= "Select Objects";
573                 WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
574         }
575         else if(event==2) {
576                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb);
577                 str= "Deselect Objects";
578                 WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
579         }
580         else if(event==4) {
581                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
582                 DAG_scene_sort(bmain, scene);
583                 str= "Delete Objects";
584                 WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
585         }
586         else if(event==5) {     /* disabled, see above enum (ton) */
587                 outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb);
588                 str= "Localized Objects";
589         }
590         else if(event==6) {
591                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
592                 str= "Toggle Visibility";
593                 WM_event_add_notifier(C, NC_SCENE|ND_OB_VISIBLE, scene);
594         }
595         else if(event==7) {
596                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
597                 str= "Toggle Selectability";
598                 WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
599         }
600         else if(event==8) {
601                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
602                 str= "Toggle Renderability";
603                 WM_event_add_notifier(C, NC_SCENE|ND_OB_RENDER, scene);
604         }
605         else if(event==9) {
606                 outliner_do_object_operation(C, scene, soops, &soops->tree, item_rename_cb);
607                 str= "Rename Object";
608         }
609
610         ED_undo_push(C, str);
611         
612         return OPERATOR_FINISHED;
613 }
614
615
616 void OUTLINER_OT_object_operation(wmOperatorType *ot)
617 {
618         /* identifiers */
619         ot->name= "Outliner Object Operation";
620         ot->idname= "OUTLINER_OT_object_operation";
621         ot->description= "";
622         
623         /* callbacks */
624         ot->invoke= WM_menu_invoke;
625         ot->exec= outliner_object_operation_exec;
626         ot->poll= ED_operator_outliner_active;
627         
628         ot->flag= 0;
629
630         ot->prop= RNA_def_enum(ot->srna, "type", prop_object_op_types, 0, "Object Operation", "");
631 }
632
633 /* **************************************** */
634
635 static EnumPropertyItem prop_group_op_types[] = {
636         {1, "UNLINK", 0, "Unlink", ""},
637         {2, "LOCAL", 0, "Make Local", ""},
638         {3, "LINK", 0, "Link Group Objects to Scene", ""},
639         {4, "TOGVIS", 0, "Toggle Visible", ""},
640         {5, "TOGSEL", 0, "Toggle Selectable", ""},
641         {6, "TOGREN", 0, "Toggle Renderable", ""},
642         {7, "RENAME", 0, "Rename", ""},
643         {0, NULL, 0, NULL, NULL}
644 };
645
646 static int outliner_group_operation_exec(bContext *C, wmOperator *op)
647 {
648         Scene *scene= CTX_data_scene(C);
649         SpaceOops *soops= CTX_wm_space_outliner(C);
650         int event;
651         const char *str= NULL;
652         
653         /* check for invalid states */
654         if (soops == NULL)
655                 return OPERATOR_CANCELLED;
656         
657         event= RNA_enum_get(op->ptr, "type");
658         
659         if(event==1) {
660                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_group_cb);
661                 str= "Unlink group";
662         }
663         else if(event==2) {
664                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb);
665                 str= "Localized Data";
666         }
667         else if(event==3) {
668                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_linkobs2scene_cb);
669                 str= "Link Group Objects to Scene";
670         }
671         else if(event==4) {
672                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_visibility_cb);
673                 str= "Toggle Visibility";
674         }
675         else if(event==5) {
676                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_selectability_cb);
677                 str= "Toggle Selectability";
678         }
679         else if(event==6) {
680                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_renderability_cb);
681                 str= "Toggle Renderability";
682         }
683         else if(event==7) {
684                 outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb);
685                 str= "Rename";
686         }
687         
688         
689         ED_undo_push(C, str);
690         WM_event_add_notifier(C, NC_GROUP, NULL);
691         
692         return OPERATOR_FINISHED;
693 }
694
695
696 void OUTLINER_OT_group_operation(wmOperatorType *ot)
697 {
698         /* identifiers */
699         ot->name= "Outliner Group Operation";
700         ot->idname= "OUTLINER_OT_group_operation";
701         ot->description= "";
702         
703         /* callbacks */
704         ot->invoke= WM_menu_invoke;
705         ot->exec= outliner_group_operation_exec;
706         ot->poll= ED_operator_outliner_active;
707         
708         ot->flag= 0;
709         
710         ot->prop= RNA_def_enum(ot->srna, "type", prop_group_op_types, 0, "Group Operation", "");
711 }
712
713 /* **************************************** */
714
715 typedef enum eOutlinerIdOpTypes {
716         OUTLINER_IDOP_INVALID = 0,
717         
718         OUTLINER_IDOP_UNLINK,
719         OUTLINER_IDOP_LOCAL,
720         OUTLINER_IDOP_SINGLE,
721         
722         OUTLINER_IDOP_FAKE_ADD,
723         OUTLINER_IDOP_FAKE_CLEAR,
724         OUTLINER_IDOP_RENAME
725 } eOutlinerIdOpTypes;
726
727 // TODO: implement support for changing the ID-block used
728 static EnumPropertyItem prop_id_op_types[] = {
729         {OUTLINER_IDOP_UNLINK, "UNLINK", 0, "Unlink", ""},
730         {OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""},
731         {OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""},
732         {OUTLINER_IDOP_FAKE_ADD, "ADD_FAKE", 0, "Add Fake User", "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"},
733         {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""},
734         {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""},
735         {0, NULL, 0, NULL, NULL}
736 };
737
738 static int outliner_id_operation_exec(bContext *C, wmOperator *op)
739 {
740         Scene *scene= CTX_data_scene(C);
741         SpaceOops *soops= CTX_wm_space_outliner(C);
742         int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
743         eOutlinerIdOpTypes event;
744         
745         /* check for invalid states */
746         if (soops == NULL)
747                 return OPERATOR_CANCELLED;
748         
749         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
750         
751         event= RNA_enum_get(op->ptr, "type");
752         
753         switch (event) {
754                 case OUTLINER_IDOP_UNLINK:
755                 {
756                         /* unlink datablock from its parent */
757                         switch (idlevel) {
758                                 case ID_AC:
759                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_action_cb);
760                                         
761                                         WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_ACTCHANGE, NULL);
762                                         ED_undo_push(C, "Unlink action");
763                                         break;
764                                 case ID_MA:
765                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_material_cb);
766                                         
767                                         WM_event_add_notifier(C, NC_OBJECT|ND_OB_SHADING, NULL);
768                                         ED_undo_push(C, "Unlink material");
769                                         break;
770                                 case ID_TE:
771                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_texture_cb);
772                                         
773                                         WM_event_add_notifier(C, NC_OBJECT|ND_OB_SHADING, NULL);
774                                         ED_undo_push(C, "Unlink texture");
775                                         break;
776                                 case ID_WO:
777                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_world_cb);
778                                         
779                                         WM_event_add_notifier(C, NC_SCENE|ND_WORLD, NULL);
780                                         ED_undo_push(C, "Unlink world");
781                                         break;
782                                 default:
783                                         BKE_report(op->reports, RPT_WARNING, "Not Yet");
784                                         break;
785                         }
786                 }
787                         break;
788                         
789                 case OUTLINER_IDOP_LOCAL:
790                 {
791                         /* make local */
792                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb);
793                         ED_undo_push(C, "Localized Data");
794                 }
795                         break;
796                         
797                 case OUTLINER_IDOP_SINGLE:
798                 {
799                         /* make single user */
800                         switch (idlevel) {
801                                 case ID_AC:
802                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_action_cb);
803                                         
804                                         WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_ACTCHANGE, NULL);
805                                         ED_undo_push(C, "Single-User Action");
806                                         break;
807                                         
808                                 case ID_WO:
809                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_world_cb);
810                                         
811                                         WM_event_add_notifier(C, NC_SCENE|ND_WORLD, NULL);
812                                         ED_undo_push(C, "Single-User World");
813                                         break;
814                                         
815                                 default:
816                                         BKE_report(op->reports, RPT_WARNING, "Not Yet");
817                                         break;
818                         }
819                 }
820                         break;
821                         
822                 case OUTLINER_IDOP_FAKE_ADD:
823                 {
824                         /* set fake user */
825                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_set_cb);
826                         
827                         WM_event_add_notifier(C, NC_ID|NA_EDITED, NULL);
828                         ED_undo_push(C, "Add Fake User");
829                 }
830                         break;
831                         
832                 case OUTLINER_IDOP_FAKE_CLEAR:
833                 {
834                         /* clear fake user */
835                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_clear_cb);
836                         
837                         WM_event_add_notifier(C, NC_ID|NA_EDITED, NULL);
838                         ED_undo_push(C, "Clear Fake User");
839                 }
840                         break;
841                 case OUTLINER_IDOP_RENAME:
842                 {
843                         /* rename */
844                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb);
845                         
846                         WM_event_add_notifier(C, NC_ID|NA_EDITED, NULL);
847                         ED_undo_push(C, "Rename");
848                 }
849                         break;
850                         
851                 default:
852                         // invalid - unhandled
853                         break;
854         }
855         
856         /* wrong notifier still... */
857         WM_event_add_notifier(C, NC_ID|NA_EDITED, NULL);
858         
859         // XXX: this is just so that outliner is always up to date 
860         WM_event_add_notifier(C, NC_SPACE|ND_SPACE_OUTLINER, NULL);
861         
862         return OPERATOR_FINISHED;
863 }
864
865
866 void OUTLINER_OT_id_operation(wmOperatorType *ot)
867 {
868         /* identifiers */
869         ot->name= "Outliner ID data Operation";
870         ot->idname= "OUTLINER_OT_id_operation";
871         ot->description= "";
872         
873         /* callbacks */
874         ot->invoke= WM_menu_invoke;
875         ot->exec= outliner_id_operation_exec;
876         ot->poll= ED_operator_outliner_active;
877         
878         ot->flag= 0;
879         
880         ot->prop= RNA_def_enum(ot->srna, "type", prop_id_op_types, 0, "ID data Operation", "");
881 }
882
883 /* **************************************** */
884
885 static void outliner_do_id_set_operation(SpaceOops *soops, int type, ListBase *lb, ID *newid,
886                                                                                  void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *, ID *))
887 {
888         TreeElement *te;
889         TreeStoreElem *tselem;
890         
891         for (te=lb->first; te; te= te->next) {
892                 tselem= TREESTORE(te);
893                 if (tselem->flag & TSE_SELECTED) {
894                         if(tselem->type==type) {
895                                 TreeStoreElem *tsep = TREESTORE(te->parent);
896                                 operation_cb(te, tselem, tsep, newid);
897                         }
898                 }
899                 if (TSELEM_OPEN(tselem,soops)) {
900                         outliner_do_id_set_operation(soops, type, &te->subtree, newid, operation_cb);
901                 }
902         }
903 }
904
905 /* ------------------------------------------ */
906
907 static void actionset_id_cb(TreeElement *UNUSED(te), TreeStoreElem *tselem, TreeStoreElem *tsep, ID *actId)
908 {
909         bAction *act = (bAction *)actId;
910         
911         if (tselem->type == TSE_ANIM_DATA) {
912                 /* "animation" entries - action is child of this */
913                 BKE_animdata_set_action(NULL, tselem->id, act);
914         }
915         /* TODO: if any other "expander" channels which own actions need to support this menu, 
916          * add: tselem->type = ...
917          */
918         else if (tsep && (tsep->type == TSE_ANIM_DATA)) {
919                 /* "animation" entries case again */
920                 BKE_animdata_set_action(NULL, tsep->id, act);
921         }
922         // TODO: other cases not supported yet
923 }
924
925 static int outliner_action_set_exec(bContext *C, wmOperator *op)
926 {
927         SpaceOops *soops= CTX_wm_space_outliner(C);
928         int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
929         
930         bAction *act;
931         
932         /* check for invalid states */
933         if (soops == NULL)
934                 return OPERATOR_CANCELLED;
935         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
936         
937         /* get action to use */
938         act= BLI_findlink(&CTX_data_main(C)->action, RNA_enum_get(op->ptr, "action"));
939         
940         if (act == NULL) {
941                 BKE_report(op->reports, RPT_ERROR, "No valid Action to add");
942                 return OPERATOR_CANCELLED;
943         }
944         else if (act->idroot == 0) {
945                 /* hopefully in this case (i.e. library of userless actions), the user knows what they're doing... */
946                 BKE_reportf(op->reports, RPT_WARNING,
947                         "Action '%s' does not specify what datablocks it can be used on. Try setting the 'ID Root Type' setting from the Datablocks Editor for this Action to avoid future problems",
948                         act->id.name+2);
949         }
950         
951         /* perform action if valid channel */
952         if (datalevel == TSE_ANIM_DATA)
953                 outliner_do_id_set_operation(soops, datalevel, &soops->tree, (ID*)act, actionset_id_cb);
954         else if (idlevel == ID_AC)
955                 outliner_do_id_set_operation(soops, idlevel, &soops->tree, (ID*)act, actionset_id_cb);
956         else
957                 return OPERATOR_CANCELLED;
958                 
959         /* set notifier that things have changed */
960         WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_ACTCHANGE, NULL);
961         ED_undo_push(C, "Set action");
962         
963         /* done */
964         return OPERATOR_FINISHED;
965 }
966
967 void OUTLINER_OT_action_set(wmOperatorType *ot)
968 {
969         PropertyRNA *prop;
970
971         /* identifiers */
972         ot->name= "Outliner Set Action";
973         ot->idname= "OUTLINER_OT_action_set";
974         ot->description= "Change the active action used";
975         
976         /* api callbacks */
977         ot->invoke= WM_enum_search_invoke;
978         ot->exec= outliner_action_set_exec;
979         ot->poll= ED_operator_outliner_active;
980         
981         /* flags */
982         ot->flag= 0;
983         
984         /* props */
985                 // TODO: this would be nicer as an ID-pointer...
986         prop= RNA_def_enum(ot->srna, "action", DummyRNA_NULL_items, 0, "Action", "");
987         RNA_def_enum_funcs(prop, RNA_action_itemf);
988         ot->prop= prop;
989 }
990
991 /* **************************************** */
992
993 typedef enum eOutliner_AnimDataOps {
994         OUTLINER_ANIMOP_INVALID = 0,
995         
996         OUTLINER_ANIMOP_SET_ACT,
997         OUTLINER_ANIMOP_CLEAR_ACT,
998         
999         OUTLINER_ANIMOP_REFRESH_DRV,
1000         OUTLINER_ANIMOP_CLEAR_DRV
1001         
1002         //OUTLINER_ANIMOP_COPY_DRIVERS,
1003         //OUTLINER_ANIMOP_PASTE_DRIVERS
1004 } eOutliner_AnimDataOps;
1005
1006 static EnumPropertyItem prop_animdata_op_types[] = {
1007         {OUTLINER_ANIMOP_SET_ACT, "SET_ACT", 0, "Set Action", ""},
1008         {OUTLINER_ANIMOP_CLEAR_ACT, "CLEAR_ACT", 0, "Unlink Action", ""},
1009         {OUTLINER_ANIMOP_REFRESH_DRV, "REFRESH_DRIVERS", 0, "Refresh Drivers", ""},
1010         //{OUTLINER_ANIMOP_COPY_DRIVERS, "COPY_DRIVERS", 0, "Copy Drivers", ""},
1011         //{OUTLINER_ANIMOP_PASTE_DRIVERS, "PASTE_DRIVERS", 0, "Paste Drivers", ""},
1012         {OUTLINER_ANIMOP_CLEAR_DRV, "CLEAR_DRIVERS", 0, "Clear Drivers", ""},
1013         {0, NULL, 0, NULL, NULL}
1014 };
1015
1016 static int outliner_animdata_operation_exec(bContext *C, wmOperator *op)
1017 {
1018         SpaceOops *soops= CTX_wm_space_outliner(C);
1019         int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
1020         eOutliner_AnimDataOps event;
1021         short updateDeps = 0;
1022         
1023         /* check for invalid states */
1024         if (soops == NULL)
1025                 return OPERATOR_CANCELLED;
1026         
1027         event= RNA_enum_get(op->ptr, "type");
1028         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1029         
1030         if (datalevel != TSE_ANIM_DATA)
1031                 return OPERATOR_CANCELLED;
1032         
1033         /* perform the core operation */
1034         switch (event) {
1035                 case OUTLINER_ANIMOP_SET_ACT:
1036                         /* delegate once again... */
1037                         WM_operator_name_call(C, "OUTLINER_OT_action_set", WM_OP_INVOKE_REGION_WIN, NULL);
1038                         break;
1039                 
1040                 case OUTLINER_ANIMOP_CLEAR_ACT:
1041                         /* clear active action - using standard rules */
1042                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, unlinkact_animdata_cb);
1043                         
1044                         WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_ACTCHANGE, NULL);
1045                         ED_undo_push(C, "Unlink action");
1046                         break;
1047                         
1048                 case OUTLINER_ANIMOP_REFRESH_DRV:
1049                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, refreshdrivers_animdata_cb);
1050                         
1051                         WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN, NULL);
1052                         //ED_undo_push(C, "Refresh Drivers"); /* no undo needed - shouldn't have any impact? */
1053                         updateDeps = 1;
1054                         break;
1055                         
1056                 case OUTLINER_ANIMOP_CLEAR_DRV:
1057                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, cleardrivers_animdata_cb);
1058                         
1059                         WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN, NULL);
1060                         ED_undo_push(C, "Clear Drivers");
1061                         updateDeps = 1;
1062                         break;
1063                         
1064                 default: // invalid
1065                         break;
1066         }
1067         
1068         /* update dependencies */
1069         if (updateDeps) {
1070                 Main *bmain = CTX_data_main(C);
1071                 Scene *scene = CTX_data_scene(C);
1072                 
1073                 /* rebuild depsgraph for the new deps */
1074                 DAG_scene_sort(bmain, scene);
1075                 
1076                 /* force an update of depsgraph */
1077                 DAG_ids_flush_update(bmain, 0);
1078         }
1079         
1080         return OPERATOR_FINISHED;
1081 }
1082
1083
1084 void OUTLINER_OT_animdata_operation(wmOperatorType *ot)
1085 {
1086         /* identifiers */
1087         ot->name= "Outliner Animation Data Operation";
1088         ot->idname= "OUTLINER_OT_animdata_operation";
1089         ot->description= "";
1090         
1091         /* callbacks */
1092         ot->invoke= WM_menu_invoke;
1093         ot->exec= outliner_animdata_operation_exec;
1094         ot->poll= ED_operator_outliner_active;
1095         
1096         ot->flag= 0;
1097         
1098         ot->prop= RNA_def_enum(ot->srna, "type", prop_animdata_op_types, 0, "Animation Operation", "");
1099 }
1100
1101 /* **************************************** */
1102
1103 static EnumPropertyItem prop_data_op_types[] = {
1104         {1, "SELECT", 0, "Select", ""},
1105         {2, "DESELECT", 0, "Deselect", ""},
1106         {3, "HIDE", 0, "Hide", ""},
1107         {4, "UNHIDE", 0, "Unhide", ""},
1108         {0, NULL, 0, NULL, NULL}
1109 };
1110
1111 static int outliner_data_operation_exec(bContext *C, wmOperator *op)
1112 {
1113         SpaceOops *soops= CTX_wm_space_outliner(C);
1114         int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
1115         int event;
1116         
1117         /* check for invalid states */
1118         if (soops == NULL)
1119                 return OPERATOR_CANCELLED;
1120         
1121         event= RNA_enum_get(op->ptr, "type");
1122         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1123         
1124         if(datalevel==TSE_POSE_CHANNEL) {
1125                 if(event>0) {
1126                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, pchan_cb);
1127                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
1128                         ED_undo_push(C, "PoseChannel operation");
1129                 }
1130         }
1131         else if(datalevel==TSE_BONE) {
1132                 if(event>0) {
1133                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, bone_cb);
1134                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
1135                         ED_undo_push(C, "Bone operation");
1136                 }
1137         }
1138         else if(datalevel==TSE_EBONE) {
1139                 if(event>0) {
1140                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, ebone_cb);
1141                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
1142                         ED_undo_push(C, "EditBone operation");
1143                 }
1144         }
1145         else if(datalevel==TSE_SEQUENCE) {
1146                 if(event>0) {
1147                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb);
1148                 }
1149         }
1150         
1151         return OPERATOR_FINISHED;
1152 }
1153
1154
1155 void OUTLINER_OT_data_operation(wmOperatorType *ot)
1156 {
1157         /* identifiers */
1158         ot->name= "Outliner Data Operation";
1159         ot->idname= "OUTLINER_OT_data_operation";
1160         ot->description= "";
1161         
1162         /* callbacks */
1163         ot->invoke= WM_menu_invoke;
1164         ot->exec= outliner_data_operation_exec;
1165         ot->poll= ED_operator_outliner_active;
1166         
1167         ot->flag= 0;
1168         
1169         ot->prop= RNA_def_enum(ot->srna, "type", prop_data_op_types, 0, "Data Operation", "");
1170 }
1171
1172
1173 /* ******************** */
1174
1175
1176 static int do_outliner_operation_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, wmEvent *event, const float mval[2])
1177 {
1178         ReportList *reports = CTX_wm_reports(C); // XXX...
1179         
1180         if(mval[1]>te->ys && mval[1]<te->ys+UI_UNIT_Y) {
1181                 int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
1182                 TreeStoreElem *tselem= TREESTORE(te);
1183                 
1184                 /* select object that's clicked on and popup context menu */
1185                 if (!(tselem->flag & TSE_SELECTED)) {
1186                         
1187                         if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
1188                                 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1189                         
1190                         tselem->flag |= TSE_SELECTED;
1191                         /* redraw, same as outliner_select function */
1192                         soops->storeflag |= SO_TREESTORE_REDRAW;
1193                         ED_region_tag_redraw(ar);
1194                 }
1195                 
1196                 set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1197                 
1198                 if(scenelevel) {
1199                         //if(objectlevel || datalevel || idlevel) error("Mixed selection");
1200                         //else pupmenu("Scene Operations%t|Delete");
1201                 }
1202                 else if(objectlevel) {
1203                         WM_operator_name_call(C, "OUTLINER_OT_object_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1204                 }
1205                 else if(idlevel) {
1206                         if(idlevel==-1 || datalevel) BKE_report(reports, RPT_WARNING, "Mixed selection");
1207                         else {
1208                                 if (idlevel==ID_GR)
1209                                         WM_operator_name_call(C, "OUTLINER_OT_group_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1210                                 else
1211                                         WM_operator_name_call(C, "OUTLINER_OT_id_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1212                         }
1213                 }
1214                 else if(datalevel) {
1215                         if(datalevel==-1) BKE_report(reports, RPT_WARNING, "Mixed selection");
1216                         else {
1217                                 if (datalevel == TSE_ANIM_DATA)
1218                                         WM_operator_name_call(C, "OUTLINER_OT_animdata_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1219                                 else if (datalevel == TSE_DRIVER_BASE)
1220                                         /* do nothing... no special ops needed yet */;
1221                                 else if ELEM3(datalevel, TSE_R_LAYER_BASE, TSE_R_LAYER, TSE_R_PASS)
1222                                         /*WM_operator_name_call(C, "OUTLINER_OT_renderdata_operation", WM_OP_INVOKE_REGION_WIN, NULL)*/;
1223                                 else
1224                                         WM_operator_name_call(C, "OUTLINER_OT_data_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1225                         }
1226                 }
1227                 
1228                 return 1;
1229         }
1230         
1231         for(te= te->subtree.first; te; te= te->next) {
1232                 if(do_outliner_operation_event(C, scene, ar, soops, te, event, mval)) 
1233                         return 1;
1234         }
1235         return 0;
1236 }
1237
1238
1239 static int outliner_operation(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
1240 {
1241         Scene *scene= CTX_data_scene(C);
1242         ARegion *ar= CTX_wm_region(C);
1243         SpaceOops *soops= CTX_wm_space_outliner(C);
1244         TreeElement *te;
1245         float fmval[2];
1246         
1247         UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval+1);
1248         
1249         for(te= soops->tree.first; te; te= te->next) {
1250                 if(do_outliner_operation_event(C, scene, ar, soops, te, event, fmval)) break;
1251         }
1252         
1253         return OPERATOR_FINISHED;
1254 }
1255
1256 /* Menu only! Calls other operators */
1257 void OUTLINER_OT_operation(wmOperatorType *ot)
1258 {
1259         ot->name= "Execute Operation";
1260         ot->idname= "OUTLINER_OT_operation";
1261         ot->description= "Context menu for item operations";
1262         
1263         ot->invoke= outliner_operation;
1264         
1265         ot->poll= ED_operator_outliner_active;
1266 }
1267
1268 /* ****************************************************** */