IO: Use FileHandlers in the View 3d

Use File Handlers to handle file drag-n-drop in the View 3d. Drop-boxes
still remain since they handle Texture ID drag-n-drop.

This will add-ons to handle drag-n-drop for images and movies while
still providing access to Blender's native support since File Handlers
let users choose which to invoke if there's multiple configured.

Pull Request: https://projects.blender.org/blender/blender/pulls/117728
This commit is contained in:
Guillermo Venegas
2024-03-26 20:01:08 +01:00
committed by Jesse Yurkovich
parent 5a1bab39d2
commit 8b6a21c122
2 changed files with 34 additions and 11 deletions

View File

@@ -3,7 +3,10 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
from bpy.types import Operator
from bpy.types import (
Operator,
FileHandler,
)
from bpy.props import (
BoolProperty,
EnumProperty,
@@ -258,10 +261,40 @@ class VIEW3D_OT_transform_gizmo_set(Operator):
return self.execute(context)
class VIEW3D_FH_empty_image(FileHandler):
bl_idname = "VIEW3D_FH_empty_image"
bl_label = "Add empty image"
bl_import_operator = "OBJECT_OT_empty_image_add"
bl_file_extensions = ';'.join(bpy.path.extensions_image) + ';' + ';'.join(bpy.path.extensions_movie)
@classmethod
def poll_drop(cls, context):
if not context.space_data or context.space_data.type != 'VIEW_3D':
return False
rv3d = context.space_data.region_3d
return rv3d.view_perspective == 'PERSP' or rv3d.view_perspective == 'ORTHO'
class VIEW3D_FH_camera_background_image(FileHandler):
bl_idname = "VIEW3D_FH_camera_background_image"
bl_label = "Add camera background image"
bl_import_operator = "VIEW3D_OT_camera_background_image_add"
bl_file_extensions = ';'.join(bpy.path.extensions_image) + ';' + ';'.join(bpy.path.extensions_movie)
@classmethod
def poll_drop(cls, context):
if not context.space_data or context.space_data.type != 'VIEW_3D':
return False
rv3d = context.space_data.region_3d
return rv3d.view_perspective == 'CAMERA'
classes = (
VIEW3D_OT_edit_mesh_extrude_individual_move,
VIEW3D_OT_edit_mesh_extrude_move,
VIEW3D_OT_edit_mesh_extrude_shrink_fatten,
VIEW3D_OT_edit_mesh_extrude_manifold_normal,
VIEW3D_OT_transform_gizmo_set,
VIEW3D_FH_camera_background_image,
VIEW3D_FH_empty_image,
)

View File

@@ -620,11 +620,6 @@ static bool view3d_ima_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event
if (ED_region_overlap_isect_any_xy(CTX_wm_area(C), event->xy)) {
return false;
}
if (drag->type == WM_DRAG_PATH) {
const eFileSel_File_Types file_type = eFileSel_File_Types(WM_drag_get_path_file_type(drag));
return ELEM(file_type, FILE_TYPE_IMAGE, FILE_TYPE_MOVIE);
}
return WM_drag_is_ID_type(drag, ID_IM);
}
@@ -887,11 +882,6 @@ static void view3d_id_path_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
RNA_struct_property_unset(drop->ptr, "filepath");
return;
}
const char *path = WM_drag_get_single_path(drag);
if (path) {
RNA_string_set(drop->ptr, "filepath", path);
RNA_struct_property_unset(drop->ptr, "image");
}
}
static void view3d_lightcache_update(bContext *C)