- Refactor and simplify the mouse support, modeling it after
do_mouse() for consistency. (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()
- Simplify. (DLR)
- Fix problems where translated versions of "(dir)" could be
truncated, and where file sizes could be too long. (DLR)
- For the ".." entry, display "(parent dir)" instead of "(dir)",
as Pico does. (DLR)
+ browser_select_filename()
+ - New function, used to select a specific filename in the list.
+ (DLR)
findnextfile()
- Simplify the uses of tail(). (DLR)
- doc/syntax/c.nanorc:
int kbinput;
bool meta_key, func_key;
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, "");
/* The last answer the user typed on the statusbar. */
char *retval = NULL;
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 {
bool abort = FALSE;
struct stat st;
dir = opendir(new_path);
if (dir == NULL) {
- /* We can't open this dir for some reason.
+ /* We can't open this directory for some reason.
* Complain. */
statusbar(_("Error reading %s: %s"), answer,
strerror(errno));
selected++;
break;
case NANO_ENTER_KEY:
- /* You can't move up from "/". */
+ /* We can't move up from "/". */
if (strcmp(filelist[selected], "/..") == 0) {
statusbar(_("Can't move up a directory"));
beep();
}
#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 outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) {
break;
}
+ /* If we've successfully opened a file, we're done, so
+ * get out. */
if (!S_ISDIR(st.st_mode)) {
- retval = mallocstrcpy(retval, filelist[selected]);
+ retval = mallocstrcpy(NULL, filelist[selected]);
abort = TRUE;
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]);
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
* 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
void browser_init(const char *path, DIR *dir);
void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key);
void browser_refresh(void);
+void browser_select_filename(const char *needle);
int filesearch_init(void);
bool findnextfile(bool no_sameline, size_t begin, const char *needle);
void findnextfile_wrap_reset(void);