[balsa] Allow only one compose window per draft message



commit fa67da785a4367b2c1211ff0cda3194269843512
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Aug 19 19:10:03 2009 -0400

    Allow only one compose window per draft message

 ChangeLog            |   11 +++++++++++
 src/balsa-index.c    |    5 +++--
 src/sendmsg-window.c |   19 ++++++++++++++++++-
 3 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6c1d179..1e382aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-08-19  Peter Bloomfield
 
+	Allow only one compose window per draft message.
+
+	* src/balsa-index.c (bndx_row_activated): check for NULL return
+	from sendmsg_window_continue.
+	* src/sendmsg-window.c (balsa_sendmsg_destroy_handler,
+	sw_save_draft): clear object data.
+	(sendmsg_window_continue): present existing window if it exists
+	and return NULL, and use object data to remember window.
+
+2009-08-19  Peter Bloomfield
+
 	* src/balsa-mime-widget-message.c (bm_header_widget_new): use
 	GTK_WRAP_WORD_CHAR so that over-long words do not force
 	over-wide window.
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 341376d..37135ed 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -642,8 +642,9 @@ bndx_row_activated(GtkTreeView * tree_view, GtkTreePath * path,
          * balsa_message_continue: */
         BalsaSendmsg *sm =
             sendmsg_window_continue(mailbox, msgno);
-        g_signal_connect(G_OBJECT(sm->window), "destroy",
-                         G_CALLBACK(sendmsg_window_destroy_cb), NULL);
+        if (sm)
+            g_signal_connect(G_OBJECT(sm->window), "destroy",
+                             G_CALLBACK(sendmsg_window_destroy_cb), NULL);
     } else
         message_window_new(mailbox, msgno);
 }
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 9b351fa..85d8bc0 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -964,6 +964,7 @@ destroy_event_cb(GtkWidget * widget, gpointer data)
 /* the balsa_sendmsg destructor; copies first the shown headers setting
    to the balsa_app structure.
 */
+#define BALSA_SENDMSG_WINDOW_KEY "balsa-sendmsg-window-key"
 static void
 balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
 {
@@ -987,6 +988,8 @@ balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
     }
 
     if (bsmsg->draft_message) {
+        g_object_set_data(G_OBJECT(bsmsg->draft_message),
+                          BALSA_SENDMSG_WINDOW_KEY, NULL);
 	if (bsmsg->draft_message->mailbox)
 	    libbalsa_mailbox_close(bsmsg->draft_message->mailbox,
 		    /* Respect pref setting: */
@@ -4108,6 +4111,8 @@ sw_save_draft(BalsaSendmsg * bsmsg)
     }
 
     if (bsmsg->draft_message) {
+        g_object_set_data(G_OBJECT(bsmsg->draft_message),
+                          BALSA_SENDMSG_WINDOW_KEY, NULL);
 	if (bsmsg->draft_message->mailbox)
 	    libbalsa_mailbox_close(bsmsg->draft_message->mailbox,
 		    /* Respect pref setting: */
@@ -4120,6 +4125,8 @@ sw_save_draft(BalsaSendmsg * bsmsg)
 	libbalsa_mailbox_get_message(balsa_app.draftbox,
 				     libbalsa_mailbox_total_messages
 				     (balsa_app.draftbox));
+    g_object_set_data(G_OBJECT(bsmsg->draft_message),
+                      BALSA_SENDMSG_WINDOW_KEY, bsmsg);
     balsa_information_parented(GTK_WINDOW(bsmsg->window),
                                LIBBALSA_INFORMATION_MESSAGE,
                                _("Message saved."));
@@ -4938,14 +4945,24 @@ sendmsg_window_continue(LibBalsaMailbox * mailbox, guint msgno)
 {
     LibBalsaMessage *message =
         libbalsa_mailbox_get_message(mailbox, msgno);
-    BalsaSendmsg *bsmsg = sendmsg_window_new();
+    BalsaSendmsg *bsmsg;
     const gchar *postpone_hdr;
     GList *list, *refs = NULL;
 
     g_assert(message);
+
+    if ((bsmsg = g_object_get_data(G_OBJECT(message),
+                                   BALSA_SENDMSG_WINDOW_KEY))) {
+        gtk_window_present(GTK_WINDOW(bsmsg->window));
+        return NULL;
+    }
+
+    bsmsg = sendmsg_window_new();
     bsmsg->is_continue = TRUE;
     bsm_prepare_for_setup(message);
     bsmsg->draft_message = message;
+    g_object_set_data(G_OBJECT(bsmsg->draft_message),
+                      BALSA_SENDMSG_WINDOW_KEY, bsmsg);
     set_identity(bsmsg, message);
     setup_headers_from_message(bsmsg, message);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]