aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/stylesheet.c22
-rw-r--r--src/stylesheet.h4
-rw-r--r--src/stylesheet_editor.c20
3 files changed, 42 insertions, 4 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c
index a057935..52bc4ff 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -230,7 +230,7 @@ int stylesheet_delete(Stylesheet *ss, const char *path, const char *key)
void stylesheet_free(Stylesheet *ss)
{
- g_object_unref(ss->root);
+ json_node_unref(ss->root);
free(ss);
}
@@ -259,3 +259,23 @@ int stylesheet_save(Stylesheet *ss, GFile *file)
g_object_unref(fh);
return 0;
}
+
+
+char *stylesheet_data(Stylesheet *ss)
+{
+ return json_to_string(ss->root, FALSE);
+}
+
+
+void stylesheet_set_data(Stylesheet *ss, const char *data)
+{
+ JsonNode *new_root;
+ GError *err = NULL;
+ new_root = json_from_string(data, &err);
+ if ( new_root == NULL ) {
+ fprintf(stderr, "Internal parse error: %s\n", err->message);
+ return;
+ }
+ json_node_unref(ss->root);
+ ss->root = new_root;
+}
diff --git a/src/stylesheet.h b/src/stylesheet.h
index 537b2f9..16d0a0a 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -36,6 +36,10 @@ extern Stylesheet *stylesheet_load(GFile *file);
extern int stylesheet_save(Stylesheet *ss, GFile *file);
+extern char *stylesheet_data(Stylesheet *ss);
+
+extern void stylesheet_set_data(Stylesheet *ss, const char *data);
+
extern int parse_colour_duo(const char *a, GdkRGBA *col1, GdkRGBA *col2);
extern char *stylesheet_lookup(Stylesheet *ss, const char *path, const char *key);
diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c
index 55ac3a9..0f5b908 100644
--- a/src/stylesheet_editor.c
+++ b/src/stylesheet_editor.c
@@ -44,6 +44,7 @@ G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor,
struct _sspriv
{
struct presentation *p;
+ char *ssdata;
};
@@ -315,9 +316,12 @@ static void update_spacing(struct presentation *p, const char *style_name,
}
-static void revert_sig(GtkButton *button, StylesheetEditor *widget)
+static void revert_sig(GtkButton *button, StylesheetEditor *se)
{
- printf("click revert!\n");
+ stylesheet_set_data(se->priv->p->stylesheet,
+ se->priv->ssdata);
+ set_values_from_presentation(se);
+ g_signal_emit_by_name(se, "changed");
}
@@ -491,6 +495,14 @@ static void narrative_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se)
}
+static void stylesheet_editor_finalize(GObject *obj)
+{
+ StylesheetEditor *se = COLLOQUIUM_STYLESHEET_EDITOR(obj);
+ free(se->priv->ssdata);
+ G_OBJECT_CLASS(stylesheet_editor_parent_class)->finalize(obj);
+}
+
+
static void stylesheet_editor_init(StylesheetEditor *se)
{
se->priv = G_TYPE_INSTANCE_GET_PRIVATE(se, COLLOQUIUM_TYPE_STYLESHEET_EDITOR,
@@ -512,7 +524,7 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass)
"/uk/me/bitwiz/Colloquium/stylesheeteditor.ui");
g_type_class_add_private(gobject_class, sizeof(StylesheetEditorPrivate));
-
+ gobject_class->finalize = stylesheet_editor_finalize;
/* Narrative style */
SE_BIND_CHILD(narrative_style_font, narrative_font_sig);
@@ -570,6 +582,8 @@ StylesheetEditor *stylesheet_editor_new(struct presentation *p)
se->priv->p = p;
set_values_from_presentation(se);
+ se->priv->ssdata = stylesheet_data(p->stylesheet);
+
return se;
}