From: Benno Schulenberg Date: Sun, 20 Mar 2016 14:34:46 +0000 (+0000) Subject: Always asking whether it's okay when the name of the file was changed. X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=4ddf1940046738f25686d0abc3ff6d151c06ee06;p=nano.git Always asking whether it's okay when the name of the file was changed. This fixes Savannah bug #46894. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5753 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 1a3913aa..d4864319 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ that is: treat the deletion of words like pressing Backspace/Delete. * src/search.c (get_history_completion, find_history): Cycle through the items from newest to oldest. This fixes Savannah bug #47205. + * src/files.c (do_writeout): When the name of the file was changed, + always ask whether this is okay. This fixes Savannah bug #46894. 2016-03-19 Benno Schulenberg * src/search.c (search_init): Always remember the last typed string, diff --git a/src/files.c b/src/files.c index 23ee8806..991050b0 100644 --- a/src/files.c +++ b/src/files.c @@ -2276,6 +2276,8 @@ int do_writeout(bool exiting) #ifndef DISABLE_EXTRA static bool did_credits = FALSE; #endif + bool maychange = FALSE; + /* Whether it's okay to save the file under a different name. */ bool result = FALSE; if (exiting && openfile->filename[0] != '\0' && ISSET(TEMP_FILE)) { @@ -2452,19 +2454,29 @@ int do_writeout(bool exiting) if (ISSET(RESTRICTED)) continue; - if (name_exists) { - i = do_yesno_prompt(FALSE, - _("File exists; OVERWRITE? ")); - if (i == 0 || i == -1) - continue; - } else + if (!maychange) { #ifndef NANO_TINY - if (exiting || !openfile->mark_set) -#endif - { - i = do_yesno_prompt(FALSE, - _("Save file under DIFFERENT NAME? ")); - if (i == 0 || i == -1) + if (exiting || !openfile->mark_set) +#endif + { + i = do_yesno_prompt(FALSE, + _("Save file under DIFFERENT NAME? ")); + if (i < 1) + continue; + maychange = TRUE; + } + } + + if (name_exists) { + char *question = _("File \"%s\" exists; OVERWRITE? "); + char *message = charalloc(strlen(question) + + strlen(answer) + 1); + sprintf(message, question, answer); + + i = do_yesno_prompt(FALSE, message); + free(message); + + if (i < 1) continue; } }