Commit c0dcdf43 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

in do_browser(), properly restore the file list display after returning

from the help browser at the "Go To Directory" prompt, and rename
variable j to i, for consistency


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3286 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 36 additions and 15 deletions
+36 -15
...@@ -25,7 +25,10 @@ CVS code - ...@@ -25,7 +25,10 @@ CVS code -
- browser.c: - browser.c:
do_browser() do_browser()
- Properly set currshortcut back to the file browser shortcut - Properly set currshortcut back to the file browser shortcut
list after a "Go To Directory" prompt. (DLR) list after a "Go To Directory" prompt, and properly restore
the file list display after returning from the help browser at
the "Go To Directory" prompt. (DLR)
- Rename variable j to i, for consistency. (DLR)
- chars.c: - chars.c:
mbstrchr() mbstrchr()
- Make parameter c const. (DLR) - Make parameter c const. (DLR)
......
...@@ -37,12 +37,13 @@ char *do_browser(char *path, DIR *dir) ...@@ -37,12 +37,13 @@ char *do_browser(char *path, DIR *dir)
int kbinput, longest, selected, width; int kbinput, longest, selected, width;
bool meta_key = FALSE, func_key = FALSE; bool meta_key = FALSE, func_key = FALSE;
bool old_const_update = ISSET(CONST_UPDATE); bool old_const_update = ISSET(CONST_UPDATE);
char *ans = mallocstrcpy(NULL, "");
/* The last answer the user typed on the statusbar. */
size_t numents; size_t numents;
char **filelist, *retval = NULL; char **filelist, *retval = NULL;
curs_set(0); curs_set(0);
blank_statusbar(); blank_statusbar();
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = browser_list; currshortcut = browser_list;
#endif #endif
...@@ -75,7 +76,7 @@ char *do_browser(char *path, DIR *dir) ...@@ -75,7 +76,7 @@ char *do_browser(char *path, DIR *dir)
do { do {
bool abort = FALSE; bool abort = FALSE;
int j, col = 0, editline = 0, fileline; int i, col = 0, editline = 0, fileline;
int filecols = 0; int filecols = 0;
/* Used only if width == 0, to calculate the number of files /* Used only if width == 0, to calculate the number of files
* per row below. */ * per row below. */
...@@ -127,7 +128,8 @@ char *do_browser(char *path, DIR *dir) ...@@ -127,7 +128,8 @@ char *do_browser(char *path, DIR *dir)
if (selected > numents - 1) if (selected > numents - 1)
selected = numents - 1; selected = numents - 1;
else if (old_selected == selected) else if (old_selected == selected)
/* Put back the 'select' key. */ /* Put back the "Select" key, so that the file
* is selected. */
unget_kbinput(NANO_ENTER_KEY, FALSE, FALSE); unget_kbinput(NANO_ENTER_KEY, FALSE, FALSE);
} else { } else {
/* We must have clicked a shortcut. Put back the /* We must have clicked a shortcut. Put back the
...@@ -245,11 +247,11 @@ char *do_browser(char *path, DIR *dir) ...@@ -245,11 +247,11 @@ char *do_browser(char *path, DIR *dir)
case NANO_GOTOLINE_KEY: case NANO_GOTOLINE_KEY:
curs_set(1); curs_set(1);
j = do_prompt(TRUE, i = do_prompt(TRUE,
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
FALSE, FALSE,
#endif #endif
gotodir_list, "", gotodir_list, ans,
#ifndef NANO_TINY #ifndef NANO_TINY
NULL, NULL,
#endif #endif
...@@ -261,11 +263,26 @@ char *do_browser(char *path, DIR *dir) ...@@ -261,11 +263,26 @@ char *do_browser(char *path, DIR *dir)
#endif #endif
bottombars(browser_list); bottombars(browser_list);
if (j < 0) { if (i < 0) {
/* We canceled. Indicate that on the statusbar, and
* blank out ans, since we're done with it. */
statusbar(_("Cancelled")); statusbar(_("Cancelled"));
ans = mallocstrcpy(ans, "");
break;
} else if (i != 0) {
/* Put back the "Go to Directory" key and save
* answer in ans, so that the file list is displayed
* again, the prompt is displayed again, and what we
* typed before at the prompt is displayed again. */
unget_kbinput(NANO_GOTOLINE_KEY, FALSE, FALSE);
ans = mallocstrcpy(ans, answer);
break; break;
} }
/* We have a directory. Blank out ans, since we're done
* with it. */
ans = mallocstrcpy(ans, "");
new_path = real_dir_from_tilde(answer); new_path = real_dir_from_tilde(answer);
if (new_path[0] != '/') { if (new_path[0] != '/') {
...@@ -312,7 +329,7 @@ char *do_browser(char *path, DIR *dir) ...@@ -312,7 +329,7 @@ char *do_browser(char *path, DIR *dir)
blank_edit(); blank_edit();
j = (width != 0) ? width * editwinrows * ((selected / width) / i = (width != 0) ? width * editwinrows * ((selected / width) /
editwinrows) : 0; editwinrows) : 0;
wmove(edit, 0, 0); wmove(edit, 0, 0);
...@@ -321,12 +338,12 @@ char *do_browser(char *path, DIR *dir) ...@@ -321,12 +338,12 @@ char *do_browser(char *path, DIR *dir)
size_t foo_len = mb_cur_max() * 7; size_t foo_len = mb_cur_max() * 7;
char *foo = charalloc(foo_len + 1); char *foo = charalloc(foo_len + 1);
for (; j < numents && editline <= editwinrows - 1; j++) { for (; i < numents && editline <= editwinrows - 1; i++) {
char *disp = display_string(tail(filelist[j]), 0, char *disp = display_string(tail(filelist[i]), 0,
longest, FALSE); longest, FALSE);
/* Highlight the currently selected file/dir. */ /* Highlight the currently selected file/dir. */
if (j == selected) if (i == selected)
wattron(edit, A_REVERSE); wattron(edit, A_REVERSE);
blank_line(edit, editline, col, longest); blank_line(edit, editline, col, longest);
...@@ -341,11 +358,11 @@ char *do_browser(char *path, DIR *dir) ...@@ -341,11 +358,11 @@ char *do_browser(char *path, DIR *dir)
* lstat() return an error if, for example, the file is * lstat() return an error if, for example, the file is
* deleted while the file browser is open. In that * deleted while the file browser is open. In that
* case, we report "--" as the file info. */ * case, we report "--" as the file info. */
if (lstat(filelist[j], &st) == -1 || if (lstat(filelist[i], &st) == -1 ||
S_ISLNK(st.st_mode)) { S_ISLNK(st.st_mode)) {
/* Aha! It's a symlink! Now, is it a dir? If so, /* Aha! It's a symlink! Now, is it a dir? If so,
* mark it as such. */ * mark it as such. */
if (stat(filelist[j], &st) == 0 && if (stat(filelist[i], &st) == 0 &&
S_ISDIR(st.st_mode)) { S_ISDIR(st.st_mode)) {
strncpy(foo, _("(dir)"), foo_len); strncpy(foo, _("(dir)"), foo_len);
foo[foo_len] = '\0'; foo[foo_len] = '\0';
...@@ -369,7 +386,7 @@ char *do_browser(char *path, DIR *dir) ...@@ -369,7 +386,7 @@ char *do_browser(char *path, DIR *dir)
mvwaddnstr(edit, editline, col - strlen(foo), foo, mvwaddnstr(edit, editline, col - strlen(foo), foo,
foo_len); foo_len);
if (j == selected) if (i == selected)
wattroff(edit, A_REVERSE); wattroff(edit, A_REVERSE);
/* Add some space between the columns. */ /* Add some space between the columns. */
...@@ -402,8 +419,9 @@ char *do_browser(char *path, DIR *dir) ...@@ -402,8 +419,9 @@ char *do_browser(char *path, DIR *dir)
SET(CONST_UPDATE); SET(CONST_UPDATE);
/* Clean up. */ /* Clean up. */
free_chararray(filelist, numents);
free(path); free(path);
free(ans);
free_chararray(filelist, numents);
return retval; return retval;
} }
......
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