fix file browser breakage

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3294 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2006-02-10 03:27:48 +00:00
parent d4bae13d8d
commit d83af2fea7
2 changed files with 26 additions and 17 deletions

View File

@ -34,8 +34,8 @@
* Assume path has already been tilde-expanded. */ * Assume path has already been tilde-expanded. */
char *do_browser(char *path, DIR *dir) char *do_browser(char *path, DIR *dir)
{ {
int kbinput, longest, selected, width; int kbinput, width, longest, selected;
bool meta_key = FALSE, func_key = FALSE; bool meta_key, func_key;
bool old_const_update = ISSET(CONST_UPDATE); bool old_const_update = ISSET(CONST_UPDATE);
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. */
@ -56,8 +56,10 @@ char *do_browser(char *path, DIR *dir)
/* We go here after the user selects a new directory. */ /* We go here after the user selects a new directory. */
kbinput = ERR; kbinput = ERR;
selected = 0; meta_key = FALSE;
func_key = FALSE;
width = 0; width = 0;
selected = 0;
path = mallocstrassn(path, get_full_path(path)); path = mallocstrassn(path, get_full_path(path));
@ -78,8 +80,6 @@ char *do_browser(char *path, DIR *dir)
bool abort = FALSE; bool abort = FALSE;
struct stat st; struct stat st;
int i, fileline; int i, fileline;
/* Used only if width == 0, to calculate the number of files
* per row below. */
char *new_path; char *new_path;
/* Used by the "Go To Directory" prompt. */ /* Used by the "Go To Directory" prompt. */
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
@ -110,9 +110,9 @@ char *do_browser(char *path, DIR *dir)
/* longest is the width of each column. There are /* longest is the width of each column. There are
* two spaces between each column. */ * two spaces between each column. */
selected = (fileline / editwinrows) * editwinrows * selected = (fileline / editwinrows) * (editwinrows *
width + mevent.y * width + mevent.x / width) + (mevent.y * width) + (mevent.x /
(longest + 2); (longest + 2));
/* If they clicked beyond the end of a row, select /* If they clicked beyond the end of a row, select
* the end of that row. */ * the end of that row. */
@ -324,7 +324,7 @@ char *do_browser(char *path, DIR *dir)
if (abort) if (abort)
break; break;
browser_draw(filelist, numents, longest, selected, width); browser_draw(&width, longest, selected, filelist, numents);
kbinput = get_kbinput(edit, &meta_key, &func_key); kbinput = get_kbinput(edit, &meta_key, &func_key);
parse_browser_input(&kbinput, &meta_key, &func_key); parse_browser_input(&kbinput, &meta_key, &func_key);
@ -499,16 +499,25 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
} }
} }
void browser_draw(char **filelist, size_t numents, int longest, int /* Display the list of files in the array filelist with the size
selected, int width) * numents. width is the number of columns in the list, which we
* calculate and return. longest is the length of the longest filename,
* and hence the width of each column of the list. selected is the
* filename that is currently selected. */
void browser_draw(int *width, int longest, int selected, char
**filelist, size_t numents)
{ {
struct stat st; struct stat st;
int i = (width != 0) ? width * editwinrows * ((selected / width) / int i;
editwinrows) : 0;
int col = 0, filecols = 0, editline = 0; int col = 0, filecols = 0, editline = 0;
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);
assert(width != NULL);
i = (*width != 0) ? *width * editwinrows * ((selected / *width) /
editwinrows) : 0;
blank_edit(); blank_edit();
wmove(edit, 0, 0); wmove(edit, 0, 0);
@ -566,8 +575,8 @@ void browser_draw(char **filelist, size_t numents, int longest, int
if (col > COLS - longest) { if (col > COLS - longest) {
editline++; editline++;
col = 0; col = 0;
if (width == 0) if (*width == 0)
width = filecols; *width = filecols;
} }
wmove(edit, editline, col); wmove(edit, editline, col);

View File

@ -142,8 +142,8 @@ char **browser_init(const char *path, int *longest, size_t *numents, DIR
*dir); *dir);
char *do_browse_from(const char *inpath); char *do_browse_from(const char *inpath);
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_draw(char **filelist, size_t numents, int longest, int void browser_draw(int *width, int longest, int selected, char
selected, int width); **filelist, size_t numents);
void striponedir(char *path); void striponedir(char *path);
#endif #endif