Fake user: add BKE_library helpers to set/clear that flag.
[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_gpencil_types.h"
37 #include "DNA_group_types.h"
38 #include "DNA_lamp_types.h"
39 #include "DNA_linestyle_types.h"
40 #include "DNA_material_types.h"
41 #include "DNA_mesh_types.h"
42 #include "DNA_meta_types.h"
43 #include "DNA_scene_types.h"
44 #include "DNA_sequence_types.h"
45 #include "DNA_world_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_constraint_types.h"
48 #include "DNA_modifier_types.h"
49
50 #include "BLI_blenlib.h"
51 #include "BLI_utildefines.h"
52
53 #include "BKE_animsys.h"
54 #include "BKE_context.h"
55 #include "BKE_constraint.h"
56 #include "BKE_depsgraph.h"
57 #include "BKE_fcurve.h"
58 #include "BKE_group.h"
59 #include "BKE_library.h"
60 #include "BKE_main.h"
61 #include "BKE_report.h"
62 #include "BKE_scene.h"
63 #include "BKE_sequencer.h"
64
65 #include "ED_armature.h"
66 #include "ED_object.h"
67 #include "ED_screen.h"
68 #include "ED_sequencer.h"
69 #include "ED_util.h"
70
71 #include "WM_api.h"
72 #include "WM_types.h"
73
74 #include "UI_interface.h"
75 #include "UI_view2d.h"
76 #include "UI_resources.h"
77
78 #include "RNA_access.h"
79 #include "RNA_define.h"
80 #include "RNA_enum_types.h"
81
82 #include "outliner_intern.h"
83
84
85 /* ****************************************************** */
86
87 /* ************ SELECTION OPERATIONS ********* */
88
89 static void set_operation_types(SpaceOops *soops, ListBase *lb,
90                                 int *scenelevel,
91                                 int *objectlevel,
92                                 int *idlevel,
93                                 int *datalevel)
94 {
95         TreeElement *te;
96         TreeStoreElem *tselem;
97         
98         for (te = lb->first; te; te = te->next) {
99                 tselem = TREESTORE(te);
100                 if (tselem->flag & TSE_SELECTED) {
101                         if (tselem->type) {
102                                 if (*datalevel == 0)
103                                         *datalevel = tselem->type;
104                                 else if (*datalevel != tselem->type)
105                                         *datalevel = -1;
106                         }
107                         else {
108                                 int idcode = GS(tselem->id->name);
109                                 switch (idcode) {
110                                         case ID_SCE:
111                                                 *scenelevel = 1;
112                                                 break;
113                                         case ID_OB:
114                                                 *objectlevel = 1;
115                                                 break;
116                                                 
117                                         case ID_ME: case ID_CU: case ID_MB: case ID_LT:
118                                         case ID_LA: case ID_AR: case ID_CA: case ID_SPK:
119                                         case ID_MA: case ID_TE: case ID_IP: case ID_IM:
120                                         case ID_SO: case ID_KE: case ID_WO: case ID_AC:
121                                         case ID_NLA: case ID_TXT: case ID_GR: case ID_LS:
122                                                 if (*idlevel == 0) *idlevel = idcode;
123                                                 else if (*idlevel != idcode) *idlevel = -1;
124                                                 break;
125                                 }
126                         }
127                 }
128                 if (TSELEM_OPEN(tselem, soops)) {
129                         set_operation_types(soops, &te->subtree,
130                                             scenelevel, objectlevel, idlevel, datalevel);
131                 }
132         }
133 }
134
135 static void unlink_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
136                              TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
137 {
138         /* just set action to NULL */
139         BKE_animdata_set_action(CTX_wm_reports(C), tsep->id, NULL);
140 }
141
142 static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te,
143                                TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
144 {
145         Material **matar = NULL;
146         int a, totcol = 0;
147         
148         if (GS(tsep->id->name) == ID_OB) {
149                 Object *ob = (Object *)tsep->id;
150                 totcol = ob->totcol;
151                 matar = ob->mat;
152         }
153         else if (GS(tsep->id->name) == ID_ME) {
154                 Mesh *me = (Mesh *)tsep->id;
155                 totcol = me->totcol;
156                 matar = me->mat;
157         }
158         else if (GS(tsep->id->name) == ID_CU) {
159                 Curve *cu = (Curve *)tsep->id;
160                 totcol = cu->totcol;
161                 matar = cu->mat;
162         }
163         else if (GS(tsep->id->name) == ID_MB) {
164                 MetaBall *mb = (MetaBall *)tsep->id;
165                 totcol = mb->totcol;
166                 matar = mb->mat;
167         }
168         else {
169                 BLI_assert(0);
170         }
171
172         if (LIKELY(matar != NULL)) {
173                 for (a = 0; a < totcol; a++) {
174                         if (a == te->index && matar[a]) {
175                                 id_us_min(&matar[a]->id);
176                                 matar[a] = NULL;
177                         }
178                 }
179         }
180 }
181
182 static void unlink_texture_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te,
183                               TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
184 {
185         MTex **mtex = NULL;
186         int a;
187         
188         if (GS(tsep->id->name) == ID_MA) {
189                 Material *ma = (Material *)tsep->id;
190                 mtex = ma->mtex;
191         }
192         else if (GS(tsep->id->name) == ID_LA) {
193                 Lamp *la = (Lamp *)tsep->id;
194                 mtex = la->mtex;
195         }
196         else if (GS(tsep->id->name) == ID_WO) {
197                 World *wrld = (World *)tsep->id;
198                 mtex = wrld->mtex;
199         }
200         else if (GS(tsep->id->name) == ID_LS) {
201                 FreestyleLineStyle *ls = (FreestyleLineStyle *)tsep->id;
202                 mtex = ls->mtex;
203         }
204         else {
205                 return;
206         }
207
208         for (a = 0; a < MAX_MTEX; a++) {
209                 if (a == te->index && mtex[a]) {
210                         if (mtex[a]->tex) {
211                                 id_us_min(&mtex[a]->tex->id);
212                                 mtex[a]->tex = NULL;
213                         }
214                 }
215         }
216 }
217
218 static void unlink_group_cb(
219         bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
220         TreeStoreElem *tsep, TreeStoreElem *tselem)
221 {
222         Group *group = (Group *)tselem->id;
223         
224         if (tsep) {
225                 if (GS(tsep->id->name) == ID_OB) {
226                         Object *ob = (Object *)tsep->id;
227                         ob->dup_group = NULL;
228                 }
229         }
230         else {
231                 Main *bmain = CTX_data_main(C);
232                 BKE_group_unlink(bmain, group);
233         }
234 }
235
236 static void unlink_world_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te),
237                             TreeStoreElem *tsep, TreeStoreElem *tselem)
238 {
239         Scene *parscene = (Scene *)tsep->id;
240         World *wo = (World *)tselem->id;
241         
242         /* need to use parent scene not just scene, otherwise may end up getting wrong one */
243         id_us_min(&wo->id);
244         parscene->world = NULL;
245 }
246
247 static void outliner_do_libdata_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
248                                           void (*operation_cb)(bContext *C, Scene *scene, TreeElement *,
249                                                                TreeStoreElem *, TreeStoreElem *))
250 {
251         TreeElement *te;
252         TreeStoreElem *tselem;
253         
254         for (te = lb->first; te; te = te->next) {
255                 tselem = TREESTORE(te);
256                 if (tselem->flag & TSE_SELECTED) {
257                         if (tselem->type == 0) {
258                                 TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : NULL;
259                                 operation_cb(C, scene, te, tsep, tselem);
260                         }
261                 }
262                 if (TSELEM_OPEN(tselem, soops)) {
263                         outliner_do_libdata_operation(C, scene, soops, &te->subtree, operation_cb);
264                 }
265         }
266 }
267
268 /* ******************************************** */
269 typedef enum eOutliner_PropSceneOps {
270         OL_SCENE_OP_DELETE = 1
271 } eOutliner_PropSceneOps;
272
273 static EnumPropertyItem prop_scene_op_types[] = {
274         {OL_SCENE_OP_DELETE, "DELETE", ICON_X, "Delete", ""},
275         {0, NULL, 0, NULL, NULL}
276 };
277
278 static bool outliner_do_scene_operation(
279         bContext *C, eOutliner_PropSceneOps event, ListBase *lb,
280         bool (*operation_cb)(bContext *, eOutliner_PropSceneOps, TreeElement *, TreeStoreElem *))
281 {
282         TreeElement *te;
283         TreeStoreElem *tselem;
284         bool success = false;
285
286         for (te = lb->first; te; te = te->next) {
287                 tselem = TREESTORE(te);
288                 if (tselem->flag & TSE_SELECTED) {
289                         if (operation_cb(C, event, te, tselem)) {
290                                 success = true;
291                         }
292                 }
293         }
294
295         return success;
296 }
297
298 static bool scene_cb(bContext *C, eOutliner_PropSceneOps event, TreeElement *UNUSED(te), TreeStoreElem *tselem)
299 {
300         Scene *scene = (Scene *)tselem->id;
301
302         if (event == OL_SCENE_OP_DELETE) {
303                 if (ED_screen_delete_scene(C, scene)) {
304                         WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
305                 }
306                 else {
307                         return false;
308                 }
309         }
310
311         return true;
312 }
313
314 static int outliner_scene_operation_exec(bContext *C, wmOperator *op)
315 {
316         SpaceOops *soops = CTX_wm_space_outliner(C);
317         const eOutliner_PropSceneOps event = RNA_enum_get(op->ptr, "type");
318
319         if (outliner_do_scene_operation(C, event, &soops->tree, scene_cb) == false) {
320                 return OPERATOR_CANCELLED;
321         }
322
323         if (event == OL_SCENE_OP_DELETE) {
324                 outliner_cleanup_tree(soops);
325                 ED_undo_push(C, "Delete Scene(s)");
326         }
327         else {
328                 BLI_assert(0);
329                 return OPERATOR_CANCELLED;
330         }
331
332         return OPERATOR_FINISHED;
333 }
334
335 void OUTLINER_OT_scene_operation(wmOperatorType *ot)
336 {
337         /* identifiers */
338         ot->name = "Outliner Scene Operation";
339         ot->idname = "OUTLINER_OT_scene_operation";
340         ot->description = "Context menu for scene operations";
341
342         /* callbacks */
343         ot->invoke = WM_menu_invoke;
344         ot->exec = outliner_scene_operation_exec;
345         ot->poll = ED_operator_outliner_active;
346
347         ot->flag = 0;
348
349         ot->prop = RNA_def_enum(ot->srna, "type", prop_scene_op_types, 0, "Scene Operation", "");
350 }
351 /* ******************************************** */
352
353 static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
354                              TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
355 {
356         Base *base = (Base *)te->directdata;
357         
358         if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
359         if (base && ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0)) {
360                 base->flag |= SELECT;
361                 base->object->flag |= SELECT;
362         }
363 }
364
365 static void object_select_hierarchy_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
366                              TreeStoreElem *UNUSED(tsep), TreeStoreElem *UNUSED(tselem))
367 {
368         /* From where do i get the x,y coordinate of the mouse event ? */
369         wmWindow *win = CTX_wm_window(C);
370         int x = win->eventstate->mval[0];
371         int y = win->eventstate->mval[1];
372         outliner_item_do_activate(C, x, y, true, true);
373 }
374
375
376 static void object_deselect_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
377                                TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
378 {
379         Base *base = (Base *)te->directdata;
380         
381         if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
382         if (base) {
383                 base->flag &= ~SELECT;
384                 base->object->flag &= ~SELECT;
385         }
386 }
387
388 static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te,
389                              TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
390 {
391         Base *base = (Base *)te->directdata;
392         
393         if (base == NULL)
394                 base = BKE_scene_base_find(scene, (Object *)tselem->id);
395         if (base) {
396                 // check also library later
397                 if (scene->obedit == base->object)
398                         ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);
399                 
400                 ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
401                 te->directdata = NULL;
402                 tselem->id = NULL;
403         }
404 }
405
406 static void id_local_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
407                         TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
408 {
409         if (tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
410                 /* if the ID type has no special local function,
411                  * just clear the lib */
412                 if (id_make_local(tselem->id, false) == false) {
413                         Main *bmain = CTX_data_main(C);
414                         id_clear_lib_data(bmain, tselem->id);
415                 }
416         }
417 }
418
419 static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te),
420                                 TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
421 {
422         ID *id = tselem->id;
423         
424         id_fake_user_set(id);
425 }
426
427 static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te),
428                                   TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
429 {
430         ID *id = tselem->id;
431         
432         id_fake_user_clear(id);
433 }
434
435 static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
436                                 TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
437 {
438         ID *id = tselem->id;
439
440         ED_object_select_linked_by_id(C, id);
441 }
442
443 static void singleuser_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
444                                  TreeStoreElem *tsep, TreeStoreElem *tselem)
445 {
446         ID *id = tselem->id;
447         
448         if (id) {
449                 IdAdtTemplate *iat = (IdAdtTemplate *)tsep->id;
450                 PointerRNA ptr = {{NULL}};
451                 PropertyRNA *prop;
452                 
453                 RNA_pointer_create(&iat->id, &RNA_AnimData, iat->adt, &ptr);
454                 prop = RNA_struct_find_property(&ptr, "action");
455                 
456                 id_single_user(C, id, &ptr, prop);
457         }
458 }
459
460 static void singleuser_world_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
461                                 TreeStoreElem *tsep, TreeStoreElem *tselem)
462 {
463         ID *id = tselem->id;
464         
465         /* need to use parent scene not just scene, otherwise may end up getting wrong one */
466         if (id) {
467                 Scene *parscene = (Scene *)tsep->id;
468                 PointerRNA ptr = {{NULL}};
469                 PropertyRNA *prop;
470                 
471                 RNA_id_pointer_create(&parscene->id, &ptr);
472                 prop = RNA_struct_find_property(&ptr, "world");
473                 
474                 id_single_user(C, id, &ptr, prop);
475         }
476 }
477
478 static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
479                                    TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
480 {
481         Group *group = (Group *)tselem->id;
482         GroupObject *gob;
483         Base *base;
484         
485         for (gob = group->gobject.first; gob; gob = gob->next) {
486                 base = BKE_scene_base_find(scene, gob->ob);
487                 if (base) {
488                         base->object->flag |= SELECT;
489                         base->flag |= SELECT;
490                 }
491                 else {
492                         /* link to scene */
493                         base = MEM_callocN(sizeof(Base), "add_base");
494                         BLI_addhead(&scene->base, base);
495                         base->lay = gob->ob->lay;
496                         gob->ob->flag |= SELECT;
497                         base->flag = gob->ob->flag;
498                         base->object = gob->ob;
499                         id_lib_extern((ID *)gob->ob); /* in case these are from a linked group */
500                 }
501         }
502 }
503
504 static void group_instance_cb(bContext *C, Scene *scene, TreeElement *UNUSED(te),
505                               TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
506 {
507         Group *group = (Group *)tselem->id;
508
509         Object *ob = ED_object_add_type(C, OB_EMPTY, group->id.name + 2, scene->cursor, NULL, false, scene->layact);
510         ob->dup_group = group;
511         ob->transflag |= OB_DUPLIGROUP;
512         id_lib_extern(&group->id);
513 }
514
515 /**
516  * \param select_recurse: Set to false for operations which are already recursively operating on their children.
517  */
518 void outliner_do_object_operation_ex(
519         bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb,
520         void (*operation_cb)(bContext *C, Scene *scene, TreeElement *,
521                              TreeStoreElem *, TreeStoreElem *),
522         bool select_recurse)
523 {
524         TreeElement *te;
525         
526         for (te = lb->first; te; te = te->next) {
527                 TreeStoreElem *tselem = TREESTORE(te);
528                 bool select_handled = false;
529                 if (tselem->flag & TSE_SELECTED) {
530                         if (tselem->type == 0 && te->idcode == ID_OB) {
531                                 // when objects selected in other scenes... dunno if that should be allowed
532                                 Scene *scene_owner = (Scene *)outliner_search_back(soops, te, ID_SCE);
533                                 if (scene_owner && scene_act != scene_owner) {
534                                         ED_screen_set_scene(C, CTX_wm_screen(C), scene_owner);
535                                 }
536                                 /* important to use 'scene_owner' not scene_act else deleting objects can crash.
537                                  * only use 'scene_act' when 'scene_owner' is NULL, which can happen when the
538                                  * outliner isn't showing scenes: Visible Layer draw mode for eg. */
539                                 operation_cb(C, scene_owner ? scene_owner : scene_act, te, NULL, tselem);
540                                 select_handled = true;
541                         }
542                 }
543                 if (TSELEM_OPEN(tselem, soops)) {
544                         if ((select_handled == false) || select_recurse) {
545                                 outliner_do_object_operation_ex(C, scene_act, soops, &te->subtree, operation_cb, select_recurse);
546                         }
547                 }
548         }
549 }
550
551 void outliner_do_object_operation(
552         bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb,
553         void (*operation_cb)(bContext *C, Scene *scene, TreeElement *,
554                              TreeStoreElem *, TreeStoreElem *))
555 {
556         outliner_do_object_operation_ex(C, scene_act, soops, lb, operation_cb, true);
557 }
558
559 /* ******************************************** */
560
561 static void clear_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te),
562                               TreeStoreElem *tselem, void *UNUSED(arg))
563 {
564         BKE_animdata_free(tselem->id);
565 }
566
567
568 static void unlinkact_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te),
569                                   TreeStoreElem *tselem, void *UNUSED(arg))
570 {
571         /* just set action to NULL */
572         BKE_animdata_set_action(NULL, tselem->id, NULL);
573 }
574
575 static void cleardrivers_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te),
576                                      TreeStoreElem *tselem, void *UNUSED(arg))
577 {
578         IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id;
579         
580         /* just free drivers - stored as a list of F-Curves */
581         free_fcurves(&iat->adt->drivers);
582 }
583
584 static void refreshdrivers_animdata_cb(int UNUSED(event), TreeElement *UNUSED(te),
585                                        TreeStoreElem *tselem, void *UNUSED(arg))
586 {
587         IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id;
588         FCurve *fcu;
589         
590         /* loop over drivers, performing refresh (i.e. check graph_buttons.c and rna_fcurve.c for details) */
591         for (fcu = iat->adt->drivers.first; fcu; fcu = fcu->next) {
592                 fcu->flag &= ~FCURVE_DISABLED;
593                 
594                 if (fcu->driver)
595                         fcu->driver->flag &= ~DRIVER_FLAG_INVALID;
596         }
597 }
598
599 /* --------------------------------- */
600
601 typedef enum eOutliner_PropDataOps {
602         OL_DOP_SELECT = 1,
603         OL_DOP_DESELECT,
604         OL_DOP_HIDE,
605         OL_DOP_UNHIDE,
606         OL_DOP_SELECT_LINKED,
607 } eOutliner_PropDataOps;
608
609 typedef enum eOutliner_PropConstraintOps {
610         OL_CONSTRAINTOP_ENABLE = 1,
611         OL_CONSTRAINTOP_DISABLE,
612         OL_CONSTRAINTOP_DELETE
613 } eOutliner_PropConstraintOps;
614
615 typedef enum eOutliner_PropModifierOps {
616         OL_MODIFIER_OP_TOGVIS = 1,
617         OL_MODIFIER_OP_TOGREN,
618         OL_MODIFIER_OP_DELETE
619 } eOutliner_PropModifierOps;
620
621 static void pchan_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *UNUSED(arg))
622 {
623         bPoseChannel *pchan = (bPoseChannel *)te->directdata;
624         
625         if (event == OL_DOP_SELECT)
626                 pchan->bone->flag |= BONE_SELECTED;
627         else if (event == OL_DOP_DESELECT)
628                 pchan->bone->flag &= ~BONE_SELECTED;
629         else if (event == OL_DOP_HIDE) {
630                 pchan->bone->flag |= BONE_HIDDEN_P;
631                 pchan->bone->flag &= ~BONE_SELECTED;
632         }
633         else if (event == OL_DOP_UNHIDE)
634                 pchan->bone->flag &= ~BONE_HIDDEN_P;
635 }
636
637 static void bone_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *UNUSED(arg))
638 {
639         Bone *bone = (Bone *)te->directdata;
640         
641         if (event == OL_DOP_SELECT)
642                 bone->flag |= BONE_SELECTED;
643         else if (event == OL_DOP_DESELECT)
644                 bone->flag &= ~BONE_SELECTED;
645         else if (event == OL_DOP_HIDE) {
646                 bone->flag |= BONE_HIDDEN_P;
647                 bone->flag &= ~BONE_SELECTED;
648         }
649         else if (event == OL_DOP_UNHIDE)
650                 bone->flag &= ~BONE_HIDDEN_P;
651 }
652
653 static void ebone_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *UNUSED(arg))
654 {
655         EditBone *ebone = (EditBone *)te->directdata;
656         
657         if (event == OL_DOP_SELECT)
658                 ebone->flag |= BONE_SELECTED;
659         else if (event == OL_DOP_DESELECT)
660                 ebone->flag &= ~BONE_SELECTED;
661         else if (event == OL_DOP_HIDE) {
662                 ebone->flag |= BONE_HIDDEN_A;
663                 ebone->flag &= ~BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL;
664         }
665         else if (event == OL_DOP_UNHIDE)
666                 ebone->flag &= ~BONE_HIDDEN_A;
667 }
668
669 static void sequence_cb(int event, TreeElement *te, TreeStoreElem *tselem, void *scene_ptr)
670 {
671         Sequence *seq = (Sequence *)te->directdata;
672         if (event == OL_DOP_SELECT) {
673                 Scene *scene = (Scene *)scene_ptr;
674                 Editing *ed = BKE_sequencer_editing_get(scene, false);
675                 if (BLI_findindex(ed->seqbasep, seq) != -1) {
676                         ED_sequencer_select_sequence_single(scene, seq, true);
677                 }
678         }
679
680         (void)tselem;
681 }
682
683 static void gp_layer_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *UNUSED(arg))
684 {
685         bGPDlayer *gpl = (bGPDlayer *)te->directdata;
686         
687         if (event == OL_DOP_SELECT)
688                 gpl->flag |= GP_LAYER_SELECT;
689         else if (event == OL_DOP_DESELECT)
690                 gpl->flag &= ~GP_LAYER_SELECT;
691         else if (event == OL_DOP_HIDE)
692                 gpl->flag |= GP_LAYER_HIDE;
693         else if (event == OL_DOP_UNHIDE)
694                 gpl->flag &= ~GP_LAYER_HIDE;
695 }
696
697 static void data_select_linked_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *C_v)
698 {
699         if (event == OL_DOP_SELECT_LINKED) {
700                 if (RNA_struct_is_ID(te->rnaptr.type)) {
701                         bContext *C = (bContext *) C_v;
702                         ID *id = te->rnaptr.data;
703
704                         ED_object_select_linked_by_id(C, id);
705                 }
706         }
707 }
708
709 static void constraint_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *C_v)
710 {
711         bContext *C = C_v;
712         SpaceOops *soops = CTX_wm_space_outliner(C);
713         bConstraint *constraint = (bConstraint *)te->directdata;
714         Object *ob = (Object *)outliner_search_back(soops, te, ID_OB);
715
716         if (event == OL_CONSTRAINTOP_ENABLE) {
717                 constraint->flag &= ~CONSTRAINT_OFF;
718                 ED_object_constraint_update(ob);
719                 WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
720         }
721         else if (event == OL_CONSTRAINTOP_DISABLE) {
722                 constraint->flag = CONSTRAINT_OFF;
723                 ED_object_constraint_update(ob);
724                 WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
725         }
726         else if (event == OL_CONSTRAINTOP_DELETE) {
727                 ListBase *lb = NULL;
728
729                 if (TREESTORE(te->parent->parent)->type == TSE_POSE_CHANNEL) {
730                         lb = &((bPoseChannel *)te->parent->parent->directdata)->constraints;
731                 }
732                 else {
733                         lb = &ob->constraints;
734                 }
735
736                 if (BKE_constraint_remove_ex(lb, ob, constraint, true)) {
737                         /* there's no active constraint now, so make sure this is the case */
738                         BKE_constraints_active_set(&ob->constraints, NULL);
739                         ED_object_constraint_update(ob); /* needed to set the flags on posebones correctly */
740                         WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
741                         te->store_elem->flag &= ~TSE_SELECTED;
742                 }
743         }
744 }
745
746 static void modifier_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *Carg)
747 {
748         bContext *C = (bContext *)Carg;
749         Main *bmain = CTX_data_main(C);
750         SpaceOops *soops = CTX_wm_space_outliner(C);
751         ModifierData *md = (ModifierData *)te->directdata;
752         Object *ob = (Object *)outliner_search_back(soops, te, ID_OB);
753
754         if (event == OL_MODIFIER_OP_TOGVIS) {
755                 md->mode ^= eModifierMode_Realtime;
756                 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
757                 WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
758         }
759         else if (event == OL_MODIFIER_OP_TOGREN) {
760                 md->mode ^= eModifierMode_Render;
761                 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
762                 WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
763         }
764         else if (event == OL_MODIFIER_OP_DELETE) {
765                 ED_object_modifier_remove(NULL, bmain, ob, md);
766                 WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER | NA_REMOVED, ob);
767                 te->store_elem->flag &= ~TSE_SELECTED;
768         }
769 }
770
771 static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb,
772                                        void (*operation_cb)(int, TreeElement *, TreeStoreElem *, void *),
773                                        void *arg)
774 {
775         TreeElement *te;
776         TreeStoreElem *tselem;
777         
778         for (te = lb->first; te; te = te->next) {
779                 tselem = TREESTORE(te);
780                 if (tselem->flag & TSE_SELECTED) {
781                         if (tselem->type == type) {
782                                 operation_cb(event, te, tselem, arg);
783                         }
784                 }
785                 if (TSELEM_OPEN(tselem, soops)) {
786                         outliner_do_data_operation(soops, type, event, &te->subtree, operation_cb, arg);
787                 }
788         }
789 }
790
791 static Base *outline_delete_hierarchy(bContext *C, Scene *scene, Base *base)
792 {
793         Base *child_base, *base_next;
794         Object *parent;
795
796         if (!base) {
797                 return NULL;
798         }
799
800         for (child_base = scene->base.first; child_base; child_base = base_next) {
801                 base_next = child_base->next;
802                 for (parent = child_base->object->parent; parent && (parent != base->object); parent = parent->parent);
803                 if (parent) {
804                         base_next = outline_delete_hierarchy(C, scene, child_base);
805                 }
806         }
807
808         base_next = base->next;
809         ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
810         return base_next;
811 }
812
813 static void object_delete_hierarchy_cb(
814         bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
815 {
816         Base *base = (Base *)te->directdata;
817         Object *obedit = scene->obedit;
818
819         if (!base) {
820                 base = BKE_scene_base_find(scene, (Object *)tselem->id);
821         }
822         if (base) {
823                 /* Check also library later. */
824                 for (; obedit && (obedit != base->object); obedit = obedit->parent);
825                 if (obedit == base->object) {
826                         ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);
827                 }
828
829                 outline_delete_hierarchy(C, scene, base);
830                 te->directdata = NULL;
831                 tselem->id = NULL;
832         }
833
834         WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
835 }
836
837 /* **************************************** */
838
839 enum {
840         OL_OP_SELECT = 1,
841         OL_OP_DESELECT,
842         OL_OP_SELECT_HIERARCHY,
843         OL_OP_DELETE,
844         OL_OP_DELETE_HIERARCHY,
845         OL_OP_LOCALIZED,  /* disabled, see below */
846         OL_OP_TOGVIS,
847         OL_OP_TOGSEL,
848         OL_OP_TOGREN,
849         OL_OP_RENAME
850 };
851
852 static EnumPropertyItem prop_object_op_types[] = {
853         {OL_OP_SELECT, "SELECT", 0, "Select", ""},
854         {OL_OP_DESELECT, "DESELECT", 0, "Deselect", ""},
855         {OL_OP_SELECT_HIERARCHY, "SELECT_HIERARCHY", 0, "Select Hierarchy", ""},
856         {OL_OP_DELETE, "DELETE", 0, "Delete", ""},
857         {OL_OP_DELETE_HIERARCHY, "DELETE_HIERARCHY", 0, "Delete Hierarchy", ""},
858         {OL_OP_TOGVIS, "TOGVIS", 0, "Toggle Visible", ""},
859         {OL_OP_TOGSEL, "TOGSEL", 0, "Toggle Selectable", ""},
860         {OL_OP_TOGREN, "TOGREN", 0, "Toggle Renderable", ""},
861         {OL_OP_RENAME, "RENAME", 0, "Rename", ""},
862         {0, NULL, 0, NULL, NULL}
863 };
864
865 static int outliner_object_operation_exec(bContext *C, wmOperator *op)
866 {
867         Main *bmain = CTX_data_main(C);
868         Scene *scene = CTX_data_scene(C);
869         SpaceOops *soops = CTX_wm_space_outliner(C);
870         int event;
871         const char *str = NULL;
872         
873         /* check for invalid states */
874         if (soops == NULL)
875                 return OPERATOR_CANCELLED;
876         
877         event = RNA_enum_get(op->ptr, "type");
878
879         if (event == OL_OP_SELECT) {
880                 Scene *sce = scene;  // to be able to delete, scenes are set...
881                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_cb);
882                 if (scene != sce) {
883                         ED_screen_set_scene(C, CTX_wm_screen(C), sce);
884                 }
885                 
886                 str = "Select Objects";
887                 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
888         }
889         else if (event == OL_OP_SELECT_HIERARCHY) {
890                 Scene *sce = scene;  // to be able to delete, scenes are set...
891                 outliner_do_object_operation_ex(C, scene, soops, &soops->tree, object_select_hierarchy_cb, false);
892                 if (scene != sce) {
893                         ED_screen_set_scene(C, CTX_wm_screen(C), sce);
894                 }       
895                 str = "Select Object Hierarchy";
896                 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
897         }
898         else if (event == OL_OP_DESELECT) {
899                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb);
900                 str = "Deselect Objects";
901                 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
902         }
903         else if (event == OL_OP_DELETE) {
904                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
905
906                 /* XXX: tree management normally happens from draw_outliner(), but when
907                  *      you're clicking to fast on Delete object from context menu in
908                  *      outliner several mouse events can be handled in one cycle without
909                  *      handling notifiers/redraw which leads to deleting the same object twice.
910                  *      cleanup tree here to prevent such cases. */
911                 outliner_cleanup_tree(soops);
912
913                 DAG_relations_tag_update(bmain);
914                 str = "Delete Objects";
915                 WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
916         }
917         else if (event == OL_OP_DELETE_HIERARCHY) {
918                 outliner_do_object_operation_ex(C, scene, soops, &soops->tree, object_delete_hierarchy_cb, false);
919
920                 /* XXX: See OL_OP_DELETE comment above. */
921                 outliner_cleanup_tree(soops);
922
923                 DAG_relations_tag_update(bmain);
924                 str = "Delete Object Hierarchy";
925                 WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
926         }
927         else if (event == OL_OP_LOCALIZED) {    /* disabled, see above enum (ton) */
928                 outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb);
929                 str = "Localized Objects";
930         }
931         else if (event == OL_OP_TOGVIS) {
932                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
933                 str = "Toggle Visibility";
934                 WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene);
935         }
936         else if (event == OL_OP_TOGSEL) {
937                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
938                 str = "Toggle Selectability";
939                 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
940         }
941         else if (event == OL_OP_TOGREN) {
942                 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
943                 str = "Toggle Renderability";
944                 WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene);
945         }
946         else if (event == OL_OP_RENAME) {
947                 outliner_do_object_operation(C, scene, soops, &soops->tree, item_rename_cb);
948                 str = "Rename Object";
949         }
950         else {
951                 BLI_assert(0);
952                 return OPERATOR_CANCELLED;
953         }
954
955         ED_undo_push(C, str);
956         
957         return OPERATOR_FINISHED;
958 }
959
960
961 void OUTLINER_OT_object_operation(wmOperatorType *ot)
962 {
963         /* identifiers */
964         ot->name = "Outliner Object Operation";
965         ot->idname = "OUTLINER_OT_object_operation";
966         ot->description = "";
967         
968         /* callbacks */
969         ot->invoke = WM_menu_invoke;
970         ot->exec = outliner_object_operation_exec;
971         ot->poll = ED_operator_outliner_active;
972         
973         ot->flag = 0;
974
975         ot->prop = RNA_def_enum(ot->srna, "type", prop_object_op_types, 0, "Object Operation", "");
976 }
977
978 /* **************************************** */
979
980 typedef enum eOutliner_PropGroupOps {
981         OL_GROUPOP_UNLINK = 1,
982         OL_GROUPOP_LOCAL,
983         OL_GROUPOP_LINK,
984         OL_GROUPOP_INSTANCE,
985         OL_GROUPOP_TOGVIS,
986         OL_GROUPOP_TOGSEL,
987         OL_GROUPOP_TOGREN,
988         OL_GROUPOP_RENAME,
989 } eOutliner_PropGroupOps;
990
991 static EnumPropertyItem prop_group_op_types[] = {
992         {OL_GROUPOP_UNLINK, "UNLINK",     0, "Unlink Group", ""},
993         {OL_GROUPOP_LOCAL, "LOCAL",       0, "Make Local Group", ""},
994         {OL_GROUPOP_LINK, "LINK",         0, "Link Group Objects to Scene", ""},
995         {OL_GROUPOP_INSTANCE, "INSTANCE", 0, "Instance Groups in Scene", ""},
996         {OL_GROUPOP_TOGVIS, "TOGVIS",     0, "Toggle Visible Group", ""},
997         {OL_GROUPOP_TOGSEL, "TOGSEL",     0, "Toggle Selectable", ""},
998         {OL_GROUPOP_TOGREN, "TOGREN",     0, "Toggle Renderable", ""},
999         {OL_GROUPOP_RENAME, "RENAME",     0, "Rename", ""},
1000         {0, NULL, 0, NULL, NULL}
1001 };
1002
1003 static int outliner_group_operation_exec(bContext *C, wmOperator *op)
1004 {
1005         Scene *scene = CTX_data_scene(C);
1006         SpaceOops *soops = CTX_wm_space_outliner(C);
1007         int event;
1008         
1009         /* check for invalid states */
1010         if (soops == NULL)
1011                 return OPERATOR_CANCELLED;
1012         
1013         event = RNA_enum_get(op->ptr, "type");
1014
1015         switch (event) {
1016                 case OL_GROUPOP_UNLINK:
1017                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_group_cb);
1018                         break;
1019                 case OL_GROUPOP_LOCAL:
1020                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb);
1021                         break;
1022                 case OL_GROUPOP_LINK:
1023                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_linkobs2scene_cb);
1024                         break;
1025                 case OL_GROUPOP_INSTANCE:
1026                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_instance_cb);
1027                         break;
1028                 case OL_GROUPOP_TOGVIS:
1029                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_visibility_cb);
1030                         break;
1031                 case OL_GROUPOP_TOGSEL:
1032                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_selectability_cb);
1033                         break;
1034                 case OL_GROUPOP_TOGREN:
1035                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_renderability_cb);
1036                         break;
1037                 case OL_GROUPOP_RENAME:
1038                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb);
1039                         break;
1040                 default:
1041                         BLI_assert(0);
1042         }
1043
1044         if (event == 3) { /* instance */
1045                 /* works without this except if you try render right after, see: 22027 */
1046                 DAG_relations_tag_update(CTX_data_main(C));
1047         }
1048
1049         ED_undo_push(C, prop_group_op_types[event - 1].name);
1050         WM_event_add_notifier(C, NC_GROUP, NULL);
1051
1052         return OPERATOR_FINISHED;
1053 }
1054
1055
1056 void OUTLINER_OT_group_operation(wmOperatorType *ot)
1057 {
1058         /* identifiers */
1059         ot->name = "Outliner Group Operation";
1060         ot->idname = "OUTLINER_OT_group_operation";
1061         ot->description = "";
1062         
1063         /* callbacks */
1064         ot->invoke = WM_menu_invoke;
1065         ot->exec = outliner_group_operation_exec;
1066         ot->poll = ED_operator_outliner_active;
1067         
1068         ot->flag = 0;
1069         
1070         ot->prop = RNA_def_enum(ot->srna, "type", prop_group_op_types, 0, "Group Operation", "");
1071 }
1072
1073 /* **************************************** */
1074
1075 typedef enum eOutlinerIdOpTypes {
1076         OUTLINER_IDOP_INVALID = 0,
1077         
1078         OUTLINER_IDOP_UNLINK,
1079         OUTLINER_IDOP_LOCAL,
1080         OUTLINER_IDOP_SINGLE,
1081         
1082         OUTLINER_IDOP_FAKE_ADD,
1083         OUTLINER_IDOP_FAKE_CLEAR,
1084         OUTLINER_IDOP_RENAME,
1085
1086         OUTLINER_IDOP_SELECT_LINKED
1087 } eOutlinerIdOpTypes;
1088
1089 // TODO: implement support for changing the ID-block used
1090 static EnumPropertyItem prop_id_op_types[] = {
1091         {OUTLINER_IDOP_UNLINK, "UNLINK", 0, "Unlink", ""},
1092         {OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""},
1093         {OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""},
1094         {OUTLINER_IDOP_FAKE_ADD, "ADD_FAKE", 0, "Add Fake User",
1095          "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"},
1096         {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""},
1097         {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""},
1098         {OUTLINER_IDOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
1099         {0, NULL, 0, NULL, NULL}
1100 };
1101
1102 static int outliner_id_operation_exec(bContext *C, wmOperator *op)
1103 {
1104         Scene *scene = CTX_data_scene(C);
1105         SpaceOops *soops = CTX_wm_space_outliner(C);
1106         int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1107         eOutlinerIdOpTypes event;
1108         
1109         /* check for invalid states */
1110         if (soops == NULL)
1111                 return OPERATOR_CANCELLED;
1112         
1113         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1114         
1115         event = RNA_enum_get(op->ptr, "type");
1116         
1117         switch (event) {
1118                 case OUTLINER_IDOP_UNLINK:
1119                 {
1120                         /* unlink datablock from its parent */
1121                         switch (idlevel) {
1122                                 case ID_AC:
1123                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_action_cb);
1124                                         
1125                                         WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
1126                                         ED_undo_push(C, "Unlink action");
1127                                         break;
1128                                 case ID_MA:
1129                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_material_cb);
1130                                         
1131                                         WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL);
1132                                         ED_undo_push(C, "Unlink material");
1133                                         break;
1134                                 case ID_TE:
1135                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_texture_cb);
1136                                         
1137                                         WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL);
1138                                         ED_undo_push(C, "Unlink texture");
1139                                         break;
1140                                 case ID_WO:
1141                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_world_cb);
1142                                         
1143                                         WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL);
1144                                         ED_undo_push(C, "Unlink world");
1145                                         break;
1146                                 default:
1147                                         BKE_report(op->reports, RPT_WARNING, "Not yet implemented");
1148                                         break;
1149                         }
1150                         break;
1151                 }
1152                 case OUTLINER_IDOP_LOCAL:
1153                 {
1154                         /* make local */
1155                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb);
1156                         ED_undo_push(C, "Localized Data");
1157                         break;
1158                 }
1159                 case OUTLINER_IDOP_SINGLE:
1160                 {
1161                         /* make single user */
1162                         switch (idlevel) {
1163                                 case ID_AC:
1164                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_action_cb);
1165                                         
1166                                         WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
1167                                         ED_undo_push(C, "Single-User Action");
1168                                         break;
1169                                         
1170                                 case ID_WO:
1171                                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_world_cb);
1172                                         
1173                                         WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL);
1174                                         ED_undo_push(C, "Single-User World");
1175                                         break;
1176                                         
1177                                 default:
1178                                         BKE_report(op->reports, RPT_WARNING, "Not yet implemented");
1179                                         break;
1180                         }
1181                         break;
1182                 }
1183                 case OUTLINER_IDOP_FAKE_ADD:
1184                 {
1185                         /* set fake user */
1186                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_set_cb);
1187                         
1188                         WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
1189                         ED_undo_push(C, "Add Fake User");
1190                         break;
1191                 }
1192                 case OUTLINER_IDOP_FAKE_CLEAR:
1193                 {
1194                         /* clear fake user */
1195                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_clear_cb);
1196                         
1197                         WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
1198                         ED_undo_push(C, "Clear Fake User");
1199                         break;
1200                 }
1201                 case OUTLINER_IDOP_RENAME:
1202                 {
1203                         /* rename */
1204                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb);
1205                         
1206                         WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
1207                         ED_undo_push(C, "Rename");
1208                         break;
1209                 }
1210                 case OUTLINER_IDOP_SELECT_LINKED:
1211                         outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_select_linked_cb);
1212                         ED_undo_push(C, "Select");
1213                         break;
1214                         
1215                 default:
1216                         // invalid - unhandled
1217                         break;
1218         }
1219         
1220         /* wrong notifier still... */
1221         WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
1222         
1223         // XXX: this is just so that outliner is always up to date 
1224         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
1225         
1226         return OPERATOR_FINISHED;
1227 }
1228
1229
1230 void OUTLINER_OT_id_operation(wmOperatorType *ot)
1231 {
1232         /* identifiers */
1233         ot->name = "Outliner ID data Operation";
1234         ot->idname = "OUTLINER_OT_id_operation";
1235         ot->description = "";
1236         
1237         /* callbacks */
1238         ot->invoke = WM_menu_invoke;
1239         ot->exec = outliner_id_operation_exec;
1240         ot->poll = ED_operator_outliner_active;
1241         
1242         ot->flag = 0;
1243         
1244         ot->prop = RNA_def_enum(ot->srna, "type", prop_id_op_types, 0, "ID data Operation", "");
1245 }
1246
1247 /* **************************************** */
1248
1249 static void outliner_do_id_set_operation(SpaceOops *soops, int type, ListBase *lb, ID *newid,
1250                                          void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *, ID *))
1251 {
1252         TreeElement *te;
1253         TreeStoreElem *tselem;
1254         
1255         for (te = lb->first; te; te = te->next) {
1256                 tselem = TREESTORE(te);
1257                 if (tselem->flag & TSE_SELECTED) {
1258                         if (tselem->type == type) {
1259                                 TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : NULL;
1260                                 operation_cb(te, tselem, tsep, newid);
1261                         }
1262                 }
1263                 if (TSELEM_OPEN(tselem, soops)) {
1264                         outliner_do_id_set_operation(soops, type, &te->subtree, newid, operation_cb);
1265                 }
1266         }
1267 }
1268
1269 /* ------------------------------------------ */
1270
1271 static void actionset_id_cb(TreeElement *UNUSED(te), TreeStoreElem *tselem, TreeStoreElem *tsep, ID *actId)
1272 {
1273         bAction *act = (bAction *)actId;
1274         
1275         if (tselem->type == TSE_ANIM_DATA) {
1276                 /* "animation" entries - action is child of this */
1277                 BKE_animdata_set_action(NULL, tselem->id, act);
1278         }
1279         /* TODO: if any other "expander" channels which own actions need to support this menu, 
1280          * add: tselem->type = ...
1281          */
1282         else if (tsep && (tsep->type == TSE_ANIM_DATA)) {
1283                 /* "animation" entries case again */
1284                 BKE_animdata_set_action(NULL, tsep->id, act);
1285         }
1286         // TODO: other cases not supported yet
1287 }
1288
1289 static int outliner_action_set_exec(bContext *C, wmOperator *op)
1290 {
1291         SpaceOops *soops = CTX_wm_space_outliner(C);
1292         int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1293         
1294         bAction *act;
1295         
1296         /* check for invalid states */
1297         if (soops == NULL)
1298                 return OPERATOR_CANCELLED;
1299         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1300         
1301         /* get action to use */
1302         act = BLI_findlink(&CTX_data_main(C)->action, RNA_enum_get(op->ptr, "action"));
1303         
1304         if (act == NULL) {
1305                 BKE_report(op->reports, RPT_ERROR, "No valid action to add");
1306                 return OPERATOR_CANCELLED;
1307         }
1308         else if (act->idroot == 0) {
1309                 /* hopefully in this case (i.e. library of userless actions), the user knows what they're doing... */
1310                 BKE_reportf(op->reports, RPT_WARNING,
1311                             "Action '%s' does not specify what datablocks it can be used on "
1312                             "(try setting the 'ID Root Type' setting from the Datablocks Editor "
1313                             "for this action to avoid future problems)",
1314                             act->id.name + 2);
1315         }
1316         
1317         /* perform action if valid channel */
1318         if (datalevel == TSE_ANIM_DATA)
1319                 outliner_do_id_set_operation(soops, datalevel, &soops->tree, (ID *)act, actionset_id_cb);
1320         else if (idlevel == ID_AC)
1321                 outliner_do_id_set_operation(soops, idlevel, &soops->tree, (ID *)act, actionset_id_cb);
1322         else
1323                 return OPERATOR_CANCELLED;
1324                 
1325         /* set notifier that things have changed */
1326         WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
1327         ED_undo_push(C, "Set action");
1328         
1329         /* done */
1330         return OPERATOR_FINISHED;
1331 }
1332
1333 void OUTLINER_OT_action_set(wmOperatorType *ot)
1334 {
1335         PropertyRNA *prop;
1336
1337         /* identifiers */
1338         ot->name = "Outliner Set Action";
1339         ot->idname = "OUTLINER_OT_action_set";
1340         ot->description = "Change the active action used";
1341         
1342         /* api callbacks */
1343         ot->invoke = WM_enum_search_invoke;
1344         ot->exec = outliner_action_set_exec;
1345         ot->poll = ED_operator_outliner_active;
1346         
1347         /* flags */
1348         ot->flag = 0;
1349         
1350         /* props */
1351         // TODO: this would be nicer as an ID-pointer...
1352         prop = RNA_def_enum(ot->srna, "action", DummyRNA_NULL_items, 0, "Action", "");
1353         RNA_def_enum_funcs(prop, RNA_action_itemf);
1354         RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
1355         ot->prop = prop;
1356 }
1357
1358 /* **************************************** */
1359
1360 typedef enum eOutliner_AnimDataOps {
1361         OUTLINER_ANIMOP_INVALID = 0,
1362         
1363         OUTLINER_ANIMOP_CLEAR_ADT,
1364         
1365         OUTLINER_ANIMOP_SET_ACT,
1366         OUTLINER_ANIMOP_CLEAR_ACT,
1367         
1368         OUTLINER_ANIMOP_REFRESH_DRV,
1369         OUTLINER_ANIMOP_CLEAR_DRV
1370         
1371         //OUTLINER_ANIMOP_COPY_DRIVERS,
1372         //OUTLINER_ANIMOP_PASTE_DRIVERS
1373 } eOutliner_AnimDataOps;
1374
1375 static EnumPropertyItem prop_animdata_op_types[] = {
1376         {OUTLINER_ANIMOP_CLEAR_ADT, "CLEAR_ANIMDATA", 0, "Clear Animation Data", "Remove this animation data container"},
1377         {OUTLINER_ANIMOP_SET_ACT, "SET_ACT", 0, "Set Action", ""},
1378         {OUTLINER_ANIMOP_CLEAR_ACT, "CLEAR_ACT", 0, "Unlink Action", ""},
1379         {OUTLINER_ANIMOP_REFRESH_DRV, "REFRESH_DRIVERS", 0, "Refresh Drivers", ""},
1380         //{OUTLINER_ANIMOP_COPY_DRIVERS, "COPY_DRIVERS", 0, "Copy Drivers", ""},
1381         //{OUTLINER_ANIMOP_PASTE_DRIVERS, "PASTE_DRIVERS", 0, "Paste Drivers", ""},
1382         {OUTLINER_ANIMOP_CLEAR_DRV, "CLEAR_DRIVERS", 0, "Clear Drivers", ""},
1383         {0, NULL, 0, NULL, NULL}
1384 };
1385
1386 static int outliner_animdata_operation_exec(bContext *C, wmOperator *op)
1387 {
1388         SpaceOops *soops = CTX_wm_space_outliner(C);
1389         int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1390         eOutliner_AnimDataOps event;
1391         short updateDeps = 0;
1392         
1393         /* check for invalid states */
1394         if (soops == NULL)
1395                 return OPERATOR_CANCELLED;
1396         
1397         event = RNA_enum_get(op->ptr, "type");
1398         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1399         
1400         if (datalevel != TSE_ANIM_DATA)
1401                 return OPERATOR_CANCELLED;
1402         
1403         /* perform the core operation */
1404         switch (event) {
1405                 case OUTLINER_ANIMOP_CLEAR_ADT:
1406                         /* Remove Animation Data - this may remove the active action, in some cases... */
1407                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, clear_animdata_cb, NULL);
1408                         
1409                         WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
1410                         ED_undo_push(C, "Clear Animation Data");
1411                         break;
1412                 
1413                 case OUTLINER_ANIMOP_SET_ACT:
1414                         /* delegate once again... */
1415                         WM_operator_name_call(C, "OUTLINER_OT_action_set", WM_OP_INVOKE_REGION_WIN, NULL);
1416                         break;
1417                 
1418                 case OUTLINER_ANIMOP_CLEAR_ACT:
1419                         /* clear active action - using standard rules */
1420                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, unlinkact_animdata_cb, NULL);
1421                         
1422                         WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
1423                         ED_undo_push(C, "Unlink action");
1424                         break;
1425                         
1426                 case OUTLINER_ANIMOP_REFRESH_DRV:
1427                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, refreshdrivers_animdata_cb, NULL);
1428                         
1429                         WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL);
1430                         //ED_undo_push(C, "Refresh Drivers"); /* no undo needed - shouldn't have any impact? */
1431                         updateDeps = 1;
1432                         break;
1433                         
1434                 case OUTLINER_ANIMOP_CLEAR_DRV:
1435                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, cleardrivers_animdata_cb, NULL);
1436                         
1437                         WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL);
1438                         ED_undo_push(C, "Clear Drivers");
1439                         updateDeps = 1;
1440                         break;
1441                         
1442                 default: // invalid
1443                         break;
1444         }
1445         
1446         /* update dependencies */
1447         if (updateDeps) {
1448                 /* rebuild depsgraph for the new deps */
1449                 DAG_relations_tag_update(CTX_data_main(C));
1450         }
1451         
1452         return OPERATOR_FINISHED;
1453 }
1454
1455
1456 void OUTLINER_OT_animdata_operation(wmOperatorType *ot)
1457 {
1458         /* identifiers */
1459         ot->name = "Outliner Animation Data Operation";
1460         ot->idname = "OUTLINER_OT_animdata_operation";
1461         ot->description = "";
1462         
1463         /* callbacks */
1464         ot->invoke = WM_menu_invoke;
1465         ot->exec = outliner_animdata_operation_exec;
1466         ot->poll = ED_operator_outliner_active;
1467         
1468         ot->flag = 0;
1469         
1470         ot->prop = RNA_def_enum(ot->srna, "type", prop_animdata_op_types, 0, "Animation Operation", "");
1471 }
1472
1473 /* **************************************** */
1474
1475 static EnumPropertyItem prop_constraint_op_types[] = {
1476         {OL_CONSTRAINTOP_ENABLE, "ENABLE", ICON_RESTRICT_VIEW_OFF, "Enable", ""},
1477         {OL_CONSTRAINTOP_DISABLE, "DISABLE", ICON_RESTRICT_VIEW_ON, "Disable", ""},
1478         {OL_CONSTRAINTOP_DELETE, "DELETE", ICON_X, "Delete", ""},
1479         {0, NULL, 0, NULL, NULL}
1480 };
1481
1482 static int outliner_constraint_operation_exec(bContext *C, wmOperator *op)
1483 {
1484         SpaceOops *soops = CTX_wm_space_outliner(C);
1485         int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1486         eOutliner_PropConstraintOps event;
1487
1488         event = RNA_enum_get(op->ptr, "type");
1489         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1490
1491         outliner_do_data_operation(soops, datalevel, event, &soops->tree, constraint_cb, C);
1492
1493         if (event == OL_CONSTRAINTOP_DELETE) {
1494                 outliner_cleanup_tree(soops);
1495         }
1496
1497         ED_undo_push(C, "Constraint operation");
1498
1499         return OPERATOR_FINISHED;
1500 }
1501
1502 void OUTLINER_OT_constraint_operation(wmOperatorType *ot)
1503 {
1504         /* identifiers */
1505         ot->name = "Outliner Constraint Operation";
1506         ot->idname = "OUTLINER_OT_constraint_operation";
1507         ot->description = "";
1508
1509         /* callbacks */
1510         ot->invoke = WM_menu_invoke;
1511         ot->exec = outliner_constraint_operation_exec;
1512         ot->poll = ED_operator_outliner_active;
1513
1514         ot->flag = 0;
1515
1516         ot->prop = RNA_def_enum(ot->srna, "type", prop_constraint_op_types, 0, "Constraint Operation", "");
1517 }
1518
1519 /* ******************** */
1520
1521 static EnumPropertyItem prop_modifier_op_types[] = {
1522         {OL_MODIFIER_OP_TOGVIS, "TOGVIS", ICON_RESTRICT_VIEW_OFF, "Toggle viewport use", ""},
1523         {OL_MODIFIER_OP_TOGREN, "TOGREN", ICON_RESTRICT_RENDER_OFF, "Toggle render use", ""},
1524         {OL_MODIFIER_OP_DELETE, "DELETE", ICON_X, "Delete", ""},
1525         {0, NULL, 0, NULL, NULL}
1526 };
1527
1528 static int outliner_modifier_operation_exec(bContext *C, wmOperator *op)
1529 {
1530         SpaceOops *soops = CTX_wm_space_outliner(C);
1531         int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1532         eOutliner_PropModifierOps event;
1533
1534         event = RNA_enum_get(op->ptr, "type");
1535         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1536
1537         outliner_do_data_operation(soops, datalevel, event, &soops->tree, modifier_cb, C);
1538
1539         if (event == OL_MODIFIER_OP_DELETE) {
1540                 outliner_cleanup_tree(soops);
1541         }
1542
1543         ED_undo_push(C, "Modifier operation");
1544
1545         return OPERATOR_FINISHED;
1546 }
1547
1548 void OUTLINER_OT_modifier_operation(wmOperatorType *ot)
1549 {
1550         /* identifiers */
1551         ot->name = "Outliner Modifier Operation";
1552         ot->idname = "OUTLINER_OT_modifier_operation";
1553         ot->description = "";
1554
1555         /* callbacks */
1556         ot->invoke = WM_menu_invoke;
1557         ot->exec = outliner_modifier_operation_exec;
1558         ot->poll = ED_operator_outliner_active;
1559
1560         ot->flag = 0;
1561
1562         ot->prop = RNA_def_enum(ot->srna, "type", prop_modifier_op_types, 0, "Modifier Operation", "");
1563 }
1564
1565 /* ******************** */
1566
1567 // XXX: select linked is for RNA structs only
1568 static EnumPropertyItem prop_data_op_types[] = {
1569         {OL_DOP_SELECT, "SELECT", 0, "Select", ""},
1570         {OL_DOP_DESELECT, "DESELECT", 0, "Deselect", ""},
1571         {OL_DOP_HIDE, "HIDE", 0, "Hide", ""},
1572         {OL_DOP_UNHIDE, "UNHIDE", 0, "Unhide", ""},
1573         {OL_DOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
1574         {0, NULL, 0, NULL, NULL}
1575 };
1576
1577 static int outliner_data_operation_exec(bContext *C, wmOperator *op)
1578 {
1579         SpaceOops *soops = CTX_wm_space_outliner(C);
1580         int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1581         eOutliner_PropDataOps event;
1582         
1583         /* check for invalid states */
1584         if (soops == NULL)
1585                 return OPERATOR_CANCELLED;
1586         
1587         event = RNA_enum_get(op->ptr, "type");
1588         set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1589         
1590         switch (datalevel) {
1591                 case TSE_POSE_CHANNEL:
1592                 {
1593                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, pchan_cb, NULL);
1594                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
1595                         ED_undo_push(C, "PoseChannel operation");
1596
1597                         break;
1598                 }
1599                 case TSE_BONE:
1600                 {
1601                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, bone_cb, NULL);
1602                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
1603                         ED_undo_push(C, "Bone operation");
1604
1605                         break;
1606                 }
1607                 case TSE_EBONE:
1608                 {
1609                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, ebone_cb, NULL);
1610                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
1611                         ED_undo_push(C, "EditBone operation");
1612
1613                         break;
1614                 }
1615                 case TSE_SEQUENCE:
1616                 {
1617                         Scene *scene = CTX_data_scene(C);
1618                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb, scene);
1619
1620                         break;
1621                 }
1622                 case TSE_GP_LAYER:
1623                 {
1624                         outliner_do_data_operation(soops, datalevel, event, &soops->tree, gp_layer_cb, NULL);
1625                         WM_event_add_notifier(C, NC_GPENCIL | ND_DATA, NULL);
1626                         ED_undo_push(C, "Grease Pencil Layer operation");
1627
1628                         break;
1629                 }
1630                 case TSE_RNA_STRUCT:
1631                         if (event == OL_DOP_SELECT_LINKED) {
1632                                 outliner_do_data_operation(soops, datalevel, event, &soops->tree, data_select_linked_cb, C);
1633                         }
1634
1635                         break;
1636
1637                 default:
1638                         BKE_report(op->reports, RPT_WARNING, "Not yet implemented");
1639                         break;
1640         }
1641         
1642         return OPERATOR_FINISHED;
1643 }
1644
1645
1646 void OUTLINER_OT_data_operation(wmOperatorType *ot)
1647 {
1648         /* identifiers */
1649         ot->name = "Outliner Data Operation";
1650         ot->idname = "OUTLINER_OT_data_operation";
1651         ot->description = "";
1652         
1653         /* callbacks */
1654         ot->invoke = WM_menu_invoke;
1655         ot->exec = outliner_data_operation_exec;
1656         ot->poll = ED_operator_outliner_active;
1657         
1658         ot->flag = 0;
1659         
1660         ot->prop = RNA_def_enum(ot->srna, "type", prop_data_op_types, 0, "Data Operation", "");
1661 }
1662
1663
1664 /* ******************** */
1665
1666
1667 static int do_outliner_operation_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops,
1668                                        TreeElement *te, const wmEvent *event, const float mval[2])
1669 {
1670         ReportList *reports = CTX_wm_reports(C); // XXX...
1671         
1672         if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
1673                 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
1674                 TreeStoreElem *tselem = TREESTORE(te);
1675                 
1676                 /* select object that's clicked on and popup context menu */
1677                 if (!(tselem->flag & TSE_SELECTED)) {
1678                         
1679                         if (outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
1680                                 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1681                         
1682                         tselem->flag |= TSE_SELECTED;
1683                         /* redraw, same as outliner_select function */
1684                         soops->storeflag |= SO_TREESTORE_REDRAW;
1685                         ED_region_tag_redraw(ar);
1686                 }
1687                 
1688                 set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
1689                 
1690                 if (scenelevel) {
1691                         if (objectlevel || datalevel || idlevel) {
1692                                 BKE_report(reports, RPT_WARNING, "Mixed selection");
1693                         }
1694                         else {
1695                                 WM_operator_name_call(C, "OUTLINER_OT_scene_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1696                         }
1697                 }
1698                 else if (objectlevel) {
1699                         WM_operator_name_call(C, "OUTLINER_OT_object_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1700                 }
1701                 else if (idlevel) {
1702                         if (idlevel == -1 || datalevel) {
1703                                 BKE_report(reports, RPT_WARNING, "Mixed selection");
1704                         }
1705                         else {
1706                                 if (idlevel == ID_GR)
1707                                         WM_operator_name_call(C, "OUTLINER_OT_group_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1708                                 else
1709                                         WM_operator_name_call(C, "OUTLINER_OT_id_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1710                         }
1711                 }
1712                 else if (datalevel) {
1713                         if (datalevel == -1) {
1714                                 BKE_report(reports, RPT_WARNING, "Mixed selection");
1715                         }
1716                         else {
1717                                 if (datalevel == TSE_ANIM_DATA)
1718                                         WM_operator_name_call(C, "OUTLINER_OT_animdata_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1719                                 else if (datalevel == TSE_DRIVER_BASE) {
1720                                         /* do nothing... no special ops needed yet */
1721                                 }
1722                                 else if (ELEM(datalevel, TSE_R_LAYER_BASE, TSE_R_LAYER, TSE_R_PASS)) {
1723                                         /*WM_operator_name_call(C, "OUTLINER_OT_renderdata_operation", WM_OP_INVOKE_REGION_WIN, NULL)*/
1724                                 }
1725                                 else if (datalevel == TSE_ID_BASE) {
1726                                         /* do nothing... there are no ops needed here yet */
1727                                 }
1728                                 else if (datalevel == TSE_CONSTRAINT) {
1729                                         WM_operator_name_call(C, "OUTLINER_OT_constraint_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1730                                 }
1731                                 else if (datalevel == TSE_MODIFIER) {
1732                                         WM_operator_name_call(C, "OUTLINER_OT_modifier_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1733                                 }
1734                                 else {
1735                                         WM_operator_name_call(C, "OUTLINER_OT_data_operation", WM_OP_INVOKE_REGION_WIN, NULL);
1736                                 }
1737                         }
1738                 }
1739                 
1740                 return 1;
1741         }
1742         
1743         for (te = te->subtree.first; te; te = te->next) {
1744                 if (do_outliner_operation_event(C, scene, ar, soops, te, event, mval))
1745                         return 1;
1746         }
1747         return 0;
1748 }
1749
1750
1751 static int outliner_operation(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
1752 {
1753         Scene *scene = CTX_data_scene(C);
1754         ARegion *ar = CTX_wm_region(C);
1755         SpaceOops *soops = CTX_wm_space_outliner(C);
1756         uiBut *but = UI_context_active_but_get(C);
1757         TreeElement *te;
1758         float fmval[2];
1759
1760         if (but) {
1761                 UI_but_tooltip_timer_remove(C, but);
1762         }
1763
1764         UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
1765         
1766         for (te = soops->tree.first; te; te = te->next) {
1767                 if (do_outliner_operation_event(C, scene, ar, soops, te, event, fmval)) {
1768                         break;
1769                 }
1770         }
1771         
1772         return OPERATOR_FINISHED;
1773 }
1774
1775 /* Menu only! Calls other operators */
1776 void OUTLINER_OT_operation(wmOperatorType *ot)
1777 {
1778         ot->name = "Execute Operation";
1779         ot->idname = "OUTLINER_OT_operation";
1780         ot->description = "Context menu for item operations";
1781         
1782         ot->invoke = outliner_operation;
1783         
1784         ot->poll = ED_operator_outliner_active;
1785 }
1786
1787 /* ****************************************************** */