Skip to content

Instantly share code, notes, and snippets.

@tin2tin
Created November 17, 2021 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tin2tin/d283c9f10126862eb702308695f559e2 to your computer and use it in GitHub Desktop.
Save tin2tin/d283c9f10126862eb702308695f559e2 to your computer and use it in GitHub Desktop.
Drag and drop files from outliner and asset browser into VSE
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 2a6e49edfb6..dd57b74cd0d 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -364,6 +364,21 @@ static void sequencer_listener(const wmSpaceTypeListenerParams *params)
/* ************* dropboxes ************* */
+static bool movie_id_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
+{
+ return WM_drag_get_local_ID(drag, 0) != NULL;
+}
+
+static bool image_id_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
+{
+ return WM_drag_get_local_ID(drag, 0) != NULL;
+}
+
+static bool sound_id_drop_poll(bContext *C, wmDrag *drag, const wmEvent *UNUSED(event))
+{
+ return WM_drag_get_local_ID(drag, 0) != NULL;
+}
+
static bool image_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
@@ -413,13 +428,34 @@ static bool sound_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
return 0;
}
-static void sequencer_drop_copy(wmDrag *drag, wmDropBox *drop)
+
+static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
{
- /* Copy drag path to properties. */
- if (RNA_struct_find_property(drop->ptr, "filepath")) {
+ ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
+
+ if (id) {
+ RNA_string_set(drop->ptr, "name", id->name + 2);
+ RNA_struct_property_unset(drop->ptr, "filepath");
+ }
+ else if (drag->path[0]) {
RNA_string_set(drop->ptr, "filepath", drag->path);
+ RNA_struct_property_unset(drop->ptr, "image");
}
+}
+
+static void sequencer_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+ ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
+ /* FIX: ID must return a path instead. */
+ if (id) {
+ RNA_string_set(drop->ptr, "name", id->name + 2);
+ RNA_struct_property_unset(drop->ptr, "filepath");
+ }
+ else if (drag->path[0]) {
+ RNA_string_set(drop->ptr, "filepath", drag->path);
+ RNA_struct_property_unset(drop->ptr, "name");
+ }
if (RNA_struct_find_property(drop->ptr, "directory")) {
PointerRNA itemptr;
char dir[FILE_MAX], file[FILE_MAX];
@@ -440,11 +476,18 @@ static void sequencer_dropboxes(void)
ListBase *lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW);
WM_dropbox_add(
- lb, "SEQUENCER_OT_image_strip_add", image_drop_poll, sequencer_drop_copy, NULL, NULL);
+ lb, "SEQUENCER_OT_movie_strip_add", movie_id_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_movie_strip_add", image_id_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_movie_strip_add", sound_id_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
+
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_image_strip_add", image_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
WM_dropbox_add(
- lb, "SEQUENCER_OT_movie_strip_add", movie_drop_poll, sequencer_drop_copy, NULL, NULL);
+ lb, "SEQUENCER_OT_movie_strip_add", movie_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
WM_dropbox_add(
- lb, "SEQUENCER_OT_sound_strip_add", sound_drop_poll, sequencer_drop_copy, NULL, NULL);
+ lb, "SEQUENCER_OT_sound_strip_add", sound_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
}
/* ************* end drop *********** */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment