From 4fc663655ff4a8ea990d7e4f4b7580cf63e233c4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 16 Jan 2017 22:42:26 +0100 Subject: Titlebar stuff, keep track of when presentation has been changed --- src/narrative_window.c | 27 +++++++++++++++++++++++++++ src/narrative_window.h | 3 ++- src/presentation.c | 7 ++++--- src/presentation.h | 3 ++- src/sc_editor.c | 16 ++++++++++++++-- src/slide_window.c | 20 -------------------- src/slide_window.h | 1 - 7 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/narrative_window.c b/src/narrative_window.c index 1a9bcf5..6f960c6 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -375,6 +375,13 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, } +static void changed_sig(GtkWidget *da, NarrativeWindow *nw) +{ + nw->p->saved = 0; + update_titlebar(nw); +} + + static void scroll_down(NarrativeWindow *nw) { gdouble inc, val; @@ -569,6 +576,23 @@ GActionEntry nw_entries_p[] = { }; +void update_titlebar(NarrativeWindow *nw) +{ + char *title; + + title = get_titlebar_string(nw->p); + title = realloc(title, strlen(title)+16); + if ( title == NULL ) return; + + strcat(title, " - Colloquium"); + if ( !nw->p->saved ) { + strcat(title, " *"); + } + gtk_window_set_title(GTK_WINDOW(nw->window), title); + free(title); +} + + NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app) { NarrativeWindow *nw; @@ -593,6 +617,7 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app) nw->window = gtk_application_window_new(GTK_APPLICATION(app)); p->narrative_window = nw; + update_titlebar(nw); g_action_map_add_action_entries(G_ACTION_MAP(nw->window), nw_entries, G_N_ELEMENTS(nw_entries), nw); @@ -692,6 +717,8 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app) g_signal_connect(G_OBJECT(nw->sceditor), "button-press-event", G_CALLBACK(button_press_sig), nw); + g_signal_connect(G_OBJECT(nw->sceditor), "changed", + G_CALLBACK(changed_sig), nw); g_signal_connect(G_OBJECT(nw->sceditor), "key-press-event", G_CALLBACK(key_press_sig), nw); g_signal_connect(G_OBJECT(nw->window), "destroy", diff --git a/src/narrative_window.h b/src/narrative_window.h index 8c32c71..0b59867 100644 --- a/src/narrative_window.h +++ b/src/narrative_window.h @@ -1,7 +1,7 @@ /* * narrative_window.h * - * Copyright © 2014 Thomas White + * Copyright © 2014-2017 Thomas White * * This file is part of Colloquium. * @@ -33,5 +33,6 @@ typedef struct _narrative_window NarrativeWindow; extern NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app); +extern void update_titlebar(NarrativeWindow *nw); #endif /* NARRATIVE_WINDOW_H */ diff --git a/src/presentation.c b/src/presentation.c index 1abf4fc..5b4a3de 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -90,7 +90,7 @@ static char *safe_basename(const char *in) char *get_titlebar_string(struct presentation *p) { - if ( p->filename == NULL ) { + if ( p == NULL || p->filename == NULL ) { return strdup("(untitled)"); } else { return safe_basename(p->filename); @@ -114,6 +114,7 @@ struct presentation *new_presentation() new->slide_height = 768.0; new->completely_empty = 1; + new->saved = 1; new->stylesheet = NULL; new->is = imagestore_new(); @@ -140,9 +141,10 @@ int save_presentation(struct presentation *p, const char *filename) imagestore_set_presentation_file(p->is, filename); p->filename = strdup(filename); if ( old_fn != NULL ) free(old_fn); - update_titlebar(p); fclose(fh); + p->saved = 1; + update_titlebar(p->narrative_window); return 0; } @@ -372,7 +374,6 @@ int load_presentation(struct presentation *p, const char *filename) assert(p->filename == NULL); p->filename = strdup(filename); - update_titlebar(p); imagestore_set_presentation_file(p->is, filename); return 0; diff --git a/src/presentation.h b/src/presentation.h index 8172972..dae4ffd 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -1,7 +1,7 @@ /* * presentation.h * - * Copyright © 2013-2015 Thomas White + * Copyright © 2013-2017 Thomas White * * This file is part of Colloquium. * @@ -46,6 +46,7 @@ struct presentation char *filename; char *titlebar; /* basename(filename) or "(untitled)" */ int completely_empty; + int saved; PangoLanguage *lang; ImageStore *is; diff --git a/src/sc_editor.c b/src/sc_editor.c index 52bd340..fe52ce8 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -1,7 +1,7 @@ /* * sc_editor.c * - * Copyright © 2013-2016 Thomas White + * Copyright © 2013-2017 Thomas White * * This file is part of Colloquium. * @@ -189,6 +189,12 @@ static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event, } +static void emit_change_sig(SCEditor *e) +{ + g_signal_emit_by_name(e, "changed"); +} + + void sc_editor_set_flow(SCEditor *e, int flow) { e->flow = flow; @@ -313,6 +319,9 @@ static void sc_editor_class_init(SCEditorClass *klass) GTK_WIDGET_CLASS(klass)->get_preferred_width = get_preferred_width; GTK_WIDGET_CLASS(klass)->get_preferred_height = get_preferred_height; GTK_WIDGET_CLASS(klass)->get_preferred_height_for_width = NULL; + + g_signal_new("changed", SC_TYPE_EDITOR, G_SIGNAL_RUN_LAST, 0, + NULL, NULL, NULL, G_TYPE_NONE, 0); } @@ -390,6 +399,7 @@ void sc_editor_delete_selected_frame(SCEditor *e) { sc_block_delete(e->scblocks, e->selection->scblocks); full_rerender(e); + emit_change_sig(e); } @@ -648,6 +658,7 @@ static void insert_text(char *t, SCEditor *e) cursor_moveh(e->cursor_frame, &e->cursor_para, &e->cursor_pos, &e->cursor_trail, +1); check_cursor_visible(e); + emit_change_sig(e); sc_editor_redraw(e); return; } @@ -696,6 +707,7 @@ static void insert_text(char *t, SCEditor *e) } + emit_change_sig(e); check_cursor_visible(e); sc_editor_redraw(e); } @@ -735,7 +747,7 @@ static void do_backspace(struct frame *fr, SCEditor *e) } - + emit_change_sig(e); sc_editor_redraw(e); } diff --git a/src/slide_window.c b/src/slide_window.c index be7215a..7201c0a 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -177,24 +177,6 @@ void slidewindow_redraw(SlideWindow *sw) } -void update_titlebar(struct presentation *p) -{ - get_titlebar_string(p); - - if ( p->slidewindow != NULL ) { - - char *title; - - title = malloc(strlen(p->titlebar)+14); - sprintf(title, "%s - Colloquium", p->titlebar); - gtk_window_set_title(GTK_WINDOW(p->slidewindow->window), title); - free(title); - - } - -} - - static gboolean close_sig(GtkWidget *w, SlideWindow *sw) { sw->p->slidewindow = NULL; @@ -251,8 +233,6 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks, g_action_map_add_action_entries(G_ACTION_MAP(window), sw_entries, G_N_ELEMENTS(sw_entries), sw); - update_titlebar(p); - g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(close_sig), sw); diff --git a/src/slide_window.h b/src/slide_window.h index 8c51a59..b9a1102 100644 --- a/src/slide_window.h +++ b/src/slide_window.h @@ -32,6 +32,5 @@ typedef struct _slidewindow SlideWindow; extern SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks, GApplication *app); extern void change_edit_slide(SlideWindow *sw, SCBlock *np); -extern void update_titlebar(struct presentation *p); #endif /* SLIDEWINDOW_H */ -- cgit v1.2.3