Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/io/io_gpencil_import.c')
-rw-r--r--source/blender/editors/io/io_gpencil_import.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/source/blender/editors/io/io_gpencil_import.c b/source/blender/editors/io/io_gpencil_import.c
index 9ac64407dcf..5325965e9a5 100644
--- a/source/blender/editors/io/io_gpencil_import.c
+++ b/source/blender/editors/io/io_gpencil_import.c
@@ -9,6 +9,8 @@
# include "BLI_path_util.h"
+# include "MEM_guardedalloc.h"
+
# include "DNA_gpencil_types.h"
# include "DNA_space_types.h"
@@ -63,7 +65,8 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false) ||
+ !RNA_struct_find_property(op->ptr, "directory")) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
return OPERATOR_CANCELLED;
}
@@ -75,9 +78,6 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
}
View3D *v3d = get_invoke_view3d(C);
- char filename[FILE_MAX];
- RNA_string_get(op->ptr, "filepath", filename);
-
/* Set flags. */
int flag = 0;
@@ -101,13 +101,31 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
.resolution = resolution,
};
- /* Do Import. */
- WM_cursor_wait(1);
- const bool done = gpencil_io_import(filename, &params);
- WM_cursor_wait(0);
-
- if (!done) {
- BKE_report(op->reports, RPT_WARNING, "Unable to import SVG");
+ /* Loop all selected files to import them. All SVG imported shared the same import
+ * parameters, but they are created in separated grease pencil objects. */
+ PropertyRNA *prop;
+ if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
+ char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
+
+ if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
+ char file_path[FILE_MAX];
+ RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
+ BLI_path_join(file_path, sizeof(file_path), directory, filename);
+ MEM_freeN(filename);
+
+ /* Do Import. */
+ WM_cursor_wait(1);
+ RNA_string_get(&itemptr, "name", params.filename);
+ const bool done = gpencil_io_import(file_path, &params);
+ WM_cursor_wait(0);
+ if (!done) {
+ BKE_reportf(op->reports, RPT_WARNING, "Unable to import '%s'", file_path);
+ }
+ }
+ RNA_PROP_END;
+ }
+ MEM_freeN(directory);
}
return OPERATOR_FINISHED;
@@ -149,10 +167,11 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot)
ot->check = wm_gpencil_import_svg_common_check;
WM_operator_properties_filesel(ot,
- FILE_TYPE_OBJECT_IO,
+ FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
FILE_BLENDER,
FILE_OPENFILE,
- WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS |
+ WM_FILESEL_DIRECTORY | WM_FILESEL_FILES,
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT);