diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-09-07 13:27:27 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-09-07 13:27:27 +0300 |
commit | 13a7516f436597e7f60d0696afa16e8e6d6735fb (patch) | |
tree | 50672e9b503e3e875b7789006d0009d540041151 /source/blender/editors/space_file | |
parent | 97bd04d665cb8c964e9159da94a3c7941cd4841c (diff) |
Cleanup: factor out "set default filepath" into a ED_fileselect_ensure_default_filepath
Follow up to D15904, a bunch of places had exact same logic for
"is filepath set? if not, set some default one", so factor all that out
into a separate ED_fileselect_ensure_default_filepath function.
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index e42e1e98660..c569a2b57a6 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -1385,3 +1385,24 @@ ScrArea *ED_fileselect_handler_area_find_any_with_op(const wmWindow *win) return NULL; } + +void ED_fileselect_ensure_default_filepath(struct bContext *C, + struct wmOperator *op, + const char *extension) +{ + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { + struct Main *bmain = CTX_data_main(C); + char filepath[FILE_MAX]; + const char *blendfile_path = BKE_main_blendfile_path(bmain); + + if (blendfile_path[0] == '\0') { + BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath)); + } + else { + BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); + } + + BLI_path_extension_replace(filepath, sizeof(filepath), extension); + RNA_string_set(op->ptr, "filepath", filepath); + } +} |