From ac8cf2c210f655675c49f04fb7c3c679db4f1fae Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 30 Oct 2001 03:45:46 +0000 Subject: new function, a "Do you want to save changes?" dialog. 2001-10-29 Chris Toshok * gui/widgets/e-addressbook-util.c (e_addressbook_prompt_save_dialog): new function, a "Do you want to save changes?" dialog. * gui/widgets/e-addressbook-util.h: add prototype for e_addressbook_prompt_save_dialog. * gui/contact-editor/e-contact-editor.c (prompt_to_save_changes): call e_addressbook_prompt_save_dialog and save the card if they select save. return TRUE if the dialog should be closed, FALSE otherwise. (file_close_cb): check prompt_to_save_changes before closing the dialog. (app_delete_event_cb): same. * gui/contact-list-editor/e-contact-list-editor.c (prompt_to_save_changes): call e_addressbook_prompt_save_dialog and save the card if they select save. return TRUE if the dialog should be closed, FALSE otherwise. (file_close_cb): check prompt_to_save_changes before closing the dialog. (app_delete_event_cb): same. svn path=/trunk/; revision=14414 --- addressbook/ChangeLog | 25 +++++++++++++++++++++ addressbook/gui/contact-editor/e-contact-editor.c | 26 ++++++++++++++++++++++ .../contact-list-editor/e-contact-list-editor.c | 26 ++++++++++++++++++++++ addressbook/gui/widgets/e-addressbook-util.c | 18 +++++++++++++++ addressbook/gui/widgets/e-addressbook-util.h | 1 + 5 files changed, 96 insertions(+) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 580c53d7a4..6fd18c407b 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,28 @@ +2001-10-29 Chris Toshok + + * gui/widgets/e-addressbook-util.c + (e_addressbook_prompt_save_dialog): new function, a "Do you want + to save changes?" dialog. + + * gui/widgets/e-addressbook-util.h: add prototype for + e_addressbook_prompt_save_dialog. + + * gui/contact-editor/e-contact-editor.c (prompt_to_save_changes): + call e_addressbook_prompt_save_dialog and save the card if they + select save. return TRUE if the dialog should be closed, FALSE + otherwise. + (file_close_cb): check prompt_to_save_changes before closing the + dialog. + (app_delete_event_cb): same. + + * gui/contact-list-editor/e-contact-list-editor.c + (prompt_to_save_changes): call e_addressbook_prompt_save_dialog + and save the card if they select save. return TRUE if the dialog + should be closed, FALSE otherwise. + (file_close_cb): check prompt_to_save_changes before closing the + dialog. + (app_delete_event_cb): same. + 2001-10-29 Chris Toshok * backend/pas/pas-backend-ldap.c (add_objectclass_mod): overload diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index 3ec4cfbe4d..25824206bb 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,7 @@ #include "addressbook/printing/e-contact-print.h" #include "addressbook/printing/e-contact-print-envelope.h" +#include "addressbook/gui/widgets/e-addressbook-util.h" #include "e-util/e-gui-utils.h" #include "widgets/misc/e-dateedit.h" #include "shell/evolution-shell-component-utils.h" @@ -900,6 +902,24 @@ close_dialog (EContactEditor *ce) } } +static gboolean +prompt_to_save_changes (EContactEditor *editor) +{ + if (!editor->changed) + return TRUE; + + switch (e_addressbook_prompt_save_dialog (GTK_WINDOW(editor->app))) { + case 0: /* Save */ + save_card (editor, FALSE); + return TRUE; + case 1: /* Discard */ + return TRUE; + case 2: /* Cancel */ + default: + return FALSE; + } +} + /* Menu callbacks */ /* File/Save callback */ @@ -919,6 +939,9 @@ file_close_cb (GtkWidget *widget, gpointer data) EContactEditor *ce; ce = E_CONTACT_EDITOR (data); + if (!prompt_to_save_changes (ce)) + return; + close_dialog (ce); } @@ -1114,6 +1137,9 @@ app_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) ce = E_CONTACT_EDITOR (data); + if (!prompt_to_save_changes (ce)) + return TRUE; + close_dialog (ce); return TRUE; } diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.c b/addressbook/gui/contact-list-editor/e-contact-list-editor.c index e458aeee22..b1bd3e351c 100644 --- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c +++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c @@ -28,6 +28,8 @@ #include #include "shell/evolution-shell-component-utils.h" +#include "addressbook/gui/widgets/e-addressbook-util.h" + #include "e-contact-editor.h" #include "e-contact-list-editor.h" #include "e-contact-list-model.h" @@ -358,11 +360,32 @@ save_card (EContactListEditor *cle, gboolean should_close) } } +static gboolean +prompt_to_save_changes (EContactListEditor *editor) +{ + if (!editor->changed) + return TRUE; + + switch (e_addressbook_prompt_save_dialog (GTK_WINDOW(editor->app))) { + case 0: /* Save */ + save_card (editor, FALSE); + return TRUE; + case 1: /* Discard */ + return TRUE; + case 2: /* Cancel */ + default: + return FALSE; + } +} + static void file_close_cb (GtkWidget *widget, gpointer data) { EContactListEditor *cle = E_CONTACT_LIST_EDITOR (data); + if (!prompt_to_save_changes (cle)) + return; + close_dialog (cle); } @@ -676,6 +699,9 @@ app_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) ce = E_CONTACT_LIST_EDITOR (data); + if (!prompt_to_save_changes (ce)) + return TRUE; + close_dialog (ce); return TRUE; } diff --git a/addressbook/gui/widgets/e-addressbook-util.c b/addressbook/gui/widgets/e-addressbook-util.c index 601a1e1183..fa29b61bba 100644 --- a/addressbook/gui/widgets/e-addressbook-util.c +++ b/addressbook/gui/widgets/e-addressbook-util.c @@ -49,6 +49,24 @@ e_addressbook_error_dialog (const gchar *msg, EBookStatus status) g_free (error_msg); } +gint +e_addressbook_prompt_save_dialog (GtkWindow *parent) +{ + GtkWidget *dialog; + + dialog = gnome_message_box_new (_("Do you want to save changes?"), + GNOME_MESSAGE_BOX_QUESTION, + GNOME_STOCK_BUTTON_YES, + GNOME_STOCK_BUTTON_NO, + GNOME_STOCK_BUTTON_CANCEL, + NULL); + + gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); + gnome_dialog_grab_focus (GNOME_DIALOG (dialog), 0); + gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent); + + return gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); +} static void added_cb (EBook* book, EBookStatus status, const char *id, diff --git a/addressbook/gui/widgets/e-addressbook-util.h b/addressbook/gui/widgets/e-addressbook-util.h index f6afa31046..3eff236654 100644 --- a/addressbook/gui/widgets/e-addressbook-util.h +++ b/addressbook/gui/widgets/e-addressbook-util.h @@ -31,6 +31,7 @@ extern "C" { void e_addressbook_error_dialog (const gchar *msg, EBookStatus status); +gint e_addressbook_prompt_save_dialog (GtkWindow *parent); EContactEditor* e_addressbook_show_contact_editor (EBook *book, ECard *card, gboolean is_new_card, gboolean editable); -- cgit