Merge branch '1532_escape_learn_keys'

* 1532_escape_learn_keys:
  Ticket #1532: Key configuration doesn't save properly
This commit is contained in:
Slava Zanko 2009-10-15 14:59:07 +03:00
commit fac2020acf
3 changed files with 55 additions and 12 deletions

View File

@ -47,6 +47,7 @@
#include "learn.h" #include "learn.h"
#include "wtools.h" #include "wtools.h"
#include "strutil.h" #include "strutil.h"
#include "strescape.h"
#define UX 4 #define UX 4
#define UY 3 #define UY 3
@ -311,12 +312,18 @@ learn_save (void)
int i; int i;
int profile_changed = 0; int profile_changed = 0;
char *section = g_strconcat ("terminal:", getenv ("TERM"), (char *) NULL); char *section = g_strconcat ("terminal:", getenv ("TERM"), (char *) NULL);
char *esc_str;
for (i = 0; i < learn_total; i++) { for (i = 0; i < learn_total; i++) {
if (learnkeys [i].sequence != NULL) { if (learnkeys [i].sequence != NULL) {
profile_changed = 1; profile_changed = 1;
mc_config_set_string(mc_main_config, section,
key_name_conv_tab [i].name, learnkeys [i].sequence); esc_str = strutils_escape (learnkeys [i].sequence, -1, ";\\", TRUE);
mc_config_direct_set_string(mc_main_config, section,
key_name_conv_tab [i].name, esc_str);
g_free(esc_str);
} }
} }

View File

@ -70,6 +70,10 @@ int *mc_config_get_int_list (mc_config_t *, const gchar *,
/* mcconfig/set.c: */ /* mcconfig/set.c: */
void
mc_config_direct_set_string (mc_config_t *, const gchar *,
const gchar *, const gchar *);
void void
mc_config_set_string (mc_config_t *, const gchar *, mc_config_set_string (mc_config_t *, const gchar *,
const gchar *, const gchar *); const gchar *, const gchar *);

View File

@ -35,19 +35,14 @@ extern int utf8_display;
/*** file scope variables **********************************************/ /*** file scope variables **********************************************/
/*** file scope functions **********************************************/ /*** file scope functions **********************************************/
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*** public functions **************************************************/ static gchar *
mc_config_normalize_before_save(const gchar * value)
void
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
{ {
GIConv conv; GIConv conv;
GString *buffer; GString *buffer;
if (!mc_config || !group || !param || !value)
return;
if (utf8_display) if (utf8_display)
{ {
buffer = g_string_new(value); buffer = g_string_new(value);
@ -69,8 +64,45 @@ mc_config_set_string (mc_config_t * mc_config, const gchar * group,
str_close_conv (conv); str_close_conv (conv);
} }
g_key_file_set_string (mc_config->handle, group, param, buffer->str); return g_string_free(buffer, FALSE);
g_string_free(buffer, TRUE); }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*** public functions **************************************************/
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
{
gchar *buffer;
if (!mc_config || !group || !param || !value)
return;
buffer = mc_config_normalize_before_save(value);
g_key_file_set_value (mc_config->handle, group, param, buffer);
g_free(buffer);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
{
gchar *buffer;
if (!mc_config || !group || !param || !value)
return;
buffer = mc_config_normalize_before_save(value);
g_key_file_set_string (mc_config->handle, group, param, buffer);
g_free(buffer);
} }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */