IO: Add initial support for File Handlers registration #112466
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#112466
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "guishe/blender:file-handler"
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?
Adds initial support for File Handlers registration with a python apy.
This file handlers will allow developers to associate file extensions
with operators and give them extended UI capabilities as drag & drop support.
Currently this changes would not have any user visible changes, but
this initial state will help create a way to provide file drag & drop
capabilities to operators that can manage files (#111242).
As proposed in #68935 this file handlers also can be extended to be
able to show dynamic import windows with dynamic import options
depending on selected files, or automatically extend file import/export
menus.
Not resolved in the PR:
Usage
WM_OT_gpencil_import_svg
operator import.svg
files as gpencil objects, we can register aFileHandler
as follows:Guillermo Venegas referenced this pull request2023-10-26 22:06:56 +02:00
@ -0,0 +25,4 @@
bool (*poll_drop)(const struct bContext *C, FileHandlerType *file_handle_type);
/* List of file extensions supported by the file handler. */
blender::Vector<bFileExtension> file_extensions;
bFileExtension
can just be astd::string
?@ -0,0 +2,4 @@
#include "BKE_file_handler.hh"
static blender::Vector<FileHandlerType *> *file_handlers = nullptr;
I think this can be simplified to
static blender::Vector<FileHandlerType> file_handlers
. For new C++ we should try to avoid this kind of manual memory allocation.The only thing is that it should be defined inside a function, so that it is lazily initialized, after the memory allocator is initialized.
I had to use
static blender::RawVector<std::unique_ptr<FileHandlerType>> file_handlers;
Vector
will not be released on closingAnd had to use a
unique_ptr
, the RNAStruc pointer can be invalid if the array is rearranged (by removing or adding new elements) with justRawVector<FileHandlerType>
Ok, that makes sense. Calling
clear_and_shrink
onVector
would have worked as well.@ -1455,0 +1563,4 @@
}
char_begin = char_end[0] ? char_end + 1 : char_end;
char_end = BLI_strchr_or_end(char_begin, char_separator);
}
Can this parsing be moved into
file_handler.cc
?@ -0,0 +10,4 @@
return file_handlers;
}
const blender::Vector<FileHandlerType *> BKE_file_handlers()
I don't think it's necessary to allocate another vector, can't this just return a
const RawVector
directly? It's less convenient, but I don't think we should be making copies just to iterate over this.My concern was more about using
unique_ptr
, but returning the RawVector as a const disables the data ownership transfer, so it really shouldn't be a problem.Besides notes below, this LGTM in general.
There are no tests for this new code though, would be good to add some in the BKE code to validate the adding, finding and removal of file handlers.
@ -0,0 +8,4 @@
struct FileHandlerType {
char idname[OP_MAX_TYPENAME]; /* Unique name. */
Use
/** */
doxygen syntax, put all comments on top.See also https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments
@ -0,0 +14,4 @@
char import_operator[OP_MAX_TYPENAME]; /* Import operator name. */
/* String list of file extensions supported by the file handler. */
Should also document the expected format of this string (separator, with or without dot, etc.)
@ -0,0 +15,4 @@
char import_operator[OP_MAX_TYPENAME]; /* Import operator name. */
/* String list of file extensions supported by the file handler. */
char file_extensions_str[OP_MAX_TYPENAME];
I don't think 64 chars is enough here? That's max 12 3-chars extensions... E.g. a handler for image files may support tens of them...
Think it needs its own define, probably at 256 or 512 chars?
@ -0,0 +27,4 @@
ExtensionRNA rna_ext;
};
void BKE_file_handler_add(std::unique_ptr<FileHandlerType> file_handler);
All of these functions need to be properly documented.
@ -0,0 +30,4 @@
void BKE_file_handler_add(std::unique_ptr<FileHandlerType> file_handler)
{
Useless empty line
@ -2201,0 +2321,4 @@
PropertyRNA *prop;
srna = RNA_def_struct(brna, "FileHandler", nullptr);
RNA_def_struct_ui_text(srna, "File Handler Type", "I/O File handler");
That description is not really useful, just rewording the struct label.
Better to get a short explanation of what is a file handler here.
As it is currently it will only add drag and drop support, I think this would fit:
Extends functionality to operators that manages files, such as adding drag and drop support.
@ -2201,0 +2348,4 @@
RNA_def_property_ui_text(
prop,
"Operator",
"Operator that can handle import files with extension in bl_file_extensions");
with the extensions given in bl_file_extensions
@ -2201,0 +2368,4 @@
func = RNA_def_function(srna, "poll_drop", nullptr);
RNA_def_function_ui_description(
func, "If this method returns a non-null output, then the file hanlder can be used");
typo:
handler
a non-null output
->True
Would also add precision:
can be used to handle the drop of a drag-and-drop action
. At some point I would expect we add more poll callbacks for other types of file handling.@ -2201,0 +2370,4 @@
RNA_def_function_ui_description(
func, "If this method returns a non-null output, then the file hanlder can be used");
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL);
RNA_def_function_return(func, RNA_def_boolean(func, "visible", true, "", ""));
visible
is very confusing name here? Also for booleans, we recommend usingis_
oruse_
prefixes, e.g. here could beis_usable
...See also https://wiki.blender.org/wiki/Source/Architecture/RNA#Defining_Structs_and_Properties
Generally LGTM now.
Details noted below can be addressed before commit and should not require another review.
@ -0,0 +16,4 @@
/** Import operator name. */
char import_operator[OP_MAX_TYPENAME];
/** Formatted string of file extensions supported by the file handler, each extension should
* start with a `.` and separated by a `;`. For Example: `".blend;.ble"`. */
picky
and be separated by
@ -0,0 +7,4 @@
namespace blender::tests {
static FileHandlerType *file_handlers[8];
Would recommend rather using a
#define
here, easier to manage if this number needs to be changed later. 'Magic numbers' should be avoided as much as possible.@ -0,0 +16,4 @@
blender::Vector<std::string> expected_file_extensions)
{
EXPECT_EQ(BKE_file_handlers().size(), test_number - 1);
Would add a check here that
test_number <= <size of file_handlers>
(using the#define
d value for the size of this static array, as suggested above).@ -0,0 +38,4 @@
"File Handler Test 1",
".blender;.blend;.ble",
{".blender", ".blend", ".ble"});
file_handler_add_test(2, "Test_FH_blender2", "File Handler Test 1", ".ble", {".ble"});
This label and the next two ones seem to be off-by-one, is this expected? or copy-paste glitch?
@ -0,0 +49,4 @@
TEST(file_handler, find)
{
Useless empty line ;)
@blender-bot build
@blender-bot build
@blender-bot build
Make format don't fixes this for me, i will adding this manually after builds ends
Lint issue was fixed in last commit,the builds are still fine