Skip to content

Commit

Permalink
Make browser behaviour more consistent with expectations.
Browse files Browse the repository at this point in the history
--HG--
branch : HEAD
  • Loading branch information
Thomas Roessler committed Dec 31, 2000
1 parent 709484d commit 6bc7bfd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
44 changes: 30 additions & 14 deletions browser.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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] = "";
Expand All @@ -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);
Expand Down Expand Up @@ -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))
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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));

}
3 changes: 2 additions & 1 deletion curs_lib.c
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions 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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion main.c
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions mutt.h
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions protos.h
Expand Up @@ -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)
Expand Down

0 comments on commit 6bc7bfd

Please sign in to comment.