[Bf-blender-cvs] [b42494cf6b0] master: VSE: Support drag and drop for datablocks

Peter Fog noreply at git.blender.org
Tue Nov 23 05:40:57 CET 2021


Commit: b42494cf6b00d0c2c681c7c84fc39f579fe74b97
Author: Peter Fog
Date:   Tue Nov 23 04:43:59 2021 +0100
Branches: master
https://developer.blender.org/rBb42494cf6b00d0c2c681c7c84fc39f579fe74b97

VSE: Support drag and drop for datablocks

For using the Outliner and/or the Asset Browser as scene independent
tools to organize a/v source material is necessary for the users to be
able to drag and drop data blocks into the VSE. This was also an
unfulfilled design target for the Outliner Gsoc project.

Datablocks won't be used directly. Path to file will be passed to strip
add operator instead.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D13304

===================================================================

M	source/blender/editors/space_sequencer/space_sequencer.c

===================================================================

diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 4b6c5e29d77..9e14aed96d7 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -28,6 +28,7 @@
 #include "DNA_gpencil_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_sound_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -400,7 +401,7 @@ static bool image_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
     }
   }
 
-  return 0;
+  return WM_drag_is_ID_type(drag, ID_IM);
 }
 
 static bool movie_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
@@ -416,7 +417,8 @@ static bool movie_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
       }
     }
   }
-  return 0;
+
+  return WM_drag_is_ID_type(drag, ID_MC);
 }
 
 static bool sound_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
@@ -432,27 +434,54 @@ static bool sound_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
       }
     }
   }
-  return 0;
+
+  return WM_drag_is_ID_type(drag, ID_SO);
 }
 
 static void sequencer_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
-  /* Copy drag path to properties. */
-  if (RNA_struct_find_property(drop->ptr, "filepath")) {
-    RNA_string_set(drop->ptr, "filepath", drag->path);
+  ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
+  /* ID dropped. */
+  if (id != NULL) {
+    const ID_Type id_type = GS(id->name);
+    if (id_type == ID_IM) {
+      Image *ima = (Image *)id;
+      PointerRNA itemptr;
+      char dir[FILE_MAX], file[FILE_MAX];
+      BLI_split_dirfile(ima->filepath, dir, file, sizeof(dir), sizeof(file));
+      RNA_string_set(drop->ptr, "directory", dir);
+      RNA_collection_clear(drop->ptr, "files");
+      RNA_collection_add(drop->ptr, "files", &itemptr);
+      RNA_string_set(&itemptr, "name", file);
+    }
+    else if (id_type == ID_MC) {
+      MovieClip *clip = (MovieClip *)id;
+      RNA_string_set(drop->ptr, "filepath", clip->filepath);
+      RNA_struct_property_unset(drop->ptr, "name");
+    }
+    else if (id_type == ID_SO) {
+      bSound *sound = (bSound *)id;
+      RNA_string_set(drop->ptr, "filepath", sound->filepath);
+      RNA_struct_property_unset(drop->ptr, "name");
+    }
   }
+  /* Path dropped. */
+  else if (drag->path[0]) {
+    if (RNA_struct_find_property(drop->ptr, "filepath")) {
+      RNA_string_set(drop->ptr, "filepath", drag->path);
+    }
+    if (RNA_struct_find_property(drop->ptr, "directory")) {
+      PointerRNA itemptr;
+      char dir[FILE_MAX], file[FILE_MAX];
 
-  if (RNA_struct_find_property(drop->ptr, "directory")) {
-    PointerRNA itemptr;
-    char dir[FILE_MAX], file[FILE_MAX];
-
-    BLI_split_dirfile(drag->path, dir, file, sizeof(dir), sizeof(file));
+      BLI_split_dirfile(drag->path, dir, file, sizeof(dir), sizeof(file));
 
-    RNA_string_set(drop->ptr, "directory", dir);
+      RNA_string_set(drop->ptr, "directory", dir);
 
-    RNA_collection_clear(drop->ptr, "files");
-    RNA_collection_add(drop->ptr, "files", &itemptr);
-    RNA_string_set(&itemptr, "name", file);
+      RNA_collection_clear(drop->ptr, "files");
+      RNA_collection_add(drop->ptr, "files", &itemptr);
+      RNA_string_set(&itemptr, "name", file);
+    }
   }
 }



More information about the Bf-blender-cvs mailing list