Example #1
0
File: listmode.c Project: dborca/mc
static char *
collect_new_format (void)
{
    char *newformat;
    int i;
    char *last;
    char *text, *extra;

    newformat = g_malloc (1024);
    if (radio_genwidth->sel)
	strcpy (newformat, "full ");
    else
	strcpy (newformat, "half ");
    if (radio_columns->sel)
	strcat (newformat, "2 ");
    last = NULL;
    for (i = 0;; i++) {
	listbox_select_by_number (l_listmode, i);
	listbox_get_current (l_listmode, &text, &extra);
	if (text == last)
	    break;
	if (last != NULL)
	    strcat (newformat, ",");
	strcat (newformat, text);
	last = text;
    }
    return newformat;
}
Example #2
0
/* 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);
	}
    }
}
Example #3
0
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);
}
static void
listbox_select (GtkWidget *widget, int row, int column, GdkEvent *event, WListbox *l)
{
	Dlg_head *h = l->widget.parent;
	static int inside;

	if (inside)
		return;
	inside = 1;

	listbox_select_by_number (l, row);
	
	if (!event){
		inside = 0;
		return;
	}

	
	if (event->type == GDK_2BUTTON_PRESS){
		switch (l->action){
		case listbox_nothing:
			break;
			
		case listbox_finish:
			h->running   = 0;
			h->ret_value = B_ENTER;
			gtk_main_quit ();
			return;
			
		case listbox_cback:
			if ((*l->cback)(l) == listbox_finish){
				gtk_main_quit ();
				return;
			}
		}
	}

	/* Send an artificial DLG_POST_KEY */
	if (event->type == GDK_BUTTON_PRESS)
		(*l->widget.parent->callback)(l->widget.parent, 0, DLG_POST_KEY);

	inside = 0;
}
Example #5
0
File: user.c Project: dborca/mc
/*
 * 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);
}
Example #6
0
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);
}