]> granicus.if.org Git - mutt/commitdiff
More addressbook fixes.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 11 Sep 2001 12:24:32 +0000 (12:24 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 11 Sep 2001 12:24:32 +0000 (12:24 +0000)
addrbook.c
alias.c
init.c
menu.c
mutt.h
query.c

index 7c738841e42255f5cc7abf4129093bfab319d664..f85c8d0673a7c348bc4a1b7bc117f7f53261b514 100644 (file)
@@ -117,7 +117,7 @@ static int alias_SortAddress (const void *a, const void *b)
 
 void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
 {
-  ALIAS *aliasp, *aliasl;
+  ALIAS *aliasp;
   MUTTMENU *menu;
   ALIAS **AliasTable = NULL;
   int t = -1;
@@ -125,17 +125,16 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
   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;
@@ -144,18 +143,26 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
   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)
   {
@@ -167,6 +174,13 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
 
   while (!done)
   {
+    if (aliases->next)
+    {
+      menu->redraw |= REDRAW_FULL;
+      aliases       = aliases->next;
+      goto new_aliases;
+    }
+    
     switch ((op = mutt_menuLoop (menu)))
     {
       case OP_DELETE:
@@ -180,7 +194,7 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
        }
         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)
          {
@@ -212,29 +226,4 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
   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;
-  }
-
 }
diff --git a/alias.c b/alias.c
index e6124f9e1bf00a6d9522ed21a92e4c0926ce1afa..96eb80f45ae502a4c4924acb76538689b0c584d5 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -241,7 +241,8 @@ void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr)
     return;
   }
 
-  new = safe_calloc (1, sizeof (ALIAS));
+  new       = safe_calloc (1, sizeof (ALIAS));
+  new->self = new;
   new->name = safe_strdup (buf);
 
   if (adr)
@@ -381,6 +382,7 @@ int mutt_alias_complete (char *s, size_t buflen)
       }
 
       /* build alias list and show it */
+
       a = Aliases;
       while (a)
       {
@@ -414,6 +416,29 @@ int mutt_alias_complete (char *s, size_t buflen)
     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;
 }
 
diff --git a/init.c b/init.c
index 46c4c51390257b17782ef46da3729146381a1bcf..dd1f3d60f441d5228e80843e6ffc76915ebfd4b3 100644 (file)
--- a/init.c
+++ b/init.c
@@ -432,7 +432,7 @@ static int parse_unalias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *er
     {
       if (mutt_strcasecmp (buf->data, tmp->name) == 0)
       {
-       if (option (OPTALIASMENU))
+       if (CurrentMenu == MENU_ALIAS)
        {
          tmp->del = 1;
          set_option (OPTFORCEREDRAWINDEX);
@@ -481,15 +481,19 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
   {
     /* 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;
diff --git a/menu.c b/menu.c
index b0d9762c705f68d10e57328609e794f3f3269ccf..bccf2c285c688d6581784f07028264c79b491717 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -794,6 +794,13 @@ int mutt_menuLoop (MUTTMENU *menu)
 
   FOREVER
   {
+    if (option (OPTMENUCALLER))
+    {
+      unset_option (OPTMENUCALLER);
+      return OP_NULL;
+    }
+    
+    
     mutt_curs_set (0);
 
 #ifdef USE_IMAP
diff --git a/mutt.h b/mutt.h
index acb179cdef2bdb35be5f725ef309f01c477da6aa..1fceba1455a0eb41b117bbe1e42a1c4192d86c4f 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -442,7 +442,7 @@ enum
                         *          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 */
@@ -486,6 +486,7 @@ void mutt_init (int, LIST *);
 
 typedef struct alias
 {
+  struct alias *self;          /* XXX - ugly hack */
   char *name;
   ADDRESS *addr;
   struct alias *next;
diff --git a/query.c b/query.c
index 93cea1ad4fe7d2caa72e9d2a8d209141318a2953..05be9841bfb0e4a3940af98f54431ef06e8e704c 100644 (file)
--- a/query.c
+++ b/query.c
@@ -207,9 +207,13 @@ static void query_entry (char *s, size_t slen, MUTTMENU *m, int num)
            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)