Making use of the new wrapper in the help viewer and the file browser.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5051 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2014-07-02 09:29:05 +00:00
parent 3933a30c9e
commit 6418ffa289
4 changed files with 51 additions and 72 deletions

View File

@ -3,6 +3,8 @@
* src/global.c (func_from_key): New wrapper. * src/global.c (func_from_key): New wrapper.
* src/prompt.c (get_prompt_string, do_prompt): Use the new * src/prompt.c (get_prompt_string, do_prompt): Use the new
wrapper to make the code a bit cleaner. wrapper to make the code a bit cleaner.
* src/help.c (do_help, parse_help_input): Use the wrapper.
* src/browser.c (do_browser, parse_browser_input): Likewise.
2014-07-01 Benno Schulenberg <bensberg@justemail.net> 2014-07-01 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (do_browser), src/help.c (do_help): Make sure * src/browser.c (do_browser), src/help.c (do_help): Make sure

View File

@ -58,8 +58,8 @@ char *do_browser(char *path, DIR *dir)
/* The last answer the user typed at the statusbar prompt. */ /* The last answer the user typed at the statusbar prompt. */
size_t old_selected; size_t old_selected;
/* The selected file we had before the current selected file. */ /* The selected file we had before the current selected file. */
const sc *s; functionptrtype func;
const subnfunc *f; /* The function of the key the user typed in. */
curs_set(0); curs_set(0);
blank_statusbar(); blank_statusbar();
@ -156,45 +156,39 @@ char *do_browser(char *path, DIR *dir)
} }
#endif /* !DISABLE_MOUSE */ #endif /* !DISABLE_MOUSE */
parse_browser_input(&kbinput); func = parse_browser_input(&kbinput);
s = get_shortcut(&kbinput);
if (!s)
continue;
f = sctofunc((sc *) s);
if (!f)
break;
if (f->scfunc == total_refresh) { if (func == total_refresh) {
total_redraw(); total_redraw();
} else if (f->scfunc == do_help_void) { } else if (func == do_help_void) {
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
do_help_void(); do_help_void();
curs_set(0); curs_set(0);
#else #else
nano_disabled_msg(); nano_disabled_msg();
#endif #endif
} else if (f->scfunc == do_search) { } else if (func == do_search) {
/* Search for a filename. */ /* Search for a filename. */
curs_set(1); curs_set(1);
do_filesearch(); do_filesearch();
curs_set(0); curs_set(0);
} else if (f->scfunc == do_research) { } else if (func == do_research) {
/* Search for another filename. */ /* Search for another filename. */
do_fileresearch(); do_fileresearch();
} else if (f->scfunc == do_page_up) { } else if (func == do_page_up) {
if (selected >= (editwinrows + fileline % editwinrows) * width) if (selected >= (editwinrows + fileline % editwinrows) * width)
selected -= (editwinrows + fileline % editwinrows) * width; selected -= (editwinrows + fileline % editwinrows) * width;
else else
selected = 0; selected = 0;
} else if (f->scfunc == do_page_down) { } else if (func == do_page_down) {
selected += (editwinrows - fileline % editwinrows) * width; selected += (editwinrows - fileline % editwinrows) * width;
if (selected > filelist_len - 1) if (selected > filelist_len - 1)
selected = filelist_len - 1; selected = filelist_len - 1;
} else if (f->scfunc == do_first_file) { } else if (func == do_first_file) {
selected = 0; selected = 0;
} else if (f->scfunc == do_last_file) { } else if (func == do_last_file) {
selected = filelist_len - 1; selected = filelist_len - 1;
} else if (f->scfunc == goto_dir_void) { } else if (func == goto_dir_void) {
/* Go to a specific directory. */ /* Go to a specific directory. */
curs_set(1); curs_set(1);
i = do_prompt(TRUE, i = do_prompt(TRUE,
@ -271,19 +265,19 @@ char *do_browser(char *path, DIR *dir)
free(path); free(path);
path = new_path; path = new_path;
goto change_browser_directory; goto change_browser_directory;
} else if (f->scfunc == do_up_void) { } else if (func == do_up_void) {
if (selected >= width) if (selected >= width)
selected -= width; selected -= width;
} else if (f->scfunc == do_left) { } else if (func == do_left) {
if (selected > 0) if (selected > 0)
selected--; selected--;
} else if (f->scfunc == do_down_void) { } else if (func == do_down_void) {
if (selected + width <= filelist_len - 1) if (selected + width <= filelist_len - 1)
selected += width; selected += width;
} else if (f->scfunc == do_right) { } else if (func == do_right) {
if (selected < filelist_len - 1) if (selected < filelist_len - 1)
selected++; selected++;
} else if (f->scfunc == do_enter_void) { } else if (func == do_enter_void) {
/* We can't move up from "/". */ /* We 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"));
@ -337,7 +331,7 @@ char *do_browser(char *path, DIR *dir)
/* Start over again with the new path value. */ /* Start over again with the new path value. */
goto change_browser_directory; goto change_browser_directory;
} else if (f->scfunc == do_exit) { } else if (func == do_exit) {
/* Exit from the file browser. */ /* Exit from the file browser. */
break; break;
} }
@ -522,41 +516,33 @@ void browser_init(const char *path, DIR *dir)
width = longest; width = longest;
} }
/* Convert certain non-shortcut keys into their corresponding shortcut /* Return the function that is bound to the given key, accepting certain
* sequences, for compatibility with Pico. */ * plain characters too, for compatibility with Pico. */
void parse_browser_input(int *kbinput) functionptrtype parse_browser_input(int *kbinput)
{ {
if (!meta_key) { if (!meta_key) {
switch (*kbinput) { switch (*kbinput) {
case ' ': case ' ':
*kbinput = KEY_NPAGE; return do_page_down;
break;
case '-': case '-':
*kbinput = KEY_PPAGE; return do_page_up;
break;
case '?': case '?':
#ifndef DISABLE_HELP return do_help_void;
*kbinput = sc_seq_or(do_help_void, 0);
#endif
break;
case 'E': case 'E':
case 'e': case 'e':
*kbinput = sc_seq_or(do_exit, 0); return do_exit;
break;
case 'G': case 'G':
case 'g': case 'g':
*kbinput = sc_seq_or(goto_dir_void, 0); return goto_dir_void;
break;
case 'S': case 'S':
case 's': case 's':
*kbinput = sc_seq_or(do_enter_void, 0); return do_enter_void;
break;
case 'W': case 'W':
case 'w': case 'w':
*kbinput = sc_seq_or(do_search, 0); return do_search;
break;
} }
} }
return func_from_key(kbinput);
} }
/* Set width to the number of files that we can display per line, if /* Set width to the number of files that we can display per line, if

View File

@ -50,8 +50,8 @@ void do_help(void (*refresh_func)(void))
/* The current line of the help text. */ /* The current line of the help text. */
size_t old_line = (size_t)-1; size_t old_line = (size_t)-1;
/* The line we were on before the current line. */ /* The line we were on before the current line. */
const sc *s; functionptrtype func;
const subnfunc *f; /* The function of the key the user typed in. */
curs_set(0); curs_set(0);
blank_edit(); blank_edit();
@ -129,36 +129,30 @@ void do_help(void (*refresh_func)(void))
} }
#endif #endif
parse_help_input(&kbinput); func = parse_help_input(&kbinput);
s = get_shortcut(&kbinput);
if (!s)
continue;
f = sctofunc((sc *) s);
if (!f)
continue;
if (f->scfunc == total_refresh) { if (func == total_refresh) {
total_redraw(); total_redraw();
} else if (f->scfunc == do_page_up) { } else if (func == do_page_up) {
if (line > editwinrows - 2) if (line > editwinrows - 2)
line -= editwinrows - 2; line -= editwinrows - 2;
else else
line = 0; line = 0;
} else if (f->scfunc == do_page_down) { } else if (func == do_page_down) {
if (line + (editwinrows - 1) < last_line) if (line + (editwinrows - 1) < last_line)
line += editwinrows - 2; line += editwinrows - 2;
} else if (f->scfunc == do_up_void) { } else if (func == do_up_void) {
if (line > 0) if (line > 0)
line--; line--;
} else if (f->scfunc == do_down_void) { } else if (func == do_down_void) {
if (line + (editwinrows - 1) < last_line) if (line + (editwinrows - 1) < last_line)
line++; line++;
} else if (f->scfunc == do_first_line) { } else if (func == do_first_line) {
line = 0; line = 0;
} else if (f->scfunc == do_last_line) { } else if (func == do_last_line) {
if (line + (editwinrows - 1) < last_line) if (line + (editwinrows - 1) < last_line)
line = last_line - (editwinrows - 1); line = last_line - (editwinrows - 1);
} else if (f->scfunc == do_exit) { } else if (func == do_exit) {
/* Exit from the help browser. */ /* Exit from the help browser. */
break; break;
} }
@ -467,25 +461,22 @@ void help_init(void)
assert(strlen(help_text) <= allocsize + 1); assert(strlen(help_text) <= allocsize + 1);
} }
/* Convert certain non-shortcut keys into their corresponding shortcut /* Return the function that is bound to the given key, accepting certain
* sequences. */ * plain characters too, for consistency with the file browser. */
void parse_help_input(int *kbinput) functionptrtype parse_help_input(int *kbinput)
{ {
if (!meta_key) { if (!meta_key) {
switch (*kbinput) { switch (*kbinput) {
/* For consistency with the file browser. */
case ' ': case ' ':
*kbinput = KEY_NPAGE; return do_page_down;
break;
case '-': case '-':
*kbinput = KEY_PPAGE; return do_page_up;
break;
case 'E': case 'E':
case 'e': case 'e':
*kbinput = sc_seq_or(do_exit, 0); return do_exit;
break;
} }
} }
return func_from_key(kbinput);
} }
/* Calculate the next line of help_text, starting at ptr. */ /* Calculate the next line of help_text, starting at ptr. */

View File

@ -146,7 +146,7 @@ typedef void (*functionptrtype)(void);
char *do_browser(char *path, DIR *dir); char *do_browser(char *path, DIR *dir);
char *do_browse_from(const char *inpath); 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); functionptrtype parse_browser_input(int *kbinput);
void browser_refresh(void); void browser_refresh(void);
bool browser_select_filename(const char *needle); bool browser_select_filename(const char *needle);
int filesearch_init(void); int filesearch_init(void);
@ -375,7 +375,7 @@ void thanks_for_all_the_fish(void);
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
void do_help(void (*refresh_func)(void)); void do_help(void (*refresh_func)(void));
void help_init(void); void help_init(void);
void parse_help_input(int *kbinput); functionptrtype parse_help_input(int *kbinput);
size_t help_line_len(const char *ptr); size_t help_line_len(const char *ptr);
#endif #endif
void do_help_void(void); void do_help_void(void);