preserve labels after an edit action is aborted; extending the menu

struct just for this is the least intrusive approach until the menu code
is reviewed.

inspired by Thomas Pfaff's report on tech@

ok oga@
This commit is contained in:
okan 2010-02-10 01:23:05 +00:00
parent c4a97053cd
commit 507480a695
3 changed files with 8 additions and 5 deletions

View File

@ -320,6 +320,7 @@ struct menu {
char print[MENU_MAXENTRY + 1]; char print[MENU_MAXENTRY + 1];
void *ctx; void *ctx;
short dummy; short dummy;
short abort;
}; };
TAILQ_HEAD(menu_q, menu); TAILQ_HEAD(menu_q, menu);

View File

@ -400,19 +400,19 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
{ {
struct menu *mi; struct menu *mi;
struct menu_q menuq; struct menu_q menuq;
char *current;
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
current = cc->label; /* dummy is set, so this will always return */
mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
search_match_text, NULL);
if ((mi = menu_filter(cc->sc, &menuq, "label", current, 1, if (!mi->abort) {
search_match_text, NULL)) != NULL) {
if (cc->label != NULL) if (cc->label != NULL)
xfree(cc->label); xfree(cc->label);
cc->label = xstrdup(mi->text); cc->label = xstrdup(mi->text);
xfree(mi);
} }
xfree(mi);
} }
void void

2
menu.c
View File

@ -223,6 +223,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
mc->searchstr, sizeof(mi->text)); mc->searchstr, sizeof(mi->text));
mi->dummy = 1; mi->dummy = 1;
} }
mi->abort = 0;
return (mi); return (mi);
case CTL_WIPE: case CTL_WIPE:
mc->searchstr[0] = '\0'; mc->searchstr[0] = '\0';
@ -235,6 +236,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
mi = xmalloc(sizeof *mi); mi = xmalloc(sizeof *mi);
mi->text[0] = '\0'; mi->text[0] = '\0';
mi->dummy = 1; mi->dummy = 1;
mi->abort = 1;
return (mi); return (mi);
default: default:
break; break;