]> granicus.if.org Git - neomutt/commitdiff
Enable tagging in the file browser.
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 22 Jan 1999 18:02:47 +0000 (18:02 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 22 Jan 1999 18:02:47 +0000 (18:02 +0000)
addrbook.c
browser.c
compose.c
curs_lib.c
enter.c
menu.c
protos.h
query.c
recvattach.c

index a24024b547c2dc339b90e47c92d1eafc56910396..ea25fdbb38e2277e41251a2f93e82d08924c7752 100644 (file)
@@ -85,7 +85,7 @@ void alias_entry (char *s, size_t slen, MUTTMENU *m, int num)
 
 int alias_tag (MUTTMENU *menu, int n)
 {
-  return (((ALIAS **) menu->data)[n]->tagged = !((ALIAS **) menu->data)[n]->tagged);
+  return ((((ALIAS **) menu->data)[n]->tagged = !((ALIAS **) menu->data)[n]->tagged) ? 1 : -1);
 }
 
 static int alias_SortAlias (const void *a, const void *b)
index 2420b0dd5e6de6902a2acffec0db1aa054cf9ef9..ae4a29d9b8bd9450346e0383a709cb5636306771 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -40,6 +40,7 @@ struct folder_file
   off_t size;
   char *name;
   char *desc;
+  short tagged;
 };
 
 struct browser_state
@@ -320,6 +321,7 @@ static void init_state (struct browser_state *state, MUTTMENU *menu)
   state->entrylen = 0;
   state->entrymax = 256;
   state->entry = (struct folder_file *) safe_malloc (sizeof (struct folder_file) * state->entrymax);
+  memset (state->entry, 0, sizeof (struct folder_file) * state->entrymax);
   if (menu)
     menu->data = state->entry;
 }
@@ -428,7 +430,10 @@ int select_file_search (MUTTMENU *menu, regex_t *re, int n)
 
 void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
 {
-  snprintf (s, slen, "%2d %s", num + 1, ((struct folder_file *) menu->data)[num].desc);
+  snprintf (s, slen, "%2d %c %s", 
+           num + 1, 
+           ((struct folder_file *) menu->data)[num].tagged ? '*' : ' ',
+           ((struct folder_file *) menu->data)[num].desc);
 }
 
 static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
@@ -457,7 +462,20 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
   menu->redraw = REDRAW_FULL;
 }
 
-void mutt_select_file (char *f, size_t flen, int buffy)
+int file_tag (MUTTMENU *menu, int n)
+{
+  struct folder_file *ff = &(((struct folder_file *)menu->data)[n]);
+  if (S_ISDIR (ff->mode) || (S_ISLNK (ff->mode) && link_is_dir (ff->name)))
+  {
+    mutt_error _("Can't attach a directory!");
+    return 0;
+  }
+  
+  return ((ff->tagged = !ff->tagged) ? 1 : -1);
+}
+
+void _mutt_select_file (char *f, size_t flen, int buffy,
+                      int multiple, char ***files, int *numfiles)
 {
   char buf[_POSIX_PATH_MAX];
   char prefix[_POSIX_PATH_MAX] = "";
@@ -522,6 +540,8 @@ void mutt_select_file (char *f, size_t flen, int buffy)
   menu->search = select_file_search;
   menu->title = title;
   menu->data = state.entry;
+  if (multiple)
+    menu->tag = file_tag;
 
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER, FolderHelp);
 
@@ -624,6 +644,38 @@ void mutt_select_file (char *f, size_t flen, int buffy)
 
       case OP_EXIT:
 
+       if (multiple)
+       {
+         char **tfiles;
+         int i, j;
+
+         if (menu->tagged)
+         {
+           *numfiles = menu->tagged;
+           tfiles = safe_malloc (*numfiles * sizeof (char *));
+           for (i = 0, j = 0; i < state.entrylen; i++)
+           {
+             struct folder_file ff = state.entry[i];
+             char full[_POSIX_PATH_MAX];
+             if (ff.tagged)
+             {
+               snprintf (full, sizeof (full), "%s/%s", LastDir, ff.name);
+               mutt_expand_path (full, sizeof (full));
+               tfiles[j++] = safe_strdup (full);
+             }
+           }
+           *files = tfiles;
+         }
+         else if (f[0]) /* no tagged entries. return selected entry */
+         {
+           *numfiles = 1;
+           tfiles = safe_malloc (*numfiles * sizeof (char *));
+           mutt_expand_path (f, flen);
+           tfiles[0] = safe_strdup (f);
+           *files = tfiles;
+         }
+       }
+
        destroy_state (&state);
        mutt_menuDestroy (&menu);
        return;
index caa192dca5c40b95fc17f26ce99bfb5ff77fc8f0..30993c1b2a1d551ccd15bea96019049d91dcc89d 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -413,6 +413,8 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
   /* Sort, SortAux could be changed in mutt_index_menu() */
   int oldSort = Sort, oldSortAux = SortAux;
   struct stat st;
+  char **files;
+  int numfiles;
 
   idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
 
@@ -569,6 +571,10 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          {
            prompt = _("Attach file");
            flag = 0;
+           numfiles = 0;
+           files = NULL;
+           if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag, 1, &files, &numfiles) == -1)
+             break;
          }
          else
          {
@@ -579,21 +585,16 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
              mutt_pretty_mailbox (fname);
            }
            flag = 1;
+           if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag) == -1 || !fname[0])
+             break;
+           mutt_expand_path (fname, sizeof (fname));
+           /* check to make sure the file exists and is readable */
+           if (access (fname, R_OK) == -1)
+           {
+             mutt_perror (fname);
+             break;
+           }
          }
-
-         if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag) == -1)
-           break;
-       }
-
-       if (!fname[0])
-         continue;
-       mutt_expand_path (fname, sizeof (fname));
-
-       /* check to make sure the file exists and is readable */
-       if (access (fname, R_OK) == -1)
-       {
-         mutt_perror (fname);
-         break;
        }
 
        if (op == OP_COMPOSE_ATTACH_MESSAGE)
@@ -638,6 +639,8 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
 
          if (op == OP_COMPOSE_ATTACH_MESSAGE)
            numtag = Context->tagged;
+         else
+           numtag = numfiles;
          if (idxlen + numtag >= idxmax)
          {
            safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numtag));
@@ -647,17 +650,27 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
 
        if (op == OP_COMPOSE_ATTACH_FILE)
        {
-         idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
-         idx[idxlen]->content = mutt_make_file_attach (fname);
-         if (idx[idxlen]->content != NULL)
-           update_idx (menu, idx, idxlen++);
-         else
+         int error = 0;
+         mutt_message _("Attaching selected files...");
+         for (i = 0; i < numfiles; i++)
          {
-           mutt_error _("Unable to attach!");
-           safe_free ((void **) &idx[idxlen]);
+           char *att = files[i];
+           idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
+           idx[idxlen]->content = mutt_make_file_attach (att);
+           if (idx[idxlen]->content != NULL)
+             update_idx (menu, idx, idxlen++);
+           else
+           {
+             error = 1;
+             mutt_error (_("Unable to attach %s!"), att);
+             safe_free ((void **) &idx[idxlen]);
+           }
+           FREE (&this);
          }
+         FREE (&files);
+         if (!error)
+           mutt_clear_error ();
          menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
-         break;
         }
        else
        {
@@ -679,19 +692,20 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
            }
          }
          menu->redraw |= REDRAW_FULL;
+
+         if (close == OP_QUIT) 
+           mx_close_mailbox (Context);
+         else
+           mx_fastclose_mailbox (Context);
+         safe_free ((void **) &Context);
+
+         /* go back to the folder we started from */
+         Context = this;
+         /* Restore old $sort and $sort_aux */
+         Sort = oldSort;
+         SortAux = oldSortAux;
        }
 
-       if (close == OP_QUIT) 
-         mx_close_mailbox (Context);
-       else
-         mx_fastclose_mailbox (Context);
-       safe_free ((void **) &Context);
-       
-       /* go back to the folder we started from */
-       Context = this;
-       /* Restore old $sort and $sort_aux */
-       Sort = oldSort;
-       SortAux = oldSortAux;
        break;
 
       case OP_DELETE:
index de10a9863b4d6ab9554af40cf729d0ab9fab8edc..0d47e4c8ddaa0b0bf8ebd3ffa62aed5e31844a49 100644 (file)
@@ -83,7 +83,7 @@ event_t mutt_getch (void)
   return (ch == ctrl ('G') ? err : ret);
 }
 
-int mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete)
+int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles)
 {
   int ret;
   int len = mutt_strlen (field); /* in case field==buffer */
@@ -93,7 +93,7 @@ int mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int compl
     CLEARLINE (LINES-1);
     addstr (field);
     mutt_refresh ();
-    ret = mutt_enter_string ((unsigned char *) buf, buflen, LINES-1, len, complete);
+    ret = _mutt_enter_string ((unsigned char *) buf, buflen, LINES-1, len, complete, multiple, files, numfiles);
   }
   while (ret == 1);
   CLEARLINE (LINES-1);
@@ -325,7 +325,7 @@ int mutt_do_pager (const char *banner,
   return rc;
 }
 
-int mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy)
+int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy, int multiple, char ***files, int *numfiles)
 {
   event_t ch;
 
@@ -346,7 +346,7 @@ int mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, i
   {
     mutt_refresh ();
     buf[0] = 0;
-    mutt_select_file (buf, blen, 0);
+    _mutt_select_file (buf, blen, 0, multiple, files, numfiles);
     *redraw = REDRAW_FULL;
   }
   else
@@ -355,7 +355,7 @@ int mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, i
 
     sprintf (pc, "%s: ", prompt);
     mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
-    if (mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR)
+    if (_mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files, numfiles)
        != 0)
       buf[0] = 0;
     MAYBE_REDRAW (*redraw);
diff --git a/enter.c b/enter.c
index 2905a56c5bf188b3fbe0a56224b959a9527fc95c..a0ec76a82a0569319b2ecff349d3eb28cd730c69 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -50,8 +50,8 @@ enum
  *     -1 if abort.
  *
  */
-int mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
-                      int flags)
+int _mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
+                      int flags, int multiple, char ***files, int *numfiles)
 {
   event_t event;
   int curpos = 0;              /* the location of the cursor */
@@ -374,7 +374,7 @@ int mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
            /* see if the path has changed from the last time */
            if (mutt_strcmp (tempbuf, (char *) buf) == 0)
            {
-             mutt_select_file ((char *) buf, buflen, 0);
+             _mutt_select_file ((char *) buf, buflen, 0, multiple, files, numfiles);
              set_option (OPTNEEDREDRAW);
              if (buf[0])
              {
diff --git a/menu.c b/menu.c
index f8cb792a8f5190ad20b1bd57c5f66a189286b869..afe8367d3c0af3148d48a5c436be932449a8f58a 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -796,11 +796,9 @@ int mutt_menuLoop (MUTTMENU *menu)
        {
          if (menu->max)
          {
-           if (menu->tag (menu, menu->current))
-             menu->tagged++;
-           else
-             menu->tagged--;
-           if (option (OPTRESOLVE) && menu->current < menu->max - 1)
+           short i = menu->tag (menu, menu->current);
+           menu->tagged += i;
+           if (i && option (OPTRESOLVE) && menu->current < menu->max - 1)
            {
              menu->current++;
              menu->redraw = REDRAW_MOTION_RESYNCH;
index a5d18c6645bd5492ec68baadf09f3517a1928e5a..0db65934b3a09663856ae8d4e8f5bf47460344f8 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -184,7 +184,8 @@ void mutt_sanitize_filename (char *);
 void mutt_save_path (char *s, size_t l, ADDRESS *a);
 void mutt_score_message (HEADER *);
 void mutt_select_fcc (char *, size_t, HEADER *);
-void mutt_select_file (char *, size_t, int);
+#define mutt_select_file(A,B,C) _mutt_select_file(A,B,C,0,NULL,NULL)
+void _mutt_select_file (char *, size_t, int, int, char ***, int *);
 void mutt_send_hook (HEADER *);
 void mutt_set_flag (CONTEXT *, HEADER *, int, int);
 void mutt_set_followup_to (ENVELOPE *);
@@ -228,9 +229,12 @@ int mutt_decode_save_attachment (FILE *, BODY *, char *, int, int);
 int mutt_display_message (HEADER *h);
 int mutt_edit_attachment(BODY *);
 int mutt_prepare_edit_message(CONTEXT *, HEADER *, HEADER *);
-int mutt_enter_fname (const char *, char *, size_t, int *, int);
-int mutt_enter_string (unsigned char *, size_t, int, int, int);
-int mutt_get_field (char *, char *, size_t, int);
+#define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
+int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char ***, int *);
+#define mutt_enter_string(A,B,C,D,E) _mutt_enter_string(A,B,C,D,E,0,NULL,NULL)
+int _mutt_enter_string (unsigned char *, size_t, int, int, int, int, char ***, int *);
+#define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)
+int _mutt_get_field (char *, char *, size_t, int, int, char ***, int *);
 int mutt_get_password (char *, char *, size_t);
 int mutt_get_postponed (CONTEXT *, HEADER *, HEADER **, char *, size_t);
 int mutt_get_tmp_attachment (BODY *);
diff --git a/query.c b/query.c
index 108d4ae330b55b94bcada0443bc98c3e37c062d1..84b90b5aad2548279f00b930f690edcf688a0b1f 100644 (file)
--- a/query.c
+++ b/query.c
@@ -180,7 +180,7 @@ static void query_entry (char *s, size_t slen, MUTTMENU *m, int num)
 
 static int query_tag (MUTTMENU *menu, int n)
 {
-  return (((ENTRY *) menu->data)[n].tagged = !((ENTRY *) menu->data)[n].tagged);
+  return ((((ENTRY *) menu->data)[n].tagged = !((ENTRY *) menu->data)[n].tagged) ? 1 : -1);
 }
 
 int mutt_query_complete (char *buf, size_t buflen)
index 21afe9161a90f5eef3cbe05a6779d8a40efbfec4..69f59078f30ed679f7bccc6cd766b0576cea22b2 100644 (file)
@@ -313,7 +313,7 @@ void attach_entry (char *b, size_t blen, MUTTMENU *menu, int num)
 
 int mutt_tag_attach (MUTTMENU *menu, int n)
 {
-  return (((ATTACHPTR **) menu->data)[n]->content->tagged = !((ATTACHPTR **) menu->data)[n]->content->tagged);
+  return ((((ATTACHPTR **) menu->data)[n]->content->tagged = !((ATTACHPTR **) menu->data)[n]->content->tagged) ? 1 : -1);
 }
 
 int mutt_is_message_type (int type, const char *subtype)