From d92d4d2767585e1956f2ce616ed795f2b1af3cc3 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 31 Mar 2019 13:53:42 +0200 Subject: Saving hooks --- src/colloquium.c | 4 ++-- src/narrative_window.c | 32 ++++++++++++++++++++++++++++---- src/narrative_window.h | 3 ++- 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/colloquium.c b/src/colloquium.c index 65647ad..d3ada61 100644 --- a/src/colloquium.c +++ b/src/colloquium.c @@ -67,7 +67,7 @@ static void colloquium_activate(GApplication *papp) ss = stylesheet_new(); narrative_add_text(n, strdup("")); narrative_add_stylesheet(n, ss); - narrative_window_new(n, papp); + narrative_window_new(n, NULL, papp); } } @@ -231,7 +231,7 @@ static void colloquium_open(GApplication *papp, GFile **files, gint n_files, Narrative *n; n = narrative_load(files[i]); if ( n != NULL ) { - narrative_window_new(n, papp); + narrative_window_new(n, files[i], papp); } else { char *uri = g_file_get_uri(files[i]); fprintf(stderr, _("Failed to load presentation '%s'\n"), diff --git a/src/narrative_window.c b/src/narrative_window.c index 772c886..2df2c1e 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -80,12 +80,24 @@ static void show_error(NarrativeWindow *nw, const char *err) } +static char *get_titlebar_string(NarrativeWindow *nw) +{ + if ( nw == NULL || nw->file == NULL ) { + return strdup(_("(untitled)")); + } else { + char *bn = g_file_get_basename(nw->file); + return bn; + } +} + + + static void update_titlebar(NarrativeWindow *nw) { char *title; char *title_new; - title = strdup("test"); // FIXME get_titlebar_string(nw->p); + title = get_titlebar_string(nw); title_new = realloc(title, strlen(title)+16); if ( title_new == NULL ) { free(title); @@ -139,9 +151,15 @@ static gint saveas_response_sig(GtkWidget *d, gint response, if ( narrative_save(nw->n, file) ) { show_error(nw, _("Failed to save presentation")); + } else { + update_titlebar(nw); } - /* save_narrative keeps a reference to both of these */ + if ( nw->file != file ) { + if ( nw->file != NULL ) g_object_unref(nw->file); + nw->file = file; + g_object_ref(nw->file); + } g_object_unref(file); } @@ -190,7 +208,11 @@ static void save_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) return saveas_sig(NULL, NULL, nw); } - narrative_save(nw->n, nw->file); + if ( narrative_save(nw->n, nw->file) ) { + show_error(nw, _("Failed to save presentation")); + } else { + update_titlebar(nw); + } } @@ -688,7 +710,7 @@ GActionEntry nw_entries[] = { //} -NarrativeWindow *narrative_window_new(Narrative *n, GApplication *papp) +NarrativeWindow *narrative_window_new(Narrative *n, GFile *file, GApplication *papp) { NarrativeWindow *nw; GtkWidget *vbox; @@ -704,6 +726,8 @@ NarrativeWindow *narrative_window_new(Narrative *n, GApplication *papp) nw->app = papp; nw->n = n; nw->n_slidewindows = 0; + nw->file = file; + g_object_ref(file); nw->window = gtk_application_window_new(GTK_APPLICATION(app)); update_titlebar(nw); diff --git a/src/narrative_window.h b/src/narrative_window.h index a2c769c..5a7646d 100644 --- a/src/narrative_window.h +++ b/src/narrative_window.h @@ -29,6 +29,7 @@ typedef struct _narrative_window NarrativeWindow; -extern NarrativeWindow *narrative_window_new(Narrative *n, GApplication *app); +extern NarrativeWindow *narrative_window_new(Narrative *n, GFile *file, + GApplication *papp); #endif /* NARRATIVE_WINDOW_H */ -- cgit v1.2.3