As discussed in https://github.com/geany/geany/pull/1180.
This change adds two new functions: `document_rename_file_and_save()`, and `document_rename_and_save()`. `document_rename_file_and_save()` is kind of like the combination of `document_rename_file()` and `document_save_file_as()`, and is strictly about renaming the associated file, and doing the stuff necessary before and after the file has been renamed, like disabling file monitoring, and putting it back if a rename fails, saving/restoring file disk status, etc.
`document_rename_and_save()` OTOH is more of a wrapper, and is about renaming the document itself. It doesn't require the document to have an associated file to it (i.e. `doc->real_path != NULL`). But if there is an associated file, the file is also renamed, i.e., `document_rename_file_and_save()` is called. The algorithm to check if the file has to be overwritten is also contained in it. This function should be adaptable to other implementations like [in-place renaming](https://github.com/konsolebox/geany/tree/docs_rename).
In `dialogs.c`, stuff about resetting `doc->tm_file` and calling `build_menu_update()` has been moved to `document_save_file_as()`, since both are essentially needed to be done by anyone that calls the function. It helps significantly simplify the two new functions and the functions in `dialogs.c`.
The function `save_as_dialog_handle_response()` has been refactored, and is now simpler since the "overwrite file?" prompt has been moved to `document_rename_and_save()`, and since it can now directly call `document_rename_and_save()` and `document_save_file_as()`. `dialogs_show_save_as()` now also directly calls `document_save_file_as()` if `interface_prefs.use_native_windows_dialogs == TRUE`. `handle_save_as()` is no longer needed, so it's been removed. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/1194
-- Commit Summary --
* Add document_rename_file_and_save() * Do not make document_rename_file_and_save() an API function for now * Add document_rename_and_save() * Move resetting GeanyDocument::tm_file, and calling build_menu_update() to document_save_file_as() * Rework Save-As functions in dialogs.c * dialogs_show_save_as: g_free(utf8_name);
-- File Changes --
M src/dialogs.c (78) M src/document.c (81) M src/document.h (4)
-- Patch Links --
https://github.com/geany/geany/pull/1194.patch https://github.com/geany/geany/pull/1194.diff
Should #1180 be closed, since this PR supersedes it?
I don't remember this or #1180 from 2016 but I did not think #1180 was correct AFAICT from the comments. Given the passage of time since they were proposed, that nobody has found them sufficiently worth progressing, and that this has conflicts anyway I suspect both could be closed. Its easy enough for someone to reopen them.
Closed #1194.
github-comments@lists.geany.org