From a0ce28d7312adc31194e2ba34974dc5de754fced Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Fri, 17 Dec 2010 19:05:34 +0000 Subject: Drag & drop feature: You now can drop a .blend inside blender window to open it. Implementation notes: - Added call to extract icon type for files. Code re-used from space_file - External files that get dropped set icon types too. Drop box polls can check for this. - Also enabled setting op-context for drop operators, this was needed to prevent filewindow to open. --- source/blender/windowmanager/WM_types.h | 3 ++- source/blender/windowmanager/intern/wm_dragdrop.c | 2 ++ source/blender/windowmanager/intern/wm_event_system.c | 8 +++++++- source/blender/windowmanager/intern/wm_window.c | 14 +++++++++++--- 4 files changed, 22 insertions(+), 5 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index ea06395c35b..0ca8c5e7f4f 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -504,7 +504,8 @@ typedef struct wmDropBox { /* if poll survives, operator is called */ wmOperatorType *ot; /* not saved in file, so can be pointer */ - + short opcontext; /* default invoke */ + struct IDProperty *properties; /* operator properties, assigned to ptr->data and can be written to a file */ struct PointerRNA *ptr; /* rna pointer to access properties */ diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 6cf2c7a9a81..a19499b3464 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -75,6 +75,7 @@ typedef struct wmDropBoxMap { } wmDropBoxMap; +/* spaceid/regionid is zero for window drop maps */ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid) { wmDropBoxMap *dm; @@ -103,6 +104,7 @@ wmDropBox *WM_dropbox_add(ListBase *lb, const char *idname, int (*poll)(bContext drop->poll= poll; drop->copy= copy; drop->ot= WM_operatortype_find(idname, 0); + drop->opcontext= WM_OP_INVOKE_DEFAULT; if(drop->ot==NULL) { MEM_freeN(drop); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 0a1f3035a84..9c8bd3f4fec 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1468,8 +1468,14 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) if(drop->poll(C, drag, event)) { drop->copy(drag, drop); - wm_operator_invoke(C, drop->ot, event, drop->ptr, NULL, FALSE); + WM_operator_name_call(C, drop->ot->idname, drop->opcontext, drop->ptr); + //wm_operator_invoke(C, drop->ot, event, drop->ptr, NULL, FALSE); action |= WM_HANDLER_BREAK; + + /* prevent hanging on file read */ + BLI_freelistN(event->customdata); + event->customdata= NULL; + event->custom= 0; } } } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index c962ee8c118..723286b09ce 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -60,6 +60,7 @@ #include "wm_event_system.h" #include "ED_screen.h" +#include "ED_fileselect.h" #include "PIL_time.h" @@ -413,6 +414,11 @@ void wm_window_add_ghostwindows(bContext* C, wmWindowManager *wm) keymap= WM_keymap_find(wm->defaultconf, "Screen Editing", 0, 0); WM_event_add_keymap_handler(&win->modalhandlers, keymap); + /* add drop boxes */ + { + ListBase *lb= WM_dropboxmap_find("Window", 0, 0); + WM_event_add_dropbox_handler(&win->handlers, lb); + } wm_window_title(wm, win); } } @@ -820,15 +826,17 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private) /* printf("Drop detected\n"); */ /* add drag data to wm for paths: */ - /* need icon type, some dropboxes check for that... see filesel code for this */ if(ddd->dataType == GHOST_kDragnDropTypeFilenames) { GHOST_TStringArray *stra= ddd->data; - int a; + int a, icon; for(a=0; acount; a++) { printf("drop file %s\n", stra->strings[a]); - WM_event_start_drag(C, 0, WM_DRAG_PATH, stra->strings[a], 0.0); + /* try to get icon type from extension */ + icon= ED_file_extension_icon((char *)stra->strings[a]); + + WM_event_start_drag(C, icon, WM_DRAG_PATH, stra->strings[a], 0.0); /* void poin should point to string, it makes a copy */ break; // only one drop element supported now } -- cgit v1.2.3