Implement setting default font
authorThomas White <taw@bitwiz.me.uk>
Sun, 29 Apr 2018 19:40:21 +0000 (21:40 +0200)
committerThomas White <taw@bitwiz.me.uk>
Sun, 29 Apr 2018 19:40:21 +0000 (21:40 +0200)
data/stylesheeteditor.ui
src/stylesheet_editor.c

index 3e1bba3..5dd473d 100644 (file)
                         <property name="receives_default">True</property>
                         <property name="font">Sans 12</property>
                         <property name="preview_text">Preview text</property>
+                        <signal name="font-set" handler="default_font_sig" swapped="no"/>
                       </object>
                       <packing>
                         <property name="expand">True</property>
index 5699385..bb65be7 100644 (file)
 G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor,
                         GTK_TYPE_DIALOG, NULL)
 
+static void set_values_from_presentation(StylesheetEditor *se);
+
 struct _sspriv
 {
        struct presentation *p;
 };
 
 
+static void set_ss(SCBlock *bl, const char *find, const char *seti)
+{
+       char *set;
+       const char *name;
+
+       set = strdup(seti);
+       if ( set == NULL ) return;
+
+       name = sc_block_name(bl);
+       if ( (name != NULL) && (strcmp(name, "stylesheet")==0) ) {
+               bl = sc_block_child(bl);
+       }
+
+       while ( bl != NULL ) {
+
+               const char *name = sc_block_name(bl);
+               if ( (name != NULL) && (strcmp(name, find)==0) ) {
+                       sc_block_set_options(bl, set);
+                       return;
+               }
+
+               bl = sc_block_next(bl);
+
+       }
+
+       fprintf(stderr, "WARNING: Didn't find block in stylesheet to set.\n");
+}
+
+
 static void revert_sig(GtkButton *button, StylesheetEditor *widget)
 {
        printf("click revert!\n");
 }
 
 
+static void default_font_sig(GtkFontButton *widget, StylesheetEditor *se)
+{
+       const gchar *font;
+       font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
+       set_ss(se->priv->p->stylesheet, "font", font);
+       set_values_from_presentation(se);
+}
+
+
 static void stylesheet_editor_init(StylesheetEditor *se)
 {
        se->priv = G_TYPE_INSTANCE_GET_PRIVATE(se, COLLOQUIUM_TYPE_STYLESHEET_EDITOR,
@@ -76,6 +116,7 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass)
                                             default_style_fgcol);
 
        gtk_widget_class_bind_template_callback(widget_class, revert_sig);
+       gtk_widget_class_bind_template_callback(widget_class, default_font_sig);
 }