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/prompt.c (get_prompt_string, do_prompt): Use the new
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>
* 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. */
size_t old_selected;
/* The selected file we had before the current selected file. */
const sc *s;
const subnfunc *f;
functionptrtype func;
/* The function of the key the user typed in. */
curs_set(0);
blank_statusbar();
@ -156,45 +156,39 @@ char *do_browser(char *path, DIR *dir)
}
#endif /* !DISABLE_MOUSE */
parse_browser_input(&kbinput);
s = get_shortcut(&kbinput);
if (!s)
continue;
f = sctofunc((sc *) s);
if (!f)
break;
func = parse_browser_input(&kbinput);
if (f->scfunc == total_refresh) {
if (func == total_refresh) {
total_redraw();
} else if (f->scfunc == do_help_void) {
} else if (func == do_help_void) {
#ifndef DISABLE_HELP
do_help_void();
curs_set(0);
#else
nano_disabled_msg();
#endif
} else if (f->scfunc == do_search) {
} else if (func == do_search) {
/* Search for a filename. */
curs_set(1);
do_filesearch();
curs_set(0);
} else if (f->scfunc == do_research) {
} else if (func == do_research) {
/* Search for another filename. */
do_fileresearch();
} else if (f->scfunc == do_page_up) {
} else if (func == do_page_up) {
if (selected >= (editwinrows + fileline % editwinrows) * width)
selected -= (editwinrows + fileline % editwinrows) * width;
else
selected = 0;
} else if (f->scfunc == do_page_down) {
} else if (func == do_page_down) {
selected += (editwinrows - fileline % editwinrows) * width;
if (selected > filelist_len - 1)
selected = filelist_len - 1;
} else if (f->scfunc == do_first_file) {
} else if (func == do_first_file) {
selected = 0;
} else if (f->scfunc == do_last_file) {
} else if (func == do_last_file) {
selected = filelist_len - 1;
} else if (f->scfunc == goto_dir_void) {
} else if (func == goto_dir_void) {
/* Go to a specific directory. */
curs_set(1);
i = do_prompt(TRUE,
@ -271,19 +265,19 @@ char *do_browser(char *path, DIR *dir)
free(path);
path = new_path;
goto change_browser_directory;
} else if (f->scfunc == do_up_void) {
} else if (func == do_up_void) {
if (selected >= width)
selected -= width;
} else if (f->scfunc == do_left) {
} else if (func == do_left) {
if (selected > 0)
selected--;
} else if (f->scfunc == do_down_void) {
} else if (func == do_down_void) {
if (selected + width <= filelist_len - 1)
selected += width;
} else if (f->scfunc == do_right) {
} else if (func == do_right) {
if (selected < filelist_len - 1)
selected++;
} else if (f->scfunc == do_enter_void) {
} else if (func == do_enter_void) {
/* We can't move up from "/". */
if (strcmp(filelist[selected], "/..") == 0) {
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. */
goto change_browser_directory;
} else if (f->scfunc == do_exit) {
} else if (func == do_exit) {
/* Exit from the file browser. */
break;
}
@ -522,41 +516,33 @@ void browser_init(const char *path, DIR *dir)
width = longest;
}
/* Convert certain non-shortcut keys into their corresponding shortcut
* sequences, for compatibility with Pico. */
void parse_browser_input(int *kbinput)
/* Return the function that is bound to the given key, accepting certain
* plain characters too, for compatibility with Pico. */
functionptrtype parse_browser_input(int *kbinput)
{
if (!meta_key) {
switch (*kbinput) {
case ' ':
*kbinput = KEY_NPAGE;
break;
return do_page_down;
case '-':
*kbinput = KEY_PPAGE;
break;
return do_page_up;
case '?':
#ifndef DISABLE_HELP
*kbinput = sc_seq_or(do_help_void, 0);
#endif
break;
return do_help_void;
case 'E':
case 'e':
*kbinput = sc_seq_or(do_exit, 0);
break;
return do_exit;
case 'G':
case 'g':
*kbinput = sc_seq_or(goto_dir_void, 0);
break;
return goto_dir_void;
case 'S':
case 's':
*kbinput = sc_seq_or(do_enter_void, 0);
break;
return do_enter_void;
case 'W':
case 'w':
*kbinput = sc_seq_or(do_search, 0);
break;
return do_search;
}
}
return func_from_key(kbinput);
}
/* 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. */
size_t old_line = (size_t)-1;
/* The line we were on before the current line. */
const sc *s;
const subnfunc *f;
functionptrtype func;
/* The function of the key the user typed in. */
curs_set(0);
blank_edit();
@ -129,36 +129,30 @@ void do_help(void (*refresh_func)(void))
}
#endif
parse_help_input(&kbinput);
s = get_shortcut(&kbinput);
if (!s)
continue;
f = sctofunc((sc *) s);
if (!f)
continue;
func = parse_help_input(&kbinput);
if (f->scfunc == total_refresh) {
if (func == total_refresh) {
total_redraw();
} else if (f->scfunc == do_page_up) {
} else if (func == do_page_up) {
if (line > editwinrows - 2)
line -= editwinrows - 2;
else
line = 0;
} else if (f->scfunc == do_page_down) {
} else if (func == do_page_down) {
if (line + (editwinrows - 1) < last_line)
line += editwinrows - 2;
} else if (f->scfunc == do_up_void) {
} else if (func == do_up_void) {
if (line > 0)
line--;
} else if (f->scfunc == do_down_void) {
} else if (func == do_down_void) {
if (line + (editwinrows - 1) < last_line)
line++;
} else if (f->scfunc == do_first_line) {
} else if (func == do_first_line) {
line = 0;
} else if (f->scfunc == do_last_line) {
} else if (func == do_last_line) {
if (line + (editwinrows - 1) < last_line)
line = last_line - (editwinrows - 1);
} else if (f->scfunc == do_exit) {
} else if (func == do_exit) {
/* Exit from the help browser. */
break;
}
@ -467,25 +461,22 @@ void help_init(void)
assert(strlen(help_text) <= allocsize + 1);
}
/* Convert certain non-shortcut keys into their corresponding shortcut
* sequences. */
void parse_help_input(int *kbinput)
/* Return the function that is bound to the given key, accepting certain
* plain characters too, for consistency with the file browser. */
functionptrtype parse_help_input(int *kbinput)
{
if (!meta_key) {
switch (*kbinput) {
/* For consistency with the file browser. */
case ' ':
*kbinput = KEY_NPAGE;
break;
return do_page_down;
case '-':
*kbinput = KEY_PPAGE;
break;
return do_page_up;
case 'E':
case 'e':
*kbinput = sc_seq_or(do_exit, 0);
break;
return do_exit;
}
}
return func_from_key(kbinput);
}
/* 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_browse_from(const char *inpath);
void browser_init(const char *path, DIR *dir);
void parse_browser_input(int *kbinput);
functionptrtype parse_browser_input(int *kbinput);
void browser_refresh(void);
bool browser_select_filename(const char *needle);
int filesearch_init(void);
@ -375,7 +375,7 @@ void thanks_for_all_the_fish(void);
#ifndef DISABLE_HELP
void do_help(void (*refresh_func)(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);
#endif
void do_help_void(void);