Commit 91a2a69c authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

rework input parsing in the file browser to be more flexible

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3275 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 9ffe78aa
Showing with 47 additions and 21 deletions
+47 -21
...@@ -14,6 +14,9 @@ CVS code - ...@@ -14,6 +14,9 @@ CVS code -
find_statusbar_bracket_match(), do_statusbar_find_bracket(), find_statusbar_bracket_match(), do_statusbar_find_bracket(),
find_bracket_match(), do_find_bracket(), main(), find_bracket_match(), do_find_bracket(), main(),
parse_rcfile(), nanorc.5, and nanorc.sample. (DLR) parse_rcfile(), nanorc.5, and nanorc.sample. (DLR)
- Rework input parsing in the file browser to be more flexible.
New function parse_browser_input(); changes to do_browser().
(DLR)
- chars.c: - chars.c:
mbstrchr() mbstrchr()
- Make parameter c const. (DLR) - Make parameter c const. (DLR)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* browser.c * * browser.c *
* * * *
* Copyright (C) 2001-2004 Chris Allegretta * * Copyright (C) 2001-2004 Chris Allegretta *
* Copyright (C) 2005 David Lawrence Ramsey * * Copyright (C) 2005-2006 David Lawrence Ramsey *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2, or (at your option) * * the Free Software Foundation; either version 2, or (at your option) *
...@@ -34,8 +34,9 @@ ...@@ -34,8 +34,9 @@
* 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 = ERR, longest, selected = 0, width = 0;
bool meta_key, func_key, old_const_update = ISSET(CONST_UPDATE); bool meta_key = FALSE, func_key = FALSE;
bool old_const_update = ISSET(CONST_UPDATE);
size_t numents; size_t numents;
char **filelist, *retval = NULL; char **filelist, *retval = NULL;
...@@ -55,10 +56,6 @@ char *do_browser(char *path, DIR *dir) ...@@ -55,10 +56,6 @@ char *do_browser(char *path, DIR *dir)
change_browser_directory: change_browser_directory:
/* We go here after the user selects a new directory. */ /* We go here after the user selects a new directory. */
kbinput = ERR;
selected = 0;
width = 0;
path = mallocstrassn(path, get_full_path(path)); path = mallocstrassn(path, get_full_path(path));
/* Assume that path exists and ends with a slash. */ /* Assume that path exists and ends with a slash. */
...@@ -95,6 +92,8 @@ char *do_browser(char *path, DIR *dir) ...@@ -95,6 +92,8 @@ char *do_browser(char *path, DIR *dir)
if (width != 0) if (width != 0)
fileline /= width; fileline /= width;
parse_browser_input(&kbinput, &meta_key, &func_key);
switch (kbinput) { switch (kbinput) {
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
case KEY_MOUSE: case KEY_MOUSE:
...@@ -154,8 +153,6 @@ char *do_browser(char *path, DIR *dir) ...@@ -154,8 +153,6 @@ char *do_browser(char *path, DIR *dir)
selected++; selected++;
break; break;
case NANO_PREVPAGE_KEY: case NANO_PREVPAGE_KEY:
case NANO_PREVPAGE_FKEY:
case '-': /* Pico compatibility. */
if (selected >= (editwinrows + fileline % editwinrows) * if (selected >= (editwinrows + fileline % editwinrows) *
width) width)
selected -= (editwinrows + fileline % editwinrows) * selected -= (editwinrows + fileline % editwinrows) *
...@@ -164,16 +161,12 @@ char *do_browser(char *path, DIR *dir) ...@@ -164,16 +161,12 @@ char *do_browser(char *path, DIR *dir)
selected = 0; selected = 0;
break; break;
case NANO_NEXTPAGE_KEY: case NANO_NEXTPAGE_KEY:
case NANO_NEXTPAGE_FKEY:
case ' ': /* Pico compatibility. */
selected += (editwinrows - fileline % editwinrows) * selected += (editwinrows - fileline % editwinrows) *
width; width;
if (selected >= numents) if (selected >= numents)
selected = numents - 1; selected = numents - 1;
break; break;
case NANO_HELP_KEY: case NANO_HELP_KEY:
case NANO_HELP_FKEY:
case '?': /* Pico compatibility. */
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
do_help(); do_help();
curs_set(0); curs_set(0);
...@@ -182,8 +175,6 @@ char *do_browser(char *path, DIR *dir) ...@@ -182,8 +175,6 @@ char *do_browser(char *path, DIR *dir)
#endif #endif
break; break;
case NANO_ENTER_KEY: case NANO_ENTER_KEY:
case 'S': /* Pico compatibility. */
case 's':
/* You can't move up from "/". */ /* You 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"));
...@@ -242,9 +233,6 @@ char *do_browser(char *path, DIR *dir) ...@@ -242,9 +233,6 @@ char *do_browser(char *path, DIR *dir)
/* Go to a specific directory. */ /* Go to a specific directory. */
case NANO_GOTOLINE_KEY: case NANO_GOTOLINE_KEY:
case NANO_GOTOLINE_FKEY:
case 'G': /* Pico compatibility. */
case 'g':
curs_set(1); curs_set(1);
j = do_prompt(FALSE, gotodir_list, "", j = do_prompt(FALSE, gotodir_list, "",
...@@ -298,9 +286,6 @@ char *do_browser(char *path, DIR *dir) ...@@ -298,9 +286,6 @@ char *do_browser(char *path, DIR *dir)
/* Abort the browser. */ /* Abort the browser. */
case NANO_EXIT_KEY: case NANO_EXIT_KEY:
case NANO_EXIT_FKEY:
case 'E': /* Pico compatibility. */
case 'e':
abort = TRUE; abort = TRUE;
break; break;
} }
...@@ -523,6 +508,43 @@ char *do_browse_from(const char *inpath) ...@@ -523,6 +508,43 @@ char *do_browse_from(const char *inpath)
return do_browser(path, dir); return do_browser(path, dir);
} }
/* Determine the shortcut key corresponding to the values of kbinput
* (the key itself), meta_key (whether the key is a meta sequence), and
* func_key (whether the key is a function key), if any. In the
* process, convert certain non-shortcut keys used by Pico's file
* browser into their corresponding shortcut keys. */
void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
{
get_shortcut(browser_list, kbinput, meta_key, func_key);
/* Pico compatibility. */
if (*meta_key == FALSE && *func_key == FALSE) {
switch (*kbinput) {
case ' ':
*kbinput = NANO_NEXTPAGE_KEY;
break;
case '-':
*kbinput = NANO_PREVPAGE_KEY;
break;
case '?':
*kbinput = NANO_HELP_KEY;
break;
case 'E':
case 'e':
*kbinput = NANO_EXIT_KEY;
break;
case 'G':
case 'g':
*kbinput = NANO_GOTOLINE_KEY;
break;
case 'S':
case 's':
*kbinput = NANO_ENTER_KEY;
break;
}
}
}
/* Strip one directory from the end of path. */ /* Strip one directory from the end of path. */
void striponedir(char *path) void striponedir(char *path)
{ {
......
...@@ -141,6 +141,7 @@ char *do_browser(char *path, DIR *dir); ...@@ -141,6 +141,7 @@ char *do_browser(char *path, DIR *dir);
char **browser_init(const char *path, int *longest, size_t *numents, DIR 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 striponedir(char *path); void striponedir(char *path);
#endif #endif
......
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