From 42fa37831def12249a43cc321b341fdfdec6b443 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sun, 14 May 2000 09:37:59 +0000 Subject: [PATCH] Transaction/Split cut/copy/paste. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2307 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 14 ++ doc/README | 1 + doc/html/C/xacc-about.html | 4 + doc/solaris.txt | 24 +-- src/Makefile.in | 3 +- src/MultiLedger.c | 25 ++- src/MultiLedger.h | 3 + src/Refresh.c | 15 ++ src/Refresh.h | 4 + src/SplitLedger.c | 341 ++++++++++++++++++++++++++++++----- src/SplitLedger.h | 8 +- src/gnome/window-register.c | 77 ++++++++ src/messages_i18n.h | 12 ++ src/scm/engine-interface.scm | 19 +- 14 files changed, 467 insertions(+), 83 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7dbc3e9518..442c2932b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2000-05-14 Dave Peticolas + + * src/guile/guile-util.c: added several interface functions to + src/scm/engine-interface.scm. + + * src/Refresh.c (gnc_account_glist_ui_refresh): added a refresh + function that takes glib lists. Much more convenient. + + * src/SplitLedger.c: add functionality for transaction + cut/copy/paste. + + * src/MultiLedger.c (ledgerIsMember): always return true + for SEARCH_LEDGERS. Simple, but safe. + 2000-05-12 Dave Peticolas * Makefile.in: add -follow arguments to find commands diff --git a/doc/README b/doc/README index d4c957bffe..91f41b5dea 100644 --- a/doc/README +++ b/doc/README @@ -548,6 +548,7 @@ Matt Armstrong for misc fixes Fred Baube for attempted Java port/MoneyDance Dennis Björklund Swedish translation Per Bojsen several core dump fixes +Simon Britnell patch to RPM spec Christopher B. Browne for perl and lots of scheme Graham Chapman for the xacc-rpts addon package George Chen for MS-Money QIF's & fixes diff --git a/doc/html/C/xacc-about.html b/doc/html/C/xacc-about.html index e9ff0661b0..c2beca2416 100644 --- a/doc/html/C/xacc-about.html +++ b/doc/html/C/xacc-about.html @@ -244,6 +244,10 @@
several core dump fixes
+
Simon Britnell
+ +
patch to RPM spec
+
Christopher B. Browne
diff --git a/doc/solaris.txt b/doc/solaris.txt index 41bbe16dfe..a5a910ae4c 100644 --- a/doc/solaris.txt +++ b/doc/solaris.txt @@ -1,25 +1,7 @@ Solaris hints: ------------- -If the Makefile won't work, try the following: - The Makefile won't work unless SHELL=/bin/bash for me (Solaris 2.5.1). - That is: - make motif SHELL=/bin/bash - -Alan Orndorff writes: - -in /src/motif/makefile - -If you want to get further before we have a chance to fix this, you -could just change those $(wildcard foo) statements to $(shell find -"foo") statements - -This will leave two unresolved dependancies. - -/usr/local/lib/libiberty.a contains asprintf, so -vi /src/motif/Makefile and added -liberty to it - -In gnucash.c changed setenv to putenv and changed -the parms from (variable, variable,1) -to (variable) on both lines +Use bash when running configure and GNU make 'gmake' to build: +bash ./configure +gmake SHELL=/bin/bash diff --git a/src/Makefile.in b/src/Makefile.in index 8ddba606cb..f6b7872398 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -28,13 +28,12 @@ INCLPATH = -I. \ -I./register \ -I./guile \ -Ireports \ - -I@prefix@/lib/glib/include \ -I@prefix@/include GNOME_CFLAGS += -I./gnome MOTIF_CFLAGS += -I./motif -CFLAGS = @CFLAGS@ @X_CFLAGS@ ${INCLPATH} ${CPPFLAGS} ${GUILE_COMPILE_ARGS} ${G_WRAP_COMPILE_ARGS} +CFLAGS = @CFLAGS@ @X_CFLAGS@ ${INCLPATH} ${CPPFLAGS} ${GUILE_COMPILE_ARGS} ${G_WRAP_COMPILE_ARGS} ${GLIB_CFLAGS} ###################################################################### # See Makefile.common for information about these variables. diff --git a/src/MultiLedger.c b/src/MultiLedger.c index 3639cfe9fc..7d4ce58b81 100644 --- a/src/MultiLedger.c +++ b/src/MultiLedger.c @@ -128,6 +128,9 @@ ledgerIsMember (xaccLedgerDisplay *reg, Account * acc) if (acc == reg->leader) return 1; + /* Simple hack. Always return true for search registers. */ + if (reg->type == SEARCH_LEDGER) return 1; + if (! (reg->displayed_accounts)) return 0; n = 0; @@ -304,7 +307,7 @@ xaccLedgerDisplaySetHelp(void *user_data, const char *help_str) } /********************************************************************\ - * xaccLedgerDisplayLedger * + * xaccLedgerDisplayGeneral * * opens up a ledger window for a list of accounts * * * * Args: lead_acc - the account associated with this register * @@ -564,6 +567,26 @@ xaccAccListDisplayRefresh (Account **acc_list) /********************************************************************\ \********************************************************************/ +void +xaccAccGListDisplayRefresh (GList *accounts) +{ + GList *node; + + node = accounts; + while (node) { + MarkDirtyAllRegs (node->data); + node = node->next; + } + node = accounts; + while (node) { + RefreshAllRegs (node->data); + node = node->next; + } +} + +/********************************************************************\ +\********************************************************************/ + void xaccTransDisplayRefresh (Transaction *trans) { diff --git a/src/MultiLedger.h b/src/MultiLedger.h index 7a124fa164..97a7a5e868 100644 --- a/src/MultiLedger.h +++ b/src/MultiLedger.h @@ -26,6 +26,8 @@ #include "config.h" +#include + #include "Account.h" #include "Query.h" #include "splitreg.h" @@ -87,6 +89,7 @@ xaccLedgerDisplay * xaccLedgerDisplayGeneral (Account *lead_acc, */ void xaccAccountDisplayRefresh (Account *acc); void xaccAccListDisplayRefresh (Account **acc); +void xaccAccGListDisplayRefresh (GList *accounts); /* * redisplay/redraw all windows that contain this transaction diff --git a/src/Refresh.c b/src/Refresh.c index ae4920077f..fc67c0f100 100644 --- a/src/Refresh.c +++ b/src/Refresh.c @@ -86,6 +86,21 @@ gnc_account_list_ui_refresh(Account **account_list) } } +/* ------------------------------------------------------ */ +void +gnc_account_glist_ui_refresh(GList *accounts) +{ + GList *node; + + xaccAccGListDisplayRefresh(accounts); + + node = accounts; + while (node != NULL) + { + recnRefresh(node->data); + node = node->next; + } +} /* ------------------------------------------------------ */ void diff --git a/src/Refresh.h b/src/Refresh.h index cc44345836..18ca0c627e 100644 --- a/src/Refresh.h +++ b/src/Refresh.h @@ -24,6 +24,8 @@ #include "config.h" +#include + #include "top-level.h" @@ -31,6 +33,8 @@ void gnc_account_ui_refresh(Account *account); void gnc_account_list_ui_refresh(Account **account_list); +void gnc_account_glist_ui_refresh(GList *accounts); + void gnc_group_ui_refresh(AccountGroup *group); void gnc_transaction_ui_refresh(Transaction *trans); diff --git a/src/SplitLedger.c b/src/SplitLedger.c index b790a8ff30..9bc820a813 100644 --- a/src/SplitLedger.c +++ b/src/SplitLedger.c @@ -99,6 +99,7 @@ #include #include +#include #include #include "top-level.h" @@ -183,10 +184,14 @@ static char account_separator = ':'; static SRReverseBalanceCallback reverse_balance = NULL; /* The copied split or transaction, if any */ +static CursorType copied_type = CURSOR_NONE; static SCM copied_item = SCM_UNDEFINED; +static GUID copied_leader_guid; /* static prototypes */ static void xaccSRLoadRegEntry (SplitRegister *reg, Split *split); +static gncBoolean xaccSRSaveRegEntryToSCM (SplitRegister *reg, + SCM trans_scm, SCM split_scm); static Transaction * xaccSRGetTrans (SplitRegister *reg, int phys_row, int phys_col); @@ -277,6 +282,51 @@ xaccSRSetReverseBalanceCallback(SRReverseBalanceCallback callback) } +static GList * +gnc_trans_prepend_account_list(Transaction *trans, GList *accounts) +{ + Account *account; + Split *split; + int i = 0; + + if (trans == NULL) + return accounts; + + do + { + split = xaccTransGetSplit(trans, i); + + if (split == NULL) + return accounts; + + account = xaccSplitGetAccount(split); + if (account != NULL) + accounts = g_list_prepend(accounts, account); + + i++; + } while(1); +} + +static int +gnc_trans_split_index(Transaction *trans, Split *split) +{ + Split *s; + int i = 0; + + do + { + s = xaccTransGetSplit(trans, i); + + if (s == split) + return i; + + if (s == NULL) + return -1; + + i++; + } while(1); +} + /* Uses the scheme split copying routines */ static void gnc_copy_split_onto_split(Split *from, Split *to) @@ -832,45 +882,28 @@ xaccSRDuplicateCurrent (SplitRegister *reg) if (cursor_type == CURSOR_SPLIT) { Split *new_split; - Account *account; /* We are on a split in an expanded transaction. * Just copy the split and add it to the transaction. */ new_split = xaccMallocSplit(); - gnc_copy_split_onto_split(split, new_split); - - account = xaccSplitGetAccount(split); - xaccTransBeginEdit(trans, GNC_T); - xaccAccountBeginEdit(account, GNC_T); - xaccTransAppendSplit(trans, new_split); - xaccAccountInsertSplit(account, new_split); - - xaccAccountCommitEdit(account); xaccTransCommitEdit(trans); + gnc_copy_split_onto_split(split, new_split); + return_split = new_split; } else { Transaction *new_trans; int split_index; - int num_splits; - int i; /* We are on a transaction row. Copy the whole transaction. */ - split_index = -1; - num_splits = xaccTransCountSplits(trans); - for (i = 0; i < num_splits; i++) - if (xaccTransGetSplit(trans, i) == split) - { - split_index = i; - break; - } + split_index = gnc_trans_split_index(trans, split); /* we should *always* find the split, but be paranoid */ if (split_index < 0) @@ -881,8 +914,7 @@ xaccSRDuplicateCurrent (SplitRegister *reg) gnc_copy_trans_onto_trans(trans, new_trans); /* This shouldn't happen, but be paranoid. */ - num_splits = xaccTransCountSplits(new_trans); - if (split_index >= num_splits) + if (split_index >= xaccTransCountSplits(new_trans)) split_index = 0; return_split = xaccTransGetSplit(new_trans, split_index); @@ -897,6 +929,228 @@ xaccSRDuplicateCurrent (SplitRegister *reg) /* ======================================================== */ +void +xaccSRCopyCurrent (SplitRegister *reg) +{ + SRInfo *info = xaccSRGetInfo(reg); + CursorType cursor_type; + unsigned int changed; + Transaction *trans; + Split *split; + SCM new_item; + + split = xaccSRGetCurrentSplit(reg); + trans = xaccSRGetCurrentTrans(reg); + + /* This shouldn't happen, but be paranoid. */ + if (trans == NULL) + return; + + cursor_type = xaccSplitRegisterGetCursorType(reg); + + /* Can't do anything with this. */ + if (cursor_type == CURSOR_NONE) + return; + + /* This shouldn't happen, but be paranoid. */ + if ((split == NULL) && (cursor_type == CURSOR_TRANS)) + return; + + changed = xaccSplitRegisterGetChangeFlag(reg); + + /* See if we were asked to copy an unchanged blank split. Don't. */ + if (!changed && ((split == NULL) || (split == info->blank_split))) + return; + + /* Ok, we are now ready to make the copy. */ + + if (cursor_type == CURSOR_SPLIT) + { + /* We are on a split in an expanded transaction. Just copy the split. */ + new_item = gnc_copy_split(split); + + if (new_item != SCM_UNDEFINED) + { + if (changed) + xaccSRSaveRegEntryToSCM(reg, SCM_UNDEFINED, new_item); + + copied_leader_guid = *xaccGUIDNULL(); + } + } + else + { + /* We are on a transaction row. Copy the whole transaction. */ + new_item = gnc_copy_trans(trans); + + if (new_item != SCM_UNDEFINED) + { + if (changed) + { + int split_index; + SCM split_scm; + + split_index = gnc_trans_split_index(trans, split); + if (split_index >= 0) + split_scm = gnc_trans_scm_get_split_scm(new_item, split_index); + else + split_scm = SCM_UNDEFINED; + + xaccSRSaveRegEntryToSCM(reg, new_item, split_scm); + } + + copied_leader_guid = *xaccAccountGetGUID(info->default_source_account); + } + } + + if (new_item == SCM_UNDEFINED) + return; + + /* unprotect the old object, if any */ + if (copied_item != SCM_UNDEFINED) + scm_unprotect_object(copied_item); + + copied_item = new_item; + scm_protect_object(copied_item); + + copied_type = cursor_type; +} + +/* ======================================================== */ + +void +xaccSRCutCurrent (SplitRegister *reg) +{ + SRInfo *info = xaccSRGetInfo(reg); + CursorType cursor_type; + unsigned int changed; + Transaction *trans; + Split *split; + + split = xaccSRGetCurrentSplit(reg); + trans = xaccSRGetCurrentTrans(reg); + + /* This shouldn't happen, but be paranoid. */ + if (trans == NULL) + return; + + cursor_type = xaccSplitRegisterGetCursorType(reg); + + /* Can't do anything with this. */ + if (cursor_type == CURSOR_NONE) + return; + + /* This shouldn't happen, but be paranoid. */ + if ((split == NULL) && (cursor_type == CURSOR_TRANS)) + return; + + changed = xaccSplitRegisterGetChangeFlag(reg); + + /* See if we were asked to cut an unchanged blank split. Don't. */ + if (!changed && ((split == NULL) || (split == info->blank_split))) + return; + + xaccSRCopyCurrent(reg); + + if (cursor_type == CURSOR_SPLIT) + xaccSRDeleteCurrentSplit(reg); + else + xaccSRDeleteCurrentTrans(reg); +} + +/* ======================================================== */ + +void +xaccSRPasteCurrent (SplitRegister *reg) +{ + SRInfo *info = xaccSRGetInfo(reg); + GList *accounts = NULL; + CursorType cursor_type; + Transaction *trans; + Split *split; + + if (copied_type == CURSOR_NONE) + return; + + split = xaccSRGetCurrentSplit(reg); + trans = xaccSRGetCurrentTrans(reg); + + /* This shouldn't happen, but be paranoid. */ + if (trans == NULL) + return; + + cursor_type = xaccSplitRegisterGetCursorType(reg); + + /* Can't do anything with this. */ + if (cursor_type == CURSOR_NONE) + return; + + /* This shouldn't happen, but be paranoid. */ + if ((split == NULL) && (cursor_type == CURSOR_TRANS)) + return; + + if (cursor_type == CURSOR_SPLIT) { + if (copied_type == CURSOR_TRANS) + return; + + accounts = gnc_trans_prepend_account_list(trans, NULL); + + if (split == NULL) + { /* We are on a null split in an expanded transaction. */ + split = xaccMallocSplit(); + + xaccTransBeginEdit(trans, GNC_T); + xaccTransAppendSplit(trans, split); + xaccTransCommitEdit(trans); + } + + gnc_copy_split_scm_onto_split(copied_item, split); + } + else { + const GUID *new_guid; + int split_index; + int num_splits; + + if (copied_type == CURSOR_SPLIT) + return; + + accounts = gnc_trans_prepend_account_list(trans, NULL); + + /* in pasting, the old split is deleted. */ + if (split == info->blank_split) + info->blank_split = NULL; + + split_index = gnc_trans_split_index(trans, split); + + if ((info->default_source_account != NULL) && + (xaccGUIDType(&copied_leader_guid) != GNC_ID_NULL)) + { + new_guid = xaccAccountGetGUID(info->default_source_account); + gnc_copy_trans_scm_onto_trans_with_new_account(copied_item, trans, + &copied_leader_guid, + new_guid); + } + else + gnc_copy_trans_scm_onto_trans(copied_item, trans); + + num_splits = xaccTransCountSplits(trans); + if (split_index >= num_splits) + split_index = 0; + + info->cursor_hint_trans = trans; + info->cursor_hint_split = xaccTransGetSplit(trans, split_index); + } + + accounts = gnc_trans_prepend_account_list(trans, accounts); + + /* Refresh the GUI. */ + gnc_account_glist_ui_refresh(accounts); + gnc_refresh_main_window(); + + g_list_free(accounts); +} + +/* ======================================================== */ + void xaccSRDeleteCurrentSplit (SplitRegister *reg) { @@ -1373,13 +1627,12 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm) gncBoolean xaccSRSaveRegEntry (SplitRegister *reg, Transaction *new_trans) { - Account *account_refresh[5]; + GList *refresh_accounts = NULL; SRInfo *info = xaccSRGetInfo(reg); Split *split; Transaction *trans; unsigned int changed; int style; - int i; /* use the changed flag to avoid heavy-weight updates * of the split & transaction fields. This will help @@ -1388,13 +1641,6 @@ xaccSRSaveRegEntry (SplitRegister *reg, Transaction *new_trans) if (!changed) return GNC_F; - /* HACK. This list will be used to refresh changed accounts. - * The list is 5 long for: 2 accounts for xfrm, 2 accounts - * for mxfrm, 1 account for NULL. This can go away once we - * have engine change callbacks. */ - for (i = 0; i < 5; i++) - account_refresh[i] = NULL; - style = (reg->type) & REG_STYLE_MASK; /* get the handle to the current split and transaction */ @@ -1533,9 +1779,8 @@ xaccSRSaveRegEntry (SplitRegister *reg, Transaction *new_trans) if ((currency != NULL) || (security != NULL)) { xaccAccountInsertSplit (new_acc, split); - /* HACK. */ - account_refresh[0] = old_acc; - account_refresh[1] = new_acc; + refresh_accounts = g_list_prepend(refresh_accounts, old_acc); + refresh_accounts = g_list_prepend(refresh_accounts, new_acc); } else { char *message = NULL; @@ -1608,15 +1853,8 @@ xaccSRSaveRegEntry (SplitRegister *reg, Transaction *new_trans) if ((currency != NULL) || (security != NULL)) { xaccAccountInsertSplit (new_acc, other_split); - /* HACK. */ - if (account_refresh[0] == NULL) { - account_refresh[0] = old_acc; - account_refresh[1] = new_acc; - } - else { - account_refresh[2] = old_acc; - account_refresh[3] = new_acc; - } + refresh_accounts = g_list_prepend(refresh_accounts, old_acc); + refresh_accounts = g_list_prepend(refresh_accounts, new_acc); } else { char *message = NULL; @@ -1809,9 +2047,10 @@ xaccSRSaveRegEntry (SplitRegister *reg, Transaction *new_trans) xaccSplitRegisterClearChangeFlag(reg); - if (account_refresh[0] != NULL) { - gnc_account_list_ui_refresh(account_refresh); + if (refresh_accounts != NULL) { + gnc_account_glist_ui_refresh(refresh_accounts); gnc_refresh_main_window(); + g_list_free(refresh_accounts); } return GNC_T; @@ -2246,14 +2485,17 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist, if (info->cursor_hint_trans != NULL) { find_trans = info->cursor_hint_trans; find_split = info->cursor_hint_split; - save_phys_col = info->cursor_hint_phys_col; } else { find_trans = xaccSRGetCurrentTrans (reg); find_split = xaccSRGetCurrentSplit (reg); - save_phys_col = table->current_cursor_phys_col; } + if (info->cursor_hint_phys_col >= 0) + save_phys_col = info->cursor_hint_phys_col; + else + save_phys_col = table->current_cursor_phys_col; + /* paranoia */ if (save_phys_col < 0) save_phys_col = 0; @@ -2458,10 +2700,11 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist, if (!found_pending) info->pending_trans = NULL; - /* clear out the hint transaction and split. We want - * to know if it has been set from the move callback. */ + /* clear out the hint transaction, split, and col. We want + * to know if it has been set from the move callback, etc. */ info->cursor_hint_trans = NULL; info->cursor_hint_split = NULL; + info->cursor_hint_phys_col = -1; xaccRefreshTableGUI (table); diff --git a/src/SplitLedger.h b/src/SplitLedger.h index 3eac1e1e05..4ec65c451c 100644 --- a/src/SplitLedger.h +++ b/src/SplitLedger.h @@ -147,6 +147,10 @@ gncBoolean xaccSRGetTransSplitRowCol (SplitRegister *reg, Split * xaccSRDuplicateCurrent (SplitRegister *reg); +void xaccSRCopyCurrent (SplitRegister *reg); +void xaccSRCutCurrent (SplitRegister *reg); +void xaccSRPasteCurrent (SplitRegister *reg); + void xaccSRDeleteCurrentSplit (SplitRegister *reg); void xaccSRDeleteCurrentTrans (SplitRegister *reg); void xaccSREmptyCurrentTrans (SplitRegister *reg); @@ -154,10 +158,6 @@ void xaccSREmptyCurrentTrans (SplitRegister *reg); void xaccSRCancelCursorSplitChanges (SplitRegister *reg); void xaccSRCancelCursorTransChanges (SplitRegister *reg); -void xaccSRCopyCurrent (SplitRegister *reg); -void xaccSRCutCurrent (SplitRegister *reg); -void xaccSRPasteCurrent (SplitRegister *reg); - void xaccSRLoadRegister (SplitRegister *reg, Split **slist, Account *default_source_acc); diff --git a/src/gnome/window-register.c b/src/gnome/window-register.c index c36cd362e4..1afcf0fd1f 100644 --- a/src/gnome/window-register.c +++ b/src/gnome/window-register.c @@ -117,6 +117,9 @@ static void gnc_register_check_close(RegWindow *regData); static void cutCB(GtkWidget *w, gpointer data); static void copyCB(GtkWidget *w, gpointer data); static void pasteCB(GtkWidget *w, gpointer data); +static void cutTransCB(GtkWidget *w, gpointer data); +static void copyTransCB(GtkWidget *w, gpointer data); +static void pasteTransCB(GtkWidget *w, gpointer data); static void startRecnCB(GtkWidget *w, gpointer data); static void xferCB(GtkWidget *w, gpointer data); static void editCB(GtkWidget *w, gpointer data); @@ -1119,6 +1122,29 @@ gnc_register_create_menu_bar(RegWindow *regData, GtkWidget *statusbar) GNOMEUIINFO_MENU_CUT_ITEM(cutCB, NULL), GNOMEUIINFO_MENU_COPY_ITEM(copyCB, NULL), GNOMEUIINFO_MENU_PASTE_ITEM(pasteCB, NULL), + GNOMEUIINFO_SEPARATOR, + { + GNOME_APP_UI_ITEM, + CUT_TRANS_STR_N, TOOLTIP_CUT_TRANS_N, + cutTransCB, NULL, NULL, + GNOME_APP_PIXMAP_NONE, NULL, + 0, 0, NULL + }, + { + GNOME_APP_UI_ITEM, + COPY_TRANS_STR_N, TOOLTIP_COPY_TRANS_N, + copyTransCB, NULL, NULL, + GNOME_APP_PIXMAP_NONE, NULL, + 0, 0, NULL + }, + { + GNOME_APP_UI_ITEM, + PASTE_TRANS_STR_N, TOOLTIP_PASTE_TRANS_N, + pasteTransCB, NULL, NULL, + GNOME_APP_PIXMAP_NONE, NULL, + 0, 0, NULL + }, + GNOMEUIINFO_END }; static GnomeUIInfo account_menu[] = @@ -1859,6 +1885,7 @@ cutCB(GtkWidget *w, gpointer data) gnucash_register_cut_clipboard(regData->reg); } + /********************************************************************\ * copyCB -- copy the selection to the clipboard * * * @@ -1874,6 +1901,7 @@ copyCB(GtkWidget *w, gpointer data) gnucash_register_copy_clipboard(regData->reg); } + /********************************************************************\ * pasteCB -- paste the clipboard to the selection * * * @@ -1889,6 +1917,55 @@ pasteCB(GtkWidget *w, gpointer data) gnucash_register_paste_clipboard(regData->reg); } + +/********************************************************************\ + * cutTransCB -- cut the current transaction to the clipboard * + * * + * Args: w - the widget that called us * + * data - the data struct for this register * + * Return: none * +\********************************************************************/ +static void +cutTransCB(GtkWidget *w, gpointer data) +{ + RegWindow *regData = data; + + xaccSRCutCurrent(regData->ledger->ledger); +} + + +/********************************************************************\ + * copyTransCB -- copy the current transaction to the clipboard * + * * + * Args: w - the widget that called us * + * data - the data struct for this register * + * Return: none * +\********************************************************************/ +static void +copyTransCB(GtkWidget *w, gpointer data) +{ + RegWindow *regData = data; + + xaccSRCopyCurrent(regData->ledger->ledger); +} + + +/********************************************************************\ + * pasteTransCB -- paste the transaction clipboard to the selection * + * * + * Args: w - the widget that called us * + * data - the data struct for this register * + * Return: none * +\********************************************************************/ +static void +pasteTransCB(GtkWidget *w, gpointer data) +{ + RegWindow *regData = data; + + xaccSRPasteCurrent(regData->ledger->ledger); +} + + /********************************************************************\ * startAdjBCB -- open up the adjust balance window... called * * from the menubar. * diff --git a/src/messages_i18n.h b/src/messages_i18n.h index 32999b198b..cd6f249d70 100644 --- a/src/messages_i18n.h +++ b/src/messages_i18n.h @@ -190,6 +190,10 @@ #define TOOLTIP_CLOSE_HTML _("Close this HTML window") #define TOOLTIP_CLOSE_REG_N N_("Close this register window") #define TOOLTIP_CLOSE_REG _(TOOLTIP_CLOSE_REG_N) +#define TOOLTIP_COPY_TRANS_N N_("Copy the selected transaction") +#define TOOLTIP_COPY_TRANS _(TOOLTIP_COPY_TRANS_N) +#define TOOLTIP_CUT_TRANS_N N_("Cut the selected transaction") +#define TOOLTIP_CUT_TRANS _(TOOLTIP_CUT_TRANS_N) #define TOOLTIP_DATE_RANGE_N N_("Set the date range of this register") #define TOOLTIP_DATE_RANGE _(TOOLTIP_DATE_RANGE_N) #define TOOLTIP_DELETE_N N_("Delete selected account") @@ -243,6 +247,8 @@ #define TOOLTIP_OPEN_SUB _(TOOLTIP_OPEN_SUB_N) #define TOOLTIP_OPEN_FILE_N N_("Open a file") #define TOOLTIP_OPEN_FILE _(TOOLTIP_OPEN_FILE_N) +#define TOOLTIP_PASTE_TRANS_N N_("Paste the transaction clipboard") +#define TOOLTIP_PASTE_TRANS _(TOOLTIP_PASTE_TRANS_N) #define TOOLTIP_PREFERENCES_N N_("Open the global preferences dialog") #define TOOLTIP_PREFERENCES _(TOOLTIP_PREFERENCES_N) #define TOOLTIP_PRINT_CHECK_N N_("Print a check using a standard format") @@ -323,6 +329,10 @@ #define BLANK_MENU_STR _(BLANK_MENU_STR_N) #define CANCEL_MENU_STR_N N_("_Cancel") #define CANCEL_MENU_STR _(CANCEL_MENU_STR_N) +#define COPY_TRANS_STR_N N_("Copy Transaction") +#define COPY_TRANS_STR _(COPY_TRANS_STR_N) +#define CUT_TRANS_STR_N N_("Cut Transaction") +#define CUT_TRANS_STR _(CUT_TRANS_STR_N) #define DATE_RANGE_MENU_STR_N N_("_Date Range") #define DATE_RANGE_MENU_STR _(DATE_RANGE_MENU_STR_N) #define DEL_ACC_MENU_STR_N N_("_Delete Account") @@ -353,6 +363,8 @@ #define OPEN_ACC_MENU_STR _(OPEN_ACC_MENU_STR_N) #define OPEN_SUB_MENU_STR_N N_("Open S_ubaccounts") #define OPEN_SUB_MENU_STR _(OPEN_SUB_MENU_STR_N) +#define PASTE_TRANS_STR_N N_("Paste Transaction") +#define PASTE_TRANS_STR _(PASTE_TRANS_STR_N) #define PREFERENCES_MENU_STR _("_Preferences") #define PREFERENCES_MENU_E_STR_N N_("_Preferences...") #define PRINT_CHECK_MENU_E_STR_N N_("_Print Check... (unfinished!)") diff --git a/src/scm/engine-interface.scm b/src/scm/engine-interface.scm index f18d2876b0..3dd9716390 100644 --- a/src/scm/engine-interface.scm +++ b/src/scm/engine-interface.scm @@ -245,7 +245,9 @@ (trans-splits 0))) ;; Copy a scheme representation of a transaction onto a C transaction. -(define (gnc:transaction-scm-onto-transaction trans-scm trans) +;; guid-mapping, if present, must be an alist, mapping guids to guids. +;; This list is used to use alternate account guids when creating splits. +(define (gnc:transaction-scm-onto-transaction trans-scm trans . guid-mapping) (if (pointer-token-null? trans) #f (begin @@ -254,10 +256,8 @@ (gnc:transaction-begin-edit trans 1) ;; copy in the transaction values - (let ((date-posted (gnc:transaction-scm-get-date-posted trans-scm)) - (description (gnc:transaction-scm-get-description trans-scm)) + (let ((description (gnc:transaction-scm-get-description trans-scm)) (docref (gnc:transaction-scm-get-docref trans-scm))) - (if date-posted (gnc:transaction-set-date-posted trans date-posted)) (if description (gnc:transaction-set-description trans description)) (if docref (gnc:transaction-set-docref trans docref))) @@ -272,9 +272,16 @@ ;; order as in the original transaction. This is important. (let loop ((split-scms (gnc:transaction-scm-get-split-scms trans-scm))) (if (pair? split-scms) - (let ((new-split (gnc:split-create))) + (let* ((new-split (gnc:split-create)) + (split-scm (car split-scms)) + (old-guid (gnc:split-scm-get-account-guid split-scm)) + (new-guid (assoc-ref guid-mapping old-guid))) + (if (not new-guid) + (set! new-guid old-guid)) (gnc:transaction-append-split trans new-split) - (gnc:split-scm-onto-split (car split-scms) new-split) + (gnc:split-scm-set-account-guid split-scm new-guid) + (gnc:split-scm-onto-split split-scm new-split) + (gnc:split-scm-set-account-guid split-scm old-guid) (loop (cdr split-scms))))) ;; close the transaction