]> git.wh0rd.org Git - nano.git/commitdiff
further simplify processing of mouse events by consolidating if clauses
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 28 Jun 2007 16:00:50 +0000 (16:00 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 28 Jun 2007 16:00:50 +0000 (16:00 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4113 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/browser.c
src/nano.c
src/prompt.c

index 279057c73c85a69f6a38a3ee624215d6fea599b1..9e98b1ffa56699afb8fd156bdf6f66f24eed8b7b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-06-28  David Lawrence Ramsey  <pooka109@gmail.com>
+
+       * browser.c (do_browser), nano.c (do_mouse), prompt.c
+       (do_statusbar_mouse, do_yesno_prompt): Further simplify
+       processing of mouse events by consolidating if clauses.
+
 2007-05-29  David Lawrence Ramsey  <pooka109@gmail.com>
 
        * winio.c (do_mouseinput): Deal with clicks of the first mouse
index 0f10bb8c3de9eeb01a0087dc08d713594ce1fbb0..b04c366235446d37218a3283ebb7b902f39714f6 100644 (file)
@@ -131,36 +131,32 @@ char *do_browser(char *path, DIR *dir)
                {
                    int mouse_x, mouse_y;
 
-                   if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0) {
-                       /* We can click in the edit window to select a
-                        * filename. */
-                       if (wmouse_trafo(edit, &mouse_y, &mouse_x,
-                               FALSE)) {
-                           /* longest is the width of each column.
-                            * There are two spaces between each
-                            * column. */
-                           selected = (fileline / editwinrows) *
+                   /* We can click on the edit window to select a
+                    * filename. */
+                   if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0 &&
+                       wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
+                       /* longest is the width of each column.  There
+                        * are two spaces between each column. */
+                       selected = (fileline / editwinrows) *
                                (editwinrows * width) + (mouse_y *
                                width) + (mouse_x / (longest + 2));
 
-                           /* If they clicked beyond the end of a row,
-                            * select the filename at the end of that
-                            * row. */
-                           if (mouse_x > width * (longest + 2))
-                               selected--;
-
-                           /* If we're off the screen, select the last
-                            * filename. */
-                           if (selected > filelist_len - 1)
-                               selected = filelist_len - 1;
-
-                           /* If we selected the same filename as last
-                            * time, put back the Enter key so that it's
-                            * read in. */
-                           if (old_selected == selected)
-                               unget_kbinput(NANO_ENTER_KEY, FALSE,
-                                       FALSE);
-                       }
+                       /* If they clicked beyond the end of a row,
+                        * select the filename at the end of that
+                        * row. */
+                       if (mouse_x > width * (longest + 2))
+                           selected--;
+
+                       /* If we're off the screen, select the last
+                        * filename. */
+                       if (selected > filelist_len - 1)
+                           selected = filelist_len - 1;
+
+                       /* If we selected the same filename as last
+                        * time, put back the Enter key so that it's
+                        * read in. */
+                       if (old_selected == selected)
+                           unget_kbinput(NANO_ENTER_KEY, FALSE, FALSE);
                    }
                }
                break;
index 6eeeadb7b746a8b48a2e718b409381365a81928b..f902e62d765920e9f57d6b0c77dd68249611a9b2 100644 (file)
@@ -1497,42 +1497,38 @@ int do_mouse(void)
     int mouse_x, mouse_y;
     int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
 
-    if (retval == 0) {
-       /* We can click in the edit window to move the cursor. */
-       if (wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
-           bool sameline;
-               /* Did they click on the line with the cursor?  If they
-                * clicked on the cursor, we set the mark. */
-           const filestruct *current_save = openfile->current;
-           size_t current_x_save = openfile->current_x;
-           size_t pww_save = openfile->placewewant;
-
-           sameline = (mouse_y == openfile->current_y);
-
-           /* Move to where the click occurred. */
-           for (; openfile->current_y < mouse_y &&
-               openfile->current != openfile->filebot;
-               openfile->current_y++)
-               openfile->current = openfile->current->next;
-           for (; openfile->current_y > mouse_y &&
-               openfile->current != openfile->fileage;
-               openfile->current_y--)
-               openfile->current = openfile->current->prev;
-
-           openfile->current_x = actual_x(openfile->current->data,
+    /* We can click on the edit window to move the cursor. */
+    if (retval == 0 && wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
+       bool sameline;
+           /* Did they click on the line with the cursor?  If they
+            * clicked on the cursor, we set the mark. */
+       const filestruct *current_save = openfile->current;
+       size_t current_x_save = openfile->current_x;
+       size_t pww_save = openfile->placewewant;
+
+       sameline = (mouse_y == openfile->current_y);
+
+       /* Move to where the click occurred. */
+       for (; openfile->current_y < mouse_y && openfile->current !=
+               openfile->filebot; openfile->current_y++)
+           openfile->current = openfile->current->next;
+       for (; openfile->current_y > mouse_y && openfile->current !=
+               openfile->fileage; openfile->current_y--)
+           openfile->current = openfile->current->prev;
+
+       openfile->current_x = actual_x(openfile->current->data,
                get_page_start(xplustabs()) + mouse_x);
-           openfile->placewewant = xplustabs();
+       openfile->placewewant = xplustabs();
 
 #ifndef NANO_TINY
-           /* Clicking where the cursor is toggles the mark, as does
-            * clicking beyond the line length with the cursor at the
-            * end of the line. */
-           if (sameline && openfile->current_x == current_x_save)
-               do_mark();
+       /* Clicking where the cursor is toggles the mark, as does
+        * clicking beyond the line length with the cursor at the end of
+        * the line. */
+       if (sameline && openfile->current_x == current_x_save)
+           do_mark();
 #endif
 
-           edit_redraw(current_save, pww_save);
-       }
+       edit_redraw(current_save, pww_save);
     }
 
     return retval;
index 85c78bf753ea2b329a00d1530632ab08a6f9a60e..a213efe28df89056673a1755507e845308b962f2 100644 (file)
@@ -278,29 +278,27 @@ int do_statusbar_mouse(void)
     int mouse_x, mouse_y;
     int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
 
-    if (retval == 0) {
-       /* We can click in the statusbar window text to move the
-        * cursor. */
-       if (wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE)) {
-           size_t start_col;
+    /* We can click on the statusbar window text to move the cursor. */
+    if (retval == 0 && wmouse_trafo(bottomwin, &mouse_y, &mouse_x,
+       FALSE)) {
+       size_t start_col;
 
-           assert(prompt != NULL);
+       assert(prompt != NULL);
 
-           start_col = strlenpt(prompt) + 1;
+       start_col = strlenpt(prompt) + 1;
 
-           /* Move to where the click occurred. */
-           if (mouse_x > start_col && mouse_y == 0) {
-               size_t pww_save = statusbar_pww;
+       /* Move to where the click occurred. */
+       if (mouse_x > start_col && mouse_y == 0) {
+           size_t pww_save = statusbar_pww;
 
-               statusbar_x = actual_x(answer,
+           statusbar_x = actual_x(answer,
                        get_statusbar_page_start(start_col, start_col +
-                       statusbar_xplustabs()) + mouse_x - start_col -
-                       1);
-               statusbar_pww = statusbar_xplustabs();
+                       statusbar_xplustabs()) + mouse_x -
+                       start_col - 1);
+           statusbar_pww = statusbar_xplustabs();
 
-               if (need_statusbar_horizontal_update(pww_save))
-                   update_statusbar_line(answer, statusbar_x);
-           }
+           if (need_statusbar_horizontal_update(pww_save))
+               update_statusbar_line(answer, statusbar_x);
        }
     }
 
@@ -1334,6 +1332,8 @@ int do_yesno_prompt(bool all, const char *msg)
                break;
 #ifndef DISABLE_MOUSE
            case KEY_MOUSE:
+               /* We can click on the shortcut list to select an
+                * answer. */
                if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 &&
                        wmouse_trafo(bottomwin, &mouse_y, &mouse_x,
                        FALSE) && !ISSET(NO_HELP) && mouse_x <