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