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