]> granicus.if.org Git - neomutt/commitdiff
Make browser behaviour more consistent with expectations.
authorThomas Roessler <roessler@does-not-exist.org>
Sun, 31 Dec 2000 11:24:18 +0000 (11:24 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sun, 31 Dec 2000 11:24:18 +0000 (11:24 +0000)
browser.c
curs_lib.c
enter.c
main.c
mutt.h
protos.h

index b4650e521c4800fbed612e215d392b13cfb8da60..2c61a8736444abce69566059e91e77e7c7a4736a 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -51,6 +51,7 @@ typedef struct folder_t
 } FOLDER;
 
 static char LastDir[_POSIX_PATH_MAX] = "";
+static char LastDirBackup[_POSIX_PATH_MAX] = "";
 
 /* Frees up the memory allocated for the local-global variables.  */
 static void destroy_state (struct browser_state *state)
@@ -518,8 +519,7 @@ int file_tag (MUTTMENU *menu, int n)
   return ((ff->tagged = !ff->tagged) ? 1 : -1);
 }
 
-void _mutt_select_file (char *f, size_t flen, int buffy,
-                      int multiple, char ***files, int *numfiles)
+void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *numfiles)
 {
   char buf[_POSIX_PATH_MAX];
   char prefix[_POSIX_PATH_MAX] = "";
@@ -529,9 +529,17 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
   MUTTMENU *menu;
   struct stat st;
   int i, killPrefix = 0;
+  int multiple = (flags & M_SEL_MULTI)  ? 1 : 0;
+  int folder   = (flags & M_SEL_FOLDER) ? 1 : 0;
+  int buffy    = (flags & M_SEL_BUFFY)  ? 1 : 0;
 
+  buffy = buffy && folder;
+  
   memset (&state, 0, sizeof (struct browser_state));
 
+  if (!folder)
+    strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup));
+
   if (*f)
   {
     mutt_expand_path (f, flen);
@@ -581,8 +589,11 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
   }
   else 
   {
-    if (!LastDir[0])
+    if (!folder)
+      getcwd (LastDir, sizeof (LastDir));
+    else if (!LastDir[0])
       strfcpy (LastDir, NONULL(Maildir), sizeof (LastDir));
+    
 #ifdef USE_IMAP
     if (!buffy && mx_is_imap (LastDir))
     {
@@ -598,14 +609,14 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
   if (buffy)
   {
     if (examine_mailboxes (NULL, &state) == -1)
-      return;
+      goto bail;
   }
   else
 #ifdef USE_IMAP
   if (!state.imap_browse)
 #endif
   if (examine_directory (NULL, &state, LastDir, prefix) == -1)
-    return;
+    goto bail;
 
   menu = mutt_new_menu ();
   menu->menu = MENU_FOLDER;
@@ -742,7 +753,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
              if (examine_directory (menu, &state, LastDir, prefix) == -1)
              {
                strfcpy (LastDir, NONULL(Homedir), sizeof (LastDir));
-               return;
+               goto bail;
              }
            }
            menu->current = 0; 
@@ -802,7 +813,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
 
        destroy_state (&state);
        mutt_menuDestroy (&menu);
-       return;
+       goto bail;
 
       case OP_BROWSER_TELL:
         if(state.entrylen)
@@ -936,7 +947,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
                mutt_error _("Error scanning directory.");
                destroy_state (&state);
                mutt_menuDestroy (&menu);
-               return;
+               goto bail;
              }
            }
            else
@@ -1002,7 +1013,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
            {
              mutt_error _("Error scanning directory.");
              mutt_menuDestroy (&menu);
-             return;
+             goto bail;
            }
            killPrefix = 0;
            if (!state.entrylen)
@@ -1068,7 +1079,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
        if (buffy)
        {
          if (examine_mailboxes (menu, &state) == -1)
-           return;
+           goto bail;
        }
 #ifdef USE_IMAP
        else if (mx_is_imap (LastDir))
@@ -1080,7 +1091,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
        }
 #endif
        else if (examine_directory (menu, &state, LastDir, prefix) == -1)
-         return;
+         goto bail;
        init_menu (&state, menu, title, sizeof (title), buffy);
        break;
 
@@ -1092,7 +1103,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
          strfcpy (f, buf, flen);
          destroy_state (&state);
          mutt_menuDestroy (&menu);
-         return;
+         goto bail;
        }
        MAYBE_REDRAW (menu->redraw);
        break;
@@ -1110,7 +1121,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
          strfcpy (f, state.entry[menu->current].name, flen);
          destroy_state (&state);
          mutt_menuDestroy (&menu);
-         return;
+         goto bail;
        }
        else
 #endif
@@ -1140,5 +1151,10 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
        }
     }
   }
-  /* not reached */
+  
+  bail:
+  
+  if (!folder)
+    strfcpy (LastDir, LastDirBackup, sizeof (LastDir));
+  
 }
index bf2924bbfdfa992291f20c1d952ebe00f5a02b7a..02c657292be028dffa8a22ea0937607f77a0cd88 100644 (file)
@@ -403,7 +403,8 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw,
   {
     mutt_refresh ();
     buf[0] = 0;
-    _mutt_select_file (buf, blen, 0, multiple, files, numfiles);
+    _mutt_select_file (buf, blen, M_SEL_FOLDER | (buffy ? M_SEL_BUFFY : 0) | (multiple ? M_SEL_MULTI : 0), 
+                      files, numfiles);
     *redraw = REDRAW_FULL;
   }
   else
diff --git a/enter.c b/enter.c
index 28ad6447ee6231723ec4d78ba2e8278ccbc7215c..6f17f3bc606d2ed12b9d25ef234982bb57683d9a 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
  * Copyright (C) 2000 Edmund Grimley Evans <edmundo@rano.org>
@@ -418,7 +419,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
            if (tempbuf && templen == state->lastchar - i &&
                !memcmp (tempbuf, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t)))
            {
-             mutt_select_file (buf, buflen, 0);
+             mutt_select_file (buf, buflen, (flags & M_EFILE) ? M_SEL_FOLDER : 0);
              set_option (OPTNEEDREDRAW);
              if (*buf)
                replace_part (state, i, buf);
@@ -471,7 +472,9 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
            if ((!tempbuf && !state->lastchar) || (tempbuf && templen == state->lastchar &&
                !memcmp (tempbuf, state->wbuf, state->lastchar * sizeof (wchar_t))))
            {
-             _mutt_select_file (buf, buflen, 0, multiple, files, numfiles);
+             _mutt_select_file (buf, buflen, 
+                                ((flags & M_EFILE) ? M_SEL_FOLDER : 0) | (multiple ? M_SEL_MULTI : 0), 
+                                files, numfiles);
              set_option (OPTNEEDREDRAW);
              if (*buf)
              {
diff --git a/main.c b/main.c
index 4179b1fc74a0a1ee89b508a479d808fd1e555b13..b4b5406b4cbacc6ec90fd4994308599a1a4b177b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -797,7 +797,7 @@ int main (int argc, char **argv)
        exit (1);
       }
       folder[0] = 0;
-      mutt_select_file (folder, sizeof (folder), 1);
+      mutt_select_file (folder, sizeof (folder), M_SEL_FOLDER);
       if (!folder[0])
       {
        mutt_endwin (NULL);
diff --git a/mutt.h b/mutt.h
index f477044ce13027b5e5040894a53b5dd0b5a806f1..59fc7d7f194a1020a455d3564d350acd38fa8544 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -280,6 +280,12 @@ enum
 #define SENDKEY                (1<<7)
 #define SENDRESEND     (1<<8)
 
+/* flags to _mutt_select_file() */
+#define M_SEL_BUFFY    (1<<0)
+#define M_SEL_MULTI    (1<<1)
+#define M_SEL_FOLDER   (1<<2)
+
+
 /* boolean vars */
 enum
 {
index 233c2f81bd4b43dc221d6b644e52fdf2bb537e67..832cbf46c5f2f3b456b449903ead1c1275d61dc2 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -203,8 +203,8 @@ void mutt_safe_path (char *s, size_t l, ADDRESS *a);
 void mutt_save_path (char *s, size_t l, ADDRESS *a);
 void mutt_score_message (CONTEXT *, HEADER *, int);
 void mutt_select_fcc (char *, size_t, HEADER *);
-#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 *);
+#define mutt_select_file(A,B,C) _mutt_select_file(A,B,C,NULL,NULL)
+void _mutt_select_file (char *, size_t, int, char ***, int *);
 void mutt_message_hook (CONTEXT *, HEADER *, int);
 void _mutt_set_flag (CONTEXT *, HEADER *, int, int, int);
 #define mutt_set_flag(a,b,c,d) _mutt_set_flag(a,b,c,d,1)