From: John Darrington Date: Sun, 22 Feb 2009 23:43:23 +0000 (+0900) Subject: Add a set_unsaved method. X-Git-Tag: v0.7.3~294 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23a109b05ec5e76c4f629338dcaafedbf1e8954b;p=pspp-builds.git Add a set_unsaved method. Added a psppire_window_set_unsaved method, which can be used to indicate that the contents of a window has been modified since it was last saved. Use this method for the syntax window. --- diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 0da8851b..9be362cf 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -479,6 +479,13 @@ on_text_changed (GtkTextBuffer *buffer, PsppireSyntaxWindow *window) gtk_statusbar_pop (GTK_STATUSBAR (window->sb), window->text_context); } +static void +on_modified_changed (GtkTextBuffer *buffer, PsppireWindow *window) +{ + psppire_window_set_unsaved (window, gtk_text_buffer_get_modified (buffer)); +} + + extern struct source_stream *the_source_stream ; static void @@ -500,6 +507,9 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window) g_signal_connect (window->buffer, "changed", G_CALLBACK (on_text_changed), window); + g_signal_connect (window->buffer, "modified-changed", + G_CALLBACK (on_modified_changed), window); + connect_help (xml); gtk_container_add (GTK_CONTAINER (window), box); diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 79149ea7..29be4c20 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -87,13 +87,17 @@ static gchar mdash[6] = {0,0,0,0,0,0}; static void psppire_window_set_title (PsppireWindow *window) { - gchar *title = - g_strdup_printf ( _("%s %s PSPPIRE %s"), - window->basename, mdash, window->description); + GString *title = g_string_sized_new (80); - gtk_window_set_title (GTK_WINDOW (window), title); + g_string_printf (title, _("%s %s PSPPIRE %s"), + window->basename, mdash, window->description); - free (title); + if ( window->unsaved) + g_string_prepend_c (title, '*'); + + gtk_window_set_title (GTK_WINDOW (window), title->str); + + g_string_free (title, TRUE); } static void @@ -290,7 +294,7 @@ insert_menuitem_into_menu (PsppireWindow *window, gpointer key) g_signal_connect (item, "activate", G_CALLBACK (menu_activate), key); gtk_widget_show (item); - + gtk_menu_shell_append (window->menu, item); /* Set the state without emitting a signal */ @@ -361,6 +365,8 @@ psppire_window_init (PsppireWindow *window) "removed", G_CALLBACK (remove_menuitem), window); + + window->unsaved = FALSE; } @@ -388,6 +394,14 @@ psppire_window_set_filename (PsppireWindow *w, const gchar *filename) g_object_set (w, "filename", filename, NULL); } +void +psppire_window_set_unsaved (PsppireWindow *w, gboolean unsaved) +{ + w->unsaved = unsaved; + + psppire_window_set_title (w); +} + diff --git a/src/ui/gui/psppire-window.h b/src/ui/gui/psppire-window.h index 835cef0b..a1861dc8 100644 --- a/src/ui/gui/psppire-window.h +++ b/src/ui/gui/psppire-window.h @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008 Free Software Foundation + Copyright (C) 2008, 2009 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -56,6 +56,7 @@ struct _PsppireWindow guint insert_handler; guint remove_handler; + gboolean unsaved; }; struct _PsppireWindowClass @@ -72,6 +73,7 @@ void psppire_window_set_filename (PsppireWindow *w, const gchar *filename); void psppire_window_minimise_all (void); +void psppire_window_set_unsaved (PsppireWindow *, gboolean ); G_END_DECLS