From bc80cb1ba7d5120f555db7ada2a0ca997d1b2ffa Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Mon, 24 Apr 2006 23:03:21 +0000
Subject: [PATCH] readd the Cancel -> Exit aliases for the file browser and
 help browser, per Benno Schulenberg's suggestion, and clean up a few other
 miscellaneous things

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3428 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog     |  8 +++++++
 src/browser.c |  4 +++-
 src/help.c    | 37 +++++++++++++++++++++--------
 src/prompt.c  | 64 +++++++++++++++++++++++++++------------------------
 src/proto.h   |  1 +
 5 files changed, 74 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ce0048ca..df653643 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -51,6 +51,10 @@ CVS code -
 	  help_init(). (DLR, suggested by Benno Schulenberg)
 	- Reduce NO_RCFILE to a static bool in nano.c, since it's only
 	  used there.  Changes to finish() and main(). (DLR)
+	- Readd the Cancel -> Exit aliases for the file browser and help
+	  browser.  New function parse_help_input(); changes to
+	  parse_browser_input() and do_help(). (DLR, suggested by Benno
+	  Schulenberg)
 - files.c:
   open_file()
 	- Remove redundant wording in the error message when we try to
@@ -106,6 +110,7 @@ CVS code -
 	- Call get_shortcut() after getting input, so that we only have
 	  to check for a main shortcut key instead of both it and all of
 	  its equivalents. (DLR)
+	- Clean up the handling of NANO_REFRESH_KEY. (DLR)
   help_init()
 	- If we have at least two entries' worth of blank space, use it
 	  to display more of "^Space" and "M-Space". (DLR, suggested by
@@ -122,6 +127,9 @@ CVS code -
 	  disabled, so that we aren't erroneously kicked out of the
 	  statusbar prompt under any circumstances. (DLR, found by Benno
 	  Schulenberg)
+  do_yesno()
+	- Handle the keys in a switch statement instead of a long if
+	  block, for simplicity. (DLR)
 - rcfile.c:
   parse_argument()
 	- Rename variable ptr_bak to ptr_save, for consistency. (DLR)
diff --git a/src/browser.c b/src/browser.c
index cddc02e2..cd9a4372 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -486,7 +486,7 @@ void browser_init(const char *path, DIR *dir)
 /* Determine the shortcut key corresponding to the values of kbinput
  * (the key itself), meta_key (whether the key is a meta sequence), and
  * func_key (whether the key is a function key), if any.  In the
- * process, convert certain non-shortcut keys used by Pico's file
+ * process, convert certain non-shortcut keys used by e.g. Pico's file
  * browser into their corresponding shortcut keys. */
 void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
 {
@@ -504,6 +504,8 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
 	    case '?':
 		*kbinput = NANO_HELP_KEY;
 		break;
+	    /* Cancel is equivalent to Exit here. */
+	    case NANO_CANCEL_KEY:
 	    case 'E':
 	    case 'e':
 		*kbinput = NANO_EXIT_KEY;
diff --git a/src/help.c b/src/help.c
index 7d9011e7..d9564033 100644
--- a/src/help.c
+++ b/src/help.c
@@ -111,17 +111,16 @@ void do_help(void (*refresh_func)(void))
 		if (!no_more)
 		    line++;
 		break;
+	    case NANO_REFRESH_KEY:
+		total_redraw();
+		break;
 	}
 
-	if (kbinput == NANO_REFRESH_KEY)
-	    /* Redraw the screen. */
-	    total_redraw();
-	else {
-	    if (kbinput != ERR && line == old_line)
-		goto skip_redisplay;
+	if ((kbinput != ERR && line == old_line) || kbinput ==
+		NANO_REFRESH_KEY)
+	    goto skip_redisplay;
 
-	    blank_edit();
-	}
+	blank_edit();
 
 	/* Calculate where in the text we should be, based on the
 	 * page. */
@@ -143,7 +142,7 @@ void do_help(void (*refresh_func)(void))
 
   skip_redisplay:
 	kbinput = get_kbinput(edit, &meta_key, &func_key);
-	get_shortcut(help_list, &kbinput, &meta_key, &func_key);
+	parse_help_input(&kbinput, &meta_key, &func_key);
     } while (kbinput != NANO_EXIT_KEY);
 
 #ifndef DISABLE_MOUSE
@@ -547,6 +546,26 @@ void help_init(void)
     assert(strlen(help_text) <= allocsize + 1);
 }
 
+/* Determine the shortcut key corresponding to the values of kbinput
+ * (the key itself), meta_key (whether the key is a meta sequence), and
+ * func_key (whether the key is a function key), if any.  In the
+ * process, convert certain non-shortcut keys used by e.g. Pico's help
+ * browser into their corresponding shortcut keys. */
+void parse_help_input(int *kbinput, bool *meta_key, bool *func_key)
+{
+    get_shortcut(help_list, kbinput, meta_key, func_key);
+
+    /* Pico compatibility. */
+    if (*meta_key == FALSE && *func_key == FALSE) {
+	switch (*kbinput) {
+	    /* Cancel is equivalent to Exit here. */
+	    case NANO_CANCEL_KEY:
+		*kbinput = NANO_EXIT_KEY;
+		break;
+	}
+    }
+}
+
 /* Calculate the next line of help_text, starting at ptr. */
 size_t help_line_len(const char *ptr)
 {
diff --git a/src/prompt.c b/src/prompt.c
index 06070b04..46c88ea6 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -1268,24 +1268,23 @@ int do_yesno_prompt(bool all, const char *msg)
 
 	kbinput = get_kbinput(bottomwin, &meta_key, &func_key);
 
-	if (kbinput == NANO_REFRESH_KEY) {
-	    total_redraw();
-	    continue;
-	} else if (kbinput == NANO_CANCEL_KEY)
-	    ok = -1;
+	switch (kbinput) {
+	    case NANO_CANCEL_KEY:
+		ok = -1;
+		break;
 #ifndef DISABLE_MOUSE
-	else if (kbinput == KEY_MOUSE) {
-	    get_mouseinput(&mouse_x, &mouse_y, FALSE);
-
-	    if (mouse_x != -1 && mouse_y != -1 && !ISSET(NO_HELP) &&
-		wenclose(bottomwin, mouse_y, mouse_x) &&
-		mouse_x < (width * 2) && mouse_y - (2 -
-		no_more_space()) - editwinrows - 1 >= 0) {
-		int x = mouse_x / width;
+	    case KEY_MOUSE:
+		get_mouseinput(&mouse_x, &mouse_y, FALSE);
+
+		if (mouse_x != -1 && mouse_y != -1 && !ISSET(NO_HELP) &&
+			wenclose(bottomwin, mouse_y, mouse_x) &&
+			mouse_x < (width * 2) && mouse_y - (2 -
+			no_more_space()) - editwinrows - 1 >= 0) {
+		    int x = mouse_x / width;
 			/* Calculate the x-coordinate relative to the
 			 * two columns of the Yes/No/All shortcuts in
 			 * bottomwin. */
-		int y = mouse_y - (2 - no_more_space()) -
+		    int y = mouse_y - (2 - no_more_space()) -
 			editwinrows - 1;
 			/* Calculate the y-coordinate relative to the
 			 * beginning of the Yes/No/All shortcuts in
@@ -1293,25 +1292,30 @@ int do_yesno_prompt(bool all, const char *msg)
 			 * edit, and the first line of bottomwin
 			 * subtracted out. */
 
-		assert(0 <= x && x <= 1 && 0 <= y && y <= 1);
+		    assert(0 <= x && x <= 1 && 0 <= y && y <= 1);
 
-		/* x == 0 means they clicked Yes or No.  y == 0 means
-		 * Yes or All. */
-		ok = -2 * x * y + x - y + 1;
+		    /* x == 0 means they clicked Yes or No.  y == 0
+		     * means Yes or All. */
+		    ok = -2 * x * y + x - y + 1;
 
-		if (ok == 2 && !all)
-		    ok = -2;
-	    }
+		    if (ok == 2 && !all)
+			ok = -2;
+		}
+		break;
+#endif /* !DISABLE_MOUSE */
+	    case NANO_REFRESH_KEY:
+		total_redraw();
+		continue;
+	    default:
+		/* Look for the kbinput in the Yes, No and (optionally)
+		 * All strings. */
+		if (strchr(yesstr, kbinput) != NULL)
+		    ok = 1;
+		else if (strchr(nostr, kbinput) != NULL)
+		    ok = 0;
+		else if (all && strchr(allstr, kbinput) != NULL)
+		    ok = 2;
 	}
-#endif
-	/* Look for the kbinput in the Yes, No and (optionally) All
-	 * strings. */
-	else if (strchr(yesstr, kbinput) != NULL)
-	    ok = 1;
-	else if (strchr(nostr, kbinput) != NULL)
-	    ok = 0;
-	else if (all && strchr(allstr, kbinput) != NULL)
-	    ok = 2;
     } while (ok == -2);
 
     return ok;
diff --git a/src/proto.h b/src/proto.h
index 9f7f6a0b..949c5fe7 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -351,6 +351,7 @@ void do_help_void(void);
 void do_browser_help(void);
 #endif
 void help_init(void);
+void parse_help_input(int *kbinput, bool *meta_key, bool *func_key);
 size_t help_line_len(const char *ptr);
 #endif
 
-- 
GitLab