Allow deletion of multiple prices at once.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12034 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2005-11-26 05:56:41 +00:00
parent bf317b5a44
commit c1d074c5c9
3 changed files with 54 additions and 27 deletions

View File

@ -1,5 +1,13 @@
2005-11-25 David Hampton <hampton@employees.org> 2005-11-25 David Hampton <hampton@employees.org>
* src/gnome/dialog-price-edit-db.c: Allow selection of multiple
prices at once. Multiple prices can be deleted at the same time,
but not edited. implements 147557.
* src/gnome-utils/gnc-tree-view-price.c: Fix the
gnc_tree_view_price_set_selected_price function to ignore exchange
and commodity entries.
* src/gnome/dialog-price-edit-db.c: Enhance the "remove old * src/gnome/dialog-price-edit-db.c: Enhance the "remove old
prices" code to have options to retain the last price entered, and prices" code to have options to retain the last price entered, and
to retain any user entered prices. The "remove old" button should to retain any user entered prices. The "remove old" button should

View File

@ -924,6 +924,7 @@ get_selected_prices_helper (GtkTreeModel *s_model,
model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model)); model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
price = gnc_tree_model_price_get_price (GNC_TREE_MODEL_PRICE(model), price = gnc_tree_model_price_get_price (GNC_TREE_MODEL_PRICE(model),
&iter); &iter);
if (price)
*return_list = g_list_append(*return_list, price); *return_list = g_list_append(*return_list, price);
} }

View File

@ -72,7 +72,6 @@ typedef struct
GtkWidget * remove_button; GtkWidget * remove_button;
GNCPriceDB *price_db; GNCPriceDB *price_db;
GNCPrice * price; /* Currently selected price */
} PricesDialog; } PricesDialog;
@ -84,12 +83,6 @@ gnc_prices_dialog_window_destroy_cb (GtkObject *object, gpointer data)
ENTER(" "); ENTER(" ");
gnc_unregister_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog); gnc_unregister_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
if (pdb_dialog->price)
{
gnc_price_unref (pdb_dialog->price);
pdb_dialog->price = NULL;
}
if (pdb_dialog->dialog) { if (pdb_dialog->dialog) {
gtk_widget_destroy(pdb_dialog->dialog); gtk_widget_destroy(pdb_dialog->dialog);
pdb_dialog->dialog = NULL; pdb_dialog->dialog = NULL;
@ -123,37 +116,58 @@ void
gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data) gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data)
{ {
PricesDialog *pdb_dialog = data; PricesDialog *pdb_dialog = data;
GList *price_list;
ENTER(" "); ENTER(" ");
if (!pdb_dialog->price) { price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (!price_list) {
LEAVE("no price selected"); LEAVE("no price selected");
return; return;
} }
if (g_list_next(!price_list)) {
LEAVE("soo many prices selected");
return;
}
gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->price, GNC_PRICE_EDIT); gnc_price_edit_dialog (pdb_dialog->dialog, price_list->data, GNC_PRICE_EDIT);
g_list_free(price_list);
LEAVE(" "); LEAVE(" ");
} }
static void
remove_helper(GNCPrice *price, GNCPriceDB *pdb)
{
gnc_pricedb_remove_price (pdb, price);
}
void void
gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data) gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
{ {
PricesDialog *pdb_dialog = data; PricesDialog *pdb_dialog = data;
const char *message = _("Are you sure you want to delete the\n" GList *price_list;
gint length;
const char *message_sg = N_("Are you sure you want to delete the %d "
"selected price?"); "selected price?");
const char *message_pl = N_("Are you sure you want to delete the %d "
"selected prices?");
ENTER(" "); ENTER(" ");
if (!pdb_dialog->price) { price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (!price_list) {
LEAVE("no price selected"); LEAVE("no price selected");
return; return;
} }
if (gnc_verify_dialog (pdb_dialog->dialog, TRUE, message)) length = g_list_length(price_list);
if (gnc_verify_dialog (pdb_dialog->dialog, TRUE,
ngettext(message_sg, message_pl, length), length))
{ {
GNCBook *book = gnc_get_current_book (); GNCBook *book = gnc_get_current_book ();
GNCPriceDB *pdb = gnc_book_get_pricedb (book); GNCPriceDB *pdb = gnc_book_get_pricedb (book);
gnc_pricedb_remove_price (pdb, pdb_dialog->price); g_list_foreach(price_list, (GFunc)remove_helper, pdb);
} }
g_list_free(price_list);
LEAVE(" "); LEAVE(" ");
} }
@ -200,9 +214,16 @@ void
gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data) gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data)
{ {
PricesDialog *pdb_dialog = data; PricesDialog *pdb_dialog = data;
GNCPrice *price = NULL;
GList *price_list;
ENTER(" "); ENTER(" ");
gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->price, GNC_PRICE_NEW); price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (price_list) {
price = price_list->data;
g_list_free(price_list);
}
gnc_price_edit_dialog (pdb_dialog->dialog, price, GNC_PRICE_NEW);
LEAVE(" "); LEAVE(" ");
} }
@ -238,22 +259,18 @@ gnc_prices_dialog_selection_changed (GtkTreeSelection *treeselection,
gpointer data) gpointer data)
{ {
PricesDialog *pdb_dialog = data; PricesDialog *pdb_dialog = data;
GList *price_list;
gint length;
ENTER(" "); ENTER(" ");
if (pdb_dialog->price) price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
gnc_price_unref (pdb_dialog->price); length = g_list_length(price_list);
pdb_dialog->price =
gnc_tree_view_price_get_selected_price (pdb_dialog->price_tree);
if (pdb_dialog->price)
gnc_price_ref (pdb_dialog->price);
gtk_widget_set_sensitive (pdb_dialog->edit_button, gtk_widget_set_sensitive (pdb_dialog->edit_button,
pdb_dialog->price != NULL); length == 1);
gtk_widget_set_sensitive (pdb_dialog->remove_button, gtk_widget_set_sensitive (pdb_dialog->remove_button,
pdb_dialog->price != NULL); length >= 1);
LEAVE(" "); LEAVE("%d prices selected", length);
} }
@ -347,6 +364,7 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
pdb_dialog, NULL); pdb_dialog, NULL);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
g_signal_connect (G_OBJECT (selection), "changed", g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_prices_dialog_selection_changed), pdb_dialog); G_CALLBACK (gnc_prices_dialog_selection_changed), pdb_dialog);