Skip to content

Instantly share code, notes, and snippets.

@tin2tin
Created November 18, 2021 14:20
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/da12bf247a69ef67ab63efbfdcfe9fd6 to your computer and use it in GitHub Desktop.
Save tin2tin/da12bf247a69ef67ab63efbfdcfe9fd6 to your computer and use it in GitHub Desktop.
dndvse
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 4b6c5e29d77..67c453d391e 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"
@@ -386,6 +387,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_is_ID_type(drag, ID_MC);
+}
+
+static bool image_id_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
+{
+ return WM_drag_is_ID_type(drag, ID_IM);
+}
+
+static bool sound_id_drop_poll(bContext *C, wmDrag *drag, const wmEvent *UNUSED(event))
+{
+ return WM_drag_is_ID_type(drag, ID_SO);
+}
+
static bool image_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
@@ -435,13 +451,42 @@ 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 sequencer_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);
+ /* 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);
+ printf("Add Ima: %s\n", dir);
+ }
+ if (id_type == ID_MC) {
+ MovieClip *clip = (MovieClip *)id;
+ RNA_string_set(drop->ptr, "filepath", clip->filepath);
+ RNA_struct_property_unset(drop->ptr, "name");
+ printf("Add Clip: %s\n", clip->filepath);
+ }
+ if (id_type == ID_SO) {
+ bSound *sound = (bSound *)id;
+ RNA_string_set(drop->ptr, "filepath", sound->filepath);
+ RNA_struct_property_unset(drop->ptr, "name");
+ printf("Add Sound: %s\n", sound->filepath);
+ }
+ }
+ /* File dropped. */
+ else if (drag->path[0]) {
RNA_string_set(drop->ptr, "filepath", drag->path);
+ RNA_struct_property_unset(drop->ptr, "name");
}
-
+ /* Folder dropped. */
if (RNA_struct_find_property(drop->ptr, "directory")) {
PointerRNA itemptr;
char dir[FILE_MAX], file[FILE_MAX];
@@ -462,11 +507,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_image_strip_add", image_id_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_sound_strip_add", sound_id_drop_poll, sequencer_id_path_drop_copy, NULL, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_movie_strip_add", movie_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