Persist font settings 20131015030506/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 14 Oct 2013 17:36:02 +0000 (19:36 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 14 Oct 2013 17:36:02 +0000 (19:36 +0200)
Allow the font size and family chosen for the data editor to
persist between sessions

Requested-by: Paul Wright <pmwrightmiller@yahoo.com>
src/ui/gui/psppire-conf.c
src/ui/gui/psppire-conf.h
src/ui/gui/psppire-data-editor.c

index fe4f934bd640193e382f1fc077c7ff661f91850b..561f933ff061369243647d6e791e471072adac29 100644 (file)
@@ -223,6 +223,31 @@ psppire_conf_get_boolean (PsppireConf *conf, const gchar *base,
 }
 
 
+
+gboolean
+psppire_conf_get_string (PsppireConf *conf, const gchar *base,
+                        const gchar *name, gchar **value)
+{
+  gboolean ok;
+  gchar *b;
+  GError *err = NULL;
+  conf_read (conf);
+  b = g_key_file_get_string (conf->keyfile,
+                            base,
+                            name, &err);
+
+  ok = (err == NULL);
+  if ( err != NULL )
+    g_error_free (err);
+
+  if (ok)
+    *value = b;
+
+  return ok;
+}
+
+
+
 void
 psppire_conf_set_int (PsppireConf *conf,
                      const gchar *base, const gchar *name,
@@ -241,6 +266,18 @@ psppire_conf_set_boolean (PsppireConf *conf,
   conf_write (conf);
 }
 
+
+void
+psppire_conf_set_string (PsppireConf *conf,
+                        const gchar *base, const gchar *name,
+                        const gchar *value)
+{
+  g_key_file_set_string (conf->keyfile, base, name, value);
+  conf_write (conf);
+}
+
+
+
 /*
   A convenience function to set the geometry of a
   window from from a saved config
index 8586022666d5757754b1af8b48da2de8e8adbbc6..8f944518e08e13bfeb3205e2373d1ca4ee5cf390 100644 (file)
@@ -79,6 +79,9 @@ PsppireConf * psppire_conf_new (void);
 gboolean psppire_conf_get_int (PsppireConf *,
                               const gchar *, const gchar *, int *);
 
+gboolean psppire_conf_get_string (PsppireConf *,
+                              const gchar *, const gchar *, gchar **);
+
 gboolean psppire_conf_get_boolean (PsppireConf *,
                                   const gchar *, const gchar *, gboolean *);
 
@@ -90,6 +93,9 @@ void psppire_conf_set_boolean (PsppireConf *conf,
                               const gchar *base, const gchar *name,
                               gboolean value);
 
+void psppire_conf_set_string (PsppireConf *conf,
+                              const gchar *base, const gchar *name,
+                             const gchar *value);
 
 void psppire_conf_set_window_geometry (PsppireConf *conf,
                                       const gchar *base,
index 8638677125a5fe1a4aa2fd31c9d7a28aea080d64..b1526ac95af529f0c875208f061caf181cf4f8fe 100644 (file)
@@ -32,6 +32,7 @@
 #include "ui/gui/psppire-value-entry.h"
 #include "ui/gui/psppire-var-sheet.h"
 #include "ui/gui/psppire.h"
+#include "ui/gui/psppire-conf.h"
 
 #include <gettext.h>
 #define _(msgid) gettext (msgid)
@@ -697,11 +698,14 @@ make_split_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines,
   return GTK_WIDGET (xpaned);
 }
 
+static void set_font_recursively (GtkWidget *w, gpointer data);
+
 static void
 psppire_data_editor_init (PsppireDataEditor *de)
 {
   GtkWidget *var_sheet_scroller;
   GtkWidget *hbox;
+  gchar *fontname = NULL;
 
   de->font = NULL;
   de->ui_manager = NULL;
@@ -751,6 +755,15 @@ psppire_data_editor_init (PsppireDataEditor *de)
 
   g_object_set (de, "can-focus", FALSE, NULL);
 
+  if (psppire_conf_get_string (psppire_conf_new (),
+                          "Data Editor", "font",
+                               &fontname) )
+    {
+      de->font = pango_font_description_from_string (fontname);
+      g_free (fontname);
+      set_font_recursively (GTK_WIDGET (de), de->font);
+    }
+
   psppire_data_editor_update_ui_manager (de);
 }
 
@@ -802,11 +815,18 @@ set_font_recursively (GtkWidget *w, gpointer data)
 void
 psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_desc)
 {
+  gchar *font_name;
   set_font_recursively (GTK_WIDGET (de), font_desc);
 
   if (de->font)
     pango_font_description_free (de->font);
   de->font = pango_font_description_copy (font_desc);
+  font_name = pango_font_description_to_string (de->font);
+
+  psppire_conf_set_string (psppire_conf_new (),
+                          "Data Editor", "font",
+                          font_name);
+
 }
 
 /* If SPLIT is TRUE, splits DE's data sheet into four panes.