Commit 30541be3 authored by Rocco Rutte's avatar Rocco Rutte

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.
parent a4eebaaf
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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?
*/
......
......@@ -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);
......
......@@ -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 *);
......
......@@ -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++)
......
......@@ -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++)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
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