WIP: Experiment: Drop import operator helper and file drop type #111242
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#111242
Loading…
Reference in New Issue
No description provided.
Delete Branch "guishe/blender:drop-helper"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Added a operator that handles files drops and redirects this drops to file importers operators
This is done with
FileHandler
type class, that can be register to poll if file a extension can be imported with a operator.Important note:
This pr is not intended for review, this pr collects changes that can be done in several patches, some changes allow file importers to show a popup dialog instead a import window, or changes that allow multiple file to be dropped at the time
For curious ones or people who want to leave a little comment the important changes are in the files
Usage
WM_OT_gpencil_import_svg
operator import.svg
files as gpencil objects, we can register aFileHandler
class likeWith this now if a
.svg
file is dropped in theview3d
we can use theWM_OT_gpencil_import_svg
operator to import this file as agpencil object
with a tiny dialog box.Multiple operators supports handling same file
When a file can be handled with multiple operators, a menu will be displayed and the user should pick which operator to use.
How to make a operator be able to receive filedrops?
Internally the operator that can handle a file with a extension will be
invoke
as a default.FILE_PATH
StringProperty
calledfilepath
DIR_PATH
StringProperty
calleddirectory
and aOperatorFileListElement
CollectionProperty
calledfiles
When the
operator
isinvoked
, it can check if thisproperties
areset
, and if set show a import a popup dialog or directly execute the operator, or if not set show the usual file importer window.Note:
Sequencer have this nice drag&drop preview, if any image or movie es dropped this operator will be checked first, so in this region adding
FileDrops
for images or movies will not workThis is an alternative to #106871 that adds static file drop zones, and based on the @Harley comment #106871 (comment)
WIP: Experiment: Drop import operator helper and file import userprefto WIP: Experiment: Drop import operator helper and file importers userprefWIP: Experiment: Drop import operator helper and file importers userprefto WIP: Experiment: Drop import operator helper and file drop type07ba92a7c1
to84a43bcb76
I do wonder why the "which importer handles which extensions" is defined in some central location, and is part of user preferences at all. Conceptually, couldn't it be that "hey, I can do these extensions, call this function on me when they are dropped" be part of each importer itself?
That way, all the built-in importers (both C++ and Python ones) could have these functions added. Any 3rd party importers would not be handling the drop operation, until they also implement this (new, optional) functionality.
Hello, Yes, doing it as a preference had many complications.
I've made a new FileDrop registrable type that can register a function poll_extension and an operator name to call in case poll_extension is successful, and is bound to a space type.
Although poll_extension could also be added to the operators instead of making the new type
The FileDrop in python looks like
Feedback is welcome
Added a menu to be able to chose what operator to use in case two or more operators can handle a extension
For extensions that only have one will just call operator that handles each dropped file
Few considerations:
filepath
anddirectory
andnames
for files infiles
collection property, should allow user to be able to define how to name this properties instead of hard makes them hard coded?There is a design proposal in #68935 for a more general type like
bpy.types.FileHandler
that would have this type of drag & drop functionality as a subset. We also want to be able to have a single File > Import ... menu entry that can automatically pick the right importer based on the extension. And some more advanced cases as explained in that issue.So I would suggest to change this
bpy.types.FileDrop
to abpy.types.FileHandler
that we can extend later. For the fields, perhaps:bl_idname
: same as it is nowbl_label
: UI name for the file format, that we may need to show in the UIbl_file_extensions
: list of strings instead of poll function, as we might want to show that list somewhere in the UIbl_import_operator
: same asbl_operator
, but leaving possibility to distinguish from an export operatorInstead of a space type, I would suggest to make a poll function that gets a context. Because we might want to inspect the state of the editor to see if dropping is supported, or support dropping in multiple types of editors.
I'm a bit swamped with 4.0 work for the next few weeks and don't have time to review this in detail, but I like the overall direction.
I would like to get some input on the overall design from @ideasman42 and @mont29.
Quick code review, would still like input from other developers who are more involved in this area.
@ -3502,0 +3573,4 @@
@classmethod
def poll(cls, context):
return context.area.type == "VIEW_3D"
Probably should not have both STL importers here, in the end only one will be used when dropping?
In case there are 2 file handlers that can be used, you can choose which one to use with a menu
But the add-on one can include the file handle registration in its owns files
Ok, that makes sense. It would be better to have to just a single importer that is stable, but that's not a problem to be solved by this PR.
@ -3502,0 +3580,4 @@
bl_idname = "WM_FH_usd"
bl_label = "USD"
bl_import_operator = "WM_OT_usd_import"
bl_file_extensions = [{"extension": ".usd"}]
There is also
usda
,usdc
,usdz
.@ -673,0 +673,4 @@
#ifdef __cplusplus
struct bFileExtension {
This should move to its own file,
BKE_file_handler.h
@ -673,0 +675,4 @@
struct bFileExtension {
char extension[64];
};
Leave empty line between struct definitions.
@ -673,0 +682,4 @@
char label[BKE_ST_MAXNAME]; /* For UI text. */
char import_operator[BKE_ST_MAXNAME]; /* Import operator name, same as #OP_MAX_TYPENAME. */
Better to use
OP_MAX_TYPENAME
then, even if it means including a header.@ -673,0 +685,4 @@
char import_operator[BKE_ST_MAXNAME]; /* Import operator name, same as #OP_MAX_TYPENAME. */
/* Check if file handler can be used in a context. */
bool (*poll)(const struct bContext *C, FileHandlerType *file_handle_type);
Maybe call this
poll_drop
to clarify that it is used for drag & drop. We could imagine adding other poll types in the future to this type.@ -1339,2 +1339,4 @@
}
}
static blender::Vector<FileHandlerType *> file_handlers{};
Move to new
file_handler.cc
file.@ -0,0 +125,4 @@
for (auto *file_handler : file_handlers) {
wmOperatorType *ot = WM_operatortype_find(file_handler->import_operator, false);
PointerRNA op_props = copy_file_properties_to_operator_type_pointer(op, ot);
char *import_label = BLI_sprintfN("Import %s", file_handler->label);
Use
IFACE_("Import %s")
for translation.@ -0,0 +139,4 @@
UI_popup_menu_end(C, pup);
return OPERATOR_INTERFACE;
}
Leave empty line between function definitions.
@ -0,0 +142,4 @@
}
void WM_OT_drop_import_helper(wmOperatorType *ot)
{
ot->name = "Drop Import Herlper";
Herlper -> Helper
But I would not put "helper" in the name, lots of operators are helpers in some way and it doesn't really explain much.
Maybe "Drop to Import File"?
@ -0,0 +146,4 @@
ot->description =
"Helper operator that handles file drops and uses file handler information to call "
"operators that can import a file with extension.";
ot->idname = "WM_OT_drop_import_helper";
Add
ot->flag = OPTYPE_INTERNAL;
, this does not need to appear in search.@ -0,0 +1,85 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#if defined(WITH_COLLADA) || defined(WITH_IO_GPENCIL) || defined(WITH_IO_WAVEFRONT_OBJ) || \
defined(WITH_IO_PLY) || defined(WITH_IO_STL) || defined(WITH_USD)
Remove these tests. The code may not be used if none of these are defined, but that's not a problem.
@ -0,0 +14,4 @@
int wm_io_import_invoke(bContext *C, wmOperator *op, const wmEvent *event);
void skip_filesel_props(wmOperatorType *ot, const eFileSel_Flag flag);
void files_drop_label_draw(bContext *C, wmOperator *op, int icon, const char *extension);
These names are bit generic to put in global namespace. The
wm_
prefix would also imply that the function is defined in thewindow_manager_module
.Maybe use a
io_util_
prefix?@ -5922,3 +5922,3 @@
{
/* copy drag path to properties */
RNA_string_set(drop->ptr, "filepath", WM_drag_get_path(drag));
RNA_string_set(drop->ptr, "filepath", WM_drag_get_paths(drag)[0].c_str());
I would rename
WM_drag_get_path
toWM_drag_get_single_path
and addWM_drag_get_paths
alongside it. It's a bit ugly to have this assumption that the first path should be used duplicated in multiple places.I made WM_drag_get_single_path return the first path it found.
Just to note, most places that use this are for drag and drop, most of which could also be converted to file handlers.
@ -2081,0 +2228,4 @@
{
StructRNA *srna;
RNA_def_property_srna(cprop, "FileExtensions");
I'm not sure about this mechanism. We don't have a good way to pass a list of strings here currently, but the easier workaround to me seems to have a string of extensions separated by
;
or something like that.I changed it to be just a string separated by
;
, and also eliminated theIDProperty
because it was only used for that purpose.To note, parts of this pr is already separated in other 2 pr
Initial support for file handler registration:
#112466
Support for multiple file drag&drop
#107230
Checkout
From your project repository, check out a new branch and test the changes.