r21627 - gnucash/trunk/src - Add "Post" and "Print" buttons in invoice search window, both for single or multiple invoices.

Christian Stimming cstim at code.gnucash.org
Sat Nov 26 17:17:22 EST 2011


Author: cstim
Date: 2011-11-26 17:17:22 -0500 (Sat, 26 Nov 2011)
New Revision: 21627
Trac: http://svn.gnucash.org/trac/changeset/21627

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/gnome-search/dialog-search.c
Log:
Add "Post" and "Print" buttons in invoice search window, both for single or multiple invoices.

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-24 14:05:32 UTC (rev 21626)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-26 22:17:22 UTC (rev 21627)
@@ -606,11 +606,9 @@
     }
 }
 
-void
-gnc_invoice_window_printCB (GtkWidget *widget, gpointer data)
+static void
+gnc_invoice_window_print_invoice(GncInvoice *invoice)
 {
-    InvoiceWindow *iw = data;
-    GncInvoice *invoice = iw_get_invoice (iw);
     SCM func, arg;
     SCM args = SCM_EOL;
     int report_id;
@@ -633,9 +631,15 @@
     if (report_id >= 0)
         reportWindow (report_id);
 }
+void
+gnc_invoice_window_printCB (GtkWidget *unused_widget, gpointer data)
+{
+    InvoiceWindow *iw = data;
+    gnc_invoice_window_print_invoice(iw_get_invoice (iw));
+}
 
 void
-gnc_invoice_window_postCB (GtkWidget *widget, gpointer data)
+gnc_invoice_window_postCB (GtkWidget *unused_widget, gpointer data)
 {
     InvoiceWindow *iw = data;
     GncInvoice *invoice;
@@ -2506,6 +2510,7 @@
 
     // Now open that newly created invoice in the "edit" window
     iw = gnc_ui_invoice_edit (new_invoice);
+    iw->created_invoice = new_invoice;
 
     if (open_properties)
     {
@@ -2513,6 +2518,7 @@
         // invoice ID won't be copied over to the tab title even though
         // it's correctly copied into the invoice.
         iw = gnc_ui_invoice_modify (new_invoice);
+        iw->created_invoice = new_invoice;
     }
 
     return iw;
@@ -2576,22 +2582,6 @@
     pay_invoice_direct (*invoice_p, user_data);
 }
 
-static void
-duplicate_invoice_direct (gpointer invoice, gpointer user_data)
-{
-    g_return_if_fail (invoice);
-    gnc_ui_invoice_duplicate (invoice, TRUE);
-}
-
-static void
-duplicate_invoice_cb (gpointer *invoice_p, gpointer user_data)
-{
-    g_return_if_fail (invoice_p); // && user_data);
-    if (! *invoice_p)
-        return;
-    duplicate_invoice_direct (*invoice_p, user_data);
-}
-
 static void multi_duplicate_invoice_one(gpointer data, gpointer user_data)
 {
     GncInvoice *old_invoice = data;
@@ -2613,13 +2603,60 @@
 multi_duplicate_invoice_cb (GList *invoice_list, gpointer user_data)
 {
     g_return_if_fail (invoice_list);
+    switch (g_list_length(invoice_list))
+    {
+    case 0:
+        return;
+    case 1:
+    {
+        // Duplicate exactly one invoice
+        GncInvoice *old_invoice = invoice_list->data;
+        gnc_ui_invoice_duplicate(old_invoice, TRUE);
+        return;
+    }
+    default:
+    {
+        // Note: If we want to have a more sophisticated duplication, we might want
+        // to ask for particular data right here, then insert this data upon
+        // duplication.
+        g_list_foreach(invoice_list, multi_duplicate_invoice_one, user_data);
+        return;
+    }
+    }
+}
 
-    // Note: If we want to have a more sophisticated duplication, we might want
-    // to ask for particular data right here, then insert this data upon
-    // duplication.
-    g_list_foreach(invoice_list, multi_duplicate_invoice_one, user_data);
+static void post_one_invoice_cb(gpointer data, gpointer user_data)
+{
+    GncInvoice *invoice = data;
+    InvoiceWindow *iw = gnc_ui_invoice_edit(invoice);
+    gnc_invoice_window_ok_save (iw);
+    gnc_invoice_window_postCB(NULL, iw);
 }
 
+static void
+multi_post_invoice_cb (GList *invoice_list, gpointer user_data)
+{
+    if (g_list_length(invoice_list) == 0)
+        return;
+
+    g_list_foreach(invoice_list, post_one_invoice_cb, user_data);
+}
+
+static void print_one_invoice_cb(gpointer data, gpointer user_data)
+{
+    GncInvoice *invoice = data;
+    gnc_invoice_window_print_invoice(invoice); // that's all!
+}
+
+static void
+multi_print_invoice_cb (GList *invoice_list, gpointer user_data)
+{
+    if (g_list_length(invoice_list) == 0)
+        return;
+
+    g_list_foreach(invoice_list, print_one_invoice_cb, user_data);
+}
+
 static gpointer
 new_invoice_cb (gpointer user_data)
 {
@@ -2658,14 +2695,18 @@
     {
         { N_("View/Edit Invoice"), edit_invoice_cb, NULL},
         { N_("Process Payment"), pay_invoice_cb, NULL},
-        { N_("Duplicate"), duplicate_invoice_cb, multi_duplicate_invoice_cb},
+        { N_("Duplicate"), NULL, multi_duplicate_invoice_cb},
+        { N_("Post"), NULL, multi_post_invoice_cb},
+        { N_("Print"), NULL, multi_print_invoice_cb},
         { NULL },
     };
     static GNCSearchCallbackButton bill_buttons[] =
     {
         { N_("View/Edit Bill"), edit_invoice_cb, NULL},
         { N_("Process Payment"), pay_invoice_cb, NULL},
-        { N_("Duplicate"), duplicate_invoice_cb, multi_duplicate_invoice_cb},
+        { N_("Duplicate"), NULL, multi_duplicate_invoice_cb},
+        { N_("Post"), NULL, multi_post_invoice_cb},
+        { N_("Print"), NULL, multi_print_invoice_cb},
         { NULL },
     };
     static GNCSearchCallbackButton emp_buttons[] =
@@ -2674,7 +2715,9 @@
            interchangeably in gnucash and mean the same thing. */
         { N_("View/Edit Voucher"), edit_invoice_cb, NULL},
         { N_("Process Payment"), pay_invoice_cb, NULL},
-        { N_("Duplicate"), duplicate_invoice_cb, multi_duplicate_invoice_cb},
+        { N_("Duplicate"), NULL, multi_duplicate_invoice_cb},
+        { N_("Post"), NULL, multi_post_invoice_cb},
+        { N_("Print"), NULL, multi_print_invoice_cb},
         { NULL },
     };
 

Modified: gnucash/trunk/src/gnome-search/dialog-search.c
===================================================================
--- gnucash/trunk/src/gnome-search/dialog-search.c	2011-11-24 14:05:32 UTC (rev 21626)
+++ gnucash/trunk/src/gnome-search/dialog-search.c	2011-11-26 22:17:22 UTC (rev 21627)
@@ -161,7 +161,7 @@
     g_assert(clist->selection_mode == GTK_SELECTION_MULTIPLE);
 
     // Do we have a callback for multi-selections, and also more than one selected item?
-    if (cb->cb_multiselect_fn && g_list_length(clist->selection) > 1)
+    if (cb->cb_multiselect_fn && (!cb->cb_fcn || g_list_length(clist->selection) > 1))
     {
         GList *selected_rows_list = clist->selection;
         // Yes, use the multi-selection callback



More information about the gnucash-changes mailing list