From 95e5e4d8d0631667d2ca22327df41a2d4a6ff719 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Sun, 30 Nov 2008 20:28:53 +0100 Subject: [PATCH] Manage last search pattern outside of menu lifecycle Previously, the pattern was thrown away during menu destruction. For the next search, mutt then can't provide a good suggestion. The new behaviour is to manage the pattern outside the lifecyle to always provide the last pattern as suggestion. --HG-- branch : HEAD --- addrbook.c | 3 +-- browser.c | 3 +-- compose.c | 3 +-- crypt-gpgme.c | 3 +-- curs_main.c | 3 +-- init.c | 2 ++ menu.c | 31 +++++++++++++++++++++++-------- mutt_menu.h | 4 ++-- mutt_ssl.c | 2 +- mutt_ssl_gnutls.c | 2 +- pager.c | 3 +-- pgpkey.c | 3 +-- postpone.c | 3 +-- query.c | 6 ++---- recvattach.c | 3 +-- remailer.c | 3 +-- smime.c | 3 +-- 17 files changed, 42 insertions(+), 38 deletions(-) diff --git a/addrbook.c b/addrbook.c index a719062a0..46ee6059f 100644 --- a/addrbook.c +++ b/addrbook.c @@ -149,10 +149,9 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases) /* tell whoever called me to redraw the screen when I return */ set_option (OPTNEEDREDRAW); - menu = mutt_new_menu (); + menu = mutt_new_menu (MENU_ALIAS); menu->make_entry = alias_entry; menu->tag = alias_tag; - menu->menu = MENU_ALIAS; menu->title = _("Aliases"); menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ALIAS, AliasHelp); diff --git a/browser.c b/browser.c index 4d76f7db4..deba84767 100644 --- a/browser.c +++ b/browser.c @@ -645,8 +645,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num if (examine_directory (NULL, &state, LastDir, prefix) == -1) goto bail; - menu = mutt_new_menu (); - menu->menu = MENU_FOLDER; + menu = mutt_new_menu (MENU_FOLDER); menu->make_entry = folder_entry; menu->search = select_file_search; menu->title = title; diff --git a/compose.c b/compose.c index 8de9fec95..0f8037cce 100644 --- a/compose.c +++ b/compose.c @@ -511,8 +511,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_attach_init (msg->content); idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); - menu = mutt_new_menu (); - menu->menu = MENU_COMPOSE; + menu = mutt_new_menu (MENU_COMPOSE); menu->offset = HDR_ATTACH; menu->max = idxlen; menu->make_entry = snd_entry; diff --git a/crypt-gpgme.c b/crypt-gpgme.c index c719bf281..d49d67cd0 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -3832,10 +3832,9 @@ static crypt_key_t *crypt_select_key (crypt_key_t *keys, mutt_make_help (buf, sizeof (buf), _("Help"), menu_to_use, OP_HELP); strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ - menu = mutt_new_menu (); + menu = mutt_new_menu (menu_to_use); menu->max = i; menu->make_entry = crypt_entry; - menu->menu = menu_to_use; menu->help = helpstr; menu->data = key_table; diff --git a/curs_main.c b/curs_main.c index 93006a046..4627fa181 100644 --- a/curs_main.c +++ b/curs_main.c @@ -435,8 +435,7 @@ int mutt_index_menu (void) int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */ int attach_msg = option(OPTATTACHMSG); - menu = mutt_new_menu (); - menu->menu = MENU_MAIN; + menu = mutt_new_menu (MENU_MAIN); menu->offset = 1; menu->pagelen = LINES - 3; menu->make_entry = index_make_entry; diff --git a/init.c b/init.c index 846a97f31..c4d08f9ac 100644 --- a/init.c +++ b/init.c @@ -2884,6 +2884,8 @@ void mutt_init (int skip_sys_rc, LIST *commands) Groups = hash_create (1031); ReverseAlias = hash_create (1031); + mutt_menu_init (); + /* * XXX - use something even more difficult to predict? */ diff --git a/menu.c b/menu.c index 26f3dcdff..bdf1efee8 100644 --- a/menu.c +++ b/menu.c @@ -32,6 +32,8 @@ extern int Charset_is_utf8; /* FIXME: bad modularisation */ extern size_t UngetCount; +char* SearchBuffers[MENU_MAX]; + static void print_enriched_string (int attr, unsigned char *s, int do_color) { wchar_t wc; @@ -673,10 +675,19 @@ static int menu_search_generic (MUTTMENU *m, regex_t *re, int n) return (regexec (re, buf, 0, NULL, 0)); } -MUTTMENU *mutt_new_menu (void) +void mutt_menu_init (void) +{ + int i; + + for (i = 0; i < MENU_MAX; i++) + SearchBuffers[i] = NULL; +} + +MUTTMENU *mutt_new_menu (int menu) { MUTTMENU *p = (MUTTMENU *) safe_calloc (1, sizeof (MUTTMENU)); + p->menu = menu; p->current = 0; p->top = 0; p->offset = 1; @@ -691,9 +702,7 @@ void mutt_menuDestroy (MUTTMENU **p) { int i; - FREE (&(*p)->searchBuf); - - if ((*p)->dialog) + if ((*p)->dialog) { for (i=0; i < (*p)->max; i++) FREE (&(*p)->dialog[i]); @@ -713,20 +722,26 @@ static int menu_search (MUTTMENU *menu, int op) int searchDir; regex_t re; char buf[SHORT_STRING]; + char* searchBuf = menu->menu >= 0 && menu->menu < MENU_MAX ? + SearchBuffers[menu->menu] : NULL; if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) { - strfcpy (buf, menu->searchBuf ? menu->searchBuf : "", sizeof (buf)); + strfcpy (buf, searchBuf ? searchBuf : "", sizeof (buf)); if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") : _("Reverse search for: "), buf, sizeof (buf), M_CLEAR) != 0 || !buf[0]) return (-1); - mutt_str_replace (&menu->searchBuf, buf); + if (menu->menu >= 0 && menu->menu < MENU_MAX) + { + mutt_str_replace (&SearchBuffers[menu->menu], buf); + searchBuf = SearchBuffers[menu->menu]; + } menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP; } else { - if (!menu->searchBuf) + if (!searchBuf || !*searchBuf) { mutt_error _("No search pattern."); return (-1); @@ -737,7 +752,7 @@ static int menu_search (MUTTMENU *menu, int op) if (op == OP_SEARCH_OPPOSITE) searchDir = -searchDir; - if ((r = REGCOMP (&re, menu->searchBuf, REG_NOSUB | mutt_which_case (menu->searchBuf))) != 0) + if ((r = REGCOMP (&re, searchBuf, REG_NOSUB | mutt_which_case (searchBuf))) != 0) { regerror (r, &re, buf, sizeof (buf)); regfree (&re); diff --git a/mutt_menu.h b/mutt_menu.h index 49500bd22..6ca70d79e 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -75,11 +75,11 @@ typedef struct menu_t /* the following are used only by mutt_menuLoop() */ int top; /* entry that is the top of the current page */ int oldcurrent; /* for driver use only. */ - char *searchBuf; /* last search pattern */ int searchDir; /* direction of search */ int tagged; /* number of tagged entries */ } MUTTMENU; +void mutt_menu_init (void); void menu_jump (MUTTMENU *); void menu_redraw_full (MUTTMENU *); void menu_redraw_index (MUTTMENU *); @@ -104,7 +104,7 @@ void menu_current_bottom (MUTTMENU *); void menu_check_recenter (MUTTMENU *); void menu_status_line (char *, size_t, MUTTMENU *, const char *); -MUTTMENU *mutt_new_menu (void); +MUTTMENU *mutt_new_menu (int); void mutt_menuDestroy (MUTTMENU **); int mutt_menuLoop (MUTTMENU *); diff --git a/mutt_ssl.c b/mutt_ssl.c index c753c5414..58d88ef33 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -761,7 +761,7 @@ static int ssl_check_certificate (CONNECTION *conn, sslsockdata * data) } /* interactive check from user */ - menu = mutt_new_menu (); + menu = mutt_new_menu (-1); menu->max = 19; menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *)); for (i = 0; i < menu->max; i++) diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index c8ca75dc4..6562ce5a0 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -700,7 +700,7 @@ static int tls_check_certificate (CONNECTION* conn) /* interactive check from user */ - menu = mutt_new_menu (); + menu = mutt_new_menu (-1); menu->max = 25; menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *)); for (i = 0; i < menu->max; i++) diff --git a/pager.c b/pager.c index 74238baaf..f7992c8eb 100644 --- a/pager.c +++ b/pager.c @@ -1652,8 +1652,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) { /* only allocate the space if/when we need the index. Initialise the menu as per the main index */ - index = mutt_new_menu(); - index->menu = MENU_MAIN; + index = mutt_new_menu(MENU_MAIN); index->make_entry = index_make_entry; index->color = index_color; index->max = Context->vcount; diff --git a/pgpkey.c b/pgpkey.c index 90e7c6e5c..6d0cc66d0 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -522,10 +522,9 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, mutt_make_help (buf, sizeof (buf), _("Help"), MENU_PGP, OP_HELP); strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ - menu = mutt_new_menu (); + menu = mutt_new_menu (MENU_PGP); menu->max = i; menu->make_entry = pgp_entry; - menu->menu = MENU_PGP; menu->help = helpstr; menu->data = KeyTable; diff --git a/postpone.c b/postpone.c index 2aa7e8cfc..1c40cb99b 100644 --- a/postpone.c +++ b/postpone.c @@ -160,9 +160,8 @@ static HEADER *select_msg (void) char helpstr[LONG_STRING]; short orig_sort; - menu = mutt_new_menu (); + menu = mutt_new_menu (MENU_POST); menu->make_entry = post_entry; - menu->menu = MENU_POST; menu->max = PostContext->msgcount; menu->title = _("Postponed Messages"); menu->data = PostContext; diff --git a/query.c b/query.c index ed0215ae1..0279778c8 100644 --- a/query.c +++ b/query.c @@ -301,11 +301,10 @@ static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf) snprintf (title, sizeof (title), _("Query")); /* FIXME */ - menu = mutt_new_menu (); + menu = mutt_new_menu (MENU_QUERY); menu->make_entry = query_entry; menu->search = query_search; menu->tag = query_tag; - menu->menu = MENU_QUERY; menu->title = title; menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_QUERY, QueryHelp); @@ -374,11 +373,10 @@ static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf) menu->current = 0; mutt_menuDestroy (&menu); - menu = mutt_new_menu (); + menu = mutt_new_menu (MENU_QUERY); menu->make_entry = query_entry; menu->search = query_search; menu->tag = query_tag; - menu->menu = MENU_QUERY; menu->title = title; menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_QUERY, QueryHelp); diff --git a/recvattach.c b/recvattach.c index c6afd06dd..d0fbe0c4c 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1005,8 +1005,7 @@ void mutt_view_attachments (HEADER *hdr) cur = hdr->content; } - menu = mutt_new_menu (); - menu->menu = MENU_ATTACH; + menu = mutt_new_menu (MENU_ATTACH); menu->title = _("Attachments"); menu->make_entry = attach_entry; menu->tag = mutt_tag_attach; diff --git a/remailer.c b/remailer.c index b732499fc..7f076ea4c 100644 --- a/remailer.c +++ b/remailer.c @@ -535,8 +535,7 @@ void mix_make_chain (LIST **chainp, int *redraw) mix_screen_coordinates (type2_list, &coords, chain, 0); - menu = mutt_new_menu (); - menu->menu = MENU_MIX; + menu = mutt_new_menu (MENU_MIX); menu->max = ttll; menu->make_entry = mix_entry; menu->tag = NULL; diff --git a/smime.c b/smime.c index 31a0ccab8..8d629b180 100644 --- a/smime.c +++ b/smime.c @@ -438,10 +438,9 @@ char* smime_ask_for_key (char *prompt, char *mailbox, short public) strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ /* Create the menu */ - menu = mutt_new_menu(); + menu = mutt_new_menu(MENU_SMIME); menu->max = cur; menu->make_entry = smime_entry; - menu->menu = MENU_SMIME; menu->help = helpstr; menu->data = Table; menu->title = title;