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);
}
Example #2
0
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);
}
Example #3
0
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;
}
Example #4
0
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 ();
}
Example #5
0
/**
 * clean old unconfirmed dialogs
 *
 */
int dlg_clean_run(ticks_t ti)
{
	unsigned int i;
	unsigned int tm;
	dlg_cell_t *dlg;
	dlg_cell_t *tdlg;

	tm = (unsigned int)time(NULL);
	for(i=0; i<d_table->size; i++)
	{
		lock_set_get(d_table->locks, d_table->entries[i].lock_idx);
		dlg = d_table->entries[i].first;
		while (dlg) {
			tdlg = dlg;
			dlg = dlg->next;
			if(tdlg->state==DLG_STATE_UNCONFIRMED && tdlg->init_ts<tm-300) {
				/* dialog in early state older than 5min */
				LM_NOTICE("dialog in early state is too old (%p ref %d)\n",
						tdlg, tdlg->ref);
				unlink_unsafe_dlg(&d_table->entries[i], tdlg);
				destroy_dlg(tdlg);
			}
		}
		lock_set_release(d_table->locks, d_table->entries[i].lock_idx);
	}
	return 0;
}
Example #6
0
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 ();
}
Example #7
0
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;
}
Example #8
0
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 ();
}
Example #9
0
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;
}
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;
}
Example #11
0
/**
 * clean old unconfirmed dialogs
 *
 */
int dlg_clean_run(ticks_t ti)
{
	unsigned int i;
	unsigned int tm;
	dlg_cell_t *dlg;
	dlg_cell_t *tdlg;

	tm = (unsigned int)time(NULL);
	for(i=0; i<d_table->size; i++)
	{
		lock_set_get(d_table->locks, d_table->entries[i].lock_idx);
		dlg = d_table->entries[i].first;
		while (dlg) {
			tdlg = dlg;
			dlg = dlg->next;
			if(tdlg->state==DLG_STATE_UNCONFIRMED && tdlg->init_ts<tm-300) {
				/* dialog in early state older than 5min */
				LM_NOTICE("dialog in early state is too old (%p ref %d)\n",
						tdlg, tdlg->ref);
				unlink_unsafe_dlg(&d_table->entries[i], tdlg);
				destroy_dlg(tdlg);
			}
			if(tdlg->state==DLG_STATE_CONFIRMED_NA && tdlg->start_ts<tm-60) {
				if(update_dlg_timer(&tdlg->tl, 10)<0) {
					LM_ERR("failed to update dialog lifetime in long non-ack state\n");
				}
				tdlg->lifetime = 10;
				tdlg->dflags |= DLG_FLAG_CHANGED;
			}
		}
		lock_set_release(d_table->locks, d_table->entries[i].lock_idx);
	}
	return 0;
}
Example #12
0
/*!
 * \brief Destroy the global dialog table
 */
void destroy_dlg_table(void)
{
	struct dlg_cell *dlg, *l_dlg;
	unsigned int i;

	if (d_table==0)
		return;

	if (d_table->locks) {
		lock_set_destroy(d_table->locks);
		lock_set_dealloc(d_table->locks);
	}

	for( i=0 ; i<d_table->size; i++ ) {
		dlg = d_table->entries[i].first;
		while (dlg) {
			l_dlg = dlg;
			dlg = dlg->next;
			destroy_dlg(l_dlg);
		}

	}

	shm_free(d_table);
	d_table = 0;

	return;
}
static void listmode_done (void)
{
    destroy_dlg (listmode_dlg);
    if (0)
	update_panels (UP_OPTIMIZE, UP_KEEPSEL);
    repaint_screen ();
}
Example #14
0
/* 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;
}
Example #15
0
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;
}
void
destroy_op_win (void)
{
    dlg_run_done (op_dlg);
    destroy_dlg (op_dlg);
#ifndef HAVE_X
    the_hint->widget.y = last_hint_line;
#endif
}
Example #17
0
File: wtools.c Project: ryanlee/mc
static void
fg_message (int flags, const char *title, const char *text)
{
    Dlg_head *d;

    d = do_create_message (flags, title, text);
    tty_getch ();
    dlg_run_done (d);
    destroy_dlg (d);
}
Example #18
0
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;
}
Example #19
0
void
dialog_switch_shutdown (void)
{
    while (mc_dialogs != NULL)
    {
        Dlg_head *dlg = (Dlg_head *) mc_dialogs->data;

        run_dlg (dlg);
        destroy_dlg (dlg);
    }
}
Example #20
0
/** 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;
}
Example #21
0
/* 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;
}
Example #22
0
File: learn.c Project: BrEacK/mc
static int
learn_button (WButton * button, int action)
{
    Dlg_head *d;
    char *seq;

    (void) button;

    d = create_message (D_ERROR, _("Teach me a key"),
                        _("Please press the %s\n"
                          "and then wait until this message disappears.\n\n"
                          "Then, press it again to see if OK appears\n"
                          "next to its button.\n\n"
                          "If you want to escape, press a single Escape key\n"
                          "and wait as well."), _(key_name_conv_tab[action - B_USER].longname));
    mc_refresh ();
    if (learnkeys[action - B_USER].sequence != NULL)
    {
        g_free (learnkeys[action - B_USER].sequence);
        learnkeys[action - B_USER].sequence = NULL;
    }
    seq = learn_key ();

    if (seq)
    {
        /* Esc hides the dialog and do not allow definitions of
         * regular characters
         */
        gboolean seq_ok = FALSE;

        if (*seq && strcmp (seq, "\\e") && strcmp (seq, "\\e\\e")
            && strcmp (seq, "^m") && strcmp (seq, "^i") && (seq[1] || (*seq < ' ' || *seq > '~')))
        {

            learnchanged = 1;
            learnkeys[action - B_USER].sequence = seq;
            seq = convert_controls (seq);
            seq_ok = define_sequence (key_name_conv_tab[action - B_USER].code, seq, MCKEY_NOACTION);
        }

        if (!seq_ok)
            message (D_NORMAL, _("Cannot accept this key"), _("You have entered \"%s\""), seq);

        g_free (seq);
    }

    dlg_run_done (d);
    destroy_dlg (d);
    dlg_select_widget (learnkeys[action - B_USER].button);
    return 0;                   /* Do not kill learn_dlg */
}
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;
    }
}
Example #24
0
/* 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;
}
Example #25
0
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;
}
Example #26
0
File: filegui.c Project: artzub/mc
void
file_op_context_destroy_ui (FileOpContext * ctx)
{
    g_return_if_fail (ctx != NULL);

    if (ctx->ui != NULL)
    {
        FileOpContextUI *ui = (FileOpContextUI *) ctx->ui;

        dlg_run_done (ui->op_dlg);
        destroy_dlg (ui->op_dlg);
        g_free (ui);
        ctx->ui = NULL;
    }
}
Example #27
0
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);
}
static int learn_button (int action, void *param)
{
    unsigned char *seq;
    Dlg_head *d = message (D_INSERT | 1, _(" Teach me a key "),
_("Please press the %s\n"
"and then wait until this message disappears.\n\n"
"Then, press it again to see if OK appears\n"
"next to its button.\n\n"
"If you want to escape, press a single Escape key\n"
"and wait as well."), 
        _(key_name_conv_tab [action - B_USER].longname));
    mc_refresh ();
    if (learnkeys [action - B_USER].sequence != NULL) {
	free (learnkeys [action - B_USER].sequence);
	learnkeys [action - B_USER].sequence = NULL;
    }
    seq = learn_key ();

    if (seq){
	/* Esc hides the dialog and do not allow definitions of
	 * regular characters
	 */
	if (*seq && strcmp (seq, "\\e") && strcmp (seq, "\\e\\e")
	    && strcmp (seq, "^m" ) 
            && (seq [1] || (*seq < ' ' || *seq > '~'))){
	    
	    learnchanged = 1;
	    learnkeys [action - B_USER].sequence = seq;
	    seq = convert_controls (seq);
	    define_sequence (key_name_conv_tab [action - B_USER].code, seq, 
			     MCKEY_NOACTION);
	} else {
	    message (0, _(" Cannot accept this key "),
		_(" You have entered \"%s\""), seq);
	}
	
    	free (seq);
    }
    
    dlg_run_done (d);
    destroy_dlg (d);
    dlg_select_widget (learn_dlg, learnkeys [action - B_USER].button);
    return 0; /* Do not kill learn_dlg */
}
Example #29
0
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;
}
Example #30
0
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;
}