From ab876591f02155a430e5cc4f2ce3e72228327561 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Fri, 22 Jan 1999 18:02:47 +0000 Subject: [PATCH] Enable tagging in the file browser. --- addrbook.c | 2 +- browser.c | 56 ++++++++++++++++++++++++++++++++++-- compose.c | 80 ++++++++++++++++++++++++++++++---------------------- curs_lib.c | 10 +++---- enter.c | 6 ++-- menu.c | 8 ++---- protos.h | 12 +++++--- query.c | 2 +- recvattach.c | 2 +- 9 files changed, 123 insertions(+), 55 deletions(-) diff --git a/addrbook.c b/addrbook.c index a24024b54..ea25fdbb3 100644 --- a/addrbook.c +++ b/addrbook.c @@ -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) diff --git a/browser.c b/browser.c index 2420b0dd5..ae4a29d9b 100644 --- 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; diff --git a/compose.c b/compose.c index caa192dca..30993c1b2 100644 --- 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: diff --git a/curs_lib.c b/curs_lib.c index de10a9863..0d47e4c8d 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -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 2905a56c5..a0ec76a82 100644 --- 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 f8cb792a8..afe8367d3 100644 --- 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; diff --git a/protos.h b/protos.h index a5d18c664..0db65934b 100644 --- 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 108d4ae33..84b90b5aa 100644 --- 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) diff --git a/recvattach.c b/recvattach.c index 21afe9161..69f59078f 100644 --- a/recvattach.c +++ b/recvattach.c @@ -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) -- 2.40.0