Fix: Always print warnings when file/folder renaming fails
Rewrite the code so that users get an error message when trying to rename something to an existing file in the file browser. Before this change Blender would not print any notifications on why the rename failed if a file with the same name already existed. Pull Request: https://projects.blender.org/blender/blender/pulls/118571
This commit is contained in:
@@ -821,26 +821,28 @@ static void renamebutton_cb(bContext *C, void * /*arg1*/, char *oldname)
|
||||
BLI_path_join(newname, sizeof(newname), params->dir, filename);
|
||||
|
||||
if (!STREQ(orgname, newname)) {
|
||||
if (!BLI_exists(newname)) {
|
||||
errno = 0;
|
||||
if ((BLI_rename(orgname, newname) != 0) || !BLI_exists(newname)) {
|
||||
WM_reportf(RPT_ERROR, "Could not rename: %s", errno ? strerror(errno) : "unknown error");
|
||||
WM_report_banner_show(wm, win);
|
||||
}
|
||||
else {
|
||||
/* If rename is successful, scroll to newly renamed entry. */
|
||||
STRNCPY(params->renamefile, filename);
|
||||
file_params_invoke_rename_postscroll(wm, win, sfile);
|
||||
}
|
||||
|
||||
/* to make sure we show what is on disk */
|
||||
ED_fileselect_clear(wm, sfile);
|
||||
}
|
||||
else {
|
||||
errno = 0;
|
||||
if ((BLI_rename(orgname, newname) != 0) || !BLI_exists(newname)) {
|
||||
WM_reportf(RPT_ERROR, "Could not rename: %s", errno ? strerror(errno) : "unknown error");
|
||||
WM_report_banner_show(wm, win);
|
||||
/* Renaming failed, reset the name for further renaming handling. */
|
||||
STRNCPY(params->renamefile, oldname);
|
||||
}
|
||||
else {
|
||||
/* If rename is successful, set renamefile to newly renamed entry.
|
||||
* This is used later to select and scroll to the file.
|
||||
*/
|
||||
STRNCPY(params->renamefile, filename);
|
||||
}
|
||||
|
||||
/* Ensure we select and scroll to the renamed file.
|
||||
* This is done even if the rename fails as we want to make sure that the file we tried to
|
||||
* rename is still selected and in view. (it can move if something added files/folders to the
|
||||
* directory while we were renaming.
|
||||
*/
|
||||
file_params_invoke_rename_postscroll(wm, win, sfile);
|
||||
/* to make sure we show what is on disk */
|
||||
ED_fileselect_clear(wm, sfile);
|
||||
ED_region_tag_redraw(region);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user