void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
{
- ALIAS *aliasp, *aliasl;
+ ALIAS *aliasp;
MUTTMENU *menu;
ALIAS **AliasTable = NULL;
int t = -1;
int op;
char helpstr[SHORT_STRING];
+ int omax;
+
if (!aliases)
{
mutt_error _("You have no aliases!");
return;
}
-
+
/* tell whoever called me to redraw the screen when I return */
set_option (OPTNEEDREDRAW);
-
- /* tell mutt_alias and mutt_unalias that this menu is active */
- set_option (OPTALIASMENU);
menu = mutt_new_menu ();
menu->make_entry = alias_entry;
menu->title = _("Aliases");
menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ALIAS, AliasHelp);
+new_aliases:
+
+ omax = menu->max;
+
/* count the number of aliases */
for (aliasp = aliases; aliasp; aliasp = aliasp->next)
{
- aliasp->del = 0;
- aliasp->tagged = 0;
+ aliasp->self->del = 0;
+ aliasp->self->tagged = 0;
menu->max++;
}
- menu->data = AliasTable = (ALIAS **) safe_calloc (menu->max, sizeof (ALIAS *));
+ safe_realloc ((void **) &AliasTable, menu->max * sizeof (ALIAS *));
+ menu->data = AliasTable;
- for (i = 0, aliasp = aliases; aliasp; aliasp = aliasp->next, i++)
- AliasTable[i] = aliasp;
+ for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++)
+ {
+ AliasTable[i] = aliasp->self;
+ aliases = aliasp;
+ }
if ((SortAlias & SORT_MASK) != SORT_ORDER)
{
while (!done)
{
+ if (aliases->next)
+ {
+ menu->redraw |= REDRAW_FULL;
+ aliases = aliases->next;
+ goto new_aliases;
+ }
+
switch ((op = mutt_menuLoop (menu)))
{
case OP_DELETE:
}
else
{
- AliasTable[menu->current]->del = (op == OP_DELETE) ? 1 : 0;
+ AliasTable[menu->current]->self->del = (op == OP_DELETE) ? 1 : 0;
menu->redraw |= REDRAW_CURRENT;
if (option (OPTRESOLVE) && menu->current < menu->max - 1)
{
mutt_menuDestroy (&menu);
safe_free ((void **) &AliasTable);
- unset_option (OPTALIASMENU);
-
- /* remove aliases marked for deletion. */
- aliasl = NULL;
- for (aliasp = Aliases; aliasp; aliasp = aliasp->next)
- {
- if (aliasp->del)
- {
- if (aliasl)
- aliasl->next = aliasp->next;
- else
- Aliases = aliasp->next;
-
- aliasp->next = NULL;
- mutt_free_alias (&aliasp);
-
- if (aliasl)
- aliasp = aliasl;
- else
- aliasp = Aliases;
- }
- else
- aliasl = aliasp;
- }
-
}
return;
}
- new = safe_calloc (1, sizeof (ALIAS));
+ new = safe_calloc (1, sizeof (ALIAS));
+ new->self = new;
new->name = safe_strdup (buf);
if (adr)
}
/* build alias list and show it */
+
a = Aliases;
while (a)
{
safe_free ((void **) &a_cur);
}
+ /* remove any aliases marked for deletion */
+ a_list = NULL;
+ for (a_cur = Aliases; a_cur; a_cur = a_cur->next)
+ {
+ if (a_cur->del)
+ {
+ if (a_list)
+ a_list->next = a_cur->next;
+ else
+ Aliases = a_cur->next;
+
+ a_cur->next = NULL;
+ mutt_free_alias (&a_cur);
+
+ if (a_list)
+ a_cur = a_list;
+ else
+ a_cur = Aliases;
+ }
+ else
+ a_list = a_cur;
+ }
+
return 0;
}
{
if (mutt_strcasecmp (buf->data, tmp->name) == 0)
{
- if (option (OPTALIASMENU))
+ if (CurrentMenu == MENU_ALIAS)
{
tmp->del = 1;
set_option (OPTFORCEREDRAWINDEX);
{
/* create a new alias */
tmp = (ALIAS *) safe_calloc (1, sizeof (ALIAS));
+ tmp->self = tmp;
tmp->name = safe_malloc (len + 1);
memcpy (tmp->name, s->dptr, len);
tmp->name[len] = 0;
+ /* give the main addressbook code a chance */
+ if (CurrentMenu == MENU_ALIAS)
+ set_option (OPTMENUCALLER);
}
else
{
/* override the previous value */
rfc822_free_address (&tmp->addr);
- if (option (OPTALIASMENU))
+ if (CurrentMenu == MENU_ALIAS)
set_option (OPTFORCEREDRAWINDEX);
}
s->dptr = p;
FOREVER
{
+ if (option (OPTMENUCALLER))
+ {
+ unset_option (OPTMENUCALLER);
+ return OP_NULL;
+ }
+
+
mutt_curs_set (0);
#ifdef USE_IMAP
* functions while we are executing an
* external program.
*/
- OPTALIASMENU, /* (pseudo) alias menu active */
+ OPTMENUCALLER, /* (pseudo) tell menu to give caller a take */
#ifdef HAVE_PGP
OPTPGPCHECKTRUST, /* (pseudo) used by pgp_select_key () */
OPTDONTHANDLEPGPKEYS, /* (pseudo) used to extract PGP keys */
typedef struct alias
{
+ struct alias *self; /* XXX - ugly hack */
char *name;
ADDRESS *addr;
struct alias *next;
NONULL (table[num].data->other));
}
-static int query_tag (MUTTMENU *menu, int n)
+static int query_tag (MUTTMENU *menu, int n, int m)
{
- return ((((ENTRY *) menu->data)[n].tagged = !((ENTRY *) menu->data)[n].tagged) ? 1 : -1);
+ ENTRY *cur = &((ENTRY *) menu->data)[n];
+ int ot = cur->tagged;
+
+ cur->tagged = m >= 0 ? m : !cur->tagged;
+ return cur->tagged - ot;
}
int mutt_query_complete (char *buf, size_t buflen)