add more miscellaneous cleanups

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3711 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2006-06-30 22:28:37 +00:00
parent a662c5579a
commit a43b10854f
3 changed files with 53 additions and 25 deletions

View File

@ -51,9 +51,11 @@ char *do_browser(char *path, DIR *dir)
char *retval = NULL; char *retval = NULL;
int kbinput; int kbinput;
bool meta_key, func_key, old_const_update = ISSET(CONST_UPDATE); bool meta_key, func_key, old_const_update = ISSET(CONST_UPDATE);
bool abort = FALSE;
/* Whether we should abort the file browser. */
char *prev_dir = NULL; char *prev_dir = NULL;
/* The directory we were in, if any, before backing up via /* The directory we were in, if any, before backing up via
* entering "..". */ * browsing to "..". */
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. */
@ -89,27 +91,29 @@ char *do_browser(char *path, DIR *dir)
titlebar(path); titlebar(path);
/* If prev_dir isn't NULL, select the directory saved in it, and while (!abort) {
* then blow it away. */
if (prev_dir != NULL) {
browser_select_filename(prev_dir);
free(prev_dir);
prev_dir = NULL;
}
do {
size_t fileline; size_t fileline;
/* The line number the selected file is on. */ /* The line number the selected file is on. */
size_t old_selected = selected; size_t old_selected = selected;
/* We display the file list only if the selected file /* The file we had selected before the current selected
* changed. */ * file. */
bool found_prev_dir = FALSE;
/* Whether we've selected a directory in prev_dir. */
struct stat st; struct stat st;
int i; int i;
char *new_path; char *new_path;
/* Compute the line number we're on now, so that we don't divide /* If prev_dir isn't NULL, select the directory saved in it, and
* by zero. */ * then blow it away. */
if (prev_dir != NULL) {
found_prev_dir = browser_select_filename(prev_dir);
free(prev_dir);
prev_dir = NULL;
}
/* Calculate the line number we're on now, so that we don't
* divide by zero. */
fileline = selected; fileline = selected;
if (width != 0) if (width != 0)
fileline /= width; fileline /= width;
@ -324,7 +328,7 @@ char *do_browser(char *path, DIR *dir)
* get out. */ * get out. */
if (!S_ISDIR(st.st_mode)) { if (!S_ISDIR(st.st_mode)) {
retval = mallocstrcpy(NULL, filelist[selected]); retval = mallocstrcpy(NULL, filelist[selected]);
kbinput = NANO_EXIT_KEY; abort = TRUE;
break; break;
/* If we've successfully opened a directory, and it's /* If we've successfully opened a directory, and it's
* "..", save the current directory in prev_dir, so that * "..", save the current directory in prev_dir, so that
@ -348,16 +352,27 @@ char *do_browser(char *path, DIR *dir)
/* Start over again with the new path value. */ /* Start over again with the new path value. */
free_chararray(filelist, filelist_len); free_chararray(filelist, filelist_len);
goto change_browser_directory; goto change_browser_directory;
case NANO_EXIT_KEY:
/* Abort the file browser. */
abort = TRUE;
break;
} }
/* If abort is TRUE, we're done, so get out. */
if (abort)
break;
/* Display the file list if we don't have a key, or if we do /* Display the file list if we don't have a key, or if we do
* have a key and the selected file has changed. */ * have a key and the selected file has changed. Don't display
if (kbinput == ERR || old_selected != selected) * it if we selected a directory in prev_dir, since the file
* list will have already been displayed then. */
if ((kbinput == ERR && !found_prev_dir) || old_selected !=
selected)
browser_refresh(); browser_refresh();
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);
} while (kbinput != NANO_EXIT_KEY); }
titlebar(NULL); titlebar(NULL);
edit_refresh(); edit_refresh();
@ -638,8 +653,9 @@ void browser_refresh(void)
/* Look for needle. If we find it, set selected to its location, and /* 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 * update the screen. Note that needle must be an exact match for a
* file in the list. */ * file in the list. The return value specifies whether we found
void browser_select_filename(const char *needle) * anything. */
bool browser_select_filename(const char *needle)
{ {
size_t currselected; size_t currselected;
bool found = FALSE; bool found = FALSE;
@ -656,6 +672,8 @@ void browser_select_filename(const char *needle)
selected = currselected; selected = currselected;
browser_refresh(); browser_refresh();
} }
return found;
} }
/* 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

View File

@ -38,6 +38,8 @@ void do_help(void (*refresh_func)(void))
{ {
int kbinput = ERR; int kbinput = ERR;
bool meta_key, func_key, old_no_help = ISSET(NO_HELP); bool meta_key, func_key, old_no_help = ISSET(NO_HELP);
bool abort = FALSE;
/* Whether we should abort the help browser. */
size_t line = 0; size_t line = 0;
/* The line number in help_text of the first displayed help /* The line number in help_text of the first displayed help
* line. This variable is zero-based. */ * line. This variable is zero-based. */
@ -87,11 +89,11 @@ void do_help(void (*refresh_func)(void))
if (last_line > 0) if (last_line > 0)
last_line--; last_line--;
do { while (!abort) {
size_t i; size_t i;
/* Generic loop variable. */ /* Generic loop variable. */
size_t old_line = line; size_t old_line = line;
/* We redisplay the help only if it moved. */ /* The line we were on before the current line. */
ptr = help_text; ptr = help_text;
@ -137,8 +139,16 @@ void do_help(void (*refresh_func)(void))
line = last_line - (editwinrows - 1); line = last_line - (editwinrows - 1);
} }
break; break;
case NANO_EXIT_KEY:
/* Abort the help browser. */
abort = TRUE;
break;
} }
/* If abort is TRUE, we're done, so get out. */
if (abort)
break;
/* Display the help text if we don't have a key, or if we do /* Display the help text if we don't have a key, or if we do
* have a key and the help text has moved. */ * have a key and the help text has moved. */
if (kbinput == ERR || line != old_line) { if (kbinput == ERR || line != old_line) {
@ -164,7 +174,7 @@ void do_help(void (*refresh_func)(void))
kbinput = get_kbinput(edit, &meta_key, &func_key); kbinput = get_kbinput(edit, &meta_key, &func_key);
parse_help_input(&kbinput, &meta_key, &func_key); parse_help_input(&kbinput, &meta_key, &func_key);
} while (kbinput != NANO_EXIT_KEY); }
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
currshortcut = oldshortcut; currshortcut = oldshortcut;

View File

@ -148,7 +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); bool 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);