static void search(int backward) { if(menu->regexp != NULL) { int was_msg; menu->match_dir = backward ? UP : DOWN; was_msg = search_menu_list(NULL, menu); wrefresh(menu_win); if(!was_msg) status_bar_messagef("%c%s", backward ? '?' : '/', menu->regexp); } else { status_bar_error("No search pattern set"); } curr_stats.save_msg = 1; }
void menus_search(menu_state_t *m, int backward) { if(m->regexp == NULL) { status_bar_error("No search pattern set"); curr_stats.save_msg = 1; return; } m->backward_search = backward; (void)search_menu_list(NULL, m->d, 1); wrefresh(menu_win); if(m->matching_entries > 0) { status_bar_messagef("(%d of %d) %c%s", get_match_index(m), m->matching_entries, backward ? '?' : '/', m->regexp); } curr_stats.save_msg = 1; }
static void cmd_ctrl_m(key_info_t key_info, keys_info_t *keys_info) { char* p; int save_hist = !keys_info->mapped; stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if((!input_stat.line || !input_stat.line[0]) && sub_mode == MENU_CMD_SUBMODE) { leave_cmdline_mode(); return; } p = input_stat.line ? to_multibyte(input_stat.line) : NULL; leave_cmdline_mode(); if(prev_mode == VISUAL_MODE && sub_mode != VSEARCH_FORWARD_SUBMODE && sub_mode != VSEARCH_BACKWARD_SUBMODE) leave_visual_mode(curr_stats.save_msg, 1, 0); if(sub_mode == CMD_SUBMODE || sub_mode == MENU_CMD_SUBMODE) { char* s = (p != NULL) ? p : ""; while(*s == ' ' || *s == ':') s++; if(sub_mode == CMD_SUBMODE) curr_stats.save_msg = exec_commands(s, curr_view, save_hist, GET_COMMAND); else curr_stats.save_msg = exec_commands(s, curr_view, save_hist, GET_MENU_COMMAND); } else if(sub_mode == PROMPT_SUBMODE) { prompt_cb cb; if(p != NULL && p[0] != '\0') save_prompt_history(p); modes_post(); modes_pre(); cb = (prompt_cb)sub_mode_ptr; cb(p); } else if(!cfg.inc_search || prev_mode == VIEW_MODE) { if(sub_mode == SEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_FSEARCH_PATTERN); } else if(sub_mode == SEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_BSEARCH_PATTERN); } else if(sub_mode == MENU_SEARCH_FORWARD_SUBMODE || sub_mode == MENU_SEARCH_BACKWARD_SUBMODE) { curr_stats.need_redraw = 1; search_menu_list(p, sub_mode_ptr); } else if(sub_mode == VSEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VFSEARCH_PATTERN); } else if(sub_mode == VSEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VBSEARCH_PATTERN); } else if(sub_mode == VIEW_SEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VWFSEARCH_PATTERN); } else if(sub_mode == VIEW_SEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VWBSEARCH_PATTERN); } } free(p); }
static void input_line_changed(void) { static wchar_t *previous; if(!cfg.inc_search || !input_stat.search_mode) return; if(prev_mode != MENU_MODE) { curr_view->top_line = input_stat.old_top; curr_view->list_pos = input_stat.old_pos; } else { load_menu_pos(); } if(input_stat.line == NULL || input_stat.line[0] == L'\0') { if(cfg.hl_search) { clean_selected_files(curr_view); draw_dir_list(curr_view, curr_view->top_line); move_to_list_pos(curr_view, curr_view->list_pos); } free(previous); previous = NULL; } else if(previous == NULL || wcscmp(previous, input_stat.line) != 0) { char *p; free(previous); previous = my_wcsdup(input_stat.line); p = to_multibyte(input_stat.line); if(sub_mode == SEARCH_FORWARD_SUBMODE) exec_command(p, curr_view, GET_FSEARCH_PATTERN); else if(sub_mode == SEARCH_BACKWARD_SUBMODE) exec_command(p, curr_view, GET_BSEARCH_PATTERN); else if(sub_mode == MENU_SEARCH_FORWARD_SUBMODE || sub_mode == MENU_SEARCH_BACKWARD_SUBMODE) search_menu_list(p, sub_mode_ptr); else if(sub_mode == VSEARCH_FORWARD_SUBMODE) exec_command(p, curr_view, GET_VFSEARCH_PATTERN); else if(sub_mode == VSEARCH_BACKWARD_SUBMODE) exec_command(p, curr_view, GET_VBSEARCH_PATTERN); free(p); } if(prev_mode != MENU_MODE) { draw_dir_list(curr_view, curr_view->top_line); move_to_list_pos(curr_view, curr_view->list_pos); } else { menu_redraw(); } }
/* Callback-like function, which is called every time input line is changed. */ static void input_line_changed(void) { static wchar_t *previous; if(!cfg.inc_search || (!input_stat.search_mode && sub_mode != FILTER_SUBMODE)) return; set_view_port(); if(input_stat.line == NULL || input_stat.line[0] == L'\0') { if(cfg.hl_search) { /* clear selection */ if(prev_mode != MENU_MODE) { clean_selected_files(curr_view); } else { search_menu_list("", sub_mode_ptr); } } free(previous); previous = NULL; if(sub_mode == FILTER_SUBMODE) { set_local_filter(""); } } else if(previous == NULL || wcscmp(previous, input_stat.line) != 0) { char *mbinput; free(previous); previous = my_wcsdup(input_stat.line); mbinput = to_multibyte(input_stat.line); switch(sub_mode) { case SEARCH_FORWARD_SUBMODE: exec_command(mbinput, curr_view, GET_FSEARCH_PATTERN); break; case SEARCH_BACKWARD_SUBMODE: exec_command(mbinput, curr_view, GET_BSEARCH_PATTERN); break; case VSEARCH_FORWARD_SUBMODE: exec_command(mbinput, curr_view, GET_VFSEARCH_PATTERN); break; case VSEARCH_BACKWARD_SUBMODE: exec_command(mbinput, curr_view, GET_VBSEARCH_PATTERN); break; case MENU_SEARCH_FORWARD_SUBMODE: case MENU_SEARCH_BACKWARD_SUBMODE: search_menu_list(mbinput, sub_mode_ptr); break; case FILTER_SUBMODE: set_local_filter(mbinput); break; default: assert("Unexpected filter type."); break; } free(mbinput); } if(prev_mode != MENU_MODE && prev_mode != VISUAL_MODE) { redraw_current_view(); } else if(prev_mode != VISUAL_MODE) { menu_redraw(); } }
static void cmd_ctrl_m(key_info_t key_info, keys_info_t *keys_info) { /* TODO: refactor this cmd_ctrl_m() function. */ char* p; stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if((!input_stat.line || !input_stat.line[0]) && sub_mode == MENU_CMD_SUBMODE) { leave_cmdline_mode(); return; } p = input_stat.line ? to_multibyte(input_stat.line) : NULL; leave_cmdline_mode(); if(prev_mode == VISUAL_MODE && sub_mode != VSEARCH_FORWARD_SUBMODE && sub_mode != VSEARCH_BACKWARD_SUBMODE) leave_visual_mode(curr_stats.save_msg, 1, 0); save_input_to_history(keys_info, p); if(sub_mode == CMD_SUBMODE || sub_mode == MENU_CMD_SUBMODE) { char* s = (p != NULL) ? p : ""; while(*s == ' ' || *s == ':') s++; if(sub_mode == CMD_SUBMODE) curr_stats.save_msg = exec_commands(s, curr_view, GET_COMMAND); else curr_stats.save_msg = exec_commands(s, curr_view, GET_MENU_COMMAND); } else if(sub_mode == PROMPT_SUBMODE) { finish_prompt_submode(p); } else if(sub_mode == FILTER_SUBMODE) { if(cfg.inc_search) { local_filter_accept(curr_view); } else { local_filter_apply(curr_view, p); load_saving_pos(curr_view, 1); } } else if(!cfg.inc_search || prev_mode == VIEW_MODE) { switch(sub_mode) { case SEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_FSEARCH_PATTERN); break; case SEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_BSEARCH_PATTERN); break; case VSEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VFSEARCH_PATTERN); break; case VSEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VBSEARCH_PATTERN); break; case VIEW_SEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VWFSEARCH_PATTERN); break; case VIEW_SEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VWBSEARCH_PATTERN); break; case MENU_SEARCH_FORWARD_SUBMODE: case MENU_SEARCH_BACKWARD_SUBMODE: curr_stats.need_update = UT_FULL; search_menu_list(p, sub_mode_ptr); break; default: assert(0 && "Unknown command line submode."); break; } } else if(cfg.inc_search && input_stat.search_mode) { /* In case of successful search and 'hlsearch' option set, a message like * "n files selected" is printed automatically. */ if(curr_view->matches == 0 || !cfg.hl_search) { print_search_msg(curr_view, is_backward_search(sub_mode)); curr_stats.save_msg = 1; } } free(p); }