in do_browser(), after entering "..", select the directory we were in

before instead of the first filename in the list, as Pico does; add new
function browser_select_filename() to help do this properly


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3698 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2006-06-30 06:41:31 +00:00
parent ef45a2528c
commit d04037760d
3 changed files with 54 additions and 4 deletions

View File

@ -14,12 +14,17 @@ CVS code -
- Refactor and simplify the mouse support, modeling it after - Refactor and simplify the mouse support, modeling it after
do_mouse() for consistency. (DLR) do_mouse() for consistency. (DLR)
- Remove unneeded call to blank_edit(). (DLR) - Remove unneeded call to blank_edit(). (DLR)
- After entering "..", select the directory we were in before
instead of the first filename in the list, as Pico does. (DLR)
browser_refresh() browser_refresh()
- Simplify. (DLR) - Simplify. (DLR)
- Fix problems where translated versions of "(dir)" could be - Fix problems where translated versions of "(dir)" could be
truncated, and where file sizes could be too long. (DLR) truncated, and where file sizes could be too long. (DLR)
- For the ".." entry, display "(parent dir)" instead of "(dir)", - For the ".." entry, display "(parent dir)" instead of "(dir)",
as Pico does. (DLR) as Pico does. (DLR)
browser_select_filename()
- New function, used to select a specific filename in the list.
(DLR)
findnextfile() findnextfile()
- Simplify the uses of tail(). (DLR) - Simplify the uses of tail(). (DLR)
- doc/syntax/c.nanorc: - doc/syntax/c.nanorc:

View File

@ -51,6 +51,9 @@ char *do_browser(char *path, DIR *dir)
int kbinput; int kbinput;
bool meta_key, func_key; bool meta_key, func_key;
bool old_const_update = ISSET(CONST_UPDATE); bool old_const_update = ISSET(CONST_UPDATE);
char *prev_dir = NULL;
/* The directory we were in, if any, before backing up via
* entering "..". */
char *ans = mallocstrcpy(NULL, ""); char *ans = mallocstrcpy(NULL, "");
/* The last answer the user typed on the statusbar. */ /* The last answer the user typed on the statusbar. */
char *retval = NULL; char *retval = NULL;
@ -89,6 +92,15 @@ char *do_browser(char *path, DIR *dir)
titlebar(path); titlebar(path);
/* If prev_dir isn't NULL, select the directory saved in it, and
* then blow it away. */
if (prev_dir != NULL) {
browser_select_filename(prev_dir);
free(prev_dir);
prev_dir = NULL;
}
do { do {
bool abort = FALSE; bool abort = FALSE;
struct stat st; struct stat st;
@ -250,7 +262,7 @@ char *do_browser(char *path, DIR *dir)
dir = opendir(new_path); dir = opendir(new_path);
if (dir == NULL) { if (dir == NULL) {
/* We can't open this dir for some reason. /* We can't open this directory for some reason.
* Complain. */ * Complain. */
statusbar(_("Error reading %s: %s"), answer, statusbar(_("Error reading %s: %s"), answer,
strerror(errno)); strerror(errno));
@ -281,7 +293,7 @@ char *do_browser(char *path, DIR *dir)
selected++; selected++;
break; break;
case NANO_ENTER_KEY: case NANO_ENTER_KEY:
/* You can't move up from "/". */ /* We can't move up from "/". */
if (strcmp(filelist[selected], "/..") == 0) { if (strcmp(filelist[selected], "/..") == 0) {
statusbar(_("Can't move up a directory")); statusbar(_("Can't move up a directory"));
beep(); beep();
@ -289,7 +301,7 @@ char *do_browser(char *path, DIR *dir)
} }
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
/* Note: the selected file can be outside the operating /* Note: The selected file can be outside the operating
* directory if it's ".." or if it's a symlink to a * directory if it's ".." or if it's a symlink to a
* directory outside the operating directory. */ * directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) { if (check_operating_dir(filelist[selected], FALSE)) {
@ -310,10 +322,20 @@ char *do_browser(char *path, DIR *dir)
break; break;
} }
/* If we've successfully opened a file, we're done, so
* get out. */
if (!S_ISDIR(st.st_mode)) { if (!S_ISDIR(st.st_mode)) {
retval = mallocstrcpy(retval, filelist[selected]); retval = mallocstrcpy(NULL, filelist[selected]);
abort = TRUE; abort = TRUE;
break; break;
/* If we've successfully opened a directory, and it's
* "..", save the current directory in prev_dir, so that
* we can select it later. */
} else if (strcmp(tail(filelist[selected]),
"..") == 0) {
prev_dir = mallocstrcpy(NULL, filelist[selected]);
striponedir(prev_dir);
align(&prev_dir);
} }
dir = opendir(filelist[selected]); dir = opendir(filelist[selected]);
@ -622,6 +644,28 @@ void browser_refresh(void)
wnoutrefresh(edit); wnoutrefresh(edit);
} }
/* Look for needle. If we find it, set selected to its location, and
* update the screen. Note that needle must be an exact match for a
* file in the list. */
void browser_select_filename(const char *needle)
{
size_t currselected;
bool found = FALSE;
for (currselected = 0; currselected < filelist_len;
currselected++) {
if (strcmp(filelist[currselected], needle) == 0) {
found = TRUE;
break;
}
}
if (found) {
selected = currselected;
browser_refresh();
}
}
/* Set up the system variables for a filename search. Return -1 if the /* Set up the system variables for a filename search. Return -1 if the
* search should be canceled (due to Cancel, a blank search string, or a * search should be canceled (due to Cancel, a blank search string, or a
* failed regcomp()), return 0 on success, and return 1 on rerun calling * failed regcomp()), return 0 on success, and return 1 on rerun calling

View File

@ -148,6 +148,7 @@ char *do_browse_from(const char *inpath);
void browser_init(const char *path, DIR *dir); void browser_init(const char *path, DIR *dir);
void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key); void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key);
void browser_refresh(void); void browser_refresh(void);
void browser_select_filename(const char *needle);
int filesearch_init(void); int filesearch_init(void);
bool findnextfile(bool no_sameline, size_t begin, const char *needle); bool findnextfile(bool no_sameline, size_t begin, const char *needle);
void findnextfile_wrap_reset(void); void findnextfile_wrap_reset(void);