- 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
master
Chris Allegretta 2003-01-28 01:23:40 +00:00
parent d26ab913f1
commit db28e96f2c
2 changed files with 49 additions and 73 deletions

View File

@ -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.

120
winio.c
View File

@ -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, ...)
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 */ if (kbinput == NANO_CONTROL_C)
for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++); ok = -1;
if (yesstr[i] != 0) { #ifndef DISABLE_MOUSE
ok = 1; /* Look ma! We get to duplicate lots of code from do_mouse!! */
break; else if (kbinput == KEY_MOUSE && getmouse(&mevent) != ERR &&
} wenclose(bottomwin, mevent.y, mevent.x) &&
!ISSET(NO_HELP) && mevent.x < 32 &&
mevent.y >= editwinrows + 3) {
int x = mevent.x /= 16;
/* Did we click in the first column of shortcuts, or the
second? */
int y = mevent.y - editwinrows - 3;
/* Did we click in the first row of shortcuts? */
for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++); assert(0 <= x && x <= 1 && 0 <= y && y <= 1);
if (nostr[i] != 0) { /* x = 0 means they clicked Yes or No.
ok = 0; y = 0 means Yes or All. */
break; ok = -2 * x * y + x - y + 1;
}
if (all) { if (ok == 2 && !all)
for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++); ok = -2;
if (allstr[i] != 0) {
ok = 2;
break;
}
}
} }
} #endif
/* Look for the kbinput in the yes, no and (optionally) all str */
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 screen */ /* 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)