/*
- * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 1996-2000,2002 Michael R. Elkins <me@mutt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "mutt_menu.h"
#include "mbyte.h"
-#ifdef USE_IMAP
-#include "imap.h"
-#endif
-
#include <string.h>
#include <stdlib.h>
extern size_t UngetCount;
+char* SearchBuffers[MENU_MAX];
+
static void print_enriched_string (int attr, unsigned char *s, int do_color)
{
wchar_t wc;
menu->make_entry (s, l, menu, i);
}
-void menu_pad_string (char *s, size_t n)
+static void menu_pad_string (char *s, size_t n)
{
char *scratch = safe_strdup (s);
int shift = option (OPTARROWCURSOR) ? 3 : 0;
menu->redraw &= REDRAW_STATUS;
}
-void menu_redraw_prompt (MUTTMENU *menu)
+static void menu_redraw_prompt (MUTTMENU *menu)
{
if (menu->dialog)
{
buf[0] = 0;
if (mutt_get_field (_("Jump to: "), buf, sizeof (buf), 0) == 0 && buf[0])
{
- n = atoi (buf) - 1;
- if (n >= 0 && n < menu->max)
+ if (mutt_atoi (buf, &n) == 0 && n > 0 && n < menu->max + 1)
{
+ n--; /* msg numbers are 0-based */
menu->current = n;
menu->redraw = REDRAW_MOTION;
}
* halfdown: jumplen == pagelen/2
*/
#define DIRECTION ((neg * 2) + 1)
-void menu_length_jump (MUTTMENU *menu, int jumplen)
+static void menu_length_jump (MUTTMENU *menu, int jumplen)
{
int tmp, neg = (jumplen >= 0) ? 0 : -1;
int c = MIN (MenuContext, menu->pagelen / 2);
mutt_error _("No entries.");
}
-void menu_next_entry (MUTTMENU *menu)
+static void menu_next_entry (MUTTMENU *menu)
{
if (menu->current < menu->max - 1)
{
mutt_error _("You are on the last entry.");
}
-void menu_prev_entry (MUTTMENU *menu)
+static void menu_prev_entry (MUTTMENU *menu)
{
if (menu->current)
{
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;
{
int i;
- FREE (&(*p)->searchBuf);
-
- if ((*p)->dialog)
+ if ((*p)->dialog)
{
for (i=0; i < (*p)->max; i++)
FREE (&(*p)->dialog[i]);
static int menu_search (MUTTMENU *menu, int op)
{
- int r;
+ int r, wrap = 0;
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)
+ if (!(searchBuf && *searchBuf) ||
+ (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE))
{
- strfcpy (buf, menu->searchBuf ? menu->searchBuf : "", sizeof (buf));
- if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") :
- _("Reverse search for: "),
- buf, sizeof (buf), M_CLEAR) != 0 || !buf[0])
+ strfcpy (buf, searchBuf && *searchBuf ? searchBuf : "", sizeof (buf));
+ if (mutt_get_field ((op == OP_SEARCH || op == OP_SEARCH_NEXT)
+ ? _("Search for: ") : _("Reverse search for: "),
+ buf, sizeof (buf), M_CLEAR) != 0 || !buf[0])
return (-1);
- mutt_str_replace (&menu->searchBuf, buf);
- menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP;
- }
- else
- {
- if (!menu->searchBuf)
+ if (menu->menu >= 0 && menu->menu < MENU_MAX)
{
- mutt_error _("No search pattern.");
- return (-1);
+ mutt_str_replace (&SearchBuffers[menu->menu], buf);
+ searchBuf = SearchBuffers[menu->menu];
}
+ menu->searchDir = (op == OP_SEARCH || op == OP_SEARCH_NEXT) ?
+ M_SEARCH_DOWN : M_SEARCH_UP;
}
searchDir = (menu->searchDir == M_SEARCH_UP) ? -1 : 1;
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);
}
r = menu->current + searchDir;
+search_next:
+ if (wrap)
+ mutt_message (_("Search wrapped to top."));
while (r >= 0 && r < menu->max)
{
if (menu->search (menu, &re, r) == 0)
r += searchDir;
}
+ if (option (OPTWRAPSEARCH) && wrap++ == 0)
+ {
+ r = searchDir == 1 ? 0 : menu->max - 1;
+ goto search_next;
+ }
regfree (&re);
mutt_error _("Not found.");
return (-1);
ch = mutt_getch ();
- if (ch.ch == -1)
+ if (ch.ch < 0)
{
*ip = -1;
return 0;
mutt_curs_set (0);
-#ifdef USE_IMAP
- imap_keepalive ();
-#endif
-
if (menu_redraw (menu) == OP_REDRAW)
return OP_REDRAW;