[Xfce4-commits] <terminal:master> Add support for color presets.

Nick Schermer noreply at xfce.org
Sun Dec 23 22:38:07 CET 2012


Updating branch refs/heads/master
         to 0236acf21bb6e17930b1e9408eb50d5e90004714 (commit)
       from 9d0ac1ce8e73c9b975a04e82e90158efe8847dd1 (commit)

commit 0236acf21bb6e17930b1e9408eb50d5e90004714
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Dec 23 22:06:59 2012 +0100

    Add support for color presets.

 terminal/terminal-preferences-dialog.c |  183 +++++++++++++++++++++++++++++++-
 terminal/terminal-preferences.c        |    2 +-
 terminal/terminal-screen.c             |    7 +-
 xfce4-terminal.glade                   |   88 ++++++++++++----
 4 files changed, 254 insertions(+), 26 deletions(-)

diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index da21184..a6a5787 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -39,6 +39,7 @@ static void terminal_preferences_dialog_response          (GtkWidget
 static void terminal_preferences_dialog_palette_changed   (GtkWidget                 *button,
                                                            TerminalPreferencesDialog *dialog);
 static void terminal_preferences_dialog_palette_notify    (TerminalPreferencesDialog *dialog);
+static void terminal_preferences_dialog_presets_load      (TerminalPreferencesDialog *dialog);
 static void terminal_preferences_dialog_reset_compat      (GtkWidget                 *button,
                                                            TerminalPreferencesDialog *dialog);
 static void terminal_preferences_dialog_reset_word_chars  (GtkWidget                 *button,
@@ -71,6 +72,14 @@ struct _TerminalPreferencesDialog
   gulong               palette_signal_id;
 };
 
+enum
+{
+  PRESET_COLUMN_TITLE,
+  PRESET_COLUMN_IS_SEPARATOR,
+  PRESET_COLUMN_PATH,
+  N_PRESET_COLUMNS
+};
+
 
 
 G_DEFINE_TYPE (TerminalPreferencesDialog, terminal_preferences_dialog, GTK_TYPE_BUILDER)
@@ -185,6 +194,9 @@ error:
       "notify::color-palette", G_CALLBACK (terminal_preferences_dialog_palette_notify), dialog);
   terminal_preferences_dialog_palette_notify (dialog);
 
+  /* color presets */
+  terminal_preferences_dialog_presets_load (dialog);
+
   /* other properties */
   BIND_PROPERTIES ("font-name", "font-name");
   BIND_PROPERTIES ("title-initial", "text");
@@ -365,12 +377,12 @@ terminal_preferences_dialog_palette_notify (TerminalPreferencesDialog *dialog)
   if (G_LIKELY (color_str != NULL))
     {
       /* make array */
-      colors = g_strsplit (color_str, ";", 16);
+      colors = g_strsplit (color_str, ";", -1);
       g_free (color_str);
 
       /* apply values to buttons */
       if (colors != NULL)
-        for (i = 0; colors[i] != NULL; i++)
+        for (i = 0; colors[i] != NULL && i < 16; i++)
           {
             g_snprintf (name, sizeof (name), "color-palette%d", i + 1);
             obj = gtk_builder_get_object (GTK_BUILDER (dialog), name);
@@ -386,6 +398,173 @@ terminal_preferences_dialog_palette_notify (TerminalPreferencesDialog *dialog)
 
 
 
+static gboolean
+terminal_preferences_dialog_presets_sepfunc (GtkTreeModel *model,
+                                             GtkTreeIter  *iter,
+                                             gpointer      user_data)
+{
+  gboolean is_separator;
+  gtk_tree_model_get (model, iter, PRESET_COLUMN_IS_SEPARATOR, &is_separator, -1);
+  return is_separator;
+}
+
+
+
+static void
+terminal_preferences_dialog_presets_changed (GtkComboBox               *combobox,
+                                             TerminalPreferencesDialog *dialog)
+{
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gchar        *path;
+  XfceRc       *rc;
+  guint         n;
+  const gchar  *blurb;
+  GObjectClass *gobject_class;
+  GParamSpec   *pspec;
+  const gchar  *str;
+  GValue        value = { 0, };
+  const gchar  *props[] = { "color-foreground", "color-background",
+                            "color-cursor", "color-selection",
+                            "color-palette", "tab-activity-color" };
+
+  if (!gtk_combo_box_get_active_iter (combobox, &iter))
+    return;
+
+  model = gtk_combo_box_get_model (combobox);
+  gtk_tree_model_get (model, &iter, PRESET_COLUMN_PATH, &path, -1);
+  if (path == NULL)
+    return;
+
+  /* load file */
+  rc = xfce_rc_simple_open (path, TRUE);
+  g_free (path);
+  if (G_UNLIKELY (rc == NULL))
+    return;
+
+  xfce_rc_set_group (rc, "Scheme");
+
+  gobject_class = G_OBJECT_GET_CLASS (dialog->preferences);
+  for (n = 0; n < G_N_ELEMENTS (props); n++)
+    {
+      /* lookup the property */
+      pspec = g_object_class_find_property (gobject_class, props[n]);
+      terminal_assert (pspec != NULL && G_IS_PARAM_SPEC_STRING (pspec));
+
+      /* read key from scheme */
+      blurb = g_param_spec_get_blurb (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);
+      else
+        g_param_value_set_default (pspec, &value);
+
+      /* set */
+      g_object_set_property (G_OBJECT (dialog->preferences), props[n], &value);
+      g_value_unset (&value);
+    }
+
+  xfce_rc_close (rc);
+}
+
+
+
+static void
+terminal_preferences_dialog_presets_load (TerminalPreferencesDialog *dialog)
+{
+  gchar   **presets;
+  guint     n;
+  GObject  *object;
+  guint     n_presets = 0;
+  XfceRc   *rc;
+  GtkListStore *store;
+  GtkTreeIter iter;
+  const gchar *title;
+  gchar *path;
+
+  /* load schemes */
+  presets = xfce_resource_match (XFCE_RESOURCE_DATA, "xfce4/terminal/colorschemes/*", TRUE);
+  if (G_LIKELY (presets != NULL))
+    {
+      /* create sorting store */
+      store = gtk_list_store_new (N_PRESET_COLUMNS, G_TYPE_STRING,
+                                  G_TYPE_BOOLEAN, G_TYPE_STRING);
+      gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+                                            PRESET_COLUMN_TITLE,
+                                            GTK_SORT_ASCENDING);
+
+      /* append files */
+      for (n = 0; presets[n] != NULL; n++)
+        {
+          /* open the scheme */
+          path = xfce_resource_lookup (XFCE_RESOURCE_DATA, presets[n]);
+          if (G_UNLIKELY (path == NULL))
+            continue;
+
+          rc = xfce_rc_simple_open (path, TRUE);
+          if (G_UNLIKELY (rc == NULL))
+            {
+              g_free (path);
+              continue;
+            }
+
+          xfce_rc_set_group (rc, "Scheme");
+
+          /* translated name */
+          title = xfce_rc_read_entry (rc, "Name", NULL);
+          if (G_LIKELY (title != NULL))
+            {
+              gtk_list_store_insert_with_values (store, NULL, n_presets++,
+                                                 PRESET_COLUMN_TITLE, title,
+                                                 PRESET_COLUMN_PATH, path,
+                                                 -1);
+            }
+
+          xfce_rc_close (rc);
+          g_free (path);
+        }
+
+      /* stop sorting */
+      gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+                                            GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
+                                            GTK_SORT_ASCENDING);
+
+      /* default item + separator */
+      gtk_list_store_insert_with_values (store, &iter, 0,
+                                         PRESET_COLUMN_TITLE, _("Load Presets..."),
+                                         -1);
+      gtk_list_store_insert_with_values (store, NULL, 1,
+                                         PRESET_COLUMN_IS_SEPARATOR, TRUE,
+                                         -1);
+
+      /* set model */
+      object = gtk_builder_get_object (GTK_BUILDER (dialog), "color-presets");
+      terminal_return_if_fail (GTK_IS_COMBO_BOX (object));
+      gtk_combo_box_set_model (GTK_COMBO_BOX (object), GTK_TREE_MODEL (store));
+      gtk_combo_box_set_active_iter  (GTK_COMBO_BOX (object), &iter);
+      gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (object),
+          terminal_preferences_dialog_presets_sepfunc, NULL, NULL);
+      g_signal_connect (G_OBJECT (object), "changed",
+          G_CALLBACK (terminal_preferences_dialog_presets_changed), dialog);
+      g_object_unref (store);
+    }
+
+  g_strfreev (presets);
+
+  if (n_presets == 0)
+    {
+      /* hide frame + combo */
+      object = gtk_builder_get_object (GTK_BUILDER (dialog), "color-presets-frame");
+      terminal_return_if_fail (GTK_IS_WIDGET (object));
+      gtk_widget_hide (GTK_WIDGET (object));
+    }
+}
+
+
+
 static void
 terminal_preferences_dialog_reset_compat (GtkWidget                 *button,
                                           TerminalPreferencesDialog *dialog)
diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c
index f8de9db..fde810a 100644
--- a/terminal/terminal-preferences.c
+++ b/terminal/terminal-preferences.c
@@ -423,7 +423,7 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass)
       g_param_spec_string ("tab-activity-color",
                            "tab-activity-color",
                            "TabActivityColor",
-                           "#af0000",
+                           "#aa0000",
                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index f6a2141..1113c78 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -842,13 +842,16 @@ terminal_screen_update_colors (TerminalScreen *screen)
 
   if (G_LIKELY (palette_str != NULL))
     {
-      colors = g_strsplit (palette_str, ";", 16);
+      colors = g_strsplit (palette_str, ";", -1);
       g_free (palette_str);
 
       if (colors != NULL)
         for (; colors[n] != NULL && n < 16; n++)
           if (!gdk_color_parse (colors[n], palette + n))
-            break;
+            {
+              g_warning ("Unable to parse color \"%s\".", colors[n]);
+              break;
+            }
 
       g_strfreev (colors);
       valid_palette = (n == 16);
diff --git a/xfce4-terminal.glade b/xfce4-terminal.glade
index 6fd0b20..b8c1fb2 100644
--- a/xfce4-terminal.glade
+++ b/xfce4-terminal.glade
@@ -134,6 +134,11 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="tab-activity-timeout">
+    <property name="upper">30</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="XfceTitledDialog" id="dialog">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Terminal Preferences</property>
@@ -1406,7 +1411,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 1</property>
+                                    <property name="tooltip_text" translatable="yes">Black</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette1-atkobject">
@@ -1422,7 +1427,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 2</property>
+                                    <property name="tooltip_text" translatable="yes">Red</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette2-atkobject">
@@ -1442,7 +1447,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 12</property>
+                                    <property name="tooltip_text" translatable="yes">Yellow</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette12-atkobject">
@@ -1464,7 +1469,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 9</property>
+                                    <property name="tooltip_text" translatable="yes">Dark Gray</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette9-atkobject">
@@ -1484,7 +1489,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 10</property>
+                                    <property name="tooltip_text" translatable="yes">Light Red</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette10-atkobject">
@@ -1506,7 +1511,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 11</property>
+                                    <property name="tooltip_text" translatable="yes">Light Green</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette11-atkobject">
@@ -1528,7 +1533,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 3</property>
+                                    <property name="tooltip_text" translatable="yes">Green</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette3-atkobject">
@@ -1548,7 +1553,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 4</property>
+                                    <property name="tooltip_text" translatable="yes">Brown / Yellow</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette4-atkobject">
@@ -1568,7 +1573,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 5</property>
+                                    <property name="tooltip_text" translatable="yes">Blue</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette5-atkobject">
@@ -1588,7 +1593,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 13</property>
+                                    <property name="tooltip_text" translatable="yes">Light Blue</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette13-atkobject">
@@ -1610,7 +1615,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 14</property>
+                                    <property name="tooltip_text" translatable="yes">Light Magenta</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette14-atkobject">
@@ -1632,7 +1637,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 6</property>
+                                    <property name="tooltip_text" translatable="yes">Magenta</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette6-atkobject">
@@ -1652,7 +1657,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 7</property>
+                                    <property name="tooltip_text" translatable="yes">Cyan</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette7-atkobject">
@@ -1672,7 +1677,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 15</property>
+                                    <property name="tooltip_text" translatable="yes">Light Cyan</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette15-atkobject">
@@ -1694,7 +1699,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 16</property>
+                                    <property name="tooltip_text" translatable="yes">White</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette16-atkobject">
@@ -1716,7 +1721,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="tooltip_text" translatable="yes">Palette entry 8</property>
+                                    <property name="tooltip_text" translatable="yes">Light Gray</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="color-palette8-atkobject">
@@ -1759,6 +1764,52 @@
                     <property name="position">2</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkFrame" id="color-presets-frame">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment21">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="xscale">0</property>
+                        <property name="top_padding">6</property>
+                        <property name="left_padding">18</property>
+                        <child>
+                          <object class="GtkComboBox" id="color-presets">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <child>
+                              <object class="GtkCellRendererText" id="cellrenderertext8"/>
+                              <attributes>
+                                <attribute name="text">0</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label17">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Presets</property>
+                        <property name="use_markup">True</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="position">2</property>
@@ -2260,9 +2311,4 @@ when double clicking:</property>
       <widget name="opacity-label"/>
     </widgets>
   </object>
-  <object class="GtkAdjustment" id="tab-activity-timeout">
-    <property name="upper">30</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
 </interface>


More information about the Xfce4-commits mailing list