Commit db28e96f authored by Chris Allegretta's avatar Chris Allegretta
Browse files

- winio.c:do_yesno() - Fix mouse interaction bugs with yes/no prompt (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1404 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent d26ab913
Showing with 52 additions and 76 deletions
+52 -76
...@@ -60,6 +60,8 @@ CVS Code - ...@@ -60,6 +60,8 @@ CVS Code -
bottombars() bottombars()
- Change strcpy of gettext() "Up" string to strncpy of max - Change strcpy of gettext() "Up" string to strncpy of max
width 8, to stop stupid strcpy crash. width 8, to stop stupid strcpy crash.
do_yesno()
- Fix mouse interaction bugs with yes/no prompt (David Benbennick).
- nanorc.sample: - nanorc.sample:
- Change comment to say magenta instead of purple. - Change comment to say magenta instead of purple.
......
...@@ -1237,14 +1237,11 @@ int statusq(int tabs, const shortcut *s, const char *def, ...@@ -1237,14 +1237,11 @@ int statusq(int tabs, const shortcut *s, const char *def,
int do_yesno(int all, int leavecursor, const char *msg, ...) int do_yesno(int all, int leavecursor, const char *msg, ...)
{ {
va_list ap; va_list ap;
char foo[133]; char *foo;
int kbinput, ok = -1, i; int ok = -2;
const char *yesstr; /* String of yes characters accepted */ const char *yesstr; /* String of yes characters accepted */
const char *nostr; /* Same for no */ const char *nostr; /* Same for no */
const char *allstr; /* And all, surprise! */ const char *allstr; /* And all, surprise! */
#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
MEVENT mevent;
#endif
/* Yes, no and all are strings of any length. Each string consists of /* Yes, no and all are strings of any length. Each string consists of
all characters accepted as a valid character for that value. all characters accepted as a valid character for that value.
...@@ -1253,112 +1250,89 @@ int do_yesno(int all, int leavecursor, const char *msg, ...) ...@@ -1253,112 +1250,89 @@ int do_yesno(int all, int leavecursor, const char *msg, ...)
nostr = _("Nn"); nostr = _("Nn");
allstr = _("Aa"); allstr = _("Aa");
/* Write the bottom of the screen */
blank_bottomwin();
/* Remove gettext call for keybindings until we clear the thing up */ /* Remove gettext call for keybindings until we clear the thing up */
if (!ISSET(NO_HELP)) { if (!ISSET(NO_HELP)) {
char shortstr[3]; /* Temp string for Y, N, A */ char shortstr[3]; /* Temp string for Y, N, A */
wmove(bottomwin, 1, 0); /* Write the bottom of the screen */
blank_bottombars();
sprintf(shortstr, " %c", yesstr[0]); sprintf(shortstr, " %c", yesstr[0]);
wmove(bottomwin, 1, 0);
onekey(shortstr, _("Yes"), 16); onekey(shortstr, _("Yes"), 16);
if (all) { if (all) {
wmove(bottomwin, 1, 16);
shortstr[1] = allstr[0]; shortstr[1] = allstr[0];
onekey(shortstr, _("All"), 16); onekey(shortstr, _("All"), 16);
} }
wmove(bottomwin, 2, 0);
wmove(bottomwin, 2, 0);
shortstr[1] = nostr[0]; shortstr[1] = nostr[0];
onekey(shortstr, _("No"), 16); onekey(shortstr, _("No"), 16);
wmove(bottomwin, 2, 16);
onekey("^C", _("Cancel"), 16); onekey("^C", _("Cancel"), 16);
} }
foo = charalloc(COLS);
va_start(ap, msg); va_start(ap, msg);
vsnprintf(foo, 132, msg, ap); vsnprintf(foo, COLS, msg, ap);
va_end(ap); va_end(ap);
foo[COLS - 1] = '\0';
wattron(bottomwin, A_REVERSE); wattron(bottomwin, A_REVERSE);
blank_statusbar(); blank_statusbar();
mvwaddstr(bottomwin, 0, 0, foo); mvwaddstr(bottomwin, 0, 0, foo);
free(foo);
wattroff(bottomwin, A_REVERSE); wattroff(bottomwin, A_REVERSE);
wrefresh(bottomwin); wrefresh(bottomwin);
if (leavecursor == 1) do {
reset_cursor(); int kbinput = wgetch(edit);
#ifndef DISABLE_MOUSE
while (ok == -1) { MEVENT mevent;
kbinput = wgetch(edit);
switch (kbinput) {
#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case KEY_MOUSE:
/* Look ma! We get to duplicate lots of code from do_mouse!! */
if (getmouse(&mevent) == ERR)
break;
if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
break;
mevent.y -= editwinrows + 3;
if (mevent.y < 0)
break;
else {
/* Rather than a bunch of if statements, set up a matrix
of possible return keystrokes based on the x and y
values */
char yesnosquare[2][2];
yesnosquare[0][0] = yesstr[0];
if (all)
yesnosquare[0][1] = allstr[0];
else
yesnosquare[0][1] = '\0';
yesnosquare[1][0] = nostr[0];
yesnosquare[1][1] = NANO_CONTROL_C;
ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]);
}
break;
#endif #endif
case NANO_CONTROL_C:
ok = -2;
break;
default:
/* Look for the kbinput in the yes, no and (optimally) all str */
for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++);
if (yesstr[i] != 0) {
ok = 1;
break;
}
for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++); if (kbinput == NANO_CONTROL_C)
if (nostr[i] != 0) { ok = -1;
ok = 0; #ifndef DISABLE_MOUSE
break; /* Look ma! We get to duplicate lots of code from do_mouse!! */
} else if (kbinput == KEY_MOUSE && getmouse(&mevent) != ERR &&
wenclose(bottomwin, mevent.y, mevent.x) &&
if (all) { !ISSET(NO_HELP) && mevent.x < 32 &&
for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++); mevent.y >= editwinrows + 3) {
if (allstr[i] != 0) { int x = mevent.x /= 16;
ok = 2; /* Did we click in the first column of shortcuts, or the
break; second? */
} int y = mevent.y - editwinrows - 3;
} /* Did we click in the first row of shortcuts? */
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;
if (ok == 2 && !all)
ok = -2;
} }
} #endif
/* Look for the kbinput in the yes, no and (optionally) all str */
/* Then blank the screen */ 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);
/* Then blank the statusbar. */
blank_statusbar_refresh(); blank_statusbar_refresh();
if (ok == -2) return ok;
return -1;
else
return ok;
} }
int total_refresh(void) int total_refresh(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment