int show_undolist_menu(FileView *view, int with_details) { char **p; size_t len; static menu_info m; init_menu_info(&m, UNDOLIST_MENU, strdup("Undolist is empty")); m.current = get_undolist_pos(with_details) + 1; m.pos = m.current - 1; m.title = strdup(" Undolist "); m.items = undolist(with_details); p = m.items; while(*p++ != NULL) m.len++; if(m.len > 0) { m.len = add_to_string_array(&m.items, m.len, 1, "list end"); /* Add current position mark to menu item. */ len = (m.items[m.pos] != NULL) ? strlen(m.items[m.pos]) : 0; m.items[m.pos] = realloc(m.items[m.pos], len + 1 + 1); memmove(m.items[m.pos] + 1, m.items[m.pos], len + 1); m.items[m.pos][0] = '*'; } return display_menu(&m, view); }
int show_volumes_menu(FileView *view) { TCHAR c; TCHAR vol_name[MAX_PATH]; TCHAR file_buf[MAX_PATH]; static menu_info m; init_menu_info(&m, VOLUMES, strdup("No volumes mounted")); m.title = strdup(" Mounted Volumes "); for(c = TEXT('a'); c < TEXT('z'); c++) { if(drive_exists(c)) { TCHAR drive[] = TEXT("?:\\"); drive[0] = c; if(GetVolumeInformation(drive, vol_name, MAX_PATH, NULL, NULL, NULL, file_buf, MAX_PATH)) { char item_buf[MAX_PATH + 5]; snprintf(item_buf, sizeof(item_buf), "%s %s ", drive, vol_name); m.len = add_to_string_array(&m.items, m.len, 1, item_buf); } } } return display_menu(&m, view); }
int show_bmarks_menu(FileView *view, const char tags[], int go_on_single_match) { static menu_info m; init_menu_info(&m, strdup("Bookmarks"), strdup("No bookmarks found")); m.execute_handler = &execute_bmarks_cb; m.key_handler = &bmarks_khandler; if(is_null_or_empty(tags)) { bmarks_list(&bmarks_cb, &m); } else { bmarks_find(tags, &bmarks_cb, &m); } if(go_on_single_match && m.len == 1) { goto_selected_file(view, m.items[m.pos], 0); reset_popup_menu(&m); return curr_stats.save_msg; } return display_menu(&m, view); }
SETUP() { init_menu_info(&m, strdup("test"), strdup("No matches")); m.search_repeat = 1; m.len = add_to_string_array(&m.items, m.len, 1, "a"); m.len = add_to_string_array(&m.items, m.len, 1, "b"); m.len = add_to_string_array(&m.items, m.len, 1, "c"); }
int show_user_menu(FileView *view, const char command[], int navigate) { static menu_info m; const int menu_type = navigate ? USER_NAVIGATE : USER; init_menu_info(&m, menu_type, strdup("No results found")); m.title = strdup(command); return capture_output_to_menu(view, command, &m); }
int show_jobs_menu(FileView *view) { job_t *p; int i; static menu_info m; init_menu_info(&m, strdup("Pid --- Command"), strdup("No jobs currently running")); m.execute_handler = &execute_jobs_cb; check_background_jobs(); bg_jobs_freeze(); p = jobs; i = 0; while(p != NULL) { if(p->running) { char info_buf[24]; char item_buf[sizeof(info_buf) + strlen(p->cmd)]; if(p->type == BJT_COMMAND) { snprintf(info_buf, sizeof(info_buf), "%" PRINTF_ULL, (unsigned long long)p->pid); } else if(p->bg_op.total == BG_UNDEFINED_TOTAL) { snprintf(info_buf, sizeof(info_buf), "n/a"); } else { snprintf(info_buf, sizeof(info_buf), "%d/%d", p->bg_op.done + 1, p->bg_op.total); } snprintf(item_buf, sizeof(item_buf), "%-8s %s", info_buf, p->cmd); i = add_to_string_array(&m.items, i, 1, item_buf); } p = p->next; } bg_jobs_unfreeze(); m.len = i; return display_menu(&m, view); }
int show_jobs_menu(FileView *view) { job_t *p; #ifndef _WIN32 sigset_t new_mask; #endif int i; static menu_info m; init_menu_info(&m, JOBS, strdup("No jobs currently running")); m.title = strdup(" Pid --- Command "); /* * SIGCHLD needs to be blocked anytime the finished_jobs list * is accessed from anywhere except the received_sigchld(). */ #ifndef _WIN32 sigemptyset(&new_mask); sigaddset(&new_mask, SIGCHLD); sigprocmask(SIG_BLOCK, &new_mask, NULL); #else check_background_jobs(); #endif p = jobs; i = 0; while(p != NULL) { if(p->running) { char item_buf[strlen(p->cmd) + 24]; if(p->pid == -1) snprintf(item_buf, sizeof(item_buf), " %d/%d %s ", p->done + 1, p->total, p->cmd); else snprintf(item_buf, sizeof(item_buf), " " PRINTF_PID_T " %s ", p->pid, p->cmd); i = add_to_string_array(&m.items, i, 1, item_buf); } p = p->next; } #ifndef _WIN32 /* Unblock SIGCHLD signal. */ sigprocmask(SIG_UNBLOCK, &new_mask, NULL); #endif m.len = i; return display_menu(&m, view); }
int show_register_menu(FileView *view, const char registers[]) { static menu_info m; init_menu_info(&m, strdup("Registers"), strdup("Registers are empty")); m.items = list_registers_content(registers); while(m.items[m.len] != NULL) m.len++; return display_menu(&m, view); }
int show_dirstack_menu(FileView *view) { static menu_info m; /* Directory stack always contains at least one item (current directories). */ init_menu_info(&m, DIRSTACK, NULL); m.title = strdup(" Directory Stack "); m.items = dir_stack_list(); m.len = -1; while(m.items[++m.len] != NULL); return display_menu(&m, view); }
int show_vifm_menu(FileView *view) { static menu_info m; int len; /* Version information menu always contains at least one item. */ init_menu_info(&m, VIFM, NULL); m.title = strdup(" vifm information "); len = fill_version_info(NULL); m.items = malloc(sizeof(char*)*len); m.len = fill_version_info(m.items); return display_menu(&m, view); }
int show_user_menu(FileView *view, const char command[], int navigate) { static menu_info m; init_menu_info(&m, strdup(command), strdup("No results found")); m.extra_data = navigate; m.execute_handler = &execute_users_cb; if(navigate) { m.key_handler = &filelist_khandler; } return capture_output_to_menu(view, command, 1, &m); }
int show_file_menu(FileView *view, int background) { static menu_info m; int i; int max_len; char *const typed_name = get_typed_current_fpath(view); assoc_records_t ft = ft_get_all_programs(typed_name); assoc_records_t magic = get_magic_handlers(typed_name); free(typed_name); init_menu_info(&m, strdup("Filetype associated commands"), strdup("No programs set for this filetype")); m.execute_handler = &execute_filetype_cb; m.key_handler = &filetypes_khandler; m.extra_data = (background ? 1 : 0); max_len = MAX(max_desc_len(&ft), max_desc_len(&magic)); for(i = 0; i < ft.count; i++) { (void)add_to_string_array(&m.data, m.len, 1, form_filetype_data_entry(ft.list[i])); m.len = add_to_string_array(&m.items, m.len, 1, form_filetype_menu_entry(ft.list[i], max_len)); } ft_assoc_records_free(&ft); #ifdef ENABLE_DESKTOP_FILES (void)add_to_string_array(&m.data, m.len, 1, form_filetype_data_entry(NONE_PSEUDO_PROG)); m.len = add_to_string_array(&m.items, m.len, 1, ""); #endif for(i = 0; i < magic.count; i++) { (void)add_to_string_array(&m.data, m.len, 1, form_filetype_data_entry(magic.list[i])); m.len = add_to_string_array(&m.items, m.len, 1, form_filetype_menu_entry(magic.list[i], max_len)); } return display_menu(&m, view); }
int show_fileviewers_menu(FileView *view, const char fname[]) { static menu_info m; assoc_records_t file_viewers; init_menu_info(&m, format_str("Viewers that match %s", fname), format_str("No viewers match %s", fname)); file_viewers = ft_get_all_viewers(fname); fill_menu_from_records(&m, &file_viewers); ft_assoc_records_free(&file_viewers); return display_menu(&m, view); }
/* Returns non-zero if status bar message should be saved. */ static int show_history(FileView *view, int type, hist_t *hist, const char title[]) { int i; static menu_info m; init_menu_info(&m, type, strdup("History disabled or empty")); m.title = strdup(title); for(i = 0; i <= hist->pos; i++) { m.len = add_to_string_array(&m.items, m.len, 1, hist->items[i]); } return display_menu(&m, view); }
int show_history_menu(FileView *view) { int i; static menu_info m; init_menu_info(&m, DIRHISTORY, strdup("History disabled or empty")); m.title = strdup(" Directory History "); for(i = 0; i < view->history_num && i < cfg.history_len; i++) { int j; if(view->history[i].dir[0] == '\0') break; for(j = i + 1; j < view->history_num && j < cfg.history_len; j++) if(stroscmp(view->history[i].dir, view->history[j].dir) == 0) break; if(j < view->history_num && j < cfg.history_len) continue; if(!is_valid_dir(view->history[i].dir)) continue; /* Change the current dir to reflect the current file. */ if(stroscmp(view->history[i].dir, view->curr_dir) == 0) { (void)replace_string(&view->history[i].file, view->dir_entry[view->list_pos].name); m.pos = m.len; } m.len = add_to_string_array(&m.items, m.len, 1, view->history[i].dir); } /* Reverse order in which items appear. */ for(i = 0; i < m.len/2; i++) { char *t = m.items[i]; m.items[i] = m.items[m.len - 1 - i]; m.items[m.len - 1 - i] = t; } m.pos = m.len - 1 - m.pos; return display_menu(&m, view); }
/* Returns non-zero if status bar message should be saved. */ static int show_history(FileView *view, HistoryType type, hist_t *hist, const char title[]) { int i; static menu_info m; init_menu_info(&m, strdup(title), strdup("History disabled or empty")); m.execute_handler = &execute_history_cb; m.key_handler = &history_khandler; m.extra_data = type; for(i = 0; i <= hist->pos; ++i) { m.len = add_to_string_array(&m.items, m.len, 1, hist->items[i]); } return display_menu(&m, view); }
int show_fileprograms_menu(FileView *view, const char fname[]) { static menu_info m; assoc_records_t file_programs; init_menu_info(&m, FILEPROGRAMS_MENU, format_str("No programs match %s", fname)); m.title = format_str(" Programs that match %s ", fname); file_programs = ft_get_all_programs(fname); fill_menu_from_records(&m, &file_programs); ft_assoc_records_free(&file_programs); return display_menu(&m, view); }
int show_commands_menu(FileView *view) { char **list; int i; int cmdname_width = CMDNAME_COLUMN_MIN_WIDTH; static menu_info m; init_menu_info(&m, COMMANDS_MENU, strdup("No commands set")); m.execute_handler = &execute_commands_cb; m.key_handler = &commands_khandler; m.title = strdup(" Command ------ Action "); list = list_udf(); m.len = -1; while(list[++m.len] != NULL) { const size_t cmdname_len = strlen(list[m.len]); if(cmdname_len > cmdname_width) { cmdname_width = cmdname_len; } m.len++; assert(list[m.len] != NULL && "Broken list of user-defined commands."); } m.len /= 2; m.items = (m.len != 0) ? malloc(sizeof(char *)*m.len) : NULL; for(i = 0; i < m.len; i++) { m.items[i] = format_str("%-*s %s", cmdname_width, list[i*2], list[i*2 + 1]); } free_string_array(list, m.len*2); return display_menu(&m, view); }
int show_map_menu(FileView *view, const char mode_str[], wchar_t *list[], const wchar_t start[]) { int x; const size_t start_len = wcslen(start); static menu_info m; init_menu_info(&m, format_str("Mappings for %s mode", mode_str), strdup("No mappings found")); x = 0; while(list[x] != NULL) { if(list[x][0] != '\0') { if(wcsncmp(start, list[x], start_len) == 0) { add_mapping_item(&m, list[x]); ++m.len; } } else if(m.len != 0) { m.len = add_to_string_array(&m.items, m.len, 1, ""); } free(list[x]); ++x; } free(list); if(m.len > 0 && m.items[m.len - 1][0] == '\0') { free(m.items[m.len - 1]); --m.len; } return display_menu(&m, view); }
int show_colorschemes_menu(FileView *view) { static menu_info m; init_menu_info(&m, strdup("Choose the default Color Scheme"), strdup("No color schemes found")); m.execute_handler = &execute_colorscheme_cb; m.items = list_color_schemes(&m.len); qsort(m.items, m.len, sizeof(*m.items), &sorter); /* It's safe to set m.pos to negative value, since menus.c handles this * correctly. */ #ifndef _WIN32 m.pos = string_array_pos(m.items, m.len, cfg.cs.name); #else m.pos = string_array_pos_case(m.items, m.len, cfg.cs.name); #endif return display_menu(&m, view); }