Fallback register "Jump" operation to the only other account

There may be multiple splits but only one other account. In this scenario
we can jump to the first split for that account.
This commit is contained in:
Simon Arlott 2023-06-05 12:41:20 +01:00
parent d924e3f624
commit ac2511bd5a
No known key found for this signature in database
GPG Key ID: DF001BFD83E75990

View File

@ -4862,6 +4862,44 @@ gnc_plugin_page_register_cmd_exchange_rate (GSimpleAction *simple,
LEAVE (" ");
}
static Split*
jump_multiple_splits_by_single_account (Account *account, Split *split)
{
Transaction *trans;
SplitList *splits;
Account *other_account = NULL;
Split *other_split = NULL;
trans = xaccSplitGetParent(split);
if (!trans)
return NULL;
for (splits = xaccTransGetSplitList(trans); splits; splits = splits->next)
{
Split *s = (Split*)splits->data;
Account *a = xaccSplitGetAccount(s);
if (!xaccTransStillHasSplit(trans, s))
continue;
if (a == account)
continue;
if (other_split)
{
if (other_account != a)
return NULL;
continue;
}
other_account = a;
other_split = s;
}
return other_split;
}
static Split*
jump_multiple_splits_by_value (Account *account, Split *split, gboolean largest)
{
@ -4921,7 +4959,8 @@ jump_multiple_splits (Account* account, Split *split)
break;
}
return NULL;
// If there's only one other account, use that one
return jump_multiple_splits_by_single_account (account, split);
}
static void