Realign source file split-register-control.cpp for spaces

This commit is contained in:
Robert Fewell 2024-10-11 11:21:56 +01:00
parent ae8bb62dc5
commit e63210f1b4

View File

@ -1,5 +1,5 @@
/********************************************************************\
* split-register-control.c -- split register control object *
* split-register-control.cpp -- split register control object *
* Copyright (C) 2017 Aaron Laws *
* *
* This program is free software; you can redistribute it and/or *
@ -50,20 +50,20 @@
static QofLogModule log_module = GNC_MOD_LEDGER;
static inline bool
check_imbalance_fraction (const SplitRegister* reg,
const gnc_monetary* imbal_mon,
const Transaction* trans)
check_imbalance_fraction (const SplitRegister *reg,
const gnc_monetary *imbal_mon,
const Transaction *trans)
{
auto commodity_fraction{gnc_commodity_get_fraction (imbal_mon->commodity)};
auto commodity_fraction {gnc_commodity_get_fraction (imbal_mon->commodity)};
auto denom_diff = imbal_mon->value.denom > commodity_fraction;
if (!denom_diff)
{
const auto imbal_comm = imbal_mon->commodity;
for (auto node = xaccTransGetSplitList(trans); node;
node = g_list_next(node))
for (auto node = xaccTransGetSplitList (trans); node;
node = g_list_next (node))
{
auto acc = xaccSplitGetAccount(GNC_SPLIT (node->data));
if (xaccAccountGetCommodity(acc) == imbal_comm &&
auto acc = xaccSplitGetAccount (GNC_SPLIT(node->data));
if (xaccAccountGetCommodity (acc) == imbal_comm &&
imbal_mon->value.denom > xaccAccountGetCommoditySCU (acc))
{
denom_diff = true;
@ -73,8 +73,11 @@ check_imbalance_fraction (const SplitRegister* reg,
}
if (denom_diff)
gnc_error_dialog(gnc_ui_get_main_window(GTK_WIDGET(reg)), "%s", _("This transaction cannot be balanced: The imbalance is a fraction smaller than the commodity allows."));
{
gnc_error_dialog (gnc_ui_get_main_window (GTK_WIDGET(reg)),
"%s",
_("This transaction cannot be balanced: The imbalance is a fraction smaller than the commodity allows."));
}
return denom_diff;
}
@ -94,7 +97,6 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
gboolean two_accounts;
gboolean multi_currency;
if (xaccTransIsBalanced (trans))
return FALSE;
@ -114,8 +116,8 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
{
imbal_mon = static_cast<gnc_monetary*>(imbal_list->data);
if (!imbal_list->next &&
gnc_commodity_equiv(gnc_monetary_commodity(*imbal_mon),
xaccTransGetCurrency(trans)))
gnc_commodity_equiv (gnc_monetary_commodity (*imbal_mon),
xaccTransGetCurrency (trans)))
multi_currency = FALSE;
else
multi_currency = TRUE;
@ -126,7 +128,7 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
/* We're done with the imbalance list, the real work will be done
by xaccTransScrubImbalance which will get it again. */
gnc_monetary_list_free(imbal_list);
gnc_monetary_list_free (imbal_list);
}
else
multi_currency = FALSE;
@ -138,8 +140,10 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
{
/* Attempt to handle the inverted many-to-one mapping */
split = xaccTransGetSplit (trans, 1);
if (split) other_split = xaccSplitGetOtherSplit (split);
else split = xaccTransGetSplit (trans, 0);
if (split)
other_split = xaccSplitGetOtherSplit (split);
else
split = xaccTransGetSplit (trans, 0);
}
if (other_split == NULL || multi_currency)
{
@ -189,8 +193,7 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
else
default_value = 0;
choice = gnc_choose_radio_option_dialog
(gnc_split_register_get_parent (reg),
choice = gnc_choose_radio_option_dialog (gnc_split_register_get_parent (reg),
title,
message,
_("_Rebalance"),
@ -199,7 +202,7 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
g_list_free (radio_list);
root = default_account ? gnc_account_get_root(default_account) : NULL;
root = default_account ? gnc_account_get_root (default_account) : NULL;
switch (choice)
{
default:
@ -264,16 +267,14 @@ gnc_split_register_check_debcred (SplitRegister *reg,
const char *cell_name)
{
if ((gnc_cell_name_equal (cell_name, DEBT_CELL) &&
gnc_table_layout_get_cell_changed (reg->table->layout,
DEBT_CELL, FALSE)) ||
gnc_table_layout_get_cell_changed (reg->table->layout, DEBT_CELL, FALSE)) ||
(gnc_cell_name_equal (cell_name, CRED_CELL) &&
gnc_table_layout_get_cell_changed (reg->table->layout,
CRED_CELL, FALSE)))
gnc_table_layout_get_cell_changed (reg->table->layout, CRED_CELL, FALSE)))
{
SRInfo *info = gnc_split_register_get_info (reg);
PriceCell *rate_cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
RATE_CELL);
if (gnc_split_reg_has_rate_cell(reg->type) && info->rate_reset != RATE_RESET_DONE)
if (gnc_split_reg_has_rate_cell (reg->type) && info->rate_reset != RATE_RESET_DONE)
{
/* Debit or credit amount changed, get a new exchange rate */
info->rate_reset = RATE_RESET_REQD;
@ -301,7 +302,7 @@ gnc_split_register_check_account (SplitRegister *reg,
Split *split;
char *name;
g_return_val_if_fail(reg, TRUE);
g_return_val_if_fail (reg, TRUE);
/* See if we are leaving an account field */
if (gnc_cell_name_equal (cell_name, XFRM_CELL))
@ -338,30 +339,30 @@ gnc_split_register_check_account (SplitRegister *reg,
if (!new_acct)
return FALSE;
split = gnc_split_register_get_current_split(reg);
split = gnc_split_register_get_current_split (reg);
gnc_split_register_set_cell_fractions (reg, split);
/* See if we need to reset the exchange rate. */
if (gnc_split_reg_has_rate_cell(reg->type))
if (gnc_split_reg_has_rate_cell (reg->type))
{
PriceCell *rate_cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
RATE_CELL);
Account *orig_acct = xaccSplitGetAccount(split);
gnc_commodity *orig_com = xaccAccountGetCommodity(orig_acct);
gnc_commodity *last_com = xaccAccountGetCommodity(info->rate_account);
gnc_commodity *new_com = xaccAccountGetCommodity(new_acct);
Account *orig_acct = xaccSplitGetAccount (split);
gnc_commodity *orig_com = xaccAccountGetCommodity (orig_acct);
gnc_commodity *last_com = xaccAccountGetCommodity (info->rate_account);
gnc_commodity *new_com = xaccAccountGetCommodity (new_acct);
if (gnc_commodity_equal(last_com ? last_com : orig_com, new_com))
if (gnc_commodity_equal (last_com ? last_com : orig_com, new_com))
{
DEBUG("Commodity is still %s. Leaving rate unchanged.",
new_com ? gnc_commodity_get_mnemonic(new_com) : "NULL");
new_com ? gnc_commodity_get_mnemonic (new_com) : "NULL");
}
else if (!gnc_commodity_equal(orig_com, new_com))
else if (!gnc_commodity_equal (orig_com, new_com))
{
/* The commodity has changed but is not the original. Reset the rate. */
DEBUG("Commodity now %s (originally %s). Clearing rate.",
new_com ? gnc_commodity_get_mnemonic(new_com) : "NULL",
orig_com ? gnc_commodity_get_mnemonic(orig_com) : "NULL");
new_com ? gnc_commodity_get_mnemonic (new_com) : "NULL",
orig_com ? gnc_commodity_get_mnemonic (orig_com) : "NULL");
gnc_price_cell_set_value (rate_cell, gnc_numeric_zero());
info->rate_account = new_acct;
@ -370,15 +371,14 @@ gnc_split_register_check_account (SplitRegister *reg,
else
{
/* Get the original rate from the split. */
gnc_numeric amt = xaccSplitGetAmount(split);
gnc_numeric val = xaccSplitGetValue(split);
gnc_numeric orig_rate = gnc_numeric_div(amt, val, GNC_DENOM_AUTO,
gnc_numeric amt = xaccSplitGetAmount (split);
gnc_numeric val = xaccSplitGetValue (split);
gnc_numeric orig_rate = gnc_numeric_div (amt, val, GNC_DENOM_AUTO,
GNC_HOW_DENOM_REDUCE);
if (!gnc_numeric_check(orig_rate))
if (!gnc_numeric_check (orig_rate))
{
DEBUG("Using original rate of %s.",
gnc_num_dbg_to_string(orig_rate));
DEBUG("Using original rate of %s.", gnc_num_dbg_to_string (orig_rate));
gnc_price_cell_set_value (rate_cell, orig_rate);
info->rate_account = new_acct;
info->rate_reset = RATE_RESET_NOT_REQD;
@ -397,10 +397,10 @@ gnc_split_register_check_account (SplitRegister *reg,
}
static inline bool
is_trading_split (Split* split)
is_trading_split (Split *split)
{
auto acct{xaccSplitGetAccount (split)};
return GNC_IS_ACCOUNT (acct) && xaccAccountGetType (acct) == ACCT_TYPE_TRADING;
return GNC_IS_ACCOUNT(acct) && xaccAccountGetType (acct) == ACCT_TYPE_TRADING;
}
static void
@ -442,7 +442,7 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
old_split = s;
old_trans = gnc_split_register_get_current_trans (reg);
if (auto s{gnc_split_register_get_current_trans_split (reg, &old_trans_split_loc)};
!is_trading_split(s))
!is_trading_split (s))
old_trans_split = s;
old_class = gnc_split_register_get_current_cursor_class (reg);
@ -469,8 +469,9 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
/* The split at the transaction line we are moving to */
new_trans_split = gnc_split_register_get_trans_split
(reg, new_virt_loc.vcell_loc, NULL);
new_trans_split = gnc_split_register_get_trans_split (reg,
new_virt_loc.vcell_loc,
NULL);
new_class = gnc_split_register_get_cursor_class (reg,
new_virt_loc.vcell_loc);
@ -499,13 +500,13 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
if ((old_class == CURSOR_CLASS_SPLIT) &&
old_split &&
(old_split != new_split) &&
gnc_split_register_old_split_empty_p(reg, old_split))
gnc_split_register_old_split_empty_p (reg, old_split))
{
if (old_split != gnc_split_register_get_blank_split (reg))
{
int current_row;
xaccSplitDestroy(old_split);
xaccSplitDestroy (old_split);
old_split = NULL;
/*
@ -537,7 +538,7 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
info->pending_trans_guid = *guid_null ();
if (xaccTransIsOpen (pending_trans))
xaccTransCommitEdit (pending_trans);
else g_assert_not_reached();
else g_assert_not_reached ();
pending_trans = NULL;
saved = TRUE;
@ -545,7 +546,7 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
}
else if (old_trans &&
(old_trans != new_trans) &&
!xaccTransHasReconciledSplits(old_trans) &&
!xaccTransHasReconciledSplits (old_trans) &&
!info->first_pass &&
gnc_split_register_balance_trans (reg, old_trans))
{
@ -591,7 +592,6 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
if (gnc_split_register_find_split (reg, new_trans, new_trans_split,
new_split, new_class, &vcell_loc))
{
new_virt_loc.vcell_loc = vcell_loc;
}
else
@ -599,8 +599,9 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
new_trans_split = gnc_split_register_get_trans_split(
reg, new_virt_loc.vcell_loc, NULL);
new_trans_split = gnc_split_register_get_trans_split (reg,
new_virt_loc.vcell_loc,
NULL);
new_class = gnc_split_register_get_cursor_class (reg,
new_virt_loc.vcell_loc);
}
@ -616,7 +617,7 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
*p_new_virt_loc = new_virt_loc;
PINFO ("after move %d %d\n",
PINFO("after move %d %d",
new_virt_loc.vcell_loc.virt_row,
new_virt_loc.vcell_loc.virt_col);
@ -638,8 +639,8 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
VirtualCellLocation vc_loc;
vc_loc = old_trans_split_loc;
gnc_table_set_virt_cell_cursor(
reg->table, vc_loc, gnc_split_register_get_passive_cursor (reg));
gnc_table_set_virt_cell_cursor (reg->table, vc_loc,
gnc_split_register_get_passive_cursor (reg));
gnc_split_register_set_trans_visible (reg, vc_loc, FALSE,
reg->style == REG_STYLE_JOURNAL);
@ -648,8 +649,8 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
{
gnc_split_register_get_trans_split (reg, new_virt_loc.vcell_loc,
&vc_loc);
gnc_table_set_virt_cell_cursor
(reg->table, vc_loc, gnc_split_register_get_active_cursor (reg));
gnc_table_set_virt_cell_cursor (reg->table, vc_loc,
gnc_split_register_get_active_cursor (reg));
gnc_split_register_set_trans_visible (reg, vc_loc, TRUE,
reg->style == REG_STYLE_JOURNAL);
}
@ -715,7 +716,8 @@ gnc_find_split_in_account_by_memo (Account *account, const char *memo,
const auto& splits = xaccAccountGetSplits (account);
for (auto it = splits.rbegin(); it != splits.rend(); it++)
if (auto split = gnc_find_split_in_trans_by_memo (xaccSplitGetParent (*it), memo, unit_price))
if (auto split = gnc_find_split_in_trans_by_memo (xaccSplitGetParent (*it),
memo, unit_price))
return split;
return nullptr;
@ -783,7 +785,7 @@ gnc_find_trans_in_reg_by_desc (SplitRegister *reg, const char *description)
VirtualCellLocation vcell_loc = { virt_row, virt_col };
split = gnc_split_register_get_split (reg, vcell_loc);
trans = xaccSplitGetParent(split);
trans = xaccSplitGetParent (split);
if (trans == last_trans)
continue;
@ -892,10 +894,10 @@ gnc_split_register_auto_completion (SplitRegister *reg,
{
Account *account = gnc_split_register_get_default_account (reg);
auto_trans = xaccAccountFindTransByDesc(account, desc);
auto_trans = xaccAccountFindTransByDesc (account, desc);
}
else
auto_trans = gnc_find_trans_in_reg_by_desc(reg, desc);
auto_trans = gnc_find_trans_in_reg_by_desc (reg, desc);
if (auto_trans == NULL)
return FALSE;
@ -908,45 +910,44 @@ gnc_split_register_auto_completion (SplitRegister *reg,
/* now perform the completion */
if (pending_trans != trans)
{
if (!xaccTransIsOpen(trans))
xaccTransBeginEdit(trans);
if (!xaccTransIsOpen (trans))
xaccTransBeginEdit (trans);
/* This is now the pending transaction */
info->pending_trans_guid = *xaccTransGetGUID(trans);
info->pending_trans_guid = *xaccTransGetGUID (trans);
if (pending_trans != NULL)
{
if (xaccTransIsOpen (pending_trans))
xaccTransCommitEdit (pending_trans);
else g_assert_not_reached();
else g_assert_not_reached ();
}
}
g_assert(xaccTransIsOpen(trans));
pending_trans = xaccTransLookup(&info->pending_trans_guid,
g_assert(xaccTransIsOpen (trans));
pending_trans = xaccTransLookup (&info->pending_trans_guid,
gnc_get_current_book ());
g_assert(pending_trans == trans);
g_assert (pending_trans == trans);
gnc_copy_trans_onto_trans (auto_trans, trans, FALSE, FALSE);
/* if there is an doclink, let's clear it */
/* if there is a doclink, let's clear it */
if (xaccTransGetDocLink (auto_trans) != NULL)
xaccTransSetDocLink (trans, "");
blank_split = NULL;
if (gnc_split_register_get_default_account (reg) != NULL)
{
Account *default_account =
gnc_split_register_get_default_account (reg);
gnc_commodity *trans_cmdty = xaccTransGetCurrency(trans);
gnc_commodity *acct_cmdty = xaccAccountGetCommodity(default_account);
if (gnc_commodity_is_currency(acct_cmdty) &&
!gnc_commodity_equal(trans_cmdty, acct_cmdty))
xaccTransSetCurrency(trans, acct_cmdty);
Account *default_account = gnc_split_register_get_default_account (reg);
gnc_commodity *trans_cmdty = xaccTransGetCurrency (trans);
gnc_commodity *acct_cmdty = xaccAccountGetCommodity (default_account);
if (gnc_commodity_is_currency (acct_cmdty) &&
!gnc_commodity_equal (trans_cmdty, acct_cmdty))
xaccTransSetCurrency (trans, acct_cmdty);
for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
{
auto s = GNC_SPLIT(n->data);
if (default_account == xaccSplitGetAccount(s))
if (default_account == xaccSplitGetAccount (s))
{
blank_split = s;
info->blank_split_guid = *xaccSplitGetGUID(blank_split);
info->blank_split_guid = *xaccSplitGetGUID (blank_split);
break;
}
}
@ -954,8 +955,8 @@ gnc_split_register_auto_completion (SplitRegister *reg,
if (blank_split == NULL)
{
blank_split = xaccTransGetSplit(trans, 0);
info->blank_split_guid = *xaccSplitGetGUID(blank_split);
blank_split = xaccTransGetSplit (trans, 0);
info->blank_split_guid = *xaccSplitGetGUID (blank_split);
}
DEBUG("blank_split=%p", blank_split);
@ -964,8 +965,8 @@ gnc_split_register_auto_completion (SplitRegister *reg,
{
SRSaveData *sd;
sd = gnc_split_register_save_data_new(
trans, blank_split, gnc_split_register_current_trans_expanded (reg));
sd = gnc_split_register_save_data_new (trans, blank_split,
gnc_split_register_current_trans_expanded (reg));
gnc_table_save_cells (reg->table, sd);
gnc_split_register_save_data_destroy (sd);
}
@ -973,14 +974,13 @@ gnc_split_register_auto_completion (SplitRegister *reg,
gnc_resume_gui_refresh ();
/* now move to the non-empty amount column unless config setting says not */
if ( !gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
GNC_PREF_TAB_TRANS_MEMORISED) )
if (!gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER,
GNC_PREF_TAB_TRANS_MEMORISED))
{
amount = xaccSplitGetAmount (blank_split);
cell_name = (gnc_numeric_negative_p (amount)) ? CRED_CELL : DEBT_CELL;
if (gnc_table_get_current_cell_location (reg->table, cell_name,
&new_virt_loc))
if (gnc_table_get_current_cell_location (reg->table, cell_name, &new_virt_loc))
*p_new_virt_loc = new_virt_loc;
}
}
@ -1062,7 +1062,7 @@ gnc_split_register_auto_completion (SplitRegister *reg,
account_name = gnc_get_account_name_for_split_register (xaccSplitGetAccount (auto_split),
reg->show_leaf_accounts);
gnc_combo_cell_set_value ((ComboCell *) cell, account_name);
g_free(account_name);
g_free (account_name);
gnc_basic_cell_set_changed (cell, TRUE);
@ -1176,10 +1176,10 @@ gnc_split_register_check_stock_shares (SplitRegister *reg,
return;
name = ((ComboCell *)cell)->cell.value;
if (!g_strcmp0(name, "") ||
!g_strcmp0(name, buy ? ACTION_SELL_STR : ACTION_BUY_STR))
if (!g_strcmp0 (name, "") ||
!g_strcmp0 (name, buy ? ACTION_SELL_STR : ACTION_BUY_STR))
{
gnc_combo_cell_set_value((ComboCell *)cell,
gnc_combo_cell_set_value ((ComboCell *)cell,
buy ? ACTION_BUY_STR : ACTION_SELL_STR);
gnc_basic_cell_set_changed (cell, TRUE);
}
@ -1224,7 +1224,7 @@ gnc_split_register_check_cell (SplitRegister *reg, const char *cell_name)
static Account *
gnc_split_register_get_account_always (SplitRegister *reg,
const char * cell_name)
const char *cell_name)
{
BasicCell *cell;
const char *name;
@ -1237,9 +1237,7 @@ gnc_split_register_get_account_always (SplitRegister *reg,
/* If 'name' is "-- Split Transaction --" then return NULL or the
register acct */
if (!g_strcmp0 (name, SPLIT_TRANS_STR))
{
return NULL;
}
return gnc_split_register_get_account_by_name (reg, cell, name);
}
@ -1248,61 +1246,62 @@ gnc_split_register_get_account_always (SplitRegister *reg,
* available) or from the provided transaction and split.
*/
static XferDialog *
gnc_split_register_xfer_dialog(SplitRegister *reg, Transaction *txn,
gnc_split_register_xfer_dialog (SplitRegister *reg, Transaction *txn,
Split *split)
{
XferDialog *xfer;
CellBlock *cur;
BasicCell *cell;
g_return_val_if_fail(reg, NULL);
g_return_val_if_fail(reg->table, NULL);
g_return_val_if_fail (reg, NULL);
g_return_val_if_fail (reg->table, NULL);
cur = reg->table->current_cursor;
/* Create the exchange rate dialog. */
xfer = gnc_xfer_dialog(gnc_split_register_get_parent (reg), NULL);
g_return_val_if_fail(xfer, NULL);
xfer = gnc_xfer_dialog (gnc_split_register_get_parent (reg), NULL);
g_return_val_if_fail (xfer, NULL);
/* Set the description. */
cell = gnc_cellblock_get_cell_by_name(cur, DESC_CELL, NULL, NULL);
cell = gnc_cellblock_get_cell_by_name (cur, DESC_CELL, NULL, NULL);
if (cell)
gnc_xfer_dialog_set_description(xfer, gnc_basic_cell_get_value(cell));
gnc_xfer_dialog_set_description (xfer, gnc_basic_cell_get_value (cell));
else
{
const char *str = xaccTransGetDescription(txn);
gnc_xfer_dialog_set_description(xfer, str ? str : "");
const char *str = xaccTransGetDescription (txn);
gnc_xfer_dialog_set_description (xfer, str ? str : "");
}
/* Set the memo. */
cell = gnc_cellblock_get_cell_by_name(cur, MEMO_CELL, NULL, NULL);
cell = gnc_cellblock_get_cell_by_name (cur, MEMO_CELL, NULL, NULL);
if (cell)
gnc_xfer_dialog_set_memo(xfer, gnc_basic_cell_get_value(cell));
gnc_xfer_dialog_set_memo (xfer, gnc_basic_cell_get_value (cell));
else
{
const char *str = xaccSplitGetMemo(split);
gnc_xfer_dialog_set_memo(xfer, str ? str : "");
const char *str = xaccSplitGetMemo (split);
gnc_xfer_dialog_set_memo (xfer, str ? str : "");
}
/* Set the num. */
cell = gnc_cellblock_get_cell_by_name(cur, NUM_CELL, NULL, NULL);
cell = gnc_cellblock_get_cell_by_name (cur, NUM_CELL, NULL, NULL);
if (cell)
gnc_xfer_dialog_set_num(xfer, gnc_basic_cell_get_value(cell));
gnc_xfer_dialog_set_num (xfer, gnc_basic_cell_get_value (cell));
else
{
const char *str = gnc_get_num_action (txn, split);
gnc_xfer_dialog_set_num(xfer, str ? str : "");
gnc_xfer_dialog_set_num (xfer, str ? str : "");
}
/* Set the date. */
cell = gnc_cellblock_get_cell_by_name(cur, DATE_CELL, NULL, NULL);
cell = gnc_cellblock_get_cell_by_name (cur, DATE_CELL, NULL, NULL);
if (cell)
{
time64 time;
gnc_date_cell_get_date((DateCell*) cell, &time, TRUE);
gnc_xfer_dialog_set_date(xfer, time);
gnc_date_cell_get_date ((DateCell*) cell, &time, TRUE);
gnc_xfer_dialog_set_date (xfer, time);
}
else
gnc_xfer_dialog_set_date(xfer, xaccTransGetDate(txn));
gnc_xfer_dialog_set_date (xfer, xaccTransGetDate (txn));
return xfer;
}
@ -1345,20 +1344,20 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
if (force_dialog)
{
message = _("This register does not support editing exchange rates.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
}
LEAVE("no rate cell");
return FALSE;
}
rate_cell = (PriceCell*) gnc_table_layout_get_cell(
reg->table->layout, RATE_CELL);
rate_cell = (PriceCell*) gnc_table_layout_get_cell (reg->table->layout, RATE_CELL);
if (!rate_cell)
{
if (force_dialog)
{
message = _("This register does not support editing exchange rates.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
}
LEAVE("null rate cell");
return FALSE;
@ -1367,7 +1366,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
/* See if we already have an exchange rate... */
info = gnc_split_register_get_info (reg);
exch_rate = gnc_price_cell_get_value (rate_cell);
if (!gnc_numeric_zero_p(exch_rate) && !force_dialog &&
if (!gnc_numeric_zero_p (exch_rate) && !force_dialog &&
info->rate_reset != RATE_RESET_REQD)
{
LEAVE("rate already non-zero");
@ -1385,22 +1384,22 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
{
message = _("You need to select a split in order to modify its exchange "
"rate.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
}
LEAVE("expanded with transaction cursor; nothing to do");
return FALSE;
}
/* Grab the xfer account */
xfer_acc = gnc_split_register_get_account_always(
reg, expanded ? XFRM_CELL : MXFRM_CELL);
xfer_acc = gnc_split_register_get_account_always (reg,
expanded ? XFRM_CELL : MXFRM_CELL);
/* If this is an un-expanded, multi-split transaction, then warn the user */
if (force_dialog && !expanded && !xfer_acc)
{
message = _("You need to expand the transaction in order to modify its "
"exchange rates.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
LEAVE("%s", message);
return TRUE;
}
@ -1411,7 +1410,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
if (force_dialog)
{
message = _("The entered account could not be found.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
}
LEAVE("no xfer account");
return FALSE;
@ -1446,7 +1445,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
if (expanded || osplit == NULL)
{
message = _("The two currencies involved equal each other.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
LEAVE("register is expanded or osplit == NULL; not forcing dialog");
return FALSE;
}
@ -1459,7 +1458,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
if (gnc_commodity_equal (txn_cur, xfer_com))
{
message = _("The two currencies involved equal each other.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
LEAVE("reg commodity == txn commodity; not forcing");
return FALSE;
}
@ -1477,7 +1476,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
"exchange rates.");
if (force_dialog)
{
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
}
LEAVE("%s", message);
return TRUE;
@ -1490,8 +1489,9 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
* XXX: perhaps I should pop up an error here? Or maybe require the
* user to go into expanded-mode?
*/
if (!expanded && osplit && !gnc_commodity_equal(reg_com, txn_cur) &&
!gnc_commodity_equal(reg_com, xfer_com))
if (!expanded && osplit &&
!gnc_commodity_equal (reg_com, txn_cur) &&
!gnc_commodity_equal (reg_com, xfer_com))
{
gnc_numeric amt = xaccSplitGetAmount (osplit);
gnc_numeric val = xaccSplitGetValue (osplit);
@ -1510,7 +1510,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
if (force_dialog)
{
message = _("The split's amount is zero, so no exchange rate is needed.");
gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), "%s", message);
gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)), "%s", message);
}
LEAVE("amount is zero; no exchange rate needed");
return FALSE;
@ -1520,7 +1520,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
* _not_ the blank split, then return FALSE -- this is a "special"
* gain/loss stock transaction.
*/
if (gnc_numeric_zero_p(exch_rate) && !force_dialog && split &&
if (gnc_numeric_zero_p (exch_rate) && !force_dialog && split &&
info->rate_reset != RATE_RESET_REQD &&
split != gnc_split_register_get_blank_split (reg))
{
@ -1529,10 +1529,10 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
}
/* Show the exchange-rate dialog */
xfer = gnc_split_register_xfer_dialog(reg, txn, split);
gnc_xfer_dialog_is_exchange_dialog(xfer, &exch_rate);
if (gnc_xfer_dialog_run_exchange_dialog(
xfer, &exch_rate, amount, reg_acc, txn, xfer_com, expanded))
xfer = gnc_split_register_xfer_dialog (reg, txn, split);
gnc_xfer_dialog_is_exchange_dialog (xfer, &exch_rate);
if (gnc_xfer_dialog_run_exchange_dialog (xfer, &exch_rate, amount,
reg_acc, txn, xfer_com, expanded))
{
/* FIXME: How should the dialog be destroyed? */
LEAVE("leaving rate unchanged");
@ -1545,13 +1545,13 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
gnc_basic_cell_set_changed (&rate_cell->cell, TRUE);
info->rate_account = xfer_acc;
info->rate_reset = RATE_RESET_DONE;
LEAVE("set rate=%s", gnc_num_dbg_to_string(exch_rate));
LEAVE("set rate=%s", gnc_num_dbg_to_string (exch_rate));
return FALSE;
}
/* Returns FALSE if dialog was canceled. */
static gboolean
transaction_changed_confirm(VirtualLocation *p_new_virt_loc,
transaction_changed_confirm (VirtualLocation *p_new_virt_loc,
VirtualLocation *virt_loc,
SplitRegister *reg, Transaction *new_trans,
gboolean exact_traversal)
@ -1564,21 +1564,21 @@ transaction_changed_confirm(VirtualLocation *p_new_virt_loc,
"record the changes before moving to a new transaction, discard the "
"changes, or return to the changed transaction?");
window = gnc_split_register_get_parent(reg);
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
window = gnc_split_register_get_parent (reg);
dialog = gtk_message_dialog_new (GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s", title);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
"%s", message);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
gtk_dialog_add_buttons (GTK_DIALOG(dialog),
_("_Discard Changes"), GTK_RESPONSE_REJECT,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Record Changes"), GTK_RESPONSE_ACCEPT,
NULL);
response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_REG_TRANS_MOD);
gtk_widget_destroy(dialog);
response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_REG_TRANS_MOD);
gtk_widget_destroy (dialog);
switch (response)
{
@ -1653,10 +1653,11 @@ gnc_split_register_traverse (VirtualLocation *p_new_virt_loc,
Split *split;
const char *cell_name;
g_return_val_if_fail(p_new_virt_loc, TRUE);
g_return_val_if_fail (p_new_virt_loc, TRUE);
ENTER("reg=%p, p_new_virt_loc=%p (%d,%d), dir=%d",
reg, p_new_virt_loc, (*p_new_virt_loc).vcell_loc.virt_row,
reg, p_new_virt_loc,
(*p_new_virt_loc).vcell_loc.virt_row,
(*p_new_virt_loc).vcell_loc.virt_col, dir);
if (!reg)
@ -1841,14 +1842,14 @@ gnc_split_register_traverse (VirtualLocation *p_new_virt_loc,
/* Ok, we are changing transactions and the current transaction has
* changed. See what the user wants to do. */
LEAVE("txn change");
return transaction_changed_confirm(p_new_virt_loc, &virt_loc, reg,
return transaction_changed_confirm (p_new_virt_loc, &virt_loc, reg,
new_trans, info->exact_traversal);
}
TableControl *
gnc_split_register_control_new (void)
{
TableControl *control = gnc_table_control_new();
TableControl *control = gnc_table_control_new ();
control->move_cursor = gnc_split_register_move_cursor;
control->traverse = gnc_split_register_traverse;
@ -1872,18 +1873,18 @@ gnc_split_register_recn_cell_confirm (char old_flag, gpointer data)
return TRUE;
/* Does the user want to be warned? */
window = gnc_split_register_get_parent(reg);
dialog =
gtk_message_dialog_new(GTK_WINDOW(window),
window = gnc_split_register_get_parent (reg);
dialog = gtk_message_dialog_new (GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CANCEL,
"%s", title);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
"%s", message);
gtk_dialog_add_button(GTK_DIALOG(dialog), _("_Unreconcile"),
gtk_dialog_add_button (GTK_DIALOG(dialog),
_("_Unreconcile"),
GTK_RESPONSE_YES);
response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_REG_RECD_SPLIT_UNREC);
gtk_widget_destroy(dialog);
response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_REG_RECD_SPLIT_UNREC);
gtk_widget_destroy (dialog);
return (response == GTK_RESPONSE_YES);
}