Пример #1
0
static void
load_keys_from_section (const char *terminal, mc_config_t * cfg)
{
    char *section_name;
    gchar **profile_keys, **keys;
    char *valcopy, *value;
    long key_code;

    if (terminal == NULL)
        return;

    section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
    keys = mc_config_get_keys (cfg, section_name, NULL);

    for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
    {
        /* copy=other causes all keys from [terminal:other] to be loaded. */
        if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
        {
            valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
            load_keys_from_section (valcopy, cfg);
            g_free (valcopy);
            continue;
        }

        key_code = lookup_key (*profile_keys, NULL);
        if (key_code != 0)
        {
            gchar **values;

            values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
            if (values != NULL)
            {
                gchar **curr_values;

                for (curr_values = values; *curr_values != NULL; curr_values++)
                {
                    valcopy = convert_controls (*curr_values);
                    define_sequence (key_code, valcopy, MCKEY_NOACTION);
                    g_free (valcopy);
                }

                g_strfreev (values);
            }
            else
            {
                value = mc_config_get_string (cfg, section_name, *profile_keys, "");
                valcopy = convert_controls (value);
                define_sequence (key_code, valcopy, MCKEY_NOACTION);
                g_free (valcopy);
                g_free (value);
            }
        }
    }
    g_strfreev (keys);
    g_free (section_name);
}
Пример #2
0
static void
load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
{
    gchar **profile_keys, **keys;
    gchar **values, **curr_values;
    char *valcopy, *value;
    int action;
    gsize len, values_len;

    if (section_name == NULL)
        return;

    profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);

    while (*profile_keys != NULL)
    {
        curr_values = values =
                          mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);

        action = keybind_lookup_action (*profile_keys);

        if (action > 0)
        {
            if (curr_values != NULL)
            {
                while (*curr_values != NULL)
                {
                    valcopy = convert_controls (*curr_values);
                    keybind_cmd_bind (keymap, valcopy, action);
                    g_free (valcopy);
                    curr_values++;
                }
            }
            else
            {
                value = mc_config_get_string (cfg, section_name, *profile_keys, "");
                valcopy = convert_controls (value);
                /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */
                g_free (valcopy);
                g_free (value);
            }
        }

        profile_keys++;
        g_strfreev (values);
    }
    g_strfreev (keys);
}
Пример #3
0
void load_keys_from_section (char *terminal, char *profile_name)
{
    char *section_name;
    void *profile_keys;
    char *key, *value, *valcopy;
    int  key_code;

    if (!terminal)
	return;

    section_name = copy_strings ("terminal:", terminal, 0);
    profile_keys = profile_init_iterator (section_name, profile_name);
    if (!profile_keys){
	free (section_name);
	return;
    }
    
    while (profile_keys){
	profile_keys = profile_iterator_next (profile_keys, &key, &value);
	key_code = lookup_key (key);
	valcopy = convert_controls (value);
	if (key_code)
	    define_sequence (key_code, valcopy, MCKEY_NOACTION);
	free (valcopy);
    }
    free (section_name);
    return;
}
Пример #4
0
Файл: learn.c Проект: CTU-OSP/mc
static int
learn_button (WButton * button, int action)
{
    WDialog *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 != NULL)
    {
        /* Esc hides the dialog and do not allow definitions of
         * regular characters
         */
        gboolean seq_ok = FALSE;

        if (*seq != '\0' && strcmp (seq, "\\e") != 0 && strcmp (seq, "\\e\\e") != 0
            && strcmp (seq, "^m") != 0 && strcmp (seq, "^i") != 0
            && (seq[1] != '\0' || *seq < ' ' || *seq > '~'))
        {
            learnchanged = TRUE;
            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);
    dlg_destroy (d);

    dlg_select_widget (learnkeys[action - B_USER].button);

    return 0;                   /* Do not kill learn_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 */
}