Cocoa : implement opening .blend file by double-clicking on it in OSX Finder
When the user double-clicks on a document file in the Finder, OSX doesn't simply give the filename as a command-line argument when calling Blender, as it is done in other OSes. Instead, it launches the app if needed, and then sends an "openFile" event. The user can also open a document file by dropping its icon on the app dock icon. But as this is not real Drag'n'drop, I've renamed the Ghost event to a less confusing "GHOST_kEventOpenMainFile" name. DND Ghost wiki page updated : http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DragnDrop
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "DNA_listBase.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_windowmanager_types.h"
|
||||
#include "RNA_access.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -714,6 +715,28 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GHOST_kEventOpenMainFile:
|
||||
{
|
||||
PointerRNA props_ptr;
|
||||
wmWindow *oldWindow;
|
||||
char *path = GHOST_GetEventData(evt);
|
||||
|
||||
if (path) {
|
||||
/* operator needs a valid window in context, ensures
|
||||
it is correctly set */
|
||||
oldWindow = CTX_wm_window(C);
|
||||
CTX_wm_window_set(C, win);
|
||||
|
||||
WM_operator_properties_create(&props_ptr, "WM_OT_open_mainfile");
|
||||
RNA_string_set(&props_ptr, "path", path);
|
||||
WM_operator_name_call(C, "WM_OT_open_mainfile", WM_OP_EXEC_DEFAULT, &props_ptr);
|
||||
WM_operator_properties_free(&props_ptr);
|
||||
|
||||
CTX_wm_window_set(C, oldWindow);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventDraggingDropDone:
|
||||
{
|
||||
wmEvent event= *(win->eventstate); /* copy last state, like mouse coords */
|
||||
|
||||
Reference in New Issue
Block a user