Clip editor: added drag-n-drop support so files can be opened in clip editor
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 2 May 2012 16:42:42 +0000 (16:42 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 2 May 2012 16:42:42 +0000 (16:42 +0000)
by drag-n-dropping them from an external application.

source/blender/editors/space_clip/space_clip.c

index 271ad84fec6168a2b8bf1e1af46261bffadac55d..80755828f7e074d4c679a447ef8459ae1fe578c0 100644 (file)
@@ -304,9 +304,12 @@ static void clip_free(SpaceLink *sl)
 }
 
 /* spacetype; init callback */
-static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
+static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
 {
+       ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
 
+       /* add drop boxes */
+       WM_event_add_dropbox_handler(&sa->handlers, lb);
 }
 
 static SpaceLink *clip_duplicate(SpaceLink *sl)
@@ -731,6 +734,30 @@ static int clip_context(const bContext *C, const char *member, bContextDataResul
        return FALSE;
 }
 
+/* dropboxes */
+static int clip_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
+{
+       if (drag->type == WM_DRAG_PATH)
+               if (ELEM3(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_BLANK)) /* rule might not work? */
+                       return TRUE;
+
+       return FALSE;
+}
+
+static void clip_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+       /* copy drag path to properties */
+       RNA_string_set(drop->ptr, "filepath", drag->path);
+}
+
+/* area+region dropbox definition */
+static void clip_dropboxes(void)
+{
+       ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
+
+       WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy);
+}
+
 static void clip_refresh(const bContext *C, ScrArea *sa)
 {
        wmWindowManager *wm = CTX_wm_manager(C);
@@ -1296,6 +1323,7 @@ void ED_spacetype_clip(void)
        st->keymap = clip_keymap;
        st->listener = clip_listener;
        st->context = clip_context;
+       st->dropboxes = clip_dropboxes;
        st->refresh = clip_refresh;
 
        /* regions: main window */