Quit the application after closing the last window
[pspp-builds.git] / src / ui / gui / psppire-syntax-window.c
index 0da8851b1d2b0f7094ddfaa059f31e99a7d767b0..7abf01f7eca5bd36420236925f6c18049f40b10a 100644 (file)
@@ -259,14 +259,17 @@ save_editor_to_file (PsppireSyntaxWindow *se,
    Otherwise just close the window.
 */
 static void
-save_if_modified (PsppireSyntaxWindow *se)
+save_if_modified (PsppireWindow *se)
 {
-  if ( TRUE == gtk_text_buffer_get_modified (se->buffer))
+  if ( TRUE == psppire_window_get_unsaved (se))
     {
       gint response;
       GtkWidget *dialog;
 
-      const gchar *filename = psppire_window_get_filename (PSPPIRE_WINDOW (se));
+      const gchar *description;
+      const gchar *filename = psppire_window_get_filename (se);
+
+      g_object_get (se, "description", &description, NULL);
 
       g_return_if_fail (filename != NULL);
 
@@ -275,7 +278,8 @@ save_if_modified (PsppireSyntaxWindow *se)
                                GTK_DIALOG_MODAL,
                                GTK_MESSAGE_QUESTION,
                                GTK_BUTTONS_NONE,
-                               _("Save contents of syntax editor to %s?"),
+                               _("Save contents of %s to \"%s\"?"),
+                               description,
                                filename);
 
       gtk_dialog_add_button  (GTK_DIALOG (dialog),
@@ -303,7 +307,7 @@ save_if_modified (PsppireSyntaxWindow *se)
              msg (ME, err->message);
              g_error_free (err);
            }
-         psppire_window_set_filename (PSPPIRE_WINDOW (se), filename);
+         psppire_window_set_filename (se, filename);
        }
 
       if ( response == GTK_RESPONSE_CANCEL )
@@ -405,7 +409,7 @@ on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
   PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
 
   save_if_modified (se);
-  return TRUE;
+  return FALSE;
 }
 
 
@@ -479,6 +483,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 +511,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);