>From 2abfa429a93a503b1b2e5c7237eb60e625463072 Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Wed, 29 Aug 2018 21:51:08 -0600 Subject: [PATCH 1/3] move menu shortcut processing to separate functions Signed-off-by: Brand Huntsman --- src/browser.c | 363 ++++++++++++++++++++++++++++++++-------------------------- src/help.c | 101 +++++++++------- src/nano.c | 185 ++++++++++++++++-------------- src/prompt.c | 108 +++++++++-------- 4 files changed, 419 insertions(+), 338 deletions(-) diff --git a/src/browser.c b/src/browser.c index 460e10be..61c8ab09 100644 --- a/src/browser.c +++ b/src/browser.c @@ -39,6 +39,183 @@ static size_t longest = 0; static size_t selected = 0; /* The currently selected filename in the list; zero-based. */ +#define DBS_CONTINUE 2 +#define DBS_GOTO_READ_DIRECTORY_CONTENTS 3 + +static char **dbs_path; +static char **dbs_retval; +static int *dbs_kbinput; +static char **dbs_present_name; + +/* Process browser shortcut functions. */ +static int do_browser_shortcuts(const sc *shortcut) +{ + if (shortcut->func == total_refresh) { + total_redraw(); +#ifndef NANO_TINY + /* Simulate a window resize to force a directory reread. */ + *dbs_kbinput = KEY_WINCH; +#endif + } else if (shortcut->func == do_help_void) { +#ifdef ENABLE_HELP + do_help_void(); +#ifndef NANO_TINY + /* The window dimensions might have changed, so act as if. */ + *dbs_kbinput = KEY_WINCH; +#endif +#else + say_there_is_no_help(); +#endif + } else if (shortcut->func == do_search_forward) { + do_filesearch(FORWARD); + } else if (shortcut->func == do_search_backward) { + do_filesearch(BACKWARD); + } else if (shortcut->func == do_findprevious) { + do_fileresearch(BACKWARD); + } else if (shortcut->func == do_findnext) { + do_fileresearch(FORWARD); + } else if (shortcut->func == do_left) { + if (selected > 0) + selected--; + } else if (shortcut->func == do_right) { + if (selected < filelist_len - 1) + selected++; + } else if (shortcut->func == do_prev_word_void) { + selected -= (selected % width); + } else if (shortcut->func == do_next_word_void) { + selected += width - 1 - (selected % width); + if (selected >= filelist_len) + selected = filelist_len - 1; + } else if (shortcut->func == do_up) { + if (selected >= width) + selected -= width; + } else if (shortcut->func == do_down) { + if (selected + width <= filelist_len - 1) + selected += width; + } else if (shortcut->func == do_prev_block) { + selected = ((selected / (editwinrows * width)) * + editwinrows * width) + selected % width; + } else if (shortcut->func == do_next_block) { + selected = ((selected / (editwinrows * width)) * + editwinrows * width) + selected % width + + editwinrows * width - width; + if (selected >= filelist_len) + selected = (filelist_len / width) * width + selected % width; + if (selected >= filelist_len) + selected -= width; + } else if (shortcut->func == do_page_up) { + if (selected < width) + selected = 0; + else if (selected < editwinrows * width) + selected = selected % width; + else + selected -= editwinrows * width; + } else if (shortcut->func == do_page_down) { + if (selected + width >= filelist_len - 1) + selected = filelist_len - 1; + else if (selected + editwinrows * width >= filelist_len) + selected = (selected + editwinrows * width - filelist_len) % + width + filelist_len - width; + else + selected += editwinrows * width; + } else if (shortcut->func == to_first_file) { + selected = 0; + } else if (shortcut->func == to_last_file) { + selected = filelist_len - 1; + } else if (shortcut->func == goto_dir_void) { + /* Ask for the directory to go to. */ + int i = do_prompt(TRUE, FALSE, MGOTODIR, NULL, NULL, + /* TRANSLATORS: This is a prompt. */ + browser_refresh, _("Go To Directory")); + + if (i < 0) { + statusbar(_("Cancelled")); + return DBS_CONTINUE; + } + + *dbs_path = free_and_assign(*dbs_path, real_dir_from_tilde(answer)); + + /* If the given path is relative, join it with the current path. */ + if (**dbs_path != '/') { + *dbs_path = charealloc(*dbs_path, strlen(present_path) + + strlen(answer) + 1); + sprintf(*dbs_path, "%s%s", present_path, answer); + } + +#ifdef ENABLE_OPERATINGDIR + if (outside_of_confinement(*dbs_path, FALSE)) { + /* TRANSLATORS: This refers to the confining effect of the + * option --operatingdir, not of --restricted. */ + statusline(ALERT, _("Can't go outside of %s"), operating_dir); + *dbs_path = mallocstrcpy(*dbs_path, present_path); + return DBS_CONTINUE; + } +#endif + /* Snip any trailing slashes, so the name can be compared. */ + while (strlen(*dbs_path) > 1 && *dbs_path[strlen(*dbs_path) - 1] == '/') + *dbs_path[strlen(*dbs_path) - 1] = '\0'; + + /* In case the specified directory cannot be entered, select it + * (if it is in the current list) so it will be highlighted. */ + for (size_t j = 0; j < filelist_len; j++) + if (strcmp(filelist[j], *dbs_path) == 0) + selected = j; + + /* Try opening and reading the specified directory. */ + return DBS_GOTO_READ_DIRECTORY_CONTENTS; + } else if (shortcut->func == do_enter) { + struct stat st; + + /* It isn't possible to move up from the root directory. */ + if (strcmp(filelist[selected], "/..") == 0) { + statusline(ALERT, _("Can't move up a directory")); + return DBS_CONTINUE; + } + +#ifdef ENABLE_OPERATINGDIR + /* Note: The selected file can be outside the operating + * directory if it's ".." or if it's a symlink to a + * directory outside the operating directory. */ + if (outside_of_confinement(filelist[selected], FALSE)) { + statusline(ALERT, _("Can't go outside of %s"), operating_dir); + return DBS_CONTINUE; + } +#endif + /* If for some reason the file is inaccessible, complain. */ + if (stat(filelist[selected], &st) == -1) { + statusline(ALERT, _("Error reading %s: %s"), + filelist[selected], strerror(errno)); + return DBS_CONTINUE; + } + + /* If it isn't a directory, a file was selected -- we're done. */ + if (!S_ISDIR(st.st_mode)) { + *dbs_retval = mallocstrcpy(NULL, filelist[selected]); + return 1; + } + + /* If we are moving up one level, remember where we came from, so + * this directory can be highlighted and easily reentered. */ + if (strcmp(tail(filelist[selected]), "..") == 0) + *dbs_present_name = strip_last_component(filelist[selected]); + + /* Try opening and reading the selected directory. */ + *dbs_path = mallocstrcpy(*dbs_path, filelist[selected]); + return DBS_GOTO_READ_DIRECTORY_CONTENTS; +#ifdef ENABLE_NANORC + } else if (shortcut->func == (functionptrtype)implant) { + implant(shortcut->expansion); +#endif + } else if (shortcut->func == do_exit) { + /* Exit from the file browser. */ + return 1; + } else + /* Unbound key. */ + return -1; + + return 0; +} + /* Our main file browser function. path is the tilde-expanded path we * start browsing from. */ char *do_browser(char *path) @@ -54,6 +231,12 @@ char *do_browser(char *path) /* The function of the key the user typed in. */ DIR *dir; /* The directory whose contents we are showing. */ + const sc *shortcut; + + dbs_path = &path; + dbs_retval = &retval; + dbs_kbinput = &kbinput; + dbs_present_name = &present_name; read_directory_contents: /* We come here when we refresh or select a new directory. */ @@ -148,172 +331,28 @@ char *do_browser(char *path) #endif /* ENABLE_MOUSE */ func = parse_browser_input(&kbinput); + shortcut = first_sc_for(MBROWSER, func); + /* If a function listed in parse_browser_input() is unbound from all + * keys in browser menu, no shortcut will be found and the key will + * fail to work. */ - if (func == total_refresh) { - total_redraw(); #ifndef NANO_TINY - /* Simulate a window resize to force a directory reread. */ - kbinput = KEY_WINCH; -#endif - } else if (func == do_help_void) { -#ifdef ENABLE_HELP - do_help_void(); -#ifndef NANO_TINY - /* The window dimensions might have changed, so act as if. */ - kbinput = KEY_WINCH; -#endif -#else - say_there_is_no_help(); -#endif - } else if (func == do_search_forward) { - do_filesearch(FORWARD); - } else if (func == do_search_backward) { - do_filesearch(BACKWARD); - } else if (func == do_findprevious) { - do_fileresearch(BACKWARD); - } else if (func == do_findnext) { - do_fileresearch(FORWARD); - } else if (func == do_left) { - if (selected > 0) - selected--; - } else if (func == do_right) { - if (selected < filelist_len - 1) - selected++; - } else if (func == do_prev_word_void) { - selected -= (selected % width); - } else if (func == do_next_word_void) { - selected += width - 1 - (selected % width); - if (selected >= filelist_len) - selected = filelist_len - 1; - } else if (func == do_up) { - if (selected >= width) - selected -= width; - } else if (func == do_down) { - if (selected + width <= filelist_len - 1) - selected += width; - } else if (func == do_prev_block) { - selected = ((selected / (editwinrows * width)) * - editwinrows * width) + selected % width; - } else if (func == do_next_block) { - selected = ((selected / (editwinrows * width)) * - editwinrows * width) + selected % width + - editwinrows * width - width; - if (selected >= filelist_len) - selected = (filelist_len / width) * width + selected % width; - if (selected >= filelist_len) - selected -= width; - } else if (func == do_page_up) { - if (selected < width) - selected = 0; - else if (selected < editwinrows * width) - selected = selected % width; - else - selected -= editwinrows * width; - } else if (func == do_page_down) { - if (selected + width >= filelist_len - 1) - selected = filelist_len - 1; - else if (selected + editwinrows * width >= filelist_len) - selected = (selected + editwinrows * width - filelist_len) % - width + filelist_len - width; - else - selected += editwinrows * width; - } else if (func == to_first_file) { - selected = 0; - } else if (func == to_last_file) { - selected = filelist_len - 1; - } else if (func == goto_dir_void) { - /* Ask for the directory to go to. */ - int i = do_prompt(TRUE, FALSE, MGOTODIR, NULL, NULL, - /* TRANSLATORS: This is a prompt. */ - browser_refresh, _("Go To Directory")); - - if (i < 0) { - statusbar(_("Cancelled")); - continue; - } - - path = free_and_assign(path, real_dir_from_tilde(answer)); - - /* If the given path is relative, join it with the current path. */ - if (*path != '/') { - path = charealloc(path, strlen(present_path) + - strlen(answer) + 1); - sprintf(path, "%s%s", present_path, answer); - } - -#ifdef ENABLE_OPERATINGDIR - if (outside_of_confinement(path, FALSE)) { - /* TRANSLATORS: This refers to the confining effect of the - * option --operatingdir, not of --restricted. */ - statusline(ALERT, _("Can't go outside of %s"), operating_dir); - path = mallocstrcpy(path, present_path); - continue; - } -#endif - /* Snip any trailing slashes, so the name can be compared. */ - while (strlen(path) > 1 && path[strlen(path) - 1] == '/') - path[strlen(path) - 1] = '\0'; - - /* In case the specified directory cannot be entered, select it - * (if it is in the current list) so it will be highlighted. */ - for (size_t j = 0; j < filelist_len; j++) - if (strcmp(filelist[j], path) == 0) - selected = j; - - /* Try opening and reading the specified directory. */ - goto read_directory_contents; - } else if (func == do_enter) { - struct stat st; - - /* It isn't possible to move up from the root directory. */ - if (strcmp(filelist[selected], "/..") == 0) { - statusline(ALERT, _("Can't move up a directory")); - continue; - } - -#ifdef ENABLE_OPERATINGDIR - /* Note: The selected file can be outside the operating - * directory if it's ".." or if it's a symlink to a - * directory outside the operating directory. */ - if (outside_of_confinement(filelist[selected], FALSE)) { - statusline(ALERT, _("Can't go outside of %s"), operating_dir); - continue; - } -#endif - /* If for some reason the file is inaccessible, complain. */ - if (stat(filelist[selected], &st) == -1) { - statusline(ALERT, _("Error reading %s: %s"), - filelist[selected], strerror(errno)); - continue; - } - - /* If it isn't a directory, a file was selected -- we're done. */ - if (!S_ISDIR(st.st_mode)) { - retval = mallocstrcpy(NULL, filelist[selected]); - break; - } - - /* If we are moving up one level, remember where we came from, so - * this directory can be highlighted and easily reentered. */ - if (strcmp(tail(filelist[selected]), "..") == 0) - present_name = strip_last_component(filelist[selected]); - - /* Try opening and reading the selected directory. */ - path = mallocstrcpy(path, filelist[selected]); - goto read_directory_contents; -#ifdef ENABLE_NANORC - } else if (func == (functionptrtype)implant) { - implant(first_sc_for(MBROWSER, func)->expansion); -#endif - } else if (func == do_exit) { - /* Exit from the file browser. */ - break; -#ifndef NANO_TINY - } else if (kbinput == KEY_WINCH) { + if (kbinput == KEY_WINCH) { ; -#endif } else - unbound_key(kbinput); +#endif + { + int result = (shortcut ? do_browser_shortcuts(shortcut) : -1); + if (result == -1) + unbound_key(kbinput); + else if (result == 1) + /* Exit from the file browser. */ + break; + else if (result == DBS_CONTINUE) + continue; + else if (result == DBS_GOTO_READ_DIRECTORY_CONTENTS) + goto read_directory_contents; + } #ifndef NANO_TINY /* If the window resized, refresh the file list. */ diff --git a/src/help.c b/src/help.c index 0a3f1552..094391a7 100644 --- a/src/help.c +++ b/src/help.c @@ -91,6 +91,51 @@ void wrap_the_help_text(bool redisplaying) openfile->edittop = openfile->current; } +/* Process help shortcut functions. */ +static int do_help_shortcuts(const sc *shortcut) +{ + if (shortcut->func == total_refresh) { + total_redraw(); + } else if (shortcut->func == do_up) { + do_scroll_up(); + } else if (shortcut->func == do_down) { + if (openfile->edittop->lineno + editwinrows - 1 < + openfile->filebot->lineno) + do_scroll_down(); + } else if (shortcut->func == do_page_up) { + do_page_up(); + } else if (shortcut->func == do_page_down) { + do_page_down(); + } else if (shortcut->func == to_first_line) { + to_first_line(); + } else if (shortcut->func == to_last_line) { + to_last_line(); + } else if (shortcut->func == do_search_forward) { + do_search_forward(); + bottombars(MHELP); + } else if (shortcut->func == do_search_backward) { + do_search_backward(); + bottombars(MHELP); + } else if (shortcut->func == do_findprevious) { + do_findprevious(); + } else if (shortcut->func == do_findnext) { + do_findnext(); +#ifdef ENABLE_NANORC + } else if (shortcut->func == (functionptrtype)implant) { + implant(shortcut->expansion); +#endif + } else if (shortcut->func == do_exit) { + /* Exit from the help viewer. */ + close_buffer(); + curs_set(0); + return 1; + } else + /* Unbound key. */ + return -1; + + return 0; +} + /* Our main help-viewer function. */ void do_help(void) { @@ -113,6 +158,7 @@ void do_help(void) filestruct *line; int length; FILE *fp; + const sc *shortcut; blank_statusbar(); @@ -187,53 +233,30 @@ void do_help(void) didfind = 0; func = parse_help_input(&kbinput); + shortcut = first_sc_for(MHELP, func); + /* If a function listed in parse_help_input() is unbound from all + * keys in help menu, no shortcut will be found and the key will + * fail to work. */ - if (func == total_refresh) { - total_redraw(); - } else if (func == do_up) { - do_scroll_up(); - } else if (func == do_down) { - if (openfile->edittop->lineno + editwinrows - 1 < - openfile->filebot->lineno) - do_scroll_down(); - } else if (func == do_page_up) { - do_page_up(); - } else if (func == do_page_down) { - do_page_down(); - } else if (func == to_first_line) { - to_first_line(); - } else if (func == to_last_line) { - to_last_line(); - } else if (func == do_search_forward) { - do_search_forward(); - bottombars(MHELP); - } else if (func == do_search_backward) { - do_search_backward(); - bottombars(MHELP); - } else if (func == do_findprevious) { - do_findprevious(); - } else if (func == do_findnext) { - do_findnext(); -#ifdef ENABLE_NANORC - } else if (func == (functionptrtype)implant) { - implant(first_sc_for(MHELP, func)->expansion); -#endif #ifndef NANO_TINY - } else if (kbinput == KEY_WINCH) { + if (kbinput == KEY_WINCH) { ; /* Nothing to do. */ + } else #endif #ifdef ENABLE_MOUSE - } else if (kbinput == KEY_MOUSE) { + if (kbinput == KEY_MOUSE) { int dummy_row, dummy_col; get_mouseinput(&dummy_row, &dummy_col, TRUE); -#endif - } else if (func == do_exit) { - /* Exit from the help viewer. */ - close_buffer(); - curs_set(0); - break; } else - unbound_key(kbinput); +#endif + { + int result = (shortcut ? do_help_shortcuts(shortcut) : -1); + if (result == -1) + unbound_key(kbinput); + else if (result == 1) + /* Exit from the help viewer. */ + break; + } currmenu = MHELP; edit_refresh(); diff --git a/src/nano.c b/src/nano.c index 9b5ee8aa..64c286db 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1662,6 +1662,101 @@ bool okay_for_view(const sc *shortcut) return (func != NULL && func->viewok); } +/* Process edit shortcut functions. */ +static int do_edit_shortcuts(const sc *shortcut) +{ + bool retain_cuts = FALSE; + /* Whether to conserve the current contents of the cutbuffer. */ + + if (ISSET(VIEW_MODE) && !okay_for_view(shortcut)) { + print_view_warning(); + return ERR; + } + + /* If the function associated with this shortcut is + * cutting or copying text, remember this. */ + if (shortcut->func == do_cut_text_void +#ifndef NANO_TINY + || shortcut->func == do_copy_text +#endif + ) + retain_cuts = TRUE; + +#ifdef ENABLE_WORDCOMPLETION + if (shortcut->func != complete_a_word) + pletion_line = NULL; +#endif +#ifdef ENABLE_NANORC + if (shortcut->func == (functionptrtype)implant) { + implant(shortcut->expansion); + return 42; + } +#endif +#ifndef NANO_TINY + if (shortcut->func == do_toggle_void) { + do_toggle(shortcut->toggle); + if (shortcut->toggle != CUT_FROM_CURSOR) + retain_cuts = TRUE; + } else +#endif + { +#ifdef ENABLE_WRAPPING + filestruct *was_next = openfile->current->next; +#endif +#ifndef NANO_TINY + filestruct *was_current = openfile->current; + size_t was_x = openfile->current_x; + + /* If Shifted movement occurs, set the mark. */ + if (shift_held && !openfile->mark) { + openfile->mark = openfile->current; + openfile->mark_x = openfile->current_x; + openfile->kind_of_mark = SOFTMARK; + } +#endif + /* Execute the function of the shortcut. */ + shortcut->func(); + +#ifndef NANO_TINY + /* When the marked region changes without Shift being held, + * discard a soft mark. And when the marked region covers a + * different set of lines, reset the "last line too" flag. */ + if (openfile->mark) { + if (!shift_held && openfile->kind_of_mark == SOFTMARK && + (openfile->current != was_current || + openfile->current_x != was_x || + wanted_to_move(shortcut->func))) { + openfile->mark = NULL; + refresh_needed = TRUE; + } else if (openfile->current != was_current) + also_the_last = FALSE; + } +#endif +#ifdef ENABLE_WRAPPING + /* If the cursor moved to another line and this was not caused + * by adding characters to the buffer, clear the prepend flag. */ + if (openfile->current->next != was_next && + shortcut->func != do_tab && + shortcut->func != do_verbatim_input) + wrap_reset(); +#endif +#ifdef ENABLE_COLOR + if (!refresh_needed && !okay_for_view(shortcut)) + check_the_multis(openfile->current); +#endif + if (!refresh_needed && (shortcut->func == do_delete || + shortcut->func == do_backspace)) + update_line(openfile->current, openfile->current_x); + } + + /* If we aren't cutting or copying text, and the key wasn't a toggle, + * blow away the text in the cutbuffer upon the next cutting action. */ + if (!retain_cuts) + cutbuffer_reset(); + + return 0; +} + /* Read in a keystroke. Act on the keystroke if it is a shortcut or a toggle; * otherwise, insert it into the edit buffer. If allow_funcs is FALSE, don't * do anything with the keystroke -- just return it. */ @@ -1673,8 +1768,6 @@ int do_input(bool allow_funcs) /* The input buffer for actual characters. */ static size_t depth = 0; /* The length of the input buffer. */ - bool retain_cuts = FALSE; - /* Whether to conserve the current contents of the cutbuffer. */ const sc *shortcut; /* Read in a keystroke, and show the cursor while waiting. */ @@ -1753,93 +1846,11 @@ int do_input(bool allow_funcs) if (shortcut == NULL) pletion_line = NULL; else { - if (ISSET(VIEW_MODE) && !okay_for_view(shortcut)) { - print_view_warning(); - return ERR; - } - - /* If the function associated with this shortcut is - * cutting or copying text, remember this. */ - if (shortcut->func == do_cut_text_void -#ifndef NANO_TINY - || shortcut->func == do_copy_text -#endif - ) - retain_cuts = TRUE; - -#ifdef ENABLE_WORDCOMPLETION - if (shortcut->func != complete_a_word) - pletion_line = NULL; -#endif -#ifdef ENABLE_NANORC - if (shortcut->func == (functionptrtype)implant) { - implant(shortcut->expansion); - return 42; - } -#endif -#ifndef NANO_TINY - if (shortcut->func == do_toggle_void) { - do_toggle(shortcut->toggle); - if (shortcut->toggle != CUT_FROM_CURSOR) - retain_cuts = TRUE; - } else -#endif - { -#ifdef ENABLE_WRAPPING - filestruct *was_next = openfile->current->next; -#endif -#ifndef NANO_TINY - filestruct *was_current = openfile->current; - size_t was_x = openfile->current_x; - - /* If Shifted movement occurs, set the mark. */ - if (shift_held && !openfile->mark) { - openfile->mark = openfile->current; - openfile->mark_x = openfile->current_x; - openfile->kind_of_mark = SOFTMARK; - } -#endif - /* Execute the function of the shortcut. */ - shortcut->func(); - -#ifndef NANO_TINY - /* When the marked region changes without Shift being held, - * discard a soft mark. And when the marked region covers a - * different set of lines, reset the "last line too" flag. */ - if (openfile->mark) { - if (!shift_held && openfile->kind_of_mark == SOFTMARK && - (openfile->current != was_current || - openfile->current_x != was_x || - wanted_to_move(shortcut->func))) { - openfile->mark = NULL; - refresh_needed = TRUE; - } else if (openfile->current != was_current) - also_the_last = FALSE; - } -#endif -#ifdef ENABLE_WRAPPING - /* If the cursor moved to another line and this was not caused - * by adding characters to the buffer, clear the prepend flag. */ - if (openfile->current->next != was_next && - shortcut->func != do_tab && - shortcut->func != do_verbatim_input) - wrap_reset(); -#endif -#ifdef ENABLE_COLOR - if (!refresh_needed && !okay_for_view(shortcut)) - check_the_multis(openfile->current); -#endif - if (!refresh_needed && (shortcut->func == do_delete || - shortcut->func == do_backspace)) - update_line(openfile->current, openfile->current_x); - } + int result = do_edit_shortcuts(shortcut); + if (result) + return result; } - /* If we aren't cutting or copying text, and the key wasn't a toggle, - * blow away the text in the cutbuffer upon the next cutting action. */ - if (!retain_cuts) - cutbuffer_reset(); - return input; } diff --git a/src/prompt.c b/src/prompt.c index e3e394ef..08ba5230 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -50,6 +50,62 @@ int do_statusbar_mouse(void) } #endif +/* Process statusbar shortcut functions. */ +static int do_statusbar_shortcuts(const sc *shortcut) +{ + if (shortcut->func == do_tab || shortcut->func == do_enter) + ; + else if (shortcut->func == do_left) + do_statusbar_left(); + else if (shortcut->func == do_right) + do_statusbar_right(); +#ifndef NANO_TINY + else if (shortcut->func == do_prev_word_void) + do_statusbar_prev_word(); + else if (shortcut->func == do_next_word_void) + do_statusbar_next_word(); +#endif + else if (shortcut->func == do_home) + do_statusbar_home(); + else if (shortcut->func == do_end) + do_statusbar_end(); + /* When in restricted mode at the "Write File" prompt and the + * filename isn't blank, disallow any input and deletion. */ + else if (ISSET(RESTRICTED) && currmenu == MWRITEFILE && + openfile->filename[0] != '\0' && + (shortcut->func == do_verbatim_input || + shortcut->func == do_cut_text_void || + shortcut->func == do_uncut_text || + shortcut->func == do_delete || + shortcut->func == do_backspace)) + ; +#ifdef ENABLE_NANORC + else if (shortcut->func == (functionptrtype)implant) + implant(shortcut->expansion); +#endif + else if (shortcut->func == do_verbatim_input) + do_statusbar_verbatim_input(); + else if (shortcut->func == do_cut_text_void) + do_statusbar_cut_text(); + else if (shortcut->func == do_delete) + do_statusbar_delete(); + else if (shortcut->func == do_backspace) + do_statusbar_backspace(); + else if (shortcut->func == do_uncut_text) { + if (cutbuffer != NULL) + do_statusbar_uncut_text(); + } else { + /* Handle any other shortcut in the current menu, setting finished + * to TRUE to indicate that we're done after running or trying to + * run its associated function. */ + if (!ISSET(VIEW_MODE) || okay_for_view(shortcut)) + shortcut->func(); + return 1; + } + + return 0; +} + /* Read in a keystroke, interpret it if it is a shortcut or toggle, and * return it. Set finished to TRUE if we're done after running * or trying to run a function associated with a shortcut key. */ @@ -123,57 +179,9 @@ int do_statusbar_input(bool *finished) kbinput = NULL; } - if (shortcut) { - if (shortcut->func == do_tab || shortcut->func == do_enter) - ; - else if (shortcut->func == do_left) - do_statusbar_left(); - else if (shortcut->func == do_right) - do_statusbar_right(); -#ifndef NANO_TINY - else if (shortcut->func == do_prev_word_void) - do_statusbar_prev_word(); - else if (shortcut->func == do_next_word_void) - do_statusbar_next_word(); -#endif - else if (shortcut->func == do_home) - do_statusbar_home(); - else if (shortcut->func == do_end) - do_statusbar_end(); - /* When in restricted mode at the "Write File" prompt and the - * filename isn't blank, disallow any input and deletion. */ - else if (ISSET(RESTRICTED) && currmenu == MWRITEFILE && - openfile->filename[0] != '\0' && - (shortcut->func == do_verbatim_input || - shortcut->func == do_cut_text_void || - shortcut->func == do_uncut_text || - shortcut->func == do_delete || - shortcut->func == do_backspace)) - ; -#ifdef ENABLE_NANORC - else if (shortcut->func == (functionptrtype)implant) - implant(shortcut->expansion); -#endif - else if (shortcut->func == do_verbatim_input) - do_statusbar_verbatim_input(); - else if (shortcut->func == do_cut_text_void) - do_statusbar_cut_text(); - else if (shortcut->func == do_delete) - do_statusbar_delete(); - else if (shortcut->func == do_backspace) - do_statusbar_backspace(); - else if (shortcut->func == do_uncut_text) { - if (cutbuffer != NULL) - do_statusbar_uncut_text(); - } else { - /* Handle any other shortcut in the current menu, setting finished - * to TRUE to indicate that we're done after running or trying to - * run its associated function. */ - if (!ISSET(VIEW_MODE) || okay_for_view(shortcut)) - shortcut->func(); + if (shortcut) + if (do_statusbar_shortcuts(shortcut)) *finished = TRUE; - } - } return input; } -- 2.16.4