Titlebar stuff, keep track of when presentation has been changed
authorThomas White <taw@bitwiz.org.uk>
Mon, 16 Jan 2017 21:42:26 +0000 (22:42 +0100)
committerThomas White <taw@bitwiz.org.uk>
Mon, 16 Jan 2017 21:42:26 +0000 (22:42 +0100)
src/narrative_window.c
src/narrative_window.h
src/presentation.c
src/presentation.h
src/sc_editor.c
src/slide_window.c
src/slide_window.h

index 1a9bcf5..6f960c6 100644 (file)
@@ -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",
index 8c32c71..0b59867 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * narrative_window.h
  *
- * Copyright © 2014 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2014-2017 Thomas White <taw@bitwiz.org.uk>
  *
  * 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 */
index 1abf4fc..5b4a3de 100644 (file)
@@ -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;
index 8172972..dae4ffd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * presentation.h
  *
- * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2017 Thomas White <taw@bitwiz.org.uk>
  *
  * 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;
index 52bd340..fe52ce8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * sc_editor.c
  *
- * Copyright © 2013-2016 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2017 Thomas White <taw@bitwiz.org.uk>
  *
  * 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);
 }
 
index be7215a..7201c0a 100644 (file)
@@ -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);
 
index 8c51a59..b9a1102 100644 (file)
@@ -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 */