Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / screen / screen_context.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) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file blender/editors/screen/screen_context.c
26  *  \ingroup edscr
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "DNA_object_types.h"
34 #include "DNA_armature_types.h"
35 #include "DNA_gpencil_types.h"
36 #include "DNA_sequence_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_windowmanager_types.h"
41 #include "DNA_workspace_types.h"
42
43 #include "BLI_utildefines.h"
44
45
46 #include "BKE_context.h"
47 #include "BKE_object.h"
48 #include "BKE_action.h"
49 #include "BKE_armature.h"
50 #include "BKE_gpencil.h"
51 #include "BKE_layer.h"
52 #include "BKE_screen.h"
53 #include "BKE_sequencer.h"
54 #include "BKE_workspace.h"
55
56 #include "DEG_depsgraph.h"
57
58 #include "RNA_access.h"
59
60 #include "ED_armature.h"
61 #include "ED_gpencil.h"
62 #include "ED_anim_api.h"
63
64 #include "WM_api.h"
65 #include "UI_interface.h"
66
67 #include "screen_intern.h"
68
69 const char *screen_context_dir[] = {
70         "scene", "view_layer", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
71         "selected_objects", "selected_bases",
72         "editable_objects", "editable_bases",
73         "selected_editable_objects", "selected_editable_bases",
74         "visible_bones", "editable_bones", "selected_bones", "selected_editable_bones",
75         "visible_pose_bones", "selected_pose_bones", "active_bone", "active_pose_bone",
76         "active_base", "active_object", "object", "edit_object",
77         "sculpt_object", "vertex_paint_object", "weight_paint_object",
78         "image_paint_object", "particle_edit_object",
79         "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */
80         "gpencil_data", "gpencil_data_owner", /* grease pencil data */
81         "visible_gpencil_layers", "editable_gpencil_layers", "editable_gpencil_strokes",
82         "active_gpencil_layer", "active_gpencil_frame", "active_gpencil_palette", 
83         "active_gpencil_palettecolor", "active_gpencil_brush",
84         "active_operator", "selected_editable_fcurves",
85         NULL};
86
87 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
88 {
89         wmWindow *win = CTX_wm_window(C);
90         bScreen *sc = CTX_wm_screen(C);
91         ScrArea *sa = CTX_wm_area(C);
92         Scene *scene = WM_window_get_active_scene(win);
93         WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
94         ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
95         Object *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL;
96
97         if (CTX_data_dir(member)) {
98                 CTX_data_dir_set(result, screen_context_dir);
99                 return 1;
100         }
101         else if (CTX_data_equals(member, "scene")) {
102                 CTX_data_id_pointer_set(result, &scene->id);
103                 return 1;
104         }
105         else if (CTX_data_equals(member, "visible_objects")) {
106                 FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, ob)
107                 {
108                         CTX_data_id_list_add(result, &ob->id);
109                 }
110                 FOREACH_VISIBLE_BASE_END
111                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
112                 return 1;
113         }
114         else if (CTX_data_equals(member, "selectable_objects")) {
115                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
116                         if (((base->flag & BASE_VISIBLED) != 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
117                                 CTX_data_id_list_add(result, &base->object->id);
118                         }
119                 }
120                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
121                 return 1;
122         }
123         else if (CTX_data_equals(member, "selected_objects")) {
124                 FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
125                 {
126                         CTX_data_id_list_add(result, &ob->id);
127                 }
128                 FOREACH_SELECTED_OBJECT_END
129                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
130                 return 1;
131         }
132         else if (CTX_data_equals(member, "selected_editable_objects")) {
133                 FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
134                 {
135                         if (0 == BKE_object_is_libdata(ob)) {
136                                 CTX_data_id_list_add(result, &ob->id);
137                         }
138                 }
139                 FOREACH_SELECTED_OBJECT_END
140                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
141                 return 1;
142         }
143         else if (CTX_data_equals(member, "editable_objects")) {
144                 /* Visible + Editable, but not necessarily selected */
145                 FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, ob)
146                 {
147                         if (0 == BKE_object_is_libdata(ob)) {
148                                 CTX_data_id_list_add(result, &ob->id);
149                         }
150                 }
151                 FOREACH_VISIBLE_OBJECT_END
152                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
153                 return 1;
154         }
155         else if ( CTX_data_equals(member, "visible_bases")) {
156                 FOREACH_VISIBLE_BASE_BEGIN(view_layer, base)
157                 {
158                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
159                 }
160                 FOREACH_VISIBLE_BASE_END
161                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
162                 return 1;
163         }
164         else if (CTX_data_equals(member, "selectable_bases")) {
165                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
166                         if ((base->flag & BASE_SELECTABLED) != 0) {
167                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
168                         }
169                 }
170                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
171                 return 1;
172         }
173         else if (CTX_data_equals(member, "selected_bases")) {
174                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
175                         if ((base->flag & BASE_SELECTED) != 0) {
176                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
177                         }
178                 }
179                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
180                 return 1;
181         }
182         else if (CTX_data_equals(member, "selected_editable_bases")) {
183                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
184                         if ((base->flag & BASE_SELECTED) != 0) {
185                                 if (0 == BKE_object_is_libdata(base->object)) {
186                                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
187                                 }
188                         }
189                 }
190                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
191                 return 1;
192         }
193         else if (CTX_data_equals(member, "editable_bases")) {
194                 /* Visible + Editable, but not necessarily selected */
195                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
196                         if ((base->flag & BASE_VISIBLED) != 0) {
197                                 if (0 == BKE_object_is_libdata(base->object)) {
198                                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
199                                 }
200                         }
201                 }
202                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
203                 return 1;
204         }
205         else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) {
206                 Object *obedit = BKE_workspace_edit_object(workspace, scene);
207                 bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
208                 EditBone *ebone, *flipbone = NULL;
209                 const bool editable_bones = CTX_data_equals(member, "editable_bones");
210                 
211                 if (arm && arm->edbo) {
212                         /* Attention: X-Axis Mirroring is also handled here... */
213                         for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
214                                 /* first and foremost, bone must be visible and selected */
215                                 if (EBONE_VISIBLE(arm, ebone)) {
216                                         /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
217                                          * so that most users of this data don't need to explicitly check for it themselves.
218                                          * 
219                                          * We need to make sure that these mirrored copies are not selected, otherwise some
220                                          * bones will be operated on twice.
221                                          */
222                                         if (arm->flag & ARM_MIRROR_EDIT)
223                                                 flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
224                                         
225                                         /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
226                                         if (editable_bones) {
227                                                 /* only selected + editable */
228                                                 if (EBONE_EDITABLE(ebone)) {
229                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
230                                                 
231                                                         if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
232                                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
233                                                 }
234                                         }
235                                         else {
236                                                 /* only include bones if visible */
237                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
238                                                 
239                                                 if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0)
240                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
241                                         }
242                                 }
243                         }
244                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
245                         return 1;
246                 }
247         }
248         else if (CTX_data_equals(member, "selected_bones") || CTX_data_equals(member, "selected_editable_bones")) {
249                 Object *obedit = BKE_workspace_edit_object(workspace, scene);
250                 bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
251                 EditBone *ebone, *flipbone = NULL;
252                 const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones");
253                 
254                 if (arm && arm->edbo) {
255                         /* Attention: X-Axis Mirroring is also handled here... */
256                         for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
257                                 /* first and foremost, bone must be visible and selected */
258                                 if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
259                                         /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
260                                          * so that most users of this data don't need to explicitly check for it themselves.
261                                          * 
262                                          * We need to make sure that these mirrored copies are not selected, otherwise some
263                                          * bones will be operated on twice.
264                                          */
265                                         if (arm->flag & ARM_MIRROR_EDIT)
266                                                 flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
267                                         
268                                         /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
269                                         if (selected_editable_bones) {
270                                                 /* only selected + editable */
271                                                 if (EBONE_EDITABLE(ebone)) {
272                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
273                                                 
274                                                         if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
275                                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
276                                                 }
277                                         }
278                                         else {
279                                                 /* only include bones if selected */
280                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
281                                                 
282                                                 if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
283                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
284                                         }
285                                 }
286                         }
287                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
288                         return 1;
289                 }
290         }
291         else if (CTX_data_equals(member, "visible_pose_bones")) {
292                 Object *obpose = BKE_object_pose_armature_get(obact);
293                 bArmature *arm = (obpose) ? obpose->data : NULL;
294                 bPoseChannel *pchan;
295                 
296                 if (obpose && obpose->pose && arm) {
297                         for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) {
298                                 /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
299                                 if (PBONE_VISIBLE(arm, pchan->bone)) {
300                                         CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
301                                 }
302                         }
303                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
304                         return 1;
305                 }
306         }
307         else if (CTX_data_equals(member, "selected_pose_bones")) {
308                 Object *obpose = BKE_object_pose_armature_get(obact);
309                 bArmature *arm = (obpose) ? obpose->data : NULL;
310                 bPoseChannel *pchan;
311                 
312                 if (obpose && obpose->pose && arm) {
313                         for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) {
314                                 /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
315                                 if (PBONE_VISIBLE(arm, pchan->bone)) {
316                                         if (pchan->bone->flag & BONE_SELECTED)
317                                                 CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
318                                 }
319                         }
320                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
321                         return 1;
322                 }
323         }
324         else if (CTX_data_equals(member, "active_bone")) {
325                 if (obact && obact->type == OB_ARMATURE) {
326                         bArmature *arm = obact->data;
327                         if (arm->edbo) {
328                                 if (arm->act_edbone) {
329                                         CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, arm->act_edbone);
330                                         return 1;
331                                 }
332                         }
333                         else {
334                                 if (arm->act_bone) {
335                                         CTX_data_pointer_set(result, &arm->id, &RNA_Bone, arm->act_bone);
336                                         return 1;
337                                 }
338                         }
339                 }
340         }
341         else if (CTX_data_equals(member, "active_pose_bone")) {
342                 bPoseChannel *pchan;
343                 Object *obpose = BKE_object_pose_armature_get(obact);
344                 
345                 pchan = BKE_pose_channel_active(obpose);
346                 if (pchan) {
347                         CTX_data_pointer_set(result, &obpose->id, &RNA_PoseBone, pchan);
348                         return 1;
349                 }
350         }
351         else if (CTX_data_equals(member, "active_base")) {
352                 if (view_layer->basact)
353                         CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
354
355                 return 1;
356         }
357         else if (CTX_data_equals(member, "active_object")) {
358                 if (obact)
359                         CTX_data_id_pointer_set(result, &obact->id);
360
361                 return 1;
362         }
363         else if (CTX_data_equals(member, "object")) {
364                 if (obact)
365                         CTX_data_id_pointer_set(result, &obact->id);
366
367                 return 1;
368         }
369         else if (CTX_data_equals(member, "edit_object")) {
370                 /* convenience for now, 1 object per scene in editmode */
371                 Object *obedit = BKE_workspace_edit_object(workspace, scene);
372                 if (obedit)
373                         CTX_data_id_pointer_set(result, &obedit->id);
374                 
375                 return 1;
376         }
377         else if (CTX_data_equals(member, "sculpt_object")) {
378                 if (obact && (workspace->object_mode & OB_MODE_SCULPT)) {
379                         CTX_data_id_pointer_set(result, &obact->id);
380                 }
381                 return 1;
382         }
383         else if (CTX_data_equals(member, "vertex_paint_object")) {
384                 if (obact && (workspace->object_mode & OB_MODE_VERTEX_PAINT))
385                         CTX_data_id_pointer_set(result, &obact->id);
386
387                 return 1;
388         }
389         else if (CTX_data_equals(member, "weight_paint_object")) {
390                 if (obact && (workspace->object_mode & OB_MODE_WEIGHT_PAINT))
391                         CTX_data_id_pointer_set(result, &obact->id);
392
393                 return 1;
394         }
395         else if (CTX_data_equals(member, "image_paint_object")) {
396                 if (obact && (workspace->object_mode & OB_MODE_TEXTURE_PAINT))
397                         CTX_data_id_pointer_set(result, &obact->id);
398
399                 return 1;
400         }
401         else if (CTX_data_equals(member, "particle_edit_object")) {
402                 if (obact && (workspace->object_mode & OB_MODE_PARTICLE_EDIT))
403                         CTX_data_id_pointer_set(result, &obact->id);
404
405                 return 1;
406         }
407         else if (CTX_data_equals(member, "sequences")) {
408                 Editing *ed = BKE_sequencer_editing_get(scene, false);
409                 if (ed) {
410                         Sequence *seq;
411                         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
412                                 CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
413                         }
414                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
415                         return 1;
416                 }
417         }
418         else if (CTX_data_equals(member, "selected_sequences")) {
419                 Editing *ed = BKE_sequencer_editing_get(scene, false);
420                 if (ed) {
421                         Sequence *seq;
422                         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
423                                 if (seq->flag & SELECT) {
424                                         CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
425                                 }
426                         }
427                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
428                         return 1;
429                 }
430         }
431         else if (CTX_data_equals(member, "selected_editable_sequences")) {
432                 Editing *ed = BKE_sequencer_editing_get(scene, false);
433                 if (ed) {
434                         Sequence *seq;
435                         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
436                                 if (seq->flag & SELECT && !(seq->flag & SEQ_LOCK)) {
437                                         CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
438                                 }
439                         }
440                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
441                         return 1;
442                 }
443         }
444         else if (CTX_data_equals(member, "gpencil_data")) {
445                 /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these situations
446                  * (as outlined above - see Campbell's #ifdefs). That causes the get_active function to fail when 
447                  * called from context. For that reason, we end up using an alternative where we pass everything in!
448                  */
449                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
450                 
451                 if (gpd) {
452                         CTX_data_id_pointer_set(result, &gpd->id);
453                         return 1;
454                 }
455         }
456         else if (CTX_data_equals(member, "gpencil_data_owner")) {
457                 /* pointer to which data/datablock owns the reference to the Grease Pencil data being used (as gpencil_data)
458                  * XXX: see comment for gpencil_data case... 
459                  */
460                 bGPdata **gpd_ptr = NULL;
461                 PointerRNA ptr;
462                 
463                 /* get pointer to Grease Pencil Data */
464                 gpd_ptr = ED_gpencil_data_get_pointers_direct((ID *)sc, scene, sa, obact, &ptr);
465                 
466                 if (gpd_ptr) {
467                         CTX_data_pointer_set(result, ptr.id.data, ptr.type, ptr.data);
468                         return 1;
469                 }
470         }
471         else if (CTX_data_equals(member, "active_gpencil_layer")) {
472                 /* XXX: see comment for gpencil_data case... */
473                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
474                 
475                 if (gpd) {
476                         bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
477                         
478                         if (gpl) {
479                                 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl);
480                                 return 1;
481                         }
482                 }
483         }
484         else if (CTX_data_equals(member, "active_gpencil_palette")) {
485                 /* XXX: see comment for gpencil_data case... */
486                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
487
488                 if (gpd) {
489                         bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
490
491                         if (palette) {
492                                 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPalette, palette);
493                                 return 1;
494                         }
495                 }
496         }
497         else if (CTX_data_equals(member, "active_gpencil_palettecolor")) {
498                 /* XXX: see comment for gpencil_data case... */
499                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
500
501                 if (gpd) {
502                         bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
503
504                         if (palette) {
505                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
506                                 if (palcolor) {
507                                         CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPaletteColor, palcolor);
508                                         return 1;
509                                 }
510                         }
511                 }
512         }
513         else if (CTX_data_equals(member, "active_gpencil_brush")) {
514                 /* XXX: see comment for gpencil_data case... */
515                 bGPDbrush *brush = BKE_gpencil_brush_getactive(scene->toolsettings);
516
517                 if (brush) {
518                         CTX_data_pointer_set(result, &scene->id, &RNA_GPencilBrush, brush);
519                         return 1;
520                 }
521         }
522         else if (CTX_data_equals(member, "active_gpencil_frame")) {
523                 /* XXX: see comment for gpencil_data case... */
524                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
525                 
526                 if (gpd) {
527                         bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
528                         
529                         if (gpl) {
530                                 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl->actframe);
531                                 return 1;
532                         }
533                 }
534         }
535         else if (CTX_data_equals(member, "visible_gpencil_layers")) {
536                 /* XXX: see comment for gpencil_data case... */
537                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
538                 
539                 if (gpd) {
540                         bGPDlayer *gpl;
541                         
542                         for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
543                                 if ((gpl->flag & GP_LAYER_HIDE) == 0) {
544                                         CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
545                                 }
546                         }
547                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
548                         return 1;
549                 }
550         }
551         else if (CTX_data_equals(member, "editable_gpencil_layers")) {
552                 /* XXX: see comment for gpencil_data case... */
553                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
554                 
555                 if (gpd) {
556                         bGPDlayer *gpl;
557                         
558                         for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
559                                 if (gpencil_layer_is_editable(gpl)) {
560                                         CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
561                                 }
562                         }
563                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
564                         return 1;
565                 }
566         }
567         else if (CTX_data_equals(member, "editable_gpencil_strokes")) {
568                 /* XXX: see comment for gpencil_data case... */
569                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
570                 
571                 if (gpd) {
572                         bGPDlayer *gpl;
573                         
574                         for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
575                                 if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) {
576                                         bGPDframe *gpf = gpl->actframe;
577                                         bGPDstroke *gps;
578                                         
579                                         for (gps = gpf->strokes.first; gps; gps = gps->next) {
580                                                 if (ED_gpencil_stroke_can_use_direct(sa, gps)) {
581                                                         /* check if the color is editable */
582                                                         if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
583                                                                 continue;
584                                                         }
585
586                                                         CTX_data_list_add(result, &gpd->id, &RNA_GPencilStroke, gps);
587                                                 }
588                                         }
589                                 }
590                         }
591                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
592                         return 1;
593                 }
594         }
595         else if (CTX_data_equals(member, "active_operator")) {
596                 wmOperator *op = NULL;
597
598                 SpaceFile *sfile = CTX_wm_space_file(C);
599                 if (sfile) {
600                         op = sfile->op;
601                 }
602                 else if ((op = UI_context_active_operator_get(C))) {
603                         /* do nothing */
604                 }
605                 else {
606                         /* note, this checks poll, could be a problem, but this also
607                          * happens for the toolbar */
608                         op = WM_operator_last_redo(C);
609                 }
610                 /* TODO, get the operator from popup's */
611
612                 if (op && op->ptr) {
613                         CTX_data_pointer_set(result, NULL, &RNA_Operator, op);
614                         return 1;
615                 }
616         }
617         else if (CTX_data_equals(member, "selected_editable_fcurves")) {
618                 bAnimContext ac;
619
620                 if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_ACTION, SPACE_IPO)) {
621                         bAnimListElem *ale;
622                         ListBase anim_data = {NULL, NULL};
623
624                         int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS | ANIMFILTER_SEL) |
625                                      (ac.spacetype == SPACE_IPO ? ANIMFILTER_CURVE_VISIBLE : ANIMFILTER_LIST_VISIBLE);
626
627                         ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
628
629                         for (ale = anim_data.first; ale; ale = ale->next) {
630                                 if (ale->type == ANIMTYPE_FCURVE)
631                                         CTX_data_list_add(result, ale->id, &RNA_FCurve, ale->data);
632                         }
633
634                         ANIM_animdata_freelist(&anim_data);
635
636                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
637                         return 1;
638                 }
639         }
640         else {
641                 return 0; /* not found */
642         }
643
644         return -1; /* found but not available */
645 }
646