implement "Delete" and "Duplicate" functions

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6877 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2002-05-18 20:10:27 +00:00
parent a61e184428
commit 094b57930f
7 changed files with 186 additions and 1 deletions

View File

@@ -270,6 +270,30 @@ void gncEntrySetDirty (GncEntry *entry, gboolean dirty)
entry->dirty = dirty;
}
void gncEntryCopy (const GncEntry *src, GncEntry *dest)
{
if (!src || !dest) return;
dest->date = src->date;
dest->date_entered = src->date_entered; /* ??? */
gncEntrySetDescription (dest, src->desc);
gncEntrySetAction (dest, src->action);
dest->quantity = src->quantity;
dest->price = src->price;
dest->tax = src->tax;
dest->tax_type = src->tax_type;
dest->discount = src->discount;
dest->disc_type = src->disc_type;
dest->account = src->account;
dest->taxaccount = src->taxaccount;
if (src->order)
gncOrderAddEntry (src->order, dest);
if (src->invoice)
gncInvoiceAddEntry (src->invoice, dest);
}
/* Get Functions */
GNCBook * gncEntryGetBook (GncEntry *entry)

View File

@@ -65,6 +65,8 @@ gnc_numeric gncEntryGetDiscount (GncEntry *entry);
gint gncEntryGetDiscountType (GncEntry *entry);
const char * gncEntryGetDiscountTypeStr (gint type);
void gncEntryCopy (const GncEntry *src, GncEntry *dest);
gnc_numeric gncEntryReturnValue (GncEntry *entry);
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry);

View File

@@ -381,13 +381,61 @@ cancelCB (GtkWidget *widget, gpointer data)
static void
deleteCB (GtkWidget *widget, gpointer data)
{
InvoiceWindow *iw = data;
GncEntry *entry;
if (!iw || !iw->ledger)
return;
/* get the current entry based on cursor position */
entry = gnc_entry_ledger_get_current_entry (iw->ledger);
if (!entry) {
gnc_entry_ledger_cancel_cursor_changes (iw->ledger);
return;
}
/* deleting the blank entry just cancels */
if (entry == gnc_entry_ledger_get_blank_entry (iw->ledger)) {
gnc_entry_ledger_cancel_cursor_changes (iw->ledger);
return;
}
/* Verify that the user really wants to delete this entry */
{
const char *message = _("Are you sure you want to delete the "
"current entry?");
const char *order_warn = _("This entry is attached to an order and "
"will be deleted from that as well!");
char *msg;
gboolean result;
if (gncEntryGetOrder (entry))
msg = g_strconcat (message, "\n\n", order_warn, NULL);
else
msg = g_strdup (message);
result = gnc_verify_dialog_parented (iw->dialog, FALSE, msg);
g_free (msg);
if (!result)
return;
}
/* Yep, let's delete */
gnc_entry_ledger_delete_current_entry (iw->ledger);
return;
}
static void
duplicateCB (GtkWidget *widget, gpointer data)
{
}
InvoiceWindow *iw = data;
if (!iw || !iw->ledger)
return;
gnc_entry_ledger_duplicate_current_entry (iw->ledger);
}
static void
blank_entry_cb (GtkWidget *widget, gpointer data)

View File

@@ -17,6 +17,9 @@
#include "recncell.h"
#include "messages.h"
#include "gnc-component-manager.h"
#include "gnc-ui.h"
#include "gncEntry.h"
#include "gncEntryLedger.h"
#include "gncEntryLedgerP.h"
@@ -494,3 +497,103 @@ gnc_entry_ledger_get_entry_virt_loc (GncEntryLedger *ledger, GncEntry *entry,
return FALSE;
}
void
gnc_entry_ledger_delete_current_entry (GncEntryLedger *ledger)
{
GncEntry *entry;
if (!ledger)
return;
/* If there is no entry, just return */
entry = gnc_entry_ledger_get_current_entry (ledger);
if (!entry)
return;
/* If this is the blank entry, just cancel the changes */
if (entry == gnc_entry_ledger_get_blank_entry (ledger)) {
gnc_entry_ledger_cancel_cursor_changes (ledger);
return;
}
/* Ok, let's delete this entry */
gnc_suspend_gui_refresh ();
{
GncOrder *order;
GncInvoice *invoice;
order = gncEntryGetOrder (entry);
if (order)
gncOrderRemoveEntry (order, entry);
invoice = gncEntryGetInvoice (entry);
if (invoice)
gncInvoiceRemoveEntry (invoice, entry);
gncEntryDestroy (entry);
/* XXX: Commit the deletion? */
}
gnc_resume_gui_refresh ();
}
void
gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger)
{
GncEntry *entry;
gboolean changed;
if (!ledger)
return;
/* Be paranoid */
entry = gnc_entry_ledger_get_current_entry (ledger);
if (!entry)
return;
changed = gnc_table_current_cursor_changed (ledger->table, FALSE);
/* See if we're asked to duplicate an unchanged blank entry --
* there is no point in doing that.
*/
if (!changed && entry == gnc_entry_ledger_get_blank_entry (ledger))
return;
gnc_suspend_gui_refresh ();
/* If the cursor has been edited, we are going to have to commit
* it before we can duplicate. Make sure the user wants to do that. */
if (changed) {
const char *message = _("The current entry has been changed.\n"
"Would you like to save it?");
GNCVerifyResult result;
result = gnc_ok_cancel_dialog_parented (ledger->parent,
GNC_VERIFY_OK, message);
if (result == GNC_VERIFY_CANCEL) {
gnc_resume_gui_refresh ();
return;
}
if (!gnc_entry_ledger_commit_entry (ledger)) {
gnc_resume_gui_refresh ();
return;
}
}
/* Ok, we're ready to make the copy */
{
GncEntry * new_entry;
new_entry = gncEntryCreate (ledger->book);
gncEntryCopy (entry, new_entry);
gncEntrySetDate (new_entry, ledger->last_date_entered);
/* Set the hint for where to display on the refresh */
ledger->hint_entry = new_entry;
}
gnc_resume_gui_refresh ();
return;
}

View File

@@ -100,4 +100,7 @@ gboolean gnc_entry_ledger_get_entry_virt_loc (GncEntryLedger *ledger,
GncEntry *entry,
VirtualCellLocation *vcell_loc);
void gnc_entry_ledger_delete_current_entry (GncEntryLedger *ledger);
void gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger);
#endif /* GNC_ENTRY_LEDGER_H */

View File

@@ -181,6 +181,8 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
/* Figure out where we are going to */
if (ledger->traverse_to_new) {
find_entry = blank_entry;
} else if (ledger->hint_entry) {
find_entry = ledger->hint_entry;
} else {
find_entry = gnc_entry_ledger_get_current_entry(ledger);
/* XXX: get current entry (cursor_hint_xxx) */
@@ -292,6 +294,7 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
/* Reset the ledger */
ledger->traverse_to_new = FALSE;
ledger->hint_entry = NULL;
/* Set the cell fractions */

View File

@@ -24,6 +24,8 @@ struct GncEntryLedger_s {
Timespec last_date_entered;
GncEntry * hint_entry; /* A Hint for where to display */
gncUIWidget parent;
GNCBook * book;
Table * table;