From 47764e46296e8c6921bbc00b95c05ff153699dc2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 27 Mar 2019 17:57:31 +0100 Subject: Show modified status in narrative title bar --- libstorycode/presentation.c | 14 ++++++++++ libstorycode/presentation.h | 2 ++ src/narrative_window.c | 64 ++++++++++++++++++++++----------------------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/libstorycode/presentation.c b/libstorycode/presentation.c index d862ac0..817a55a 100644 --- a/libstorycode/presentation.c +++ b/libstorycode/presentation.c @@ -50,6 +50,7 @@ struct _presentation int n_slides; Slide **slides; int max_slides; + int saved; const char *language; }; @@ -65,6 +66,7 @@ Presentation *presentation_new() p->n_slides = 0; p->max_slides = 0; p->imagestore = NULL; + p->saved = 1; #ifdef HAVE_PANGO p->language = pango_language_to_string(pango_language_get_default()); #else @@ -102,6 +104,18 @@ int presentation_save(Presentation *p, GFile *file) } +void presentation_set_unsaved(Presentation *p) +{ + p->saved = 0; +} + + +int presentation_get_unsaved(Presentation *p) +{ + return !p->saved; +} + + void presentation_free(Presentation *p) { /* FIXME: Free narrative, slides, imagestore */ diff --git a/libstorycode/presentation.h b/libstorycode/presentation.h index ad01382..444024b 100644 --- a/libstorycode/presentation.h +++ b/libstorycode/presentation.h @@ -39,6 +39,8 @@ extern Presentation *presentation_new(void); extern Presentation *presentation_load(GFile *file); extern int presentation_save(Presentation *p, GFile *file); extern void presentation_free(Presentation *p); +extern void presentation_set_unsaved(Presentation *p); +extern int presentation_get_unsaved(Presentation *p); extern void presentation_add_stylesheet(Presentation *p, Stylesheet *ss); extern void presentation_add_narrative(Presentation *p, Narrative *n); diff --git a/src/narrative_window.c b/src/narrative_window.c index d80d9cf..c51d3a3 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -81,6 +81,32 @@ static void show_error(NarrativeWindow *nw, const char *err) } +static void update_titlebar(NarrativeWindow *nw) +{ + char *title; + char *title_new; + + title = strdup("test"); // FIXME get_titlebar_string(nw->p); + title_new = realloc(title, strlen(title)+16); + if ( title_new == NULL ) { + free(title); + return; + } else { + title = title_new; + } + + strcat(title, " - Colloquium"); + if ( presentation_get_unsaved(nw->p) ) { + strcat(title, " *"); + } + gtk_window_set_title(GTK_WINDOW(nw->window), title); + + /* FIXME: Update all slide windows belonging to this NW */ + + free(title); +} + + static void update_toolbar(NarrativeWindow *nw) { // int cur_para; @@ -282,12 +308,10 @@ static void load_ss_sig(GSimpleAction *action, GVariant *parameter, static void add_slide_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { - //NarrativeWindow *nw = vp; - - /* FIXME: implementation */ + NarrativeWindow *nw = vp; - //nw->p->saved = 0; - //update_titlebar(nw); + presentation_set_unsaved(nw->p); + update_titlebar(nw); } @@ -441,8 +465,8 @@ static gboolean nw_button_press_sig(GtkWidget *da, GdkEventButton *event, static void changed_sig(GtkWidget *da, NarrativeWindow *nw) { - //nw->p->saved = 0; - //update_titlebar(nw); + presentation_set_unsaved(nw->p); + update_titlebar(nw); } @@ -631,32 +655,6 @@ GActionEntry nw_entries[] = { }; -void update_titlebar(NarrativeWindow *nw) -{ - char *title; - char *title_new; - - title = strdup("test"); // FIXME get_titlebar_string(nw->p); - title_new = realloc(title, strlen(title)+16); - if ( title_new == NULL ) { - free(title); - return; - } else { - title = title_new; - } - - strcat(title, " - Colloquium"); -//FIXME if ( !nw->p->saved ) { -// strcat(title, " *"); -// } - gtk_window_set_title(GTK_WINDOW(nw->window), title); - - /* FIXME: Update all slide windows belonging to this NW */ - - free(title); -} - - //void narrative_window_sw_closed(NarrativeWindow *nw, SlideWindow *sw) //{ // int i; -- cgit v1.2.3