OUTLINER_OT_scene_drop -- "Drag object to scene in Outliner" operator
[blender.git] / source / blender / editors / space_outliner / space_outliner.c
index 3110ff3e29eb322c8436cdc630969992a5621164..f3f6e3cf49f55976e2bd6ff7e6248b237d8dd96a 100644 (file)
@@ -144,6 +144,35 @@ static void outliner_parent_clear_copy(wmDrag *drag, wmDropBox *drop)
        RNA_enum_set(drop->ptr, "type", 0);
 }
 
+static int outliner_scene_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+{
+       ARegion *ar = CTX_wm_region(C);
+       SpaceOops *soops = CTX_wm_space_outliner(C);
+       TreeElement *te = NULL;
+       float fmval[2];
+       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
+
+       if (drag->type == WM_DRAG_ID) {
+               ID *id = (ID *)drag->poin;
+               if (GS(id->name) == ID_OB) {
+                       /* Ensure item under cursor is valid drop target */
+                       /* Find object hovered over */
+                       for (te = soops->tree.first; te; te = te->next) {
+                               if (outliner_dropzone_scene(C, event, te, fmval))
+                                       return 1;
+                       }
+               }
+       }
+       return 0;
+}
+
+static void outliner_scene_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+       ID *id = (ID *)drag->poin;
+
+       RNA_string_set(drop->ptr, "object", id->name + 2);
+}
+
 /* region dropbox definition */
 static void outliner_dropboxes(void)
 {
@@ -151,6 +180,7 @@ static void outliner_dropboxes(void)
 
        WM_dropbox_add(lb, "OUTLINER_OT_parent_drop", outliner_parent_drop_poll, outliner_parent_drop_copy);
        WM_dropbox_add(lb, "OUTLINER_OT_parent_clear", outliner_parent_clear_poll, outliner_parent_clear_copy);
+       WM_dropbox_add(lb, "OUTLINER_OT_scene_drop", outliner_scene_drop_poll, outliner_scene_drop_copy);
 }
 
 static void outliner_main_area_draw(const bContext *C, ARegion *ar)