From 7b302ea4b906b162c37c3370434165f6e83a9def Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 13 Sep 2014 09:54:11 +0200 Subject: Restore notes --- src/mainwindow.c | 6 +++--- src/notes.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- src/notes.h | 2 ++ src/presentation.c | 5 +++-- src/presentation.h | 2 +- src/sc_parse.c | 7 +++++++ src/sc_parse.h | 1 + 7 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/mainwindow.c b/src/mainwindow.c index 5b03828..22e4ce8 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -380,9 +380,9 @@ static gint new_sig(GtkWidget *widget, struct presentation *pnn) new = add_slide(p, 0); p->completely_empty = 1; /* FIXME: position */ - new->scblocks = sc_block_append_inside(p->scblocks, "slide", - NULL, NULL); - + new->scblocks = sc_block_append_end(p->scblocks, "slide", + NULL, NULL); + attach_notes(new); open_mainwindow(p); } diff --git a/src/notes.c b/src/notes.c index 2e57d25..2210f55 100644 --- a/src/notes.c +++ b/src/notes.c @@ -51,11 +51,20 @@ static void set_notes_title(struct presentation *p) static void update_notes(struct presentation *p) { GtkTextBuffer *tb; + const char *ntext; + SCBlock *ch; if ( p->notes == NULL ) return; + ch = sc_block_child(p->cur_edit_slide->notes); + if ( ch != NULL ) { + ntext = sc_block_contents(ch); + } else { + ntext = "NOTES ERROR"; + } + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(p->notes->v)); - gtk_text_buffer_set_text(tb, p->cur_edit_slide->notes, -1); + gtk_text_buffer_set_text(tb, ntext, -1); } @@ -64,6 +73,7 @@ void grab_current_notes(struct presentation *p) gchar *text; GtkTextBuffer *tb; GtkTextIter i1, i2; + SCBlock *ch; struct notes *n = p->notes; if ( n == NULL ) return; @@ -73,8 +83,12 @@ void grab_current_notes(struct presentation *p) gtk_text_buffer_get_end_iter(tb, &i2); text = gtk_text_buffer_get_text(tb, &i1, &i2, TRUE); - free(n->slide->notes); - n->slide->notes = text; + ch = sc_block_child(n->slide->notes); + if ( ch != NULL ) { + sc_block_set_contents(ch, text); + } else { + fprintf(stderr, "NOTES ERROR\n"); + } } @@ -130,3 +144,29 @@ void open_notes(struct presentation *p) update_notes(p); } + + +void attach_notes(struct slide *s) +{ + SCBlock *bl = s->scblocks; + + while ( bl != NULL ) { + + const char *name = sc_block_name(bl); + + if ( (name != NULL) && (strcmp(name, "notes") == 0) ) { + s->notes = bl; + if ( sc_block_child(bl) == NULL ) { + sc_block_append_inside(s->notes, NULL, NULL, + strdup("")); + } + return; + } + + bl = sc_block_next(bl); + + } + + s->notes = sc_block_append_end(s->scblocks, "notes", NULL, NULL); + sc_block_append_inside(s->notes, NULL, NULL, strdup("")); +} diff --git a/src/notes.h b/src/notes.h index 89d050c..31c5e3a 100644 --- a/src/notes.h +++ b/src/notes.h @@ -36,4 +36,6 @@ extern void notify_notes_slide_changed(struct presentation *p, extern void grab_current_notes(struct presentation *p); +extern void attach_notes(struct slide *s); + #endif /* NOTES_H */ diff --git a/src/presentation.c b/src/presentation.c index 5afd041..56bbbd6 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -125,7 +125,6 @@ void delete_slide(struct presentation *p, struct slide *s) } - struct slide *new_slide() { struct slide *new; @@ -140,7 +139,8 @@ struct slide *new_slide() new->top = frame_new(); /* FIXME: Set zero margins etc on top level frame */ - new->notes = strdup(""); + new->scblocks = NULL; + new->notes = NULL; return new; } @@ -424,6 +424,7 @@ int load_presentation(struct presentation *p, const char *filename) s->scblocks = sc_block_child(block); s->top = frame_new(); s->top->scblocks = sc_block_child(block); + attach_notes(s); } diff --git a/src/presentation.h b/src/presentation.h index 591efe9..a7bb0e9 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -49,7 +49,7 @@ struct slide struct frame *top; SCBlock *scblocks; - char *notes; + SCBlock *notes; }; diff --git a/src/sc_parse.c b/src/sc_parse.c index 93a346e..0f8e893 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -514,6 +514,13 @@ void sc_block_set_options(SCBlock *bl, char *opt) } +void sc_block_set_contents(SCBlock *bl, char *con) +{ + free(bl->contents); + bl->contents = con; +} + + SCBlock *find_last_child(SCBlock *bl) { if ( bl == NULL ) return NULL; diff --git a/src/sc_parse.h b/src/sc_parse.h index 1e80c8c..b86293c 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -66,6 +66,7 @@ extern SCBlock *find_last_child(SCBlock *bl); extern void sc_block_set_options(SCBlock *bl, char *opt); +extern void sc_block_set_contents(SCBlock *bl, char *con); extern void sc_insert_text(SCBlock *b1, int o1, const char *t); extern void sc_delete_text(SCBlock *b1, int o1, SCBlock *b2, int o2); -- cgit v1.2.3