Fix screenshot path defaulting to the root directory for unsaved files

Using a "//" prefix resolves to the root directory which isn't a good
default as it typically doesn't have write permissions.
Only set the name and let the file selector pick a directory to use
(matches how saving from the text editor works).
This commit is contained in:
Campbell Barton
2023-04-17 13:31:08 +10:00
parent 153cb7e1df
commit 0b1fb22f69

View File

@@ -167,12 +167,15 @@ static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* extension is added by 'screenshot_check' after */
char filepath[FILE_MAX];
BLI_snprintf(filepath, FILE_MAX, "//%s", DATA_("screen"));
const char *blendfile_path = BKE_main_blendfile_path_from_global();
if (blendfile_path[0] != '\0') {
BLI_strncpy(filepath, blendfile_path, sizeof(filepath));
BLI_path_extension_replace(filepath, sizeof(filepath), ""); /* strip '.blend' */
}
else {
/* As the file isn't saved, only set the name and let the file selector pick a directory. */
STRNCPY(filepath, DATA_("screen"));
}
RNA_string_set(op->ptr, "filepath", filepath);
WM_event_add_fileselect(C, op);