Skip to content

Commit

Permalink
Merge Bob Fewell's 'cutpaste' into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Sep 21, 2024
2 parents 60e7497 + 35cd037 commit e4d2443
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions gnucash/register/ledger-core/split-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ typedef struct
FloatingSplit *fs;
FloatingTxn *ft;
};
CursorClass cursor_class;
GncGUID leader_guid;
gint anchor_split_index;
} ft_fs_store;

static ft_fs_store copied_item = { 0, { NULL } };
static CursorClass copied_class = CURSOR_CLASS_NONE;
static GncGUID copied_leader_guid;

/** static prototypes *****************************************************/

Expand All @@ -98,8 +99,10 @@ clear_copied_item()
gnc_float_txn_free (copied_item.ft);
copied_item.ftype = 0;
copied_item.fs = NULL;
copied_class = CURSOR_CLASS_NONE;
copied_leader_guid = *guid_null();
copied_item.ft = NULL;
copied_item.cursor_class = CURSOR_CLASS_NONE;
copied_item.leader_guid = *guid_null();
copied_item.anchor_split_index = 0;
}

static void
Expand Down Expand Up @@ -785,6 +788,9 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
return;
}

/* unprotect the old object, if any */
clear_copied_item();

/* Ok, we are now ready to make the copy. */

if (cursor_class == CURSOR_CLASS_SPLIT)
Expand All @@ -798,7 +804,7 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
gnc_split_register_save_to_copy_buffer (reg, NULL, new_fs,
use_cut_semantics);

copied_leader_guid = *guid_null ();
copied_item.leader_guid = *guid_null ();
}
}
else
Expand All @@ -823,7 +829,8 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
use_cut_semantics);
}

copied_leader_guid = info->default_account;
copied_item.leader_guid = info->default_account;
copied_item.anchor_split_index = xaccTransGetSplitIndex (trans, split);
}
}

Expand All @@ -834,9 +841,6 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
return;
}

/* unprotect the old object, if any */
clear_copied_item();

if (new_fs)
{
copied_item.fs = new_fs;
Expand All @@ -848,7 +852,7 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
copied_item.ftype = GNC_TYPE_TRANSACTION;
}

copied_class = cursor_class;
copied_item.cursor_class = cursor_class;
gnc_hook_add_dangler (HOOK_BOOK_CLOSED, clear_copied_item, NULL, NULL);
LEAVE ("%s %s", use_cut_semantics ? "cut" : "copied",
cursor_class == CURSOR_CLASS_SPLIT ? "split" : "transaction");
Expand Down Expand Up @@ -916,7 +920,7 @@ gnc_split_register_paste_current (SplitRegister* reg)

ENTER ("reg=%p", reg);

if (copied_class == CURSOR_CLASS_NONE)
if (copied_item.cursor_class == CURSOR_CLASS_NONE)
{
LEAVE ("no copied cursor class");
return;
Expand Down Expand Up @@ -964,7 +968,7 @@ gnc_split_register_paste_current (SplitRegister* reg)
"you navigate to a register that shows another "
"side of this same transaction.");

if (copied_class == CURSOR_CLASS_TRANS)
if (copied_item.cursor_class == CURSOR_CLASS_TRANS)
{
/* An entire transaction was copied, but we're just on a split. */
LEAVE ("can't copy trans to split");
Expand Down Expand Up @@ -1025,7 +1029,7 @@ gnc_split_register_paste_current (SplitRegister* reg)
int split_index;
int num_splits;

if (copied_class == CURSOR_CLASS_SPLIT)
if (copied_item.cursor_class == CURSOR_CLASS_SPLIT)
{
LEAVE ("can't copy split to transaction");
return;
Expand Down Expand Up @@ -1062,7 +1066,7 @@ gnc_split_register_paste_current (SplitRegister* reg)
split_index = xaccTransGetSplitIndex (trans, split);
trans_split_index = xaccTransGetSplitIndex (trans, trans_split);

copied_leader = xaccAccountLookup (&copied_leader_guid,
copied_leader = xaccAccountLookup (&copied_item.leader_guid,
gnc_get_current_book ());
default_account = gnc_split_register_get_default_account (reg);
if (copied_leader && default_account)
Expand All @@ -1081,7 +1085,11 @@ gnc_split_register_paste_current (SplitRegister* reg)
if (trans == blank_trans)
{
/* In pasting, the blank split is deleted. Pick a new one. */
blank_split = xaccTransGetSplit (trans, 0);
gint anchor_split_index = copied_item.anchor_split_index;
if (anchor_split_index > num_splits)
anchor_split_index = 0;

blank_split = xaccTransGetSplit (trans, anchor_split_index);
info->blank_split_guid = *xaccSplitGetGUID (blank_split);
info->blank_split_edited = TRUE;
info->auto_complete = FALSE;
Expand Down

0 comments on commit e4d2443

Please sign in to comment.