From 992cf2451ad3720466fb8957e1296d3468dab17e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 29 Apr 2018 21:40:21 +0200 Subject: Implement setting default font --- data/stylesheeteditor.ui | 1 + src/stylesheet_editor.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/data/stylesheeteditor.ui b/data/stylesheeteditor.ui index 3e1bba3..5dd473d 100644 --- a/data/stylesheeteditor.ui +++ b/data/stylesheeteditor.ui @@ -109,6 +109,7 @@ True Sans 12 Preview text + True diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 5699385..bb65be7 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -38,18 +38,58 @@ 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); } -- cgit v1.2.3