int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel) { int w, wq; int y = 2; WDialog *raw_dlg; w = str_term_width1 (heading) + 6; wq = str_term_width1 (query); w = max (w, wq + 3 * 2 + 1 + 2); raw_dlg = create_dlg (TRUE, 0, 0, cancel ? 7 : 5, w, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL, NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB); add_widget (raw_dlg, label_new (y, 3, query)); add_widget (raw_dlg, input_new (y++, 3 + wq + 1, input_get_default_colors (), w - (6 + wq + 1), "", 0, INPUT_COMPLETE_NONE)); if (cancel) { add_widget (raw_dlg, hline_new (y++, -1, -1)); /* Button w/o hotkey to allow use any key as raw or macro one */ add_widget_autopos (raw_dlg, button_new (y, 1, B_CANCEL, NORMAL_BUTTON, _("Cancel"), NULL), WPOS_KEEP_TOP | WPOS_CENTER_HORZ, NULL); } w = run_dlg (raw_dlg); destroy_dlg (raw_dlg); return (cancel && (w == ESC_CHAR || w == B_CANCEL)) ? 0 : w; }
void history_cmd (void) { Listbox *listbox; GList *current; if (cmdline->need_push) { if (push_history (cmdline, cmdline->buffer) == 2) cmdline->need_push = 0; } if (!cmdline->history) { message (1, MSG_ERROR, _(" The command history is empty ")); return; } current = g_list_first (cmdline->history); listbox = create_listbox_window (60, 10, _(" Command history "), "[Command Menu]"); while (current) { LISTBOX_APPEND_TEXT (listbox, 0, (char *) current->data, current); current = g_list_next(current); } run_dlg (listbox->dlg); if (listbox->dlg->ret_value == B_CANCEL) current = NULL; else current = listbox->list->current->data; destroy_dlg (listbox->dlg); g_free (listbox); if (!current) return; cmdline->history = current; assign_text (cmdline, (char *) current->data); update_input (cmdline, 1); }
int dialog_switch_process_pending (void) { int ret = 0; while (dialog_switch_pending) { Dlg_head *h = (Dlg_head *) mc_current->data; dialog_switch_pending = FALSE; h->state = DLG_SUSPENDED; ret = run_dlg (h); if (h->state == DLG_CLOSED) { destroy_dlg (h); /* return to panels */ if (mc_global.mc_run_mode == MC_RUN_FULL) { mc_current = g_list_find (mc_dialogs, midnight_dlg); mc_event_raise (MCEVENT_GROUP_FILEMANAGER, "update_panels", NULL); } } } repaint_screen (); return ret; }
void display_bits_box (void) { Dlg_head *dbits_dlg; new_display_codepage = display_codepage; application_keypad_mode (); dbits_dlg = init_disp_bits_box (); run_dlg (dbits_dlg); if (dbits_dlg->ret_value == B_ENTER) { char *errmsg; display_codepage = new_display_codepage; errmsg = init_translation_table (source_codepage, display_codepage); if (errmsg != NULL) { message (D_ERROR, MSG_ERROR, "%s", errmsg); g_free (errmsg); } #ifdef HAVE_SLANG tty_display_8bit (display_codepage != 0 && display_codepage != 1); #else tty_display_8bit (display_codepage != 0); #endif use_8th_bit_as_meta = !(inpcheck->state & C_BOOL); } destroy_dlg (dbits_dlg); repaint_screen (); }
void learn_keys (void) { int save_old_esc_mode = old_esc_mode; int save_alternate_plus_minus = alternate_plus_minus; old_esc_mode = 0; /* old_esc_mode cannot work in learn keys dialog */ alternate_plus_minus = 1; /* don't translate KP_ADD, KP_SUBTRACT and KP_MULTIPLY to '+', '-' and '*' in correct_key_code */ application_keypad_mode (); init_learn (); run_dlg (learn_dlg); old_esc_mode = save_old_esc_mode; alternate_plus_minus = save_alternate_plus_minus; if (!alternate_plus_minus) numeric_keypad_mode (); switch (learn_dlg->ret_value) { case B_ENTER: learn_save (); break; } learn_done (); }
void display_bits_box (void) { Dlg_head *dbits_dlg; new_display_codepage = display_codepage; application_keypad_mode (); dbits_dlg = init_disp_bits_box (); run_dlg (dbits_dlg); if (dbits_dlg->ret_value == B_ENTER) { const char *errmsg; display_codepage = new_display_codepage; errmsg = init_translation_table (source_codepage, display_codepage); if (errmsg) message (1, MSG_ERROR, "%s", errmsg); #ifndef HAVE_SLANG meta (stdscr, display_codepage != 0); #else SLsmg_Display_Eight_Bit = (display_codepage != 0 && display_codepage != 1) ? 128 : 160; #endif use_8th_bit_as_meta = !(inpcheck->state & C_BOOL); } destroy_dlg (dbits_dlg); repaint_screen (); }
/* Show tree in a box, not on a panel */ char * tree_box (const char *current_dir) { WTree *mytree; Dlg_head *dlg; char *val; WButtonBar *bar; /* Create the components */ dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors, tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE); mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5); add_widget (dlg, mytree); bar = buttonbar_new(1); add_widget (dlg, bar); bar->widget.x = 0; bar->widget.y = LINES - 1; run_dlg (dlg); if (dlg->ret_value == B_ENTER) val = g_strdup (tree_selected_name (mytree)); else val = 0; destroy_dlg (dlg); return val; }
char * tree_box (const char *current_dir) { WTree *mytree; Dlg_head *dlg; char *val = NULL; WButtonBar *bar; (void) current_dir; /* Create the components */ dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, "[Directory Tree]", _("Directory tree"), DLG_CENTER | DLG_REVERSE); mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE); add_widget (dlg, mytree); add_widget (dlg, hline_new (dlg->lines - 4, 1, -1)); bar = buttonbar_new (TRUE); add_widget (dlg, bar); /* restore ButtonBar coordinates after add_widget() */ ((Widget *) bar)->x = 0; ((Widget *) bar)->y = LINES - 1; if (run_dlg (dlg) == B_ENTER) val = g_strdup (tree_selected_name (mytree)); destroy_dlg (dlg); return val; }
void layout_cmd (void) { int result; int i; init_layout (); run_dlg (layout_dlg); result = layout_dlg->ret_value; if (result == B_ENTER || result == B_EXIT){ for (i = 0; check_options [i].text; i++) if (check_options [i].widget) *check_options [i].variable = check_options [i].widget->state & C_BOOL; #ifndef HAVE_X horizontal_split = radio_widget->sel; first_panel_size = _first_panel_size; output_lines = _output_lines; layout_do_change = 1; #endif } if (result == B_EXIT){ save_layout (); sync_profiles (); } destroy_dlg (layout_dlg); if (layout_do_change) layout_change (); }
char * tree (char *current_dir) { WTree *mytree; Dlg_head *dlg; char *val; WButtonBar *bar; tree_colors [3] = dialog_colors [0]; tree_colors [1] = dialog_colors [1]; /* Create the components */ dlg = create_dlg (0, 0, TREE_Y, TREE_X, tree_colors, tree_callback, "[Directory Tree]", "tree", DLG_CENTER); mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5); add_widget (dlg, mytree); bar = buttonbar_new(1); add_widget (dlg, bar); bar->widget.x = 0; bar->widget.y = LINES - 1; run_dlg (dlg); if (dlg->ret_value == B_ENTER) val = strdup (mytree->selected_ptr->name); else val = 0; destroy_dlg (dlg); return val; }
void configure_box (void) { int result, i; init_configure (); run_dlg (conf_dlg); result = conf_dlg->ret_value; if (result == B_ENTER || result == B_EXIT){ for (i = 0; check_options [i].text; i++) if (check_options [i].widget->state & C_CHANGE){ if (check_options [i].toggle_function) (*check_options [i].toggle_function)(); else *check_options [i].variable = !(*check_options [i].variable); } pause_after_run = pause_radio->sel; } /* If they pressed the save button */ if (result == B_EXIT){ save_configure (); sync_profiles (); } destroy_dlg (conf_dlg); }
gboolean edit_files (const GList * files) { static gboolean made_directory = FALSE; Dlg_head *edit_dlg; WMenuBar *menubar; const GList *file; gboolean ok = FALSE; if (!made_directory) { char *dir; dir = mc_build_filename (mc_config_get_cache_path (), EDIT_DIR, NULL); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); dir = mc_build_filename (mc_config_get_path (), EDIT_DIR, NULL); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); dir = mc_build_filename (mc_config_get_data_path (), EDIT_DIR, NULL); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); } /* Create a new dialog and add it widgets to it */ edit_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback, edit_dialog_event, "[Internal File Editor]", NULL, DLG_WANT_TAB); edit_dlg->get_shortcut = edit_get_shortcut; edit_dlg->get_title = edit_get_title; menubar = menubar_new (0, 0, COLS, NULL); add_widget (edit_dlg, menubar); edit_init_menu (menubar); add_widget (edit_dlg, buttonbar_new (TRUE)); for (file = files; file != NULL; file = g_list_next (file)) { mcedit_arg_t *f = (mcedit_arg_t *) file->data; gboolean f_ok; f_ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x, edit_dlg->lines - 2, edit_dlg->cols, f->file_vpath, f->line_number); /* at least one file has been opened succefully */ ok = ok || f_ok; } if (ok) run_dlg (edit_dlg); if (!ok || edit_dlg->state == DLG_CLOSED) destroy_dlg (edit_dlg); return ok; }
int edit_file (const char *_file, int line) { static gboolean made_directory = FALSE; Dlg_head *edit_dlg; WEdit *wedit; WMenuBar *menubar; if (!made_directory) { char *dir = concat_dir_and_file (mc_config_get_cache_path (), EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); dir = concat_dir_and_file (mc_config_get_path (), EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); dir = concat_dir_and_file (mc_config_get_data_path (), EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); } wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file, line); if (wedit == NULL) return 0; /* Create a new dialog and add it widgets to it */ edit_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback, "[Internal File Editor]", NULL, DLG_WANT_TAB); edit_dlg->get_shortcut = edit_get_shortcut; edit_dlg->get_title = edit_get_title; menubar = menubar_new (0, 0, COLS, NULL); add_widget (edit_dlg, menubar); edit_init_menu (menubar); init_widget (&wedit->widget, wedit->widget.y, wedit->widget.x, wedit->widget.lines, wedit->widget.cols, edit_callback, edit_event); widget_want_cursor (wedit->widget, TRUE); add_widget (edit_dlg, wedit); add_widget (edit_dlg, buttonbar_new (TRUE)); run_dlg (edit_dlg); if (edit_dlg->state == DLG_CLOSED) destroy_dlg (edit_dlg); return 1; }
/** Returns the number of the item selected */ int run_listbox (Listbox * l) { int val = -1; if (run_dlg (l->dlg) != B_CANCEL) val = l->list->pos; destroy_dlg (l->dlg); g_free (l); return val; }
void dialog_switch_shutdown (void) { while (mc_dialogs != NULL) { Dlg_head *dlg = (Dlg_head *) mc_dialogs->data; run_dlg (dlg); destroy_dlg (dlg); } }
/* Returns the number of the item selected */ int run_listbox (Listbox *l) { int val; run_dlg (l->dlg); if (l->dlg->ret_value == B_CANCEL) val = -1; else val = l->list->pos; destroy_dlg (l->dlg); g_free (l); return val; }
FileProgressStatus file_progress_real_query_replace (enum OperationMode mode, char *destname, struct stat *_s_stat, struct stat *_d_stat) { if (file_progress_replace_result < REPLACE_ALWAYS){ file_progress_replace_filename = destname; s_stat = _s_stat; d_stat = _d_stat; init_replace (mode); run_dlg (replace_dlg); file_progress_replace_result = replace_dlg->ret_value; if (file_progress_replace_result == B_CANCEL) file_progress_replace_result = REPLACE_ABORT; destroy_dlg (replace_dlg); } switch (file_progress_replace_result){ case REPLACE_UPDATE: do_refresh (); if (_s_stat->st_mtime > _d_stat->st_mtime) return FILE_CONT; else return FILE_SKIP; case REPLACE_SIZE: do_refresh (); if (_s_stat->st_size == _d_stat->st_size) return FILE_SKIP; else return FILE_CONT; case REPLACE_REGET: /* Carefull: we fall through and set do_append */ file_progress_do_reget = _d_stat->st_size; case REPLACE_APPEND: file_progress_do_append = 1; case REPLACE_YES: case REPLACE_ALWAYS: do_refresh (); return FILE_CONT; case REPLACE_NO: case REPLACE_NEVER: do_refresh (); return FILE_SKIP; case REPLACE_ABORT: default: return FILE_ABORT; } }
/* return list type */ int display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num) { int result = -1; Dlg_head *dd; char *section = NULL; size_t i; if (panel == NULL) { const char *p = get_nth_panel_name (num); panel = g_new (WPanel, 1); panel->list_type = list_full; panel->user_format = g_strdup (DEFAULT_USER_FORMAT); panel->user_mini_status = 0; for (i = 0; i < LIST_TYPES; i++) panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); section = g_strconcat ("Temporal:", p, (char *) NULL); if (!mc_config_has_group (mc_main_config, section)) { g_free (section); section = g_strdup (p); } panel_load_setup (panel, section); g_free (section); } dd = display_init (panel->list_type, panel->user_format, panel->user_mini_status, panel->user_status_format); if (run_dlg (dd) != B_CANCEL) { result = display_radio->sel; *userp = g_strdup (display_user_format->buffer); *minip = g_strdup (display_mini_status->buffer); *use_msformat = display_check_status->state & C_BOOL; } if (section != NULL) { g_free (panel->user_format); for (i = 0; i < LIST_TYPES; i++) g_free (panel->user_status_format[i]); g_free (panel); } destroy_dlg (dd); return result; }
int display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num) { int result, i; char *section = NULL; const char *p; if (!panel) { p = get_nth_panel_name (num); panel = g_new (WPanel, 1); panel->list_type = list_full; panel->user_format = g_strdup (DEFAULT_USER_FORMAT); panel->user_mini_status = 0; for (i = 0; i < LIST_TYPES; i++) panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); section = g_strconcat ("Temporal:", p, (char *) NULL); if (!profile_has_section (section, profile_name)) { g_free (section); section = g_strdup (p); } panel_load_setup (panel, section); g_free (section); } current_mode = panel->list_type; display_init (current_mode, panel->user_format, panel->user_mini_status, panel->user_status_format); run_dlg (dd); result = -1; if (section) { g_free (panel->user_format); for (i = 0; i < LIST_TYPES; i++) g_free (panel->user_status_format [i]); g_free (panel); } if (dd->ret_value != B_CANCEL){ result = my_radio->sel; *userp = g_strdup (user->buffer); *minip = g_strdup (status->buffer); *use_msformat = check_status->state & C_BOOL; } destroy_dlg (dd); return result; }
static void edit_about (void) { const char *header = N_("About"); const char *button_name = N_("&OK"); const char *const version = "MCEdit " VERSION; char text[BUF_LARGE]; int win_len, version_len, button_len; int cols, lines; Dlg_head *about_dlg; #ifdef ENABLE_NLS header = _(header); button_name = _(button_name); #endif button_len = str_term_width1 (button_name) + 5; version_len = str_term_width1 (version); g_snprintf (text, sizeof (text), _("Copyright (C) 1996-2012 the Free Software Foundation\n\n" " A user friendly text editor\n" " written for the Midnight Commander")); win_len = str_term_width1 (header); win_len = max (win_len, version_len); win_len = max (win_len, button_len); /* count width and height of text */ str_msg_term_size (text, &lines, &cols); lines += 9; cols = max (win_len, cols) + 6; /* dialog */ about_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL, "[Internal File Editor]", header, DLG_CENTER | DLG_TRYUP); add_widget (about_dlg, label_new (3, (cols - version_len) / 2, version)); add_widget (about_dlg, label_new (5, 3, text)); add_widget (about_dlg, button_new (lines - 3, (cols - button_len) / 2, B_ENTER, NORMAL_BUTTON, button_name, NULL)); run_dlg (about_dlg); destroy_dlg (about_dlg); }
/* Return new format or NULL if the user cancelled the dialog */ char * listmode_edit (char *oldlistformat) { char *newformat = NULL; char *s; Dlg_head *listmode_dlg; s = g_strdup (oldlistformat); listmode_dlg = init_listmode (s); g_free (s); if (run_dlg (listmode_dlg) == B_ENTER) { newformat = collect_new_format (); } listmode_done (listmode_dlg); return newformat; }
int xdiff_view (const char *file1, const char *file2) { int error; WDiff *view; WButtonBar *bar; Dlg_head *view_dlg; /* Create dialog and widgets, put them on the dialog */ view_dlg = create_dlg(0, 0, LINES, COLS, NULL, view_dialog_callback, "[Binary Diff Viewer]", NULL, DLG_WANT_TAB); view = g_new0(WDiff, 1); init_widget(&view->widget, 0, 0, LINES - 1, COLS, (callback_fn)view_callback, (mouse_h)view_event); widget_want_cursor(view->widget, 0); bar = buttonbar_new(1); add_widget(view_dlg, bar); add_widget(view_dlg, view); error = view_init(view, file1, file2); /* Please note that if you add another widget, * you have to modify view_adjust_size to * be aware of it */ if (!error) { run_dlg(view_dlg); view_search(view, -1); view_fini(view, 1); } destroy_dlg(view_dlg); return error; }
char *listmode_edit (char *oldlistformat) { char *newformat = NULL; char *s; s = strdup (oldlistformat); init_listmode (s); free (s); while (newformat == NULL) { /* display file info */ attrset (SELECTED_COLOR); run_dlg (listmode_dlg); switch (listmode_dlg->ret_value) { case B_CANCEL: newformat = strdup (oldlistformat); break; case B_ADD: s = select_new_item (); if (s) listbox_add_item (l_listmode, 0, 0, s, NULL); break; case B_REMOVE: listbox_remove_current (l_listmode, 0); break; case B_ENTER: newformat = collect_new_format (); break; } } listmode_done (); return newformat; }
int editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel) { int w = str_term_width1 (query) + 7; struct Dlg_head *raw_dlg = create_dlg (0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB); add_widget (raw_dlg, input_new (3 - cancel, w - 5, INPUT_COLOR, 2, "", 0, INPUT_COMPLETE_DEFAULT)); add_widget (raw_dlg, label_new (3 - cancel, 2, query)); if (cancel) add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0)); w = run_dlg (raw_dlg); destroy_dlg (raw_dlg); if (cancel) { if (w == XCTRL ('g') || w == XCTRL ('c') || w == ESC_CHAR || w == B_CANCEL) return 0; } return w; }
void layout_box (void) { Dlg_head *layout_dlg; gboolean layout_do_change = FALSE; layout_dlg = init_layout (); if (run_dlg (layout_dlg) == B_ENTER) { size_t i; for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++) if (check_options[i].widget != NULL) *check_options[i].variable = check_options[i].widget->state & C_BOOL; horizontal_split = radio_widget->sel; first_panel_size = _first_panel_size; output_lines = _output_lines; layout_do_change = TRUE; } destroy_dlg (layout_dlg); if (layout_do_change) layout_change (); }
gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line) { gboolean succeeded; mcview_t *lc_mcview; WDialog *view_dlg; /* Create dialog and widgets, put them on the dialog */ view_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, mcview_dialog_callback, NULL, "[Internal File Viewer]", NULL, DLG_WANT_TAB); lc_mcview = mcview_new (0, 0, LINES - 1, COLS, FALSE); add_widget (view_dlg, lc_mcview); add_widget (view_dlg, buttonbar_new (TRUE)); view_dlg->get_title = mcview_get_title; { char *file; file = vfs_path_to_str (file_vpath); succeeded = mcview_load (lc_mcview, command, file, start_line); g_free (file); } if (succeeded) run_dlg (view_dlg); else view_dlg->state = DLG_CLOSED; if (view_dlg->state == DLG_CLOSED) destroy_dlg (view_dlg); return succeeded; }
/* * FIXME: probably it is better to replace this with quick dialog machinery, * but actually I'm not familiar with it and have not much time :( * alex */ static replace_action_t overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode) { #define ADD_RD_BUTTON(i) \ add_widget (ui->replace_dlg, \ button_new (rd_widgets [i].ypos, rd_widgets [i].xpos, rd_widgets [i].value, \ NORMAL_BUTTON, rd_widgets [i].text, 0)) #define ADD_RD_LABEL(i, p1, p2) \ g_snprintf (buffer, sizeof (buffer), rd_widgets [i].text, p1, p2); \ add_widget (ui->replace_dlg, label_new (rd_widgets [i].ypos, rd_widgets [i].xpos, buffer)) /* dialog sizes */ const int rd_ylen = 17; int rd_xlen = 60; struct { const char *text; int ypos, xpos; int value; /* 0 for labels */ } rd_widgets[] = { /* *INDENT-OFF* */ /* 0 */ { N_("Target file already exists!"), 3, 4, 0 }, /* 1 */ { "%s", 4, 4, 0 }, /* 2 */ /* cannot use PRIuMAX here; %llu is used instead */ { N_("Source date: %s, size %llu"), 6, 4, 0 }, /* 3 */ /* cannot use PRIuMAX here; %llu is used instead */ { N_("Target date: %s, size %llu"), 7, 4, 0 }, /* 4 */ { N_("&Abort"), 14, 25, REPLACE_ABORT }, /* 5 */ { N_("If &size differs"), 12, 28, REPLACE_SIZE }, /* 6 */ { N_("Non&e"), 11, 47, REPLACE_NEVER }, /* 7 */ { N_("&Update"), 11, 36, REPLACE_UPDATE }, /* 8 */ { N_("A&ll"), 11, 28, REPLACE_ALWAYS }, /* 9 */ { N_("Overwrite all targets?"), 11, 4, 0 }, /* 10 */ { N_("&Reget"), 10, 28, REPLACE_REGET }, /* 11 */ { N_("A&ppend"), 9, 45, REPLACE_APPEND }, /* 12 */ { N_("&No"), 9, 37, REPLACE_NO }, /* 13 */ { N_("&Yes"), 9, 28, REPLACE_YES }, /* 14 */ { N_("Overwrite this target?"), 9, 4, 0 } /* *INDENT-ON* */ }; const int num = sizeof (rd_widgets) / sizeof (rd_widgets[0]); int *widgets_len; FileOpContextUI *ui = ctx->ui; char buffer[BUF_SMALL]; const char *title; const char *stripped_name = strip_home_and_password (ui->replace_filename); int stripped_name_len; int result; widgets_len = g_new0 (int, num); if (mode == Foreground) title = _("File exists"); else title = _("Background process: File exists"); stripped_name_len = str_term_width1 (stripped_name); { int i, l1, l2, l, row; for (i = 0; i < num; i++) { #ifdef ENABLE_NLS if (i != 1) /* skip filename */ rd_widgets[i].text = _(rd_widgets[i].text); #endif /* ENABLE_NLS */ widgets_len[i] = str_term_width1 (rd_widgets[i].text); } /* * longest of "Overwrite..." labels * (assume "Target date..." are short enough) */ l1 = max (widgets_len[9], widgets_len[14]); /* longest of button rows */ i = num; for (row = l = l2 = 0; i--;) if (rd_widgets[i].value != 0) { if (row != rd_widgets[i].ypos) { row = rd_widgets[i].ypos; l2 = max (l2, l); l = 0; } l += widgets_len[i] + 4; } l2 = max (l2, l); /* last row */ rd_xlen = max (rd_xlen, l1 + l2 + 8); rd_xlen = max (rd_xlen, str_term_width1 (title) + 2); rd_xlen = max (rd_xlen, min (COLS, stripped_name_len + 8)); /* Now place widgets */ l1 += 5; /* start of first button in the row */ i = num; for (l = l1, row = 0; --i > 1;) if (rd_widgets[i].value != 0) { if (row != rd_widgets[i].ypos) { row = rd_widgets[i].ypos; l = l1; } rd_widgets[i].xpos = l; l += widgets_len[i] + 4; } /* Abort button is centered */ rd_widgets[4].xpos = (rd_xlen - widgets_len[4] - 3) / 2; } /* FIXME - missing help node */ ui->replace_dlg = create_dlg (TRUE, 0, 0, rd_ylen, rd_xlen, alarm_colors, NULL, "[Replace]", title, DLG_CENTER | DLG_REVERSE); /* prompt -- centered */ add_widget (ui->replace_dlg, label_new (rd_widgets[0].ypos, (rd_xlen - widgets_len[0]) / 2, rd_widgets[0].text)); /* file name -- centered */ stripped_name = str_trunc (stripped_name, rd_xlen - 8); stripped_name_len = str_term_width1 (stripped_name); add_widget (ui->replace_dlg, label_new (rd_widgets[1].ypos, (rd_xlen - stripped_name_len) / 2, stripped_name)); /* source date and size */ ADD_RD_LABEL (2, file_date (ui->s_stat->st_mtime), (unsigned long long) ui->s_stat->st_size); /* destination date and size */ ADD_RD_LABEL (3, file_date (ui->d_stat->st_mtime), (unsigned long long) ui->d_stat->st_size); ADD_RD_BUTTON (4); /* Abort */ ADD_RD_BUTTON (5); /* If size differs */ ADD_RD_BUTTON (6); /* None */ ADD_RD_BUTTON (7); /* Update */ ADD_RD_BUTTON (8); /* All" */ ADD_RD_LABEL (9, 0, 0); /* Overwrite all targets? */ /* "this target..." widgets */ if (!S_ISDIR (ui->d_stat->st_mode)) { if ((ctx->operation == OP_COPY) && (ui->d_stat->st_size != 0) && (ui->s_stat->st_size > ui->d_stat->st_size)) ADD_RD_BUTTON (10); /* Reget */ ADD_RD_BUTTON (11); /* Append */ } ADD_RD_BUTTON (12); /* No */ ADD_RD_BUTTON (13); /* Yes */ ADD_RD_LABEL (14, 0, 0); /* Overwrite this target? */ result = run_dlg (ui->replace_dlg); destroy_dlg (ui->replace_dlg); g_free (widgets_len); return (result == B_CANCEL) ? REPLACE_ABORT : (replace_action_t) result; #undef ADD_RD_LABEL #undef ADD_RD_BUTTON }
void chmod_cmd (void) { char buffer [BUF_TINY]; char *fname; int i; struct stat sf_stat; Dlg_head *ch_dlg; do { /* do while any files remaining */ ch_dlg = init_chmod (); if (current_panel->marked) fname = next_file (); /* next marked file */ else fname = selection (current_panel)->fname; /* single file */ if (mc_stat (fname, &sf_stat) != 0) { /* get status of file */ destroy_dlg (ch_dlg); break; } c_stat = sf_stat.st_mode; mode_change = 0; /* clear changes flag */ /* set check buttons */ for (i = 0; i < PERMISSIONS; i++) { check_perm[i].check->state = (c_stat & check_perm[i].mode) ? 1 : 0; check_perm[i].selected = 0; } /* Set the labels */ c_fname = name_trunc (fname, 21); add_widget (ch_dlg, label_new (FY+2, FX+2, c_fname)); c_fown = name_trunc (get_owner (sf_stat.st_uid), 21); add_widget (ch_dlg, label_new (FY+6, FX+2, c_fown)); c_fgrp = name_trunc (get_group (sf_stat.st_gid), 21); add_widget (ch_dlg, label_new (FY+8, FX+2, c_fgrp)); g_snprintf (buffer, sizeof (buffer), "%o", c_stat); statl = label_new (FY+4, FX+2, buffer); add_widget (ch_dlg, statl); run_dlg (ch_dlg); /* retrieve an action */ /* do action */ switch (ch_dlg->ret_value) { case B_ENTER: if (mode_change) if (mc_chmod (fname, c_stat) == -1) message (1, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "), fname, unix_error_string (errno)); need_update = 1; break; case B_CANCEL: end_chmod = 1; break; case B_ALL: case B_MARKED: and_mask = or_mask = 0; and_mask = ~and_mask; for (i = 0; i < PERMISSIONS; i++) { if (check_perm[i].selected || ch_dlg->ret_value == B_ALL) { if (check_perm[i].check->state & C_BOOL) or_mask |= check_perm[i].mode; else and_mask &= ~check_perm[i].mode; } } apply_mask (&sf_stat); break; case B_SETMRK: and_mask = or_mask = 0; and_mask = ~and_mask; for (i = 0; i < PERMISSIONS; i++) { if (check_perm[i].selected) or_mask |= check_perm[i].mode; } apply_mask (&sf_stat); break; case B_CLRMRK: and_mask = or_mask = 0; and_mask = ~and_mask; for (i = 0; i < PERMISSIONS; i++) { if (check_perm[i].selected) and_mask &= ~check_perm[i].mode; } apply_mask (&sf_stat); break; } if (current_panel->marked && ch_dlg->ret_value!=B_CANCEL) { do_file_mark (current_panel, c_file, 0); need_update = 1; } destroy_dlg (ch_dlg); } while (current_panel->marked && !end_chmod); chmod_done (); }
/* Returns 1 if the user would like to see us again */ static int complete_engine (WInput *in, int what_to_do) { if (in->completions && in->point != end) free_completions (in); if (!in->completions){ end = in->point; for (start = end ? end - 1 : 0; start > -1; start--) if (strchr (" \t;|<>", in->buffer [start])) break; if (start < end) start++; in->completions = try_complete (in->buffer, &start, &end, in->completion_flags); } if (in->completions){ if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { if (insert_text (in, in->completions [0], strlen (in->completions [0]))){ if (in->completions [1]) beep (); else free_completions (in); } else beep (); } if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) { int maxlen = 0, i, count = 0; int x, y, w, h; int start_x, start_y; char **p, *q; Dlg_head *query_dlg; WListbox *query_list; for (p=in->completions + 1; *p; count++, p++) if ((i = strlen (*p)) > maxlen) maxlen = i; start_x = in->widget.x; start_y = in->widget.y; if (start_y - 2 >= count) { y = start_y - 2 - count; h = 2 + count; } else { if (start_y >= LINES - start_y - 1) { y = 0; h = start_y; } else { y = start_y + 1; h = LINES - start_y - 1; } } x = start - in->first_shown - 2 + start_x; w = maxlen + 4; if (x + w > COLS) x = COLS - w; if (x < 0) x = 0; if (x + w > COLS) w = COLS; input = in; min_end = end; query_height = h; query_width = w; query_dlg = create_dlg (y, x, query_height, query_width, dialog_colors, query_callback, "[Completion]", NULL, DLG_COMPACT); query_list = listbox_new (1, 1, w - 2, h - 2, NULL); add_widget (query_dlg, query_list); for (p = in->completions + 1; *p; p++) listbox_add_item (query_list, 0, 0, *p, NULL); run_dlg (query_dlg); q = NULL; if (query_dlg->ret_value == B_ENTER){ listbox_get_current (query_list, &q, NULL); if (q) insert_text (in, q, strlen (q)); } if (q || end != min_end) free_completions (in); i = query_dlg->ret_value; /* B_USER if user wants to start over again */ destroy_dlg (query_dlg); if (i == B_USER) return 1; } } else beep (); return 0; }
int quick_dialog_skip (QuickDialog * qd, int nskip) { #ifdef ENABLE_NLS #define I18N(x) (x = !qd->i18n && x != NULL && *x != '\0' ? _(x): x) #else #define I18N(x) (x = x) #endif Dlg_head *dd; QuickWidget *qw; WInput *in; WRadio *r; int return_val; I18N (qd->title); if ((qd->xpos == -1) || (qd->ypos == -1)) dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen, dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, DLG_CENTER | DLG_TRYUP | DLG_REVERSE); else dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen, dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, DLG_REVERSE); for (qw = qd->widgets; qw->widget_type != quick_end; qw++) { int xpos; int ypos; xpos = (qd->xlen * qw->relative_x) / qw->x_divisions; ypos = (qd->ylen * qw->relative_y) / qw->y_divisions; switch (qw->widget_type) { case quick_checkbox: qw->widget = (Widget *) check_new (ypos, xpos, *qw->u.checkbox.state, I18N (qw->u.checkbox.text)); break; case quick_button: qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action, (qw->u.button.action == B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON, I18N (qw->u.button.text), qw->u.button.callback); break; case quick_input: in = input_new (ypos, xpos, input_get_default_colors (), qw->u.input.len, qw->u.input.text, qw->u.input.histname, INPUT_COMPLETE_DEFAULT); in->is_password = (qw->u.input.flags == 1); if ((qw->u.input.flags & 2) != 0) in->completion_flags |= INPUT_COMPLETE_CD; if ((qw->u.input.flags & 4) != 0) in->strip_password = TRUE; qw->widget = (Widget *) in; *qw->u.input.result = NULL; break; case quick_label: qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text)); break; case quick_groupbox: qw->widget = (Widget *) groupbox_new (ypos, xpos, qw->u.groupbox.height, qw->u.groupbox.width, I18N (qw->u.groupbox.title)); break; case quick_radio: { int i; char **items = NULL; /* create the copy of radio_items to avoid mwmory leak */ items = g_new0 (char *, qw->u.radio.count + 1); if (!qd->i18n) for (i = 0; i < qw->u.radio.count; i++) items[i] = g_strdup (_(qw->u.radio.items[i])); else for (i = 0; i < qw->u.radio.count; i++) items[i] = g_strdup (qw->u.radio.items[i]); r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items); r->pos = r->sel = *qw->u.radio.value; qw->widget = (Widget *) r; g_strfreev (items); break; } default: qw->widget = NULL; fprintf (stderr, "QuickWidget: unknown widget type\n"); break; } if (qw->widget != NULL) { qw->widget->options |= qw->options; /* FIXME: cannot reset flags, setup only */ add_widget (dd, qw->widget); } } while (nskip-- != 0) { dd->current = g_list_next (dd->current); if (dd->current == NULL) dd->current = dd->widgets; } return_val = run_dlg (dd); /* Get the data if we found something interesting */ if (return_val != B_CANCEL) { for (qw = qd->widgets; qw->widget_type != quick_end; qw++) { switch (qw->widget_type) { case quick_checkbox: *qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL; break; case quick_input: if ((qw->u.input.flags & 2) != 0) *qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer); else *qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer); break; case quick_radio: *qw->u.radio.value = ((WRadio *) qw->widget)->sel; break; default: break; } } } destroy_dlg (dd); return return_val; #undef I18N }