static char * select_new_item (void) { /* NOTE: The following array of possible items must match the formats array in screen.c. Better approach might be to make the formats array global */ char *possible_items[] = { "name", "size", "type", "mtime", "perm", "mode", "|", "nlink", "owner", "group", "atime", "ctime", "space", "mark", "inode", NULL }; int i; Listbox *mylistbox; mylistbox = create_listbox_window (12, 20, " Add listing format item ", listmode_section); for (i = 0; possible_items[i]; i++) { listbox_add_item (mylistbox->list, 0, 0, possible_items[i], NULL); } i = run_listbox (mylistbox); if (i >= 0) return possible_items[i]; else return NULL; }
/* Return value: * -2 (SELECT_CHARSET_CANCEL) : Cancel * -1 (SELECT_CHARSET_OTHER_8BIT) : "Other 8 bit" if seldisplay == TRUE * -1 (SELECT_CHARSET_NO_TRANSLATE) : "No translation" if seldisplay == FALSE * >= 0 : charset number */ int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay) { int i; char buffer[255]; /* Create listbox */ Listbox *listbox = create_listbox_window_centered (center_y, center_x, n_codepages + 1, ENTRY_LEN + 2, _("Choose codepage"), "[Codepages Translation]"); if (!seldisplay) LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL); /* insert all the items found */ for (i = 0; i < n_codepages; i++) { char *name = codepages[i].name; g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name); LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL); } if (seldisplay) { g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (n_codepages), _("Other 8 bit")); LISTBOX_APPEND_TEXT (listbox, get_hotkey (n_codepages), buffer, NULL); } /* Select the default entry */ i = (seldisplay) ? ((current_charset < 0) ? n_codepages : current_charset) : (current_charset + 1); listbox_select_by_number (listbox->list, i); i = run_listbox (listbox); if (i < 0) { /* Cancel dialog */ return SELECT_CHARSET_CANCEL; } else { /* some charset has been selected */ if (seldisplay) { /* charset list is finished with "Other 8 bit" item */ return (i >= n_codepages) ? SELECT_CHARSET_OTHER_8BIT : i; } else { /* charset list is began with "- < No translation >" item */ return (i - 1); } } }
static void edit_window_list (const Dlg_head * h) { const size_t offset = 2; /* skip menu and buttonbar */ const size_t dlg_num = g_list_length (h->widgets) - offset; int lines, cols; Listbox *listbox; GList *w; int i = 0; int rv; lines = min ((size_t) (LINES * 2 / 3), dlg_num); cols = COLS * 2 / 3; listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); for (w = h->widgets; w != NULL; w = g_list_next (w)) if (edit_widget_is_editor ((Widget *) w->data)) { WEdit *e = (WEdit *) w->data; char *fname; if (e->filename_vpath == NULL) fname = g_strdup_printf ("%c [%s]", e->modified ? '*' : ' ', _("NoName")); else { char *fname2; fname2 = vfs_path_to_str (e->filename_vpath); fname = g_strdup_printf ("%c%s", e->modified ? '*' : ' ', fname2); g_free (fname2); } listbox_add_item (listbox->list, LISTBOX_APPEND_AT_END, get_hotkey (i++), str_term_trim (fname, listbox->list->widget.cols - 2), NULL); g_free (fname); } rv = g_list_position (h->widgets, h->current) - offset; listbox_select_entry (listbox->list, rv); rv = run_listbox (listbox); if (rv >= 0) { w = g_list_nth (h->widgets, rv + offset); dlg_set_top_widget (w->data); } }
static int exec_edit_syntax_dialog (const char **names) { int i; Listbox *syntaxlist = create_listbox_window (MAX_ENTRY_LEN, LIST_LINES, _(" Choose syntax highlighting "), NULL); LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL); LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL); for (i = 0; names[i]; i++) { LISTBOX_APPEND_TEXT (syntaxlist, 0, names[i], NULL); if (! option_auto_syntax && option_syntax_type && (strcmp (names[i], option_syntax_type) == 0)) listbox_select_by_number (syntaxlist->list, i + N_DFLT_ENTRIES); } return run_listbox (syntaxlist); }
void dialog_switch_list (void) { const size_t dlg_num = g_list_length (mc_dialogs); int lines, cols; Listbox *listbox; GList *h; int i = 0; int rv; if (mc_global.widget.midnight_shutdown || mc_current == NULL) return; lines = min ((size_t) (LINES * 2 / 3), dlg_num); cols = COLS * 2 / 3; listbox = create_listbox_window (lines, cols, _("Screens"), "[Screen selector]"); for (h = mc_dialogs; h != NULL; h = g_list_next (h)) { Dlg_head *dlg; char *title; dlg = (Dlg_head *) h->data; if ((dlg != NULL) && (dlg->get_title != NULL)) title = dlg->get_title (dlg, listbox->list->widget.cols - 2); /* FIXME! */ else title = g_strdup (""); listbox_add_item (listbox->list, LISTBOX_APPEND_BEFORE, get_hotkey (i++), title, NULL); g_free (title); } listbox_select_entry (listbox->list, dlg_num - 1 - g_list_position (mc_dialogs, mc_current)); rv = run_listbox (listbox); if (rv >= 0) { h = g_list_nth (mc_dialogs, dlg_num - 1 - rv); dialog_switch_goto (h); } }
static int exec_edit_syntax_dialog (const GPtrArray * names, const char *current_syntax) { size_t i; Listbox *syntaxlist; syntaxlist = create_listbox_window (LIST_LINES, MAX_ENTRY_LEN, _("Choose syntax highlighting"), NULL); LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL); LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL); for (i = 0; i < names->len; i++) { const char *name; name = g_ptr_array_index (names, i); LISTBOX_APPEND_TEXT (syntaxlist, 0, name, NULL); if (current_syntax != NULL && strcmp (name, current_syntax) == 0) listbox_select_entry (syntaxlist->list, i + N_DFLT_ENTRIES); } return run_listbox (syntaxlist); }
static char * select_new_item (void) { char **possible_items; char *ret = NULL; int i; Listbox *mylistbox; possible_items = panel_get_user_possible_fields (NULL); mylistbox = create_listbox_window (20, 12, "Add listing format item", listmode_section); for (i = 0; possible_items[i]; i++) { listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL); } i = run_listbox (mylistbox); if (i >= 0) ret = g_strdup (possible_items[i]); g_strfreev (possible_items); return ret; }
/* * If edit_widget is NULL then we are called from the mc menu, * otherwise we are called from the mcedit menu. */ void user_menu_cmd (struct WEdit *edit_widget) { char *p; char *data, **entries; int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; if (!vfs_current_is_local ()){ message (1, MSG_ERROR, _(" Cannot execute commands on non-local filesystems")); return; } menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)){ g_free (menu); menu = concat_dir_and_file \ (home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU); if (!exist_file (menu)){ g_free (menu); menu = concat_dir_and_file \ (mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); } } if ((data = load_file (menu)) == NULL){ message (1, MSG_ERROR, _(" Cannot open file %s \n %s "), menu, unix_error_string (errno)); g_free (menu); menu = NULL; return; } max_cols = 0; selected = 0; menu_limit = 0; entries = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; p++){ if (menu_lines >= menu_limit){ char ** new_entries; menu_limit += MAX_ENTRIES; new_entries = g_realloc (entries, sizeof (new_entries[0]) * menu_limit); if (new_entries == 0) break; entries = new_entries; new_entries += menu_limit; while (--new_entries >= &entries[menu_lines]) *new_entries = 0; } if (col == 0 && !entries [menu_lines]){ if (*p == '#'){ /* A commented menu entry */ accept_entry = 1; } else if (*p == '+'){ if (*(p+1) == '='){ /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (edit_widget, p, &accept_entry); } } else if (*p == '='){ if (*(p+1) == '+'){ /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (edit_widget, p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p != ' ' && *p != '\t' && is_printable (*p)) { /* A menu entry title line */ if (accept_entry) entries [menu_lines] = p; else accept_entry = 1; } } if (*p == '\n'){ if (entries [menu_lines]){ menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } else { if (*p == '\t') *p = ' '; col++; } } if (menu_lines == 0) { message (1, MSG_ERROR, _(" No suitable entries found in %s "), menu); } else { max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) { p = entries [i]; LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], extract_line (p, p + MAX_ENTRY_LEN), p ); } /* Select the default entry */ listbox_select_by_number (listbox->list, selected); selected = run_listbox (listbox); if (selected >= 0) execute_menu_command (edit_widget, entries [selected]); do_refresh (); } easy_patterns = old_patterns; g_free (menu); menu = NULL; g_free (entries); g_free (data); }
gboolean user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_entry) { char *p; char *data, **entries; int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; gboolean res = FALSE; gboolean interactive = TRUE; if (!vfs_current_is_local ()) { message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems")); return FALSE; } if (menu_file != NULL) menu = g_strdup (menu_file); else menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)) { if (menu_file != NULL) { message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), menu, unix_error_string (errno)); MC_PTR_FREE (menu); return FALSE; } g_free (menu); if (edit_widget) menu = mc_config_get_full_path (EDIT_HOME_MENU); else menu = mc_config_get_full_path (MC_USERMENU_FILE); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_config_get_home_dir (), edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_global.sysconfig_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); } } } } if (!g_file_get_contents (menu, &data, NULL, NULL)) { message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno)); MC_PTR_FREE (menu); return FALSE; } max_cols = 0; selected = 0; menu_limit = 0; entries = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; str_next_char (&p)) { if (menu_lines >= menu_limit) { char **new_entries; menu_limit += MAX_ENTRIES; new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit); if (new_entries == NULL) break; entries = new_entries; new_entries += menu_limit; while (--new_entries >= &entries[menu_lines]) *new_entries = NULL; } if (col == 0 && !entries[menu_lines]) { if (*p == '#') { /* show prompt if first line of external script is #interactive */ if (selected_entry >= 0 && strncmp (p, "#silent", 7) == 0) interactive = FALSE; /* A commented menu entry */ accept_entry = 1; } else if (*p == '+') { if (*(p + 1) == '=') { /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (edit_widget, p, &accept_entry); } } else if (*p == '=') { if (*(p + 1) == '+') { /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (edit_widget, p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p != ' ' && *p != '\t' && str_isprint (p)) { /* A menu entry title line */ if (accept_entry) entries[menu_lines] = p; else accept_entry = 1; } } if (*p == '\n') { if (entries[menu_lines]) { menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } else { if (*p == '\t') *p = ' '; col++; } } if (menu_lines == 0) { message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu); res = FALSE; } else { if (selected_entry >= 0) selected = selected_entry; else { Listbox *listbox; max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (menu_lines, max_cols + 2, _("User menu"), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) { p = entries[i]; LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], extract_line (p, p + MAX_ENTRY_LEN), p); } /* Select the default entry */ listbox_select_entry (listbox->list, selected); selected = run_listbox (listbox); } if (selected >= 0) { execute_menu_command (edit_widget, entries[selected], interactive); res = TRUE; } do_refresh (); } easy_patterns = old_patterns; MC_PTR_FREE (menu); g_free (entries); g_free (data); return res; }
void user_menu_cmd (void) { char *menu, *p; int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; if (!vfs_current_is_local ()){ message (1, _(" Oops... "), _(" I can't run programs while logged on a non local directory ")); return; } menu = strdup (MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)){ free (menu); #ifdef OS2_NT menu = strdup("NC.MNU"); if (!exist_file (menu)) #endif { menu = concat_dir_and_file (home_dir, MC_HOME_MENU); if (!exist_file (menu)){ free (menu); menu = concat_dir_and_file (mc_home, MC_GLOBAL_MENU); } } } if ((data = load_file (menu)) == NULL){ message (1, MSG_ERROR, _(" Can't open file %s \n %s "), menu, unix_error_string (errno)); free (menu); return; } free (menu); max_cols = 0; for (i = 0; i < MAX_ENTRIES; i++) entries [i] = 0; selected = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; p++){ if (col == 0 && !entries [menu_lines]){ if (*p == '#'){ /* A commented menu entry */ accept_entry = 1; } else if (*p == '+'){ if (*(p+1) == '='){ /* Combined adding and default */ char *q = p++; p = test_line (q, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (p, &accept_entry); } } else if (*p == '='){ if (*(p+1) == '+'){ char *q = p++; /* Combined adding and default */ p = test_line (q, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p > ' ' && *p < 127){ /* A menu entry title line */ if (accept_entry) entries [menu_lines] = p; else accept_entry = 1; } } if (menu_lines == MAX_ENTRIES) break; if (*p == '\t') *p = ' '; col++; if (*p == '\n'){ if (entries [menu_lines]){ menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } } max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) LISTBOX_APPEND_TEXT (listbox, entries [i][0], extract_line (entries [i], entries [i]+MAX_ENTRY_LEN), entries [i]); /* Select the default entry */ listbox_select_by_number (listbox->list, selected); selected = run_listbox (listbox); if (selected >= 0) execute_menu_command (entries [selected]); easy_patterns = old_patterns; do_refresh (); free (data); }