[Xfce4-commits] <terminal:master> More flexible color scheme handling.
Nick Schermer
noreply at xfce.org
Tue Dec 25 13:54:01 CET 2012
Updating branch refs/heads/master
to 8b7f1c2cdb89a6ba003aae5c397e5b43a8e30f5b (commit)
from 1cb91001d3ee1e45793a1ad3f0e0db631597440d (commit)
commit 8b7f1c2cdb89a6ba003aae5c397e5b43a8e30f5b
Author: Nick Schermer <nick at xfce.org>
Date: Tue Dec 25 13:51:41 2012 +0100
More flexible color scheme handling.
Allow all Color properties, so also enabling custom
bold/selection colors. Demonstrate in solarized theme.
colorschemes/dark-pastels.scheme.in | 3 -
colorschemes/solarized-dark.scheme.in | 2 +
colorschemes/white-on-black.scheme.in | 1 -
terminal/terminal-preferences-dialog.c | 67 ++++++++++++++++++++++----------
4 files changed, 48 insertions(+), 25 deletions(-)
diff --git a/colorschemes/dark-pastels.scheme.in b/colorschemes/dark-pastels.scheme.in
index ec614ef..f925a35 100644
--- a/colorschemes/dark-pastels.scheme.in
+++ b/colorschemes/dark-pastels.scheme.in
@@ -3,7 +3,4 @@ _Name=Dark Pastels
ColorForeground=#dcdcdc
ColorBackground=#2c2c2c
ColorCursor=#dcdcdc
-ColorSelection=
ColorPalette=#3f3f3f;#705050;#60b48a;#dfaf8f;#9ab8d7;#dc8cc3;#8cd0d3;#dcdcdc;#709080;#dca3a3;#72d5a3;#f0dfaf;#94bff3;#ec93d3;#93e0e3;#ffffff
-
-
diff --git a/colorschemes/solarized-dark.scheme.in b/colorschemes/solarized-dark.scheme.in
index 8283954..0d2b86a 100644
--- a/colorschemes/solarized-dark.scheme.in
+++ b/colorschemes/solarized-dark.scheme.in
@@ -5,3 +5,5 @@ ColorBackground=#002b36
ColorCursor=#93a1a1
TabActivityColor=#dc322f
ColorPalette=#073642;#dc322f;#859900;#b58900;#268bd2;#d33682;#2aa198;#eee8d5;#002b36;#cb4b16;#586e75;#657b83;#839496;#6c71c4;#93a1a1;#fdf6e3
+ColorBold=#93a1a1
+ColorBoldUseDefault=FALSE
diff --git a/colorschemes/white-on-black.scheme.in b/colorschemes/white-on-black.scheme.in
index 9f977ef..35dcfa5 100644
--- a/colorschemes/white-on-black.scheme.in
+++ b/colorschemes/white-on-black.scheme.in
@@ -1,3 +1,2 @@
[Scheme]
_Name=White on Black
-
diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index 8a14aab..c1663ac 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -423,15 +423,14 @@ terminal_preferences_dialog_presets_changed (GtkComboBox *combobox
GtkTreeIter iter;
gchar *path;
XfceRc *rc;
+ GParamSpec **pspecs, *pspec;
+ guint nspecs;
guint n;
const gchar *blurb;
- GObjectClass *gobject_class;
- GParamSpec *pspec;
+ const gchar *name;
const gchar *str;
- GValue value = { 0, };
- const gchar *props[] = { "color-foreground", "color-background",
- "color-cursor", "color-selection",
- "color-palette", "tab-activity-color" };
+ GValue src = { 0, };
+ GValue dst = { 0, };
if (!gtk_combo_box_get_active_iter (combobox, &iter))
return;
@@ -449,29 +448,55 @@ terminal_preferences_dialog_presets_changed (GtkComboBox *combobox
xfce_rc_set_group (rc, "Scheme");
- gobject_class = G_OBJECT_GET_CLASS (dialog->preferences);
- for (n = 0; n < G_N_ELEMENTS (props); n++)
+ g_value_init (&src, G_TYPE_STRING);
+
+ /* walk all properties and look for items in the scheme */
+ pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (dialog->preferences), &nspecs);
+ for (n = 0; n < nspecs; ++n)
{
- /* lookup the property */
- pspec = g_object_class_find_property (gobject_class, props[n]);
- terminal_assert (pspec != NULL && G_IS_PARAM_SPEC_STRING (pspec));
+ pspec = pspecs[n];
- /* read key from scheme */
+ /* get color keys */
blurb = g_param_spec_get_blurb (pspec);
+ if (strstr (blurb, "Color") == NULL)
+ continue;
+
+ /* read value */
+ name = g_param_spec_get_name (pspec);
str = xfce_rc_read_entry_untranslated (rc, blurb, NULL);
- /* store value or use default */
- g_value_init (&value, G_TYPE_STRING);
- if (str != NULL)
- g_value_set_static_string (&value, str);
+ if (str == NULL || *str == '\0')
+ {
+ /* reset to the default value */
+ g_value_init (&dst, G_PARAM_SPEC_VALUE_TYPE (pspec));
+ g_param_value_set_default (pspec, &dst);
+ g_object_set_property (G_OBJECT (dialog->preferences), name, &dst);
+ g_value_unset (&dst);
+ }
else
- g_param_value_set_default (pspec, &value);
+ {
+ g_value_set_static_string (&src, str);
- /* set */
- g_object_set_property (G_OBJECT (dialog->preferences), props[n], &value);
- g_value_unset (&value);
+ if (G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_STRING)
+ {
+ /* set the string property */
+ g_object_set_property (G_OBJECT (dialog->preferences), name, &src);
+ }
+ else
+ {
+ /* transform value */
+ g_value_init (&dst, G_PARAM_SPEC_VALUE_TYPE (pspec));
+ if (G_LIKELY (g_value_transform (&src, &dst)))
+ g_object_set_property (G_OBJECT (dialog->preferences), name, &dst);
+ else
+ g_warning ("Unable to convert scheme property \"%s\"", name);
+ g_value_unset (&dst);
+ }
+ }
}
+ g_free (pspecs);
+ g_value_unset (&src);
xfce_rc_close (rc);
}
More information about the Xfce4-commits
mailing list