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.
This commit is contained in:
2022-09-07 13:27:27 +03:00
parent 97bd04d665
commit 13a7516f43
8 changed files with 44 additions and 94 deletions

View File

@@ -18,6 +18,7 @@
# include "BLT_translation.h"
# include "ED_fileselect.h"
# include "ED_outliner.h"
# include "MEM_guardedalloc.h"
@@ -58,20 +59,7 @@ static const EnumPropertyItem io_obj_path_mode[] = {
static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
Main *bmain = CTX_data_main(C);
char filepath[FILE_MAX];
if (BKE_main_blendfile_path(bmain)[0] == '\0') {
BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
}
else {
BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
}
BLI_path_extension_replace(filepath, sizeof(filepath), ".obj");
RNA_string_set(op->ptr, "filepath", filepath);
}
ED_fileselect_ensure_default_filepath(C, op, ".obj");
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;