Drag & Drop: Support Open/Link/Append when dropping .blend file
authorJacques Lucke <mail@jlucke.com>
Mon, 22 Oct 2018 15:18:42 +0000 (17:18 +0200)
committerJacques Lucke <mail@jlucke.com>
Mon, 22 Oct 2018 15:18:42 +0000 (17:18 +0200)
When a .blend file is dropped into Blender a small menu opens.
In that menu the user can choose between three options: Open, Link and Append.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D3801

release/scripts/startup/bl_operators/wm.py
source/blender/editors/screen/screen_ops.c
source/blender/windowmanager/intern/wm_files_link.c

index 4e2cea5e4db8f3f99bcc0b52fc484395931fbb99..5ba430ab9f5edc435c0990b386c188da5e06fcd7 100644 (file)
@@ -2677,6 +2677,30 @@ class WM_MT_splash(Menu):
         layout.separator()
 
 
+class WM_OT_drop_blend_file(Operator):
+    bl_idname = "wm.drop_blend_file"
+    bl_label = "Handle dropped .blend file"
+    bl_options = {'INTERNAL'}
+
+    filepath: StringProperty()
+
+    def invoke(self, context, event):
+        context.window_manager.popup_menu(self.draw_menu, title=bpy.path.basename(self.filepath), icon='QUESTION')
+        return {"FINISHED"}
+
+    def draw_menu(self, menu, context):
+        layout = menu.layout
+
+        col = layout.column()
+        col.operator_context = 'EXEC_DEFAULT'
+        col.operator("wm.open_mainfile", text="Open", icon='FILE_FOLDER').filepath = self.filepath
+
+        layout.separator()
+        col = layout.column()
+        col.operator_context = 'INVOKE_DEFAULT'
+        col.operator("wm.link", text="Link...", icon='LINK_BLEND').filepath = self.filepath
+        col.operator("wm.append", text="Append...", icon='APPEND_BLEND').filepath = self.filepath
+
 classes = (
     BRUSH_OT_active_index_set,
     WM_OT_addon_disable,
@@ -2710,6 +2734,7 @@ classes = (
     WM_OT_copy_prev_settings,
     WM_OT_doc_view,
     WM_OT_doc_view_manual,
+    WM_OT_drop_blend_file,
     WM_OT_keyconfig_activate,
     WM_OT_keyconfig_export,
     WM_OT_keyconfig_import,
index 27c9f522c54626c1819bc473ce9c96b1dcfc70d3..150e1b1f5a5979462a042e2b5b62237096bbc6ed 100644 (file)
@@ -4855,7 +4855,7 @@ static void keymap_modal_set(wmKeyConfig *keyconf)
 
 }
 
-static bool open_file_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
+static bool blend_file_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
 {
        if (drag->type == WM_DRAG_PATH) {
                if (drag->icon == ICON_FILE_BLEND)
@@ -4864,11 +4864,10 @@ static bool open_file_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent
        return 0;
 }
 
-static void open_file_drop_copy(wmDrag *drag, wmDropBox *drop)
+static void blend_file_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
        /* copy drag path to properties */
        RNA_string_set(drop->ptr, "filepath", drag->path);
-       drop->opcontext = WM_OP_EXEC_DEFAULT;
 }
 
 
@@ -5055,7 +5054,7 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
 
        /* dropbox for entire window */
        lb = WM_dropboxmap_find("Window", 0, 0);
-       WM_dropbox_add(lb, "WM_OT_open_mainfile", open_file_drop_poll, open_file_drop_copy);
+       WM_dropbox_add(lb, "WM_OT_drop_blend_file", blend_file_drop_poll, blend_file_drop_copy);
        WM_dropbox_add(lb, "UI_OT_drop_color", UI_drop_color_poll, UI_drop_color_copy);
 
        keymap_modal_set(keyconf);
index f8beb2ef80b8b6b463eef7db347bce5656146614..a1e298b91d0e77446f3d68371f6fcc105a333ee5 100644 (file)
@@ -106,11 +106,7 @@ static bool wm_link_append_poll(bContext *C)
 
 static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
-       if (RNA_struct_property_is_set(op->ptr, "filepath")) {
-               return WM_operator_call_notest(C, op);
-       }
-       else {
-               /* XXX TODO solve where to get last linked library from */
+       if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
                if (G.lib[0] != '\0') {
                        RNA_string_set(op->ptr, "filepath", G.lib);
                }
@@ -120,9 +116,10 @@ static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNU
                        BLI_parent_dir(path);
                        RNA_string_set(op->ptr, "filepath", path);
                }
-               WM_event_add_fileselect(C, op);
-               return OPERATOR_RUNNING_MODAL;
        }
+
+       WM_event_add_fileselect(C, op);
+       return OPERATOR_RUNNING_MODAL;
 }
 
 static short wm_link_append_flag(wmOperator *op)