2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2008 Blender Foundation.
19 * All rights reserved.
22 * ***** END GPL LICENSE BLOCK *****
25 /** \file blender/editors/screen/screen_context.c
33 #include "MEM_guardedalloc.h"
35 #include "DNA_object_types.h"
36 #include "DNA_armature_types.h"
37 #include "DNA_brush_types.h"
38 #include "DNA_gpencil_types.h"
39 #include "DNA_sequence_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_space_types.h"
43 #include "DNA_windowmanager_types.h"
44 #include "DNA_workspace_types.h"
46 #include "BLI_utildefines.h"
48 #include "BKE_brush.h"
49 #include "BKE_context.h"
50 #include "BKE_object.h"
51 #include "BKE_action.h"
52 #include "BKE_armature.h"
53 #include "BKE_paint.h"
55 #include "BKE_gpencil.h"
56 #include "BKE_layer.h"
57 #include "BKE_screen.h"
58 #include "BKE_sequencer.h"
59 #include "BKE_workspace.h"
61 #include "DEG_depsgraph.h"
63 #include "RNA_access.h"
65 #include "ED_armature.h"
66 #include "ED_gpencil.h"
67 #include "ED_anim_api.h"
68 #include "ED_uvedit.h"
71 #include "UI_interface.h"
73 #include "screen_intern.h"
75 const char *screen_context_dir[] = {
76 "scene", "view_layer", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
77 "selected_objects", "selected_bases",
78 "editable_objects", "editable_bases",
79 "selected_editable_objects", "selected_editable_bases",
80 "objects_in_mode", "objects_in_mode_unique_data",
81 "visible_bones", "editable_bones", "selected_bones", "selected_editable_bones",
82 "visible_pose_bones", "selected_pose_bones", "selected_pose_bones_from_active_object",
83 "active_bone", "active_pose_bone",
84 "active_base", "active_object", "object", "edit_object",
85 "sculpt_object", "vertex_paint_object", "weight_paint_object",
86 "image_paint_object", "particle_edit_object", "uv_sculpt_object",
87 "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */
88 "gpencil_data", "gpencil_data_owner", /* grease pencil data */
89 "visible_gpencil_layers", "editable_gpencil_layers", "editable_gpencil_strokes",
90 "active_gpencil_layer", "active_gpencil_frame",
91 "active_operator", "selected_editable_fcurves",
94 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
96 wmWindow *win = CTX_wm_window(C);
97 View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
98 bScreen *sc = CTX_wm_screen(C);
99 ScrArea *sa = CTX_wm_area(C);
100 Scene *scene = WM_window_get_active_scene(win);
101 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
102 Object *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL;
103 Object *obedit = view_layer ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
105 if (CTX_data_dir(member)) {
106 CTX_data_dir_set(result, screen_context_dir);
109 else if (CTX_data_equals(member, "scene")) {
110 CTX_data_id_pointer_set(result, &scene->id);
113 else if (CTX_data_equals(member, "visible_objects")) {
114 FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, v3d, ob)
116 CTX_data_id_list_add(result, &ob->id);
118 FOREACH_VISIBLE_BASE_END;
119 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
122 else if (CTX_data_equals(member, "selectable_objects")) {
123 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
124 if (v3d && v3d->localvd && ((base->local_view_bits & v3d->local_view_uuid) == 0)) {
127 if (v3d && ((v3d->object_type_exclude_viewport & (1 << base->object->type)) != 0)) {
130 if (v3d && ((v3d->object_type_exclude_select & (1 << base->object->type)) != 0)) {
133 if (((base->flag & BASE_VISIBLE) != 0) && ((base->flag & BASE_SELECTABLE) != 0)) {
134 CTX_data_id_list_add(result, &base->object->id);
137 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
140 else if (CTX_data_equals(member, "selected_objects")) {
141 FOREACH_SELECTED_OBJECT_BEGIN(view_layer, v3d, ob)
143 CTX_data_id_list_add(result, &ob->id);
145 FOREACH_SELECTED_OBJECT_END;
146 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
149 else if (CTX_data_equals(member, "selected_editable_objects")) {
150 FOREACH_SELECTED_OBJECT_BEGIN(view_layer, v3d, ob)
152 if (0 == BKE_object_is_libdata(ob)) {
153 CTX_data_id_list_add(result, &ob->id);
156 FOREACH_SELECTED_OBJECT_END;
157 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
160 else if (CTX_data_equals(member, "editable_objects")) {
161 /* Visible + Editable, but not necessarily selected */
162 FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, v3d, ob)
164 if (0 == BKE_object_is_libdata(ob)) {
165 CTX_data_id_list_add(result, &ob->id);
168 FOREACH_VISIBLE_OBJECT_END;
169 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
172 else if ( CTX_data_equals(member, "visible_bases")) {
173 FOREACH_VISIBLE_BASE_BEGIN(view_layer, v3d, base)
175 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
177 FOREACH_VISIBLE_BASE_END;
178 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
181 else if (CTX_data_equals(member, "selectable_bases")) {
182 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
183 if (v3d && v3d->localvd && ((base->local_view_bits & v3d->local_view_uuid) == 0)) {
186 if (v3d && ((v3d->object_type_exclude_viewport & (1 << base->object->type)) != 0)) {
189 if (v3d && ((v3d->object_type_exclude_select & (1 << base->object->type)) != 0)) {
192 if ((base->flag & BASE_VISIBLE) && (base->flag & BASE_SELECTABLE) != 0) {
193 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
196 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
199 else if (CTX_data_equals(member, "selected_bases")) {
200 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
201 if (v3d && v3d->localvd && ((base->local_view_bits & v3d->local_view_uuid) == 0)) {
204 if (v3d && ((v3d->object_type_exclude_viewport & (1 << base->object->type)) != 0)) {
207 if ((base->flag & BASE_SELECTED) != 0) {
208 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
211 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
214 else if (CTX_data_equals(member, "selected_editable_bases")) {
215 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
216 if (v3d && v3d->localvd && ((base->local_view_bits & v3d->local_view_uuid) == 0)) {
219 if (v3d && ((v3d->object_type_exclude_viewport & (1 << base->object->type)) != 0)) {
222 if ((base->flag & BASE_SELECTED) != 0) {
223 if (0 == BKE_object_is_libdata(base->object)) {
224 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
228 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
231 else if (CTX_data_equals(member, "editable_bases")) {
232 /* Visible + Editable, but not necessarily selected */
233 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
234 if (v3d && v3d->localvd && ((base->local_view_bits & v3d->local_view_uuid) == 0)) {
237 if (v3d && ((v3d->object_type_exclude_viewport & (1 << base->object->type)) != 0)) {
240 if ((base->flag & BASE_VISIBLE) != 0) {
241 if (0 == BKE_object_is_libdata(base->object)) {
242 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
246 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
249 else if (CTX_data_equals(member, "objects_in_mode")) {
250 if (obact && (obact->mode != OB_MODE_OBJECT)) {
251 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
252 CTX_data_id_list_add(result, &ob_iter->id);
253 } FOREACH_OBJECT_IN_MODE_END;
255 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
258 else if (CTX_data_equals(member, "objects_in_mode_unique_data")) {
259 if (obact && (obact->mode != OB_MODE_OBJECT)) {
260 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
261 ob_iter->id.tag |= LIB_TAG_DOIT;
262 } FOREACH_OBJECT_IN_MODE_END;
263 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
264 if (ob_iter->id.tag & LIB_TAG_DOIT) {
265 ob_iter->id.tag &= ~LIB_TAG_DOIT;
266 CTX_data_id_list_add(result, &ob_iter->id);
268 } FOREACH_OBJECT_IN_MODE_END;
270 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
273 else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) {
274 bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
275 EditBone *ebone, *flipbone = NULL;
276 const bool editable_bones = CTX_data_equals(member, "editable_bones");
278 if (arm && arm->edbo) {
280 Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, CTX_wm_view3d(C), &objects_len);
281 for (uint i = 0; i < objects_len; i++) {
282 Object *ob = objects[i];
285 /* Attention: X-Axis Mirroring is also handled here... */
286 for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
287 /* first and foremost, bone must be visible and selected */
288 if (EBONE_VISIBLE(arm, ebone)) {
289 /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
290 * so that most users of this data don't need to explicitly check for it themselves.
292 * We need to make sure that these mirrored copies are not selected, otherwise some
293 * bones will be operated on twice.
295 if (arm->flag & ARM_MIRROR_EDIT)
296 flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
298 /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
299 if (editable_bones) {
300 /* only selected + editable */
301 if (EBONE_EDITABLE(ebone)) {
302 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
304 if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
305 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
309 /* only include bones if visible */
310 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
312 if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0)
313 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
320 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
324 else if (CTX_data_equals(member, "selected_bones") || CTX_data_equals(member, "selected_editable_bones")) {
325 bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
326 EditBone *ebone, *flipbone = NULL;
327 const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones");
329 if (arm && arm->edbo) {
331 Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, CTX_wm_view3d(C), &objects_len);
332 for (uint i = 0; i < objects_len; i++) {
333 Object *ob = objects[i];
336 /* Attention: X-Axis Mirroring is also handled here... */
337 for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
338 /* first and foremost, bone must be visible and selected */
339 if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
340 /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
341 * so that most users of this data don't need to explicitly check for it themselves.
343 * We need to make sure that these mirrored copies are not selected, otherwise some
344 * bones will be operated on twice.
346 if (arm->flag & ARM_MIRROR_EDIT)
347 flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
349 /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
350 if (selected_editable_bones) {
351 /* only selected + editable */
352 if (EBONE_EDITABLE(ebone)) {
353 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
355 if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
356 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
360 /* only include bones if selected */
361 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
363 if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
364 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
371 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
375 else if (CTX_data_equals(member, "visible_pose_bones")) {
376 Object *obpose = BKE_object_pose_armature_get(obact);
377 if (obpose && obpose->pose && obpose->data) {
378 if (obpose != obact) {
379 FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (obpose, pchan) {
380 CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
381 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
383 else if (obact->mode & OB_MODE_POSE) {
384 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) {
385 FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob_iter, pchan) {
386 CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
387 } FOREACH_PCHAN_VISIBLE_IN_OBJECT_END;
388 } FOREACH_OBJECT_IN_MODE_END;
390 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
394 else if (CTX_data_equals(member, "selected_pose_bones")) {
395 Object *obpose = BKE_object_pose_armature_get(obact);
396 if (obpose && obpose->pose && obpose->data) {
397 if (obpose != obact) {
398 FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) {
399 CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
400 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
402 else if (obact->mode & OB_MODE_POSE) {
403 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) {
404 FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) {
405 CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
406 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
407 } FOREACH_OBJECT_IN_MODE_END;
409 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
413 else if (CTX_data_equals(member, "selected_pose_bones_from_active_object")) {
414 Object *obpose = BKE_object_pose_armature_get(obact);
415 if (obpose && obpose->pose && obpose->data) {
416 if (obpose != obact) {
417 FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) {
418 CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
419 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
421 else if (obact->mode & OB_MODE_POSE) {
422 FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obact, pchan) {
423 CTX_data_list_add(result, &obact->id, &RNA_PoseBone, pchan);
424 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
426 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
430 else if (CTX_data_equals(member, "active_bone")) {
431 if (obact && obact->type == OB_ARMATURE) {
432 bArmature *arm = obact->data;
434 if (arm->act_edbone) {
435 CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, arm->act_edbone);
441 CTX_data_pointer_set(result, &arm->id, &RNA_Bone, arm->act_bone);
447 else if (CTX_data_equals(member, "active_pose_bone")) {
449 Object *obpose = BKE_object_pose_armature_get(obact);
451 pchan = BKE_pose_channel_active(obpose);
453 CTX_data_pointer_set(result, &obpose->id, &RNA_PoseBone, pchan);
457 else if (CTX_data_equals(member, "active_base")) {
458 if (view_layer->basact)
459 CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
463 else if (CTX_data_equals(member, "active_object")) {
465 CTX_data_id_pointer_set(result, &obact->id);
469 else if (CTX_data_equals(member, "object")) {
471 CTX_data_id_pointer_set(result, &obact->id);
475 else if (CTX_data_equals(member, "edit_object")) {
476 /* convenience for now, 1 object per scene in editmode */
478 CTX_data_id_pointer_set(result, &obedit->id);
482 else if (CTX_data_equals(member, "sculpt_object")) {
483 if (obact && (obact->mode & OB_MODE_SCULPT))
484 CTX_data_id_pointer_set(result, &obact->id);
488 else if (CTX_data_equals(member, "vertex_paint_object")) {
489 if (obact && (obact->mode & OB_MODE_VERTEX_PAINT))
490 CTX_data_id_pointer_set(result, &obact->id);
494 else if (CTX_data_equals(member, "weight_paint_object")) {
495 if (obact && (obact->mode & OB_MODE_WEIGHT_PAINT))
496 CTX_data_id_pointer_set(result, &obact->id);
500 else if (CTX_data_equals(member, "image_paint_object")) {
501 if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT))
502 CTX_data_id_pointer_set(result, &obact->id);
506 else if (CTX_data_equals(member, "particle_edit_object")) {
507 if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT))
508 CTX_data_id_pointer_set(result, &obact->id);
512 else if (CTX_data_equals(member, "uv_sculpt_object")) {
513 /* TODO(campbell): most likely we change rules for uv_sculpt. */
514 if (obact && (obact->mode & OB_MODE_EDIT)) {
515 const ToolSettings *ts = scene->toolsettings;
516 if (ts->use_uv_sculpt) {
517 if (ED_uvedit_test(obedit)) {
518 WorkSpace *workspace = CTX_wm_workspace(C);
519 if ((workspace->tools_space_type == SPACE_IMAGE) &&
520 (workspace->tools_mode == SI_MODE_UV))
522 CTX_data_id_pointer_set(result, &obact->id);
529 else if (CTX_data_equals(member, "sequences")) {
530 Editing *ed = BKE_sequencer_editing_get(scene, false);
533 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
534 CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
536 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
540 else if (CTX_data_equals(member, "selected_sequences")) {
541 Editing *ed = BKE_sequencer_editing_get(scene, false);
544 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
545 if (seq->flag & SELECT) {
546 CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
549 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
553 else if (CTX_data_equals(member, "selected_editable_sequences")) {
554 Editing *ed = BKE_sequencer_editing_get(scene, false);
557 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
558 if (seq->flag & SELECT && !(seq->flag & SEQ_LOCK)) {
559 CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
562 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
566 else if (CTX_data_equals(member, "gpencil_data")) {
567 /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these situations
568 * (as outlined above - see Campbell's #ifdefs). That causes the get_active function to fail when
569 * called from context. For that reason, we end up using an alternative where we pass everything in!
571 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
574 CTX_data_id_pointer_set(result, &gpd->id);
578 else if (CTX_data_equals(member, "gpencil_data_owner")) {
579 /* pointer to which data/datablock owns the reference to the Grease Pencil data being used (as gpencil_data)
580 * XXX: see comment for gpencil_data case...
582 bGPdata **gpd_ptr = NULL;
585 /* get pointer to Grease Pencil Data */
586 gpd_ptr = ED_gpencil_data_get_pointers_direct((ID *)sc, sa, scene, obact, &ptr);
589 CTX_data_pointer_set(result, ptr.id.data, ptr.type, ptr.data);
593 else if (CTX_data_equals(member, "active_gpencil_layer")) {
594 /* XXX: see comment for gpencil_data case... */
595 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
598 bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
601 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl);
606 else if (CTX_data_equals(member, "active_gpencil_frame")) {
607 /* XXX: see comment for gpencil_data case... */
608 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
611 bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
614 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl->actframe);
619 else if (CTX_data_equals(member, "visible_gpencil_layers")) {
620 /* XXX: see comment for gpencil_data case... */
621 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
626 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
627 if ((gpl->flag & GP_LAYER_HIDE) == 0) {
628 CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
631 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
635 else if (CTX_data_equals(member, "editable_gpencil_layers")) {
636 /* XXX: see comment for gpencil_data case... */
637 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
642 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
643 if (gpencil_layer_is_editable(gpl)) {
644 CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
647 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
651 else if (CTX_data_equals(member, "editable_gpencil_strokes")) {
652 /* XXX: see comment for gpencil_data case... */
653 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
654 const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
659 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
660 if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) {
663 bGPDframe *init_gpf = gpl->actframe;
665 init_gpf = gpl->frames.first;
668 for (gpf = init_gpf; gpf; gpf = gpf->next) {
669 if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
670 for (gps = gpf->strokes.first; gps; gps = gps->next) {
671 if (ED_gpencil_stroke_can_use_direct(sa, gps)) {
672 /* check if the color is editable */
673 if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) {
677 CTX_data_list_add(result, &gpd->id, &RNA_GPencilStroke, gps);
681 /* if not multiedit out of loop */
688 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
692 else if (CTX_data_equals(member, "active_operator")) {
693 wmOperator *op = NULL;
695 SpaceFile *sfile = CTX_wm_space_file(C);
699 else if ((op = UI_context_active_operator_get(C))) {
703 /* note, this checks poll, could be a problem, but this also
704 * happens for the toolbar */
705 op = WM_operator_last_redo(C);
707 /* TODO, get the operator from popup's */
710 CTX_data_pointer_set(result, NULL, &RNA_Operator, op);
714 else if (CTX_data_equals(member, "selected_editable_fcurves")) {
717 if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_ACTION, SPACE_IPO)) {
719 ListBase anim_data = {NULL, NULL};
721 int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS | ANIMFILTER_SEL) |
722 (ac.spacetype == SPACE_IPO ? ANIMFILTER_CURVE_VISIBLE : ANIMFILTER_LIST_VISIBLE);
724 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
726 for (ale = anim_data.first; ale; ale = ale->next) {
727 if (ale->type == ANIMTYPE_FCURVE)
728 CTX_data_list_add(result, ale->id, &RNA_FCurve, ale->data);
731 ANIM_animdata_freelist(&anim_data);
733 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
738 return 0; /* not found */
741 return -1; /* found but not available */