From 23e421e7262fd5f7be2a68648234cf44eea1e289 Mon Sep 17 00:00:00 2001 From: Eduardo Chappa Date: Sun, 20 Sep 2015 19:20:54 -0600 Subject: [PATCH] * When saving an attachment, the ^Y and ^V commands allow a user to scroll through the history of directories used to save attachments, while preserving the given name of the file. Suggested by Peter Koellner. --- alpine/mailcmd.c | 76 ++++++++++++++++++++++++++++++++++++++++++-------------- pith/hist.c | 1 - pith/hist.h | 2 +- pith/pine.hlp | 7 +++++- 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/alpine/mailcmd.c b/alpine/mailcmd.c index f8ae770..f066c89 100644 --- a/alpine/mailcmd.c +++ b/alpine/mailcmd.c @@ -4168,6 +4168,7 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, char def[500]; ESCKEY_S *opts = NULL; struct variable *vars = ps->vars; + static HISTORY_S *dir_hist = NULL; if(flags & GE_ALLPARTS || history){ /* @@ -4177,7 +4178,7 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, ; if(history) - i += 2; + i += 4; if(flags & GE_ALLPARTS) i++; @@ -4223,12 +4224,24 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, opts[i].rval = 31; opts[i].name = ""; opts[i++].label = ""; + + opts[i].ch = ctrl('Y'); + opts[i].rval = 32; + opts[i].name = ""; + opts[i++].label = ""; + + opts[i].ch = ctrl('V'); + opts[i].rval = 33; + opts[i].name = ""; + opts[i++].label = ""; } opts[i].ch = -1; - if(history) + if(history){ init_hist(history, HISTSIZE); + init_hist(&dir_hist, HISTSIZE); + } } else opts = optsarg; @@ -4385,6 +4398,18 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, opts[ku].label = HISTORY_KEYLABEL; opts[ku+1].name = HISTORY_DOWN_KEYNAME; opts[ku+1].label = HISTORY_KEYLABEL; + if(items_in_hist(dir_hist) > 0){ /* any directories */ + opts[ku+2].name = "^Y"; + opts[ku+2].label = "Prev Dir"; + opts[ku+3].name = "^V"; + opts[ku+3].label = "Next Dir"; + } + else{ + opts[ku+2].name = ""; + opts[ku+2].label = ""; + opts[ku+3].name = ""; + opts[ku+3].label = ""; + } } else{ opts[ku].name = ""; @@ -4399,6 +4424,7 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, r = optionally_enter(filename, qline, 0, len, prompt_buf, opts, NO_HELP, &oeflags); + dprint((2, "\n - export_filename = \"%s\", r = %d -\n", filename, r)); /*--- Help ----*/ if(r == 3){ /* @@ -4671,33 +4697,41 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, else if(r == 4){ continue; } - else if(r == 30 || r == 31){ + else if(r >= 30 && r <= 33){ char *p = NULL; if(history){ - if(r == 30) - p = get_prev_hist(*history, filename, 0, NULL); - else - p = get_next_hist(*history, filename, 0, NULL); + switch(r){ + case 30: p = get_prev_hist(*history, filename, 0, NULL); break; + case 31: p = get_next_hist(*history, filename, 0, NULL); break; + case 32: p = get_prev_hist(dir_hist, NULL, 0, NULL); break; + case 33: p = get_next_hist(dir_hist, NULL, 0, NULL); break; + default: alpine_panic("Impossible case in save attachment"); break; + } } - if(p != NULL && (fn = last_cmpnt(p)) != NULL){ - strncpy(dir, p, MIN(fn - p, sizeof(dir)-1)); - dir[MIN(fn - p, sizeof(dir)-1)] = '\0'; - if(fn - p > 1) - dir[fn - p - 1] = '\0'; - + if(p != NULL && *p != '\0'){ + if(r == 30 || r == 31){ + if((fn = last_cmpnt(p)) != NULL){ + strncpy(dir, p, MIN(fn - p, sizeof(dir)-1)); + dir[MIN(fn - p, sizeof(dir)-1)] = '\0'; + if(fn - p > 1) + dir[fn - p - 1] = '\0'; + strncpy(filename, fn, len-1); + filename[len-1] = '\0'; + } + } else { /* r == 32 || r == 33 */ + strncpy(dir, p, sizeof(dir)-1); + dir[sizeof(dir)-1] = '\0'; + } + if(!strcmp(dir, ps->home_dir)){ dir[0] = '~'; dir[1] = '\0'; } - - strncpy(filename, fn, len-1); - filename[len-1] = '\0'; } else Writechar(BELL, 0); - continue; } else if(r != 0){ @@ -4848,8 +4882,14 @@ get_export_filename(struct pine *ps, char *filename, char *deefault, } done: - if(history && ret == 0) + if(history && ret == 0){ save_hist(*history, full_filename, 0, NULL); + strncpy(tmp, full_filename, MAXPATH); + tmp[MAXPATH] = '\0'; + if((fn = strrchr(tmp, C_FILESEP)) != NULL) + *fn = '\0'; + save_hist(dir_hist, tmp, 0, NULL); + } if(opts && opts != optsarg) fs_give((void **) &opts); diff --git a/pith/hist.c b/pith/hist.c index 77a4b01..b980848 100644 --- a/pith/hist.c +++ b/pith/hist.c @@ -49,7 +49,6 @@ free_hist(HISTORY_S **history) int i; if(history && *history){ - for(i = 0; i < (*history)->histsize; i++) if((*history)->hist[i] && (*history)->hist[i]->str) fs_give((void **) &(*history)->hist[i]->str); diff --git a/pith/hist.h b/pith/hist.h index 504b8ad..f5a7165 100644 --- a/pith/hist.h +++ b/pith/hist.h @@ -39,7 +39,6 @@ typedef struct history_s { #define HISTORY_DOWN_KEYNAME "Down" #define HISTORY_KEYLABEL N_("History") - void init_hist(HISTORY_S **, int); void free_hist(HISTORY_S **); char *get_prev_hist(HISTORY_S *, char *, unsigned, void *); @@ -48,6 +47,7 @@ void save_hist(HISTORY_S *, char *, unsigned, void *); int items_in_hist(HISTORY_S *); void add_to_histlist(HISTORY_S **); void free_histlist(void); +int dirs_in_hist(HISTORY_S *); #endif /* PITH_HIST_INCLUDED */ diff --git a/pith/pine.hlp b/pith/pine.hlp index 5d34e65..79de8e6 100644 --- a/pith/pine.hlp +++ b/pith/pine.hlp @@ -140,7 +140,7 @@ with help text for the config screen and the composer that didn't have any reasonable place to be called from. Dummy change to get revision in pine.hlp ============= h_revision ================= -Alpine Commit 104 2015-09-19 12:51:36 +Alpine Commit 105 2015-09-20 19:20:48 ============= h_news ================= @@ -275,6 +275,11 @@ Additions include: "A" command can be used to add a file. A directory can be added by pressing "^X" after the "A" command. Added after a suggestion by Stefan Goessling. + +
  • When saving an attachment, the ^Y and ^V commands allow a user to + scroll through the history of directories used to save attachments, + while preserving the given name of the file. Suggested by Peter + Koellner. -- 2.11.4.GIT