From: John Darrington Date: Tue, 24 Feb 2009 22:26:03 +0000 (+0900) Subject: Quit the application after closing the last window X-Git-Tag: v0.7.3~276 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03e9ea4ed60c790091ab1ea85fffa29f0965f83e;p=pspp-builds.git Quit the application after closing the last window --- diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index c0f81685..ac5ce610 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -483,7 +483,7 @@ on_insert_variable (GtkAction *action, gpointer data) /* Callback for data_save_as action. Prompt for a filename and save */ static void -data_save_as_dialog (GtkAction *action, PsppireDataWindow *de) +data_save_as_dialog (PsppireDataWindow *de) { GtkWidget *button_sys; GtkWidget *dialog = @@ -564,12 +564,12 @@ data_save_as_dialog (GtkAction *action, PsppireDataWindow *de) If there's an existing file name, then just save, otherwise prompt for a file name, then save */ static void -data_save (GtkAction *action, PsppireDataWindow *de) +data_save (PsppireDataWindow *de) { if (de->file_name) save_file (de); else - data_save_as_dialog (action, de); + data_save_as_dialog (de); } @@ -994,6 +994,17 @@ set_unsaved (gpointer w) psppire_window_set_unsaved (PSPPIRE_WINDOW (w), TRUE); } +/* Callback for the "delete" action (clicking the x on the top right + hand corner of the window) */ +static gboolean +on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data) +{ + PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (user_data); + + return FALSE; +} + + static void psppire_data_window_init (PsppireDataWindow *de) { @@ -1144,8 +1155,8 @@ psppire_data_window_init (PsppireDataWindow *de) "stock-id", "gtk-save", NULL); - g_signal_connect (action_data_save, "activate", - G_CALLBACK (data_save), de); + g_signal_connect_swapped (action_data_save, "activate", + G_CALLBACK (data_save), de); } @@ -1161,7 +1172,7 @@ psppire_data_window_init (PsppireDataWindow *de) "stock-id", "gtk-save-as", NULL); - g_signal_connect (action_data_save_as, "activate", + g_signal_connect_swapped (action_data_save_as, "activate", G_CALLBACK (data_save_as_dialog), de); } @@ -1739,6 +1750,9 @@ psppire_data_window_init (PsppireDataWindow *de) "varsheet-row-menu", de->var_sheet_variable_popup_menu, NULL); + g_signal_connect (de, "delete-event", G_CALLBACK (on_delete), de); + + gtk_widget_show (GTK_WIDGET (de->data_editor)); gtk_widget_show (box); } diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 9be362cf..7abf01f7 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -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; } diff --git a/src/ui/gui/psppire-window-register.c b/src/ui/gui/psppire-window-register.c index dfa46c65..07ac2825 100644 --- a/src/ui/gui/psppire-window-register.c +++ b/src/ui/gui/psppire-window-register.c @@ -187,3 +187,10 @@ psppire_window_register_new (void) { return g_object_new (psppire_window_register_get_type (), NULL); } + + +gint +psppire_window_register_n_items (PsppireWindowRegister *wr) +{ + return g_hash_table_size (wr->name_table); +} diff --git a/src/ui/gui/psppire-window-register.h b/src/ui/gui/psppire-window-register.h index cc24f4ef..afc24a3d 100644 --- a/src/ui/gui/psppire-window-register.h +++ b/src/ui/gui/psppire-window-register.h @@ -86,6 +86,8 @@ void psppire_window_register_foreach (PsppireWindowRegister *wr, GHFunc func, Ps void psppire_window_register_minimise_all (PsppireWindowRegister *wr); +gint psppire_window_register_n_items (PsppireWindowRegister *wr); + G_END_DECLS diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 45cd66c1..61bebb28 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -345,6 +345,22 @@ insert_existing_items (PsppireWindow *window) psppire_window_register_foreach (psppire_window_register_new (), insert_item, window); } + +static gboolean +on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data) +{ + PsppireWindow *dw = PSPPIRE_WINDOW (user_data); + + PsppireWindowRegister *reg = psppire_window_register_new (); + + + if ( 1 == psppire_window_register_n_items (reg)) + gtk_main_quit (); + + return FALSE; +} + + static void psppire_window_init (PsppireWindow *window) { @@ -367,6 +383,8 @@ psppire_window_init (PsppireWindow *window) window); window->unsaved = FALSE; + + g_signal_connect (window, "delete-event", G_CALLBACK (on_delete), window); } @@ -393,6 +411,13 @@ psppire_window_set_unsaved (PsppireWindow *w, gboolean unsaved) psppire_window_set_title (w); } +gboolean +psppire_window_get_unsaved (PsppireWindow *w) +{ + return w->unsaved; +} + + diff --git a/src/ui/gui/psppire-window.h b/src/ui/gui/psppire-window.h index c9352df8..3d1873e4 100644 --- a/src/ui/gui/psppire-window.h +++ b/src/ui/gui/psppire-window.h @@ -74,6 +74,8 @@ void psppire_window_minimise_all (void); void psppire_window_set_unsaved (PsppireWindow *, gboolean ); +gboolean psppire_window_get_unsaved (PsppireWindow *); + G_END_DECLS #endif /* __PSPPIRE_WINDOW_H__ */