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