Merge branch '1785_editor_normal_color'

* 1785_editor_normal_color:
  Some optimization and cleanup of color-related code in skin layer.
  Some optimization and cleanup of color-related code in TTY layer.
  Ticket #1785: fix of editor default color usage.
This commit is contained in:
Slava Zanko 2010-10-06 12:18:17 +03:00
commit 99149c5c54
8 changed files with 64 additions and 64 deletions

View File

@ -127,13 +127,14 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
mc_skin_color_t *mc_skin_color, *tmp;
values = mc_config_get_string_list (mc_skin->config, group, key, &items_count);
if (values == NULL || *values == NULL)
if (values == NULL)
return NULL;
if (*values == NULL)
{
if (values != NULL)
g_strfreev (values);
g_strfreev (values);
return NULL;
}
mc_skin_color = g_try_new0 (mc_skin_color_t, 1);
if (mc_skin_color == NULL)
{
@ -145,7 +146,7 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
{
case 0:
tmp = mc_skin_color_get_with_defaults (group, "_default_");
if (tmp)
if (tmp != NULL)
{
mc_skin_color->fgcolor = g_strdup (tmp->fgcolor);
mc_skin_color->bgcolor = g_strdup (tmp->bgcolor);
@ -330,13 +331,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
if (keys == NULL)
continue;
if (*keys == NULL)
{
g_strfreev (keys);
continue;
}
for (; *keys; keys++)
for (; *keys != NULL; keys++)
{
mc_skin_color = mc_skin_color_get_from_ini_file (mc_skin, *groups, *keys);
if (mc_skin_color != NULL)

View File

@ -48,14 +48,6 @@ static gboolean mc_skin_is_init = FALSE;
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static inline void
mc_skin_hash_destroy_key (gpointer data)
{
g_free (data);
}
/* --------------------------------------------------------------------------------------------- */
static void
mc_skin_hash_destroy_value (gpointer data)
{
@ -93,7 +85,7 @@ mc_skin_reinit (void)
mc_skin_deinit ();
mc_skin__default.name = mc_skin_get_default_name ();
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
mc_skin_hash_destroy_key,
g_free,
mc_skin_hash_destroy_value);
}
@ -124,7 +116,7 @@ mc_skin_init (GError ** error)
mc_skin__default.name = mc_skin_get_default_name ();
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
mc_skin_hash_destroy_key,
g_free,
mc_skin_hash_destroy_value);
if (!mc_skin_ini_file_load (&mc_skin__default)) {

View File

@ -82,12 +82,14 @@ mc_tty_color_table_t const color_table[] = {
const char *
tty_color_get_valid_name (const char *color_name)
{
int i;
if (color_name != NULL)
{
size_t i;
for (i = 0; color_table[i].name != NULL; i++)
if (strcmp (color_name, color_table[i].name) == 0)
return color_table[i].name;
}
return NULL;
}
@ -96,12 +98,14 @@ tty_color_get_valid_name (const char *color_name)
int
tty_color_get_index_by_name (const char *color_name)
{
int i;
if (color_name != NULL)
{
size_t i;
for (i = 0; color_table[i].name != NULL; i++)
if (strcmp (color_name, color_table[i].name) == 0)
return color_table[i].value;
}
return -1;
}

View File

@ -25,7 +25,7 @@ typedef struct mc_color_pair_struct
const char *cbg;
int ifg;
int ibg;
size_t pair_index;
int pair_index;
gboolean is_temp;
} tty_color_pair_t;

View File

@ -61,6 +61,7 @@ static int
mc_tty_color_save_attr_lib (int color_pair, int color_attr)
{
int *attr, *key;
attr = g_try_new0 (int, 1);
if (attr == NULL)
return color_attr;

View File

@ -61,23 +61,6 @@ static GHashTable *mc_tty_color__hashtable = NULL;
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static inline void
color_hash_destroy_key (gpointer data)
{
g_free (data);
}
/* --------------------------------------------------------------------------------------------- */
static void
color_hash_destroy_value (gpointer data)
{
tty_color_pair_t *mc_color_pair = (tty_color_pair_t *) data;
g_free (mc_color_pair);
}
/* --------------------------------------------------------------------------------------------- */
static gboolean
tty_color_free_condition_cb (gpointer key, gpointer value, gpointer user_data)
{
@ -96,7 +79,7 @@ static void
tty_color_free_all (gboolean is_temp_color)
{
g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_condition_cb,
(is_temp_color) ? (gpointer) 1 : NULL);
is_temp_color ? GINT_TO_POINTER (1) : NULL);
}
/* --------------------------------------------------------------------------------------------- */
@ -104,33 +87,29 @@ tty_color_free_all (gboolean is_temp_color)
static gboolean
tty_color_get_next_cpn_cb (gpointer key, gpointer value, gpointer user_data)
{
size_t cp;
int cp;
tty_color_pair_t *mc_color_pair;
(void) key;
cp = (size_t) user_data;
cp = GPOINTER_TO_INT (user_data);
mc_color_pair = (tty_color_pair_t *) value;
if (cp == mc_color_pair->pair_index)
return TRUE;
return FALSE;
return (cp == mc_color_pair->pair_index);
}
/* --------------------------------------------------------------------------------------------- */
static int
tty_color_get_next__color_pair_number ()
tty_color_get_next__color_pair_number (void)
{
size_t cp_count = g_hash_table_size (mc_tty_color__hashtable);
size_t cp = 0;
const size_t cp_count = g_hash_table_size (mc_tty_color__hashtable);
int cp;
for (cp = 0; cp < cp_count; cp++)
{
if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb, (gpointer) cp) ==
NULL)
return cp;
}
if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb,
GINT_TO_POINTER (cp)) == NULL)
break;
return cp;
}
@ -142,9 +121,7 @@ void
tty_init_colors (gboolean disable, gboolean force)
{
tty_color_init_lib (disable, force);
mc_tty_color__hashtable = g_hash_table_new_full (g_str_hash, g_str_equal,
color_hash_destroy_key,
color_hash_destroy_value);
mc_tty_color__hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
/* --------------------------------------------------------------------------------------------- */
@ -178,11 +155,9 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo
if (fg == NULL)
fg = tty_color_defaults__fg;
if (bg == NULL)
{
bg = tty_color_defaults__bg;
}
c_fg = tty_color_get_valid_name (fg);
c_bg = tty_color_get_valid_name (bg);

View File

@ -207,7 +207,6 @@ edit_status (WEdit * edit)
widget_move (edit, 0, edit->widget.cols - 5);
tty_printf (" %3d%%", percent);
}
tty_setcolor (EDITOR_NORMAL_COLOR);
g_free (status);
}

View File

@ -744,6 +744,10 @@ this_try_alloc_color_pair (const char *fg, const char *bg)
bg = NULL;
if (fg != NULL && *fg == '\0')
fg = NULL;
if ((fg == NULL) && (bg == NULL))
return EDITOR_NORMAL_COLOR;
if (fg != NULL)
{
g_strlcpy (f, fg, sizeof (f));
@ -760,6 +764,36 @@ this_try_alloc_color_pair (const char *fg, const char *bg)
*p = '\0';
bg = b;
}
if ((fg == NULL) || (bg == NULL))
{
/* get colors from skin */
char *editnormal;
editnormal = mc_skin_get ("editor", "_default_", "default;default");
if (fg == NULL)
{
g_strlcpy (f, editnormal, sizeof (f));
p = strchr (f, ';');
if (p != NULL)
*p = '\0';
if (f[0] == '\0')
g_strlcpy (f, "default", sizeof (f));
fg = f;
}
if (bg == NULL)
{
p = strchr (editnormal, ';');
if ((p != NULL) && (*(++p) != '\0'))
g_strlcpy (b, p, sizeof (b));
else
g_strlcpy (b, "default", sizeof (b));
bg = b;
}
g_free (editnormal);
}
return tty_try_alloc_color_pair (fg, bg);
}