Commit 88b3020d authored by Thomas Roessler's avatar Thomas Roessler

Make browser behaviour more consistent with expectations.

parent 921e82ce
......@@ -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));
}
......@@ -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
......
/*
* Copyright (C) 1996-2000 Michael R. Elkins <[email protected]>
* Copyright (C) 2000 Edmund Grimley Evans <[email protected]>
......@@ -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)
{
......
......@@ -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);
......
......@@ -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
{
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment