r21623 - gnucash/trunk/src - Enable the "Duplicate Invoice" button even for multiple selected items.

Christian Stimming cstim at code.gnucash.org
Wed Nov 23 14:05:56 EST 2011


Author: cstim
Date: 2011-11-23 14:05:56 -0500 (Wed, 23 Nov 2011)
New Revision: 21623
Trac: http://svn.gnucash.org/trac/changeset/21623

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/gnome-search/dialog-search.c
Log:
Enable the "Duplicate Invoice" button even for multiple selected items.

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-23 13:11:10 UTC (rev 21622)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-23 19:05:56 UTC (rev 21623)
@@ -2586,7 +2586,7 @@
 static void
 duplicate_invoice_cb (gpointer *invoice_p, gpointer user_data)
 {
-    g_return_if_fail (invoice_p && user_data);
+    g_return_if_fail (invoice_p); // && user_data);
     if (! *invoice_p)
         return;
     duplicate_invoice_direct (*invoice_p, user_data);
@@ -2594,16 +2594,30 @@
 
 static void multi_duplicate_invoice_one(gpointer data, gpointer user_data)
 {
-    GncInvoice *invoice = data;
-    if (invoice)
-        gnc_ui_invoice_duplicate(invoice, FALSE);
+    GncInvoice *old_invoice = data;
+    if (old_invoice)
+    {
+        GncInvoice *new_invoice;
+        // In this simplest form, we just use the existing duplication
+        // algorithm, only without opening the "edit invoice" window for editing
+        // the number etc. for each of the invoices.
+        InvoiceWindow *iw = gnc_ui_invoice_duplicate(old_invoice, FALSE);
+        // FIXME: Now we could use this invoice and manipulate further data.
+        g_assert(iw);
+        new_invoice = iw->created_invoice;
+        //g_assert(new_invoice); // FIXME: This is NULL?!?
+    }
 }
 
 static void
 multi_duplicate_invoice_cb (GList *invoice_list, gpointer user_data)
 {
-    g_return_if_fail (invoice_list && user_data);
-    g_list_foreach(invoice_list, multi_duplicate_invoice_one, NULL);
+    g_return_if_fail (invoice_list);
+
+    // 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 gpointer

Modified: gnucash/trunk/src/gnome-search/dialog-search.c
===================================================================
--- gnucash/trunk/src/gnome-search/dialog-search.c	2011-11-23 13:11:10 UTC (rev 21622)
+++ gnucash/trunk/src/gnome-search/dialog-search.c	2011-11-23 19:05:56 UTC (rev 21623)
@@ -75,7 +75,6 @@
     GtkWidget *	result_list;
     gpointer	selected_item;
     GList *selected_item_list;
-    GTree *selected_row_btree;
 
     /* The search_type radio-buttons */
     GtkWidget *	new_rb;
@@ -140,27 +139,43 @@
 
 /** The callback for converting the row numbers from a GTree to actual item
 pointers in a GList */
-static gboolean cb_tree_to_itemlist (gpointer key,
-                                     gpointer value,
-                                     gpointer user_data)
+static void cb_tree_to_itemlist (gpointer element,
+                                 gpointer user_data)
 {
     GNCSearchWindow *sw = user_data;
-    gpointer item = gtk_clist_get_row_data (GTK_CLIST(sw->result_list), GPOINTER_TO_INT(key));
+    gint row_number = GPOINTER_TO_INT(element);
+    gpointer item = gtk_clist_get_row_data (GTK_CLIST(sw->result_list), row_number);
     sw->selected_item_list = g_list_prepend(sw->selected_item_list, item);
-    return FALSE;
 }
 
 static void
 gnc_search_callback_button_execute (GNCSearchCallbackButton *cb,
                                     GNCSearchWindow *sw)
 {
+    GNCQueryList* gql = GNC_QUERY_LIST(sw->result_list);
+    GtkCList* clist;
+
+    // Sanity check
+    g_assert(gql);
+    clist = &gql->clist;
+    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_tree_nnodes(sw->selected_row_btree) > 1))
+    if (cb->cb_multiselect_fn && g_list_length(clist->selection) > 1)
     {
+        GList *selected_rows_list = clist->selection;
         // Yes, use the multi-selection callback
+
+        // Obtain the GncInvoice pointer for each selected row
         sw->selected_item_list = NULL;
-        g_tree_foreach(sw->selected_row_btree, cb_tree_to_itemlist, sw);
+        g_list_foreach(selected_rows_list, cb_tree_to_itemlist, sw);
+        // We use g_list_prepend (for performance reasons), so we have to reverse once here
+        sw->selected_item_list = g_list_reverse(sw->selected_item_list);
+
+        // Call the callback
         (cb->cb_multiselect_fn)(sw->selected_item_list, sw->user_data);
+
+        // And clean up again
         g_list_free(sw->selected_item_list);
         sw->selected_item_list = NULL;
     }
@@ -241,9 +256,6 @@
     sw->selected_item = gtk_clist_get_row_data (clist, row);
     //g_message("select-row, row=%d", row);
 
-    // Keep note of the selection of this row
-    g_tree_insert(sw->selected_row_btree, GINT_TO_POINTER(row), NULL);
-
     /* If we double-click an item, then either "select" it, or run it
      * through the first button (which should be view/edit
      */
@@ -269,9 +281,6 @@
     gpointer item = gtk_clist_get_row_data (clist, row);
     //g_message("unselect-row, row=%d", row);
 
-    // Remove this row from the noted selection
-    g_tree_remove(sw->selected_row_btree, GINT_TO_POINTER(row));
-
     if (sw->selected_item == item)
         sw->selected_item = NULL;
 }
@@ -281,11 +290,10 @@
 gnc_search_dialog_init_result_list (GNCSearchWindow *sw)
 {
     sw->result_list = gnc_query_list_new(sw->display_list, sw->q);
-//#if GTK_CHECK_VERSION(2, 24, 0)
-//    // Apparently the multi-selection mode of GtkCList is broken in gtk-2.20
-//    gtk_clist_set_selection_mode(GTK_CLIST(sw->result_list), GTK_SELECTION_MULTIPLE);
-//#endif
 
+    // We want the multi-selection mode of GtkCList.
+    gtk_clist_set_selection_mode(&GNC_QUERY_LIST(sw->result_list)->clist, GTK_SELECTION_MULTIPLE);
+
     /* Setup the list callbacks */
     g_signal_connect (G_OBJECT (sw->result_list), "select-row",
                       G_CALLBACK (gnc_search_dialog_select_row_cb), sw);
@@ -1085,7 +1093,6 @@
     if (!sw) return;
     if (sw->gconf_section)
         gnc_save_window_size(sw->gconf_section, GTK_WINDOW(sw->dialog));
-    g_tree_destroy(sw->selected_row_btree);
     gnc_close_gui_component (sw->component_id);
 }
 
@@ -1097,12 +1104,6 @@
     gtk_window_present (GTK_WINDOW(sw->dialog));
 }
 
-static gint
-my_comparefunc_gint(gconstpointer a, gconstpointer b)
-{
-    return GPOINTER_TO_INT(a) < GPOINTER_TO_INT(b);
-}
-
 GNCSearchWindow *
 gnc_search_dialog_create (QofIdTypeConst obj_type, const gchar *title,
                           GList *param_list,
@@ -1139,8 +1140,6 @@
     sw->gconf_section = gconf_section;
     sw->type_label = type_label;
 
-    sw->selected_row_btree = g_tree_new(my_comparefunc_gint);
-
     /* Grab the get_guid function */
     sw->get_guid = qof_class_get_parameter (sw->search_for, QOF_PARAM_GUID);
     if (start_query)



More information about the gnucash-changes mailing list