mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
2001-08-22 Dave Peticolas <dave@krondo.com>
* src/gnome/query-user.c (gnc_choose_radio_option_dialog_parented): add a cancel button * src/guile/gw-gnc-spec.scm: fix api naming * src/report/locale-specific/us/taxtxf.scm: fix api naming Also: Add table cell save handler. Move split register saving code to split-register-model-save.c git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5215 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
6f53d989e2
commit
ef951846dc
@ -1,3 +1,12 @@
|
||||
2001-08-22 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/gnome/query-user.c
|
||||
(gnc_choose_radio_option_dialog_parented): add a cancel button
|
||||
|
||||
* src/guile/gw-gnc-spec.scm: fix api naming
|
||||
|
||||
* src/report/locale-specific/us/taxtxf.scm: fix api naming
|
||||
|
||||
2001-08-20 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* others: xaccGetAccountRoot->xaccAccountGetRoot
|
||||
|
10
src/gnc-ui.h
10
src/gnc-ui.h
@ -78,11 +78,11 @@ void gnc_warning_dialog_parented(gncUIWidget parent, const char *message);
|
||||
gboolean gnc_verify_dialog(const char *message, gboolean yes_is_default);
|
||||
void gnc_error_dialog(const char *message);
|
||||
|
||||
int gnc_choose_radio_option_dialog_parented(gncUIWidget parent,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
int default_value,
|
||||
GList *radio_list);
|
||||
int gnc_choose_radio_option_dialog_parented (gncUIWidget parent,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
int default_value,
|
||||
GList *radio_list);
|
||||
|
||||
gboolean gnc_dup_trans_dialog (gncUIWidget parent, time_t *date_p,
|
||||
const char *num, char **out_num);
|
||||
|
@ -330,8 +330,8 @@ gnc_choose_radio_button_cb(GtkWidget *w, gpointer data)
|
||||
|
||||
display a group of radio_buttons and return the index of
|
||||
the selected one
|
||||
|
||||
*/
|
||||
|
||||
int
|
||||
gnc_choose_radio_option_dialog_parented(gncUIWidget parent,
|
||||
const char *title,
|
||||
@ -389,9 +389,10 @@ gnc_choose_radio_option_dialog_parented(gncUIWidget parent,
|
||||
&radio_result);
|
||||
}
|
||||
|
||||
dialog = gnome_dialog_new(title,
|
||||
GNOME_STOCK_BUTTON_OK,
|
||||
NULL);
|
||||
dialog = gnome_dialog_new (title,
|
||||
GNOME_STOCK_BUTTON_OK,
|
||||
GNOME_STOCK_BUTTON_CANCEL,
|
||||
NULL);
|
||||
|
||||
if (parent)
|
||||
gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (parent));
|
||||
|
@ -23,9 +23,6 @@
|
||||
#ifndef QUERY_USER_H
|
||||
#define QUERY_USER_H
|
||||
|
||||
// +jsled: for line below.
|
||||
#include "gnc-ui.h"
|
||||
|
||||
void gnc_info_dialog(const char *message);
|
||||
void gnc_info_dialog_parented(GtkWindow *parent, const char *message);
|
||||
|
||||
@ -33,7 +30,4 @@ void gnc_warning_dialog(const char *message);
|
||||
|
||||
void gnc_error_dialog_parented(GtkWindow *parent, const char *message);
|
||||
|
||||
// +jsled: export so dialog-scheduledxaction can see it...
|
||||
gboolean gnc_verify_dialog_parented(gncUIWidget parent, const char *message, gboolean yes_is_default);
|
||||
|
||||
#endif
|
||||
|
@ -1,11 +1,12 @@
|
||||
pkglib_LTLIBRARIES=libgncmod-ledger-core.la
|
||||
pkglib_LTLIBRARIES = libgncmod-ledger-core.la
|
||||
|
||||
libgncmod_ledger_core_la_SOURCES=\
|
||||
libgncmod_ledger_core_la_SOURCES = \
|
||||
gncmod-ledger-core.c \
|
||||
SplitLedger.c \
|
||||
MultiLedger.c \
|
||||
split-register-control.c \
|
||||
split-register-model.c \
|
||||
split-register-model-save.c \
|
||||
split-register-util.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
@ -14,18 +15,18 @@ noinst_HEADERS = \
|
||||
SplitLedger.h \
|
||||
split-register-control.h \
|
||||
split-register-model.h \
|
||||
split-register-model-save.h \
|
||||
split-register-p.h
|
||||
|
||||
libgncmod_ledger_core_la_LDFLAGS=-module
|
||||
libgncmod_ledger_core_la_LDFLAGS = -module
|
||||
|
||||
CFLAGS=@CFLAGS@
|
||||
CFLAGS = @CFLAGS@ ${GLIB_CFLAGS}
|
||||
|
||||
INCLUDES= \
|
||||
INCLUDES = \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/engine \
|
||||
-I${top_srcdir}/src/guile \
|
||||
-I${top_srcdir}/src/gnc-module \
|
||||
-I${top_srcdir}/src/app-utils \
|
||||
-I${top_srcdir}/src/register/register-core \
|
||||
${GNOME_INCLUDEDIR} \
|
||||
${GLIB_CFLAGS}
|
||||
${GNOME_INCLUDEDIR}
|
||||
|
@ -92,7 +92,7 @@
|
||||
*
|
||||
* HISTORY:
|
||||
* Copyright (c) 1998-2000 Linas Vepstas
|
||||
* Copyright (c) 2000 Dave Peticolas
|
||||
* Copyright (c) 2000-2001 Dave Peticolas <dave@krondo.com>
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
@ -126,6 +126,7 @@
|
||||
#include "quickfillcell.h"
|
||||
#include "recncell.h"
|
||||
#include "splitreg.h"
|
||||
#include "split-register-model-save.h"
|
||||
#include "table-allgui.h"
|
||||
|
||||
|
||||
@ -147,8 +148,7 @@ static gboolean xaccSRSaveRegEntryToSCM (SplitRegister *reg,
|
||||
gboolean use_cut_semantics);
|
||||
static void xaccSRActuallySaveChangedCells (SplitRegister *reg,
|
||||
Transaction *trans, Split *split);
|
||||
static void sr_set_last_num (SplitRegister *reg, const char *num);
|
||||
static void sr_split_auto_calc (SplitRegister *reg, Split *split);
|
||||
static gboolean sr_split_auto_calc (SplitRegister *reg, Split *split);
|
||||
|
||||
|
||||
/** implementations *******************************************************/
|
||||
@ -390,8 +390,6 @@ LedgerDestroy (SplitRegister *reg)
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
Transaction *
|
||||
xaccSRGetCurrentTrans (SplitRegister *reg)
|
||||
{
|
||||
@ -416,8 +414,6 @@ xaccSRGetCurrentTrans (SplitRegister *reg)
|
||||
return xaccSplitGetParent (split);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
Split *
|
||||
xaccSRGetCurrentSplit (SplitRegister *reg)
|
||||
{
|
||||
@ -427,8 +423,6 @@ xaccSRGetCurrentSplit (SplitRegister *reg)
|
||||
return sr_get_split (reg, reg->table->current_cursor_loc.vcell_loc);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
Split *
|
||||
xaccSRGetBlankSplit (SplitRegister *reg)
|
||||
{
|
||||
@ -438,8 +432,6 @@ xaccSRGetBlankSplit (SplitRegister *reg)
|
||||
return blank_split;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
gboolean
|
||||
xaccSRGetSplitVirtLoc (SplitRegister *reg, Split *split,
|
||||
VirtualCellLocation *vcell_loc)
|
||||
@ -484,8 +476,6 @@ xaccSRGetSplitVirtLoc (SplitRegister *reg, Split *split,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
gboolean
|
||||
xaccSRGetSplitAmountVirtLoc (SplitRegister *reg, Split *split,
|
||||
VirtualLocation *virt_loc)
|
||||
@ -524,8 +514,6 @@ xaccSRGetSplitAmountVirtLoc (SplitRegister *reg, Split *split,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
Split *
|
||||
xaccSRDuplicateCurrent (SplitRegister *reg)
|
||||
{
|
||||
@ -689,8 +677,6 @@ xaccSRDuplicateCurrent (SplitRegister *reg)
|
||||
return return_split;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static void
|
||||
xaccSRCopyCurrentInternal (SplitRegister *reg, gboolean use_cut_semantics)
|
||||
{
|
||||
@ -779,16 +765,12 @@ xaccSRCopyCurrentInternal (SplitRegister *reg, gboolean use_cut_semantics)
|
||||
copied_class = cursor_class;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRCopyCurrent (SplitRegister *reg)
|
||||
{
|
||||
xaccSRCopyCurrentInternal (reg, FALSE);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRCutCurrent (SplitRegister *reg)
|
||||
{
|
||||
@ -830,8 +812,6 @@ xaccSRCutCurrent (SplitRegister *reg)
|
||||
xaccSRDeleteCurrentTrans(reg);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRPasteCurrent (SplitRegister *reg)
|
||||
{
|
||||
@ -894,7 +874,8 @@ xaccSRPasteCurrent (SplitRegister *reg)
|
||||
gnc_copy_split_scm_onto_split(copied_item, split);
|
||||
xaccTransCommitEdit(trans);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
const char *message = _("You are about to overwrite an existing "
|
||||
"transaction.\n"
|
||||
"Are you sure you want to do that?");
|
||||
@ -955,8 +936,6 @@ xaccSRPasteCurrent (SplitRegister *reg)
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRDeleteCurrentSplit (SplitRegister *reg)
|
||||
{
|
||||
@ -1006,8 +985,6 @@ xaccSRDeleteCurrentSplit (SplitRegister *reg)
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRDeleteCurrentTrans (SplitRegister *reg)
|
||||
{
|
||||
@ -1075,8 +1052,6 @@ xaccSRDeleteCurrentTrans (SplitRegister *reg)
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSREmptyCurrentTrans (SplitRegister *reg)
|
||||
{
|
||||
@ -1146,8 +1121,6 @@ xaccSREmptyCurrentTrans (SplitRegister *reg)
|
||||
g_list_free (splits);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRCancelCursorSplitChanges (SplitRegister *reg)
|
||||
{
|
||||
@ -1171,8 +1144,6 @@ xaccSRCancelCursorSplitChanges (SplitRegister *reg)
|
||||
gnc_table_refresh_gui (reg->table, TRUE);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRCancelCursorTransChanges (SplitRegister *reg)
|
||||
{
|
||||
@ -1200,19 +1171,14 @@ xaccSRCancelCursorTransChanges (SplitRegister *reg)
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRRedrawReg (SplitRegister *reg)
|
||||
{
|
||||
xaccLedgerDisplayRefreshByReg (reg);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
/* Copy from the register object to scheme. This needs to be
|
||||
* in sync with xaccSRSaveRegEntry and xaccSRSaveChangedCells. */
|
||||
|
||||
|
||||
/* jsled: This will need to be modified, as well. */
|
||||
static gboolean
|
||||
xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
@ -1298,13 +1264,8 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, XFRM_CELL, TRUE))
|
||||
{
|
||||
Account *new_account;
|
||||
const char *new_name;
|
||||
|
||||
new_name = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
|
||||
|
||||
new_account = xaccGetAccountFromFullName (gncGetCurrentGroup (),
|
||||
new_name,
|
||||
gnc_get_account_separator ());
|
||||
new_account = gnc_split_register_get_account (reg, XFRM_CELL);
|
||||
|
||||
if (new_account != NULL)
|
||||
gnc_split_scm_set_account (split_scm, new_account);
|
||||
@ -1334,13 +1295,8 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
if (other_split_scm != SCM_UNDEFINED)
|
||||
{
|
||||
Account *new_account;
|
||||
const char *name;
|
||||
|
||||
name = gnc_table_layout_get_cell_value (reg->table->layout, MXFRM_CELL);
|
||||
|
||||
new_account = xaccGetAccountFromFullName (gncGetCurrentGroup (),
|
||||
name,
|
||||
gnc_get_account_separator ());
|
||||
new_account = gnc_split_register_get_account (reg, MXFRM_CELL);
|
||||
|
||||
if (new_account != NULL)
|
||||
gnc_split_scm_set_account (other_split_scm, new_account);
|
||||
@ -1409,10 +1365,6 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
/* Copy from the register object to the engine */
|
||||
/* jsled: okay... the fun. actually, not really the fun, but scan
|
||||
this to see if anything jumps out */
|
||||
gboolean
|
||||
xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit)
|
||||
{
|
||||
@ -1468,6 +1420,9 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit)
|
||||
|
||||
ENTER ("xaccSRSaveRegEntry(): save split is %p \n", split);
|
||||
|
||||
if (!sr_split_auto_calc (reg, split))
|
||||
return FALSE;
|
||||
|
||||
gnc_suspend_gui_refresh ();
|
||||
|
||||
/* determine whether we should commit the pending transaction */
|
||||
@ -1517,10 +1472,12 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit)
|
||||
|
||||
DEBUG ("updating trans addr=%p\n", trans);
|
||||
|
||||
if ( reg->template ) {
|
||||
xaccSRSaveChangedTemplateCells( reg, trans, split );
|
||||
} else {
|
||||
xaccSRSaveChangedCells (reg, trans, split);
|
||||
{
|
||||
SRSaveData *sd;
|
||||
|
||||
sd = gnc_split_register_save_data_new (trans, split);
|
||||
gnc_table_save_cells (reg->table, sd);
|
||||
gnc_split_register_save_data_destroy (sd);
|
||||
}
|
||||
|
||||
memo = xaccSplitGetMemo (split);
|
||||
@ -1564,23 +1521,21 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static void
|
||||
sr_set_last_num (SplitRegister *reg, const char *num)
|
||||
Account *
|
||||
gnc_split_register_get_account (SplitRegister *reg, int cell_type)
|
||||
{
|
||||
Account *account;
|
||||
const char *name;
|
||||
|
||||
account = sr_get_default_account (reg);
|
||||
if (!account)
|
||||
return;
|
||||
if (!gnc_table_layout_get_cell_changed (reg->table->layout, cell_type, TRUE))
|
||||
return NULL;
|
||||
|
||||
xaccAccountSetLastNum (account, num);
|
||||
name = gnc_table_layout_get_cell_value (reg->table->layout, cell_type);
|
||||
|
||||
return xaccGetAccountFromFullName (gncGetCurrentGroup (),
|
||||
name, gnc_get_account_separator ());
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
sr_split_auto_calc (SplitRegister *reg, Split *split)
|
||||
{
|
||||
PriceCell *cell;
|
||||
@ -1598,17 +1553,25 @@ sr_split_auto_calc (SplitRegister *reg, Split *split)
|
||||
Account *account;
|
||||
int denom;
|
||||
|
||||
/* First, check if this is an account other than STOCK or
|
||||
* MUTUAL type. If it is, this is a bank balancing split, so
|
||||
* don't recalc anything.*/
|
||||
if (STOCK_REGISTER != reg->type &&
|
||||
CURRENCY_REGISTER != reg->type &&
|
||||
PORTFOLIO_LEDGER != reg->type)
|
||||
return TRUE;
|
||||
|
||||
account = gnc_split_register_get_account (reg, XFRM_CELL);
|
||||
|
||||
if (!account)
|
||||
account = xaccSplitGetAccount (split);
|
||||
|
||||
if (!account)
|
||||
account = sr_get_default_account (reg);
|
||||
|
||||
account = xaccSplitGetAccount (split);
|
||||
account_type = xaccAccountGetType (account);
|
||||
|
||||
if (account_type != STOCK &&
|
||||
account_type != MUTUAL &&
|
||||
account_type != CURRENCY)
|
||||
return;
|
||||
return TRUE;
|
||||
|
||||
price_changed = gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
PRIC_CELL, TRUE);
|
||||
@ -1619,6 +1582,9 @@ sr_split_auto_calc (SplitRegister *reg, Split *split)
|
||||
shares_changed = gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
SHRS_CELL, TRUE);
|
||||
|
||||
if (!price_changed && !amount_changed && !shares_changed)
|
||||
return TRUE;
|
||||
|
||||
if (shares_changed)
|
||||
{
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
@ -1752,7 +1718,7 @@ sr_split_auto_calc (SplitRegister *reg, Split *split)
|
||||
|
||||
g_list_free (radio_list);
|
||||
|
||||
switch(choice)
|
||||
switch (choice)
|
||||
{
|
||||
case 0: /* Modify number of shares */
|
||||
recalc_shares = TRUE;
|
||||
@ -1763,8 +1729,8 @@ sr_split_auto_calc (SplitRegister *reg, Split *split)
|
||||
case 2: /* Modify total value */
|
||||
recalc_value = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: /* Cancel */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1849,448 +1815,8 @@ sr_split_auto_calc (SplitRegister *reg, Split *split)
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRSaveChangedTemplateCells( SplitRegister *reg,
|
||||
Transaction *trans,
|
||||
Split *split )
|
||||
{
|
||||
SRInfo *info = xaccSRGetInfo( reg );
|
||||
Split *other_split = NULL;
|
||||
kvp_frame *kvpf;
|
||||
AccountGroup *template_ag;
|
||||
Account *template_acc;
|
||||
kvp_value *tag_val;
|
||||
BasicCell *cell;
|
||||
|
||||
DEBUG (" ");
|
||||
|
||||
template_acc = reg->templateAcct;
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DATE_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
NUM_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
RECN_CELL, TRUE) )
|
||||
{
|
||||
PERR( "unexpected changed fields in a template register\n" );
|
||||
}
|
||||
|
||||
/* We'll be using the Split's KVP frame a lot */
|
||||
kvpf = xaccSplitGetSlots( split );
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
XFRM_CELL, TRUE) )
|
||||
{
|
||||
/* FIXME: This should probably do the same checks as
|
||||
xaccSRSaveChangedCells regarding account types
|
||||
[between different currency accounts, mainly] */
|
||||
const char *new_name;
|
||||
Account *acct;
|
||||
AccountGroup *acctGrp;
|
||||
const GUID *acctGUID;
|
||||
|
||||
/* save the account GUID into the kvp_data. */
|
||||
new_name = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
|
||||
acctGrp = gnc_book_get_group (gncGetCurrentBook());
|
||||
acct = xaccGetAccountFromFullName (acctGrp, new_name,
|
||||
gnc_get_account_separator());
|
||||
if ( acct == NULL ) {
|
||||
PERR( "unknown group \"%s\"\n", new_name );
|
||||
return;
|
||||
}
|
||||
acctGUID = xaccAccountGetGUID( acct );
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/xfrm",
|
||||
kvp_value_new_guid( acctGUID ) );
|
||||
kvpf = xaccSplitGetSlots( split );
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
|
||||
/* DEBUG */
|
||||
if ( 0 ) {
|
||||
GList *foo = xaccAccountGetSplitList( template_acc );
|
||||
if ( foo ) {
|
||||
printf( "Splits:\n" );
|
||||
do {
|
||||
printf ("\tsplit: \"%s\"\n", xaccSplitGetMemo( (Split*)foo->data ) );
|
||||
} while ( (foo = foo->next) );
|
||||
} else {
|
||||
printf( "No Splits.\n" );
|
||||
}
|
||||
}
|
||||
|
||||
/* set the actual account to the fake account for these templates */
|
||||
xaccAccountInsertSplit (template_acc, split);
|
||||
|
||||
/* DEBUG */
|
||||
if ( 0 ) {
|
||||
GList *foo = xaccAccountGetSplitList( template_acc );
|
||||
if ( foo ) {
|
||||
printf( "Splits:\n" );
|
||||
do {
|
||||
printf ("\tsplit: \"%s\"\n", xaccSplitGetMemo( (Split*)foo->data ) );
|
||||
} while ( (foo = foo->next) );
|
||||
} else {
|
||||
printf( "No Splits.\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
MXFRM_CELL, TRUE) )
|
||||
{
|
||||
DEBUG( "Template: Got MXFRM changed\n" );
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, MXFRM_CELL);
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
}
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
FCRED_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
FDEBT_CELL, TRUE) )
|
||||
{
|
||||
const char *value;
|
||||
char *amountStr = "x + y/42";
|
||||
gnc_numeric new_amount;
|
||||
gnc_numeric credit;
|
||||
gnc_numeric debit;
|
||||
|
||||
DEBUG( "kvp_frame before: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
|
||||
/* amountStr = gnc_numeric_to_string( new_amount ); */
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, FCRED_CELL);
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/credit_formula",
|
||||
kvp_value_new_string( value ) );
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, FDEBT_CELL);
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/debit_formula",
|
||||
kvp_value_new_string( value ) );
|
||||
|
||||
DEBUG( "kvp_frame after: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
|
||||
/* set the amount to an innocuous value */
|
||||
xaccSplitSetValue (split, gnc_numeric_create(0, 1) );
|
||||
}
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
SHRS_CELL, TRUE) )
|
||||
{
|
||||
char *sharesStr = "(x + y)/42";
|
||||
|
||||
/* FIXME: shares cells are numeric by definition. */
|
||||
DEBUG( "kvp_frame before: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
|
||||
/* sharesStr = gnc_numeric_to_string( sharesStr ); */
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/shares",
|
||||
kvp_value_new_string( sharesStr ) );
|
||||
DEBUG( "kvp_frame after: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
/* set the shares to an innocuous value */
|
||||
xaccSplitSetSharePriceAndAmount (split,
|
||||
gnc_numeric_create(0, 1),
|
||||
gnc_numeric_create(0, 1) );
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
}
|
||||
|
||||
xaccSRActuallySaveChangedCells( reg, trans, split );
|
||||
}
|
||||
|
||||
static void
|
||||
xaccSRActuallySaveChangedCells (SplitRegister *reg,
|
||||
Transaction *trans, Split *split)
|
||||
{
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Split *other_split = NULL;
|
||||
|
||||
/* copy the contents from the cursor to the split */
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, DATE_CELL, TRUE))
|
||||
{
|
||||
BasicCell *cell;
|
||||
const char *value;
|
||||
Timespec ts;
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, DATE_CELL);
|
||||
value = gnc_basic_cell_get_value (cell);
|
||||
|
||||
/* commit any pending changes */
|
||||
gnc_date_cell_commit ((DateCell *) cell);
|
||||
|
||||
DEBUG ("DATE: %s", value ? value : "(null)");
|
||||
|
||||
gnc_date_cell_get_date ((DateCell *) cell, &ts);
|
||||
|
||||
xaccTransSetDatePostedTS (trans, &ts);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, NUM_CELL, TRUE))
|
||||
{
|
||||
BasicCell *cell;
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, NUM_CELL);
|
||||
|
||||
DEBUG ("NUM: %s\n", value ? value : "(null)");
|
||||
|
||||
xaccTransSetNum (trans, value);
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, NUM_CELL);
|
||||
|
||||
if (gnc_num_cell_set_last_num ((NumCell *) cell, value))
|
||||
{
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Split *blank_split = xaccSplitLookup(&info->blank_split_guid);
|
||||
Transaction *blank_trans = xaccSplitGetParent (blank_split);
|
||||
|
||||
if (trans != blank_trans)
|
||||
sr_set_last_num (reg, gnc_basic_cell_get_value (cell));
|
||||
}
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, DESC_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, DESC_CELL);
|
||||
|
||||
DEBUG ("DESC: %s", value ? value : "(null)");
|
||||
|
||||
xaccTransSetDescription (trans, value);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, NOTES_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, NOTES_CELL);
|
||||
|
||||
DEBUG ("NOTES: %s", value ? value : "(null)");
|
||||
|
||||
xaccTransSetNotes (trans, value);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, RECN_CELL, TRUE))
|
||||
{
|
||||
RecnCell *cell;
|
||||
|
||||
cell = (RecnCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
RECN_CELL);
|
||||
|
||||
DEBUG ("RECN: %c", gnc_recn_cell_get_flag (cell));
|
||||
|
||||
xaccSplitSetReconcile (split, gnc_recn_cell_get_flag (cell));
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, ACTN_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, ACTN_CELL);
|
||||
|
||||
DEBUG ("ACTN: %s", value ? value : "(null)");
|
||||
|
||||
xaccSplitSetAction (split, value);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, MEMO_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
|
||||
|
||||
DEBUG ("MEMO: %s", value ? value : "(null)");
|
||||
|
||||
xaccSplitSetMemo (split, value);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* OK, the handling of transfers gets complicated because it depends
|
||||
* on what was displayed to the user. For a multi-line display, we
|
||||
* just reparent the indicated split, its it, and that's that. For
|
||||
* a two-line display, we want to reparent the "other" split, but
|
||||
* only if there is one. XFRM is the straight split, MXFRM is the
|
||||
* mirrored split. */
|
||||
|
||||
/* jsled: this is where it starts to get fun. in the template
|
||||
* register, we save the XFRM account in the kvp frame.
|
||||
* also, when loading, we load from the kvp data. */
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, XFRM_CELL, TRUE))
|
||||
{
|
||||
Account *old_acc;
|
||||
Account *new_acc;
|
||||
const char *new_name;
|
||||
|
||||
new_name = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
|
||||
|
||||
DEBUG ("XFRM: %s", new_name ? new_name : "(null)");
|
||||
|
||||
/* do some reparenting. Insertion into new account will automatically
|
||||
* delete this split from the old account */
|
||||
old_acc = xaccSplitGetAccount (split);
|
||||
|
||||
new_acc = xaccGetAccountFromFullName (gncGetCurrentGroup (),
|
||||
new_name,
|
||||
gnc_get_account_separator ());
|
||||
|
||||
if ((new_acc != NULL) && (old_acc != new_acc))
|
||||
xaccAccountInsertSplit (new_acc, split);
|
||||
}
|
||||
|
||||
if (reg->style == REG_STYLE_LEDGER && !info->trans_expanded)
|
||||
other_split = xaccSplitGetOtherSplit (split);
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, MXFRM_CELL, TRUE))
|
||||
{
|
||||
const char *name;
|
||||
|
||||
name = gnc_table_layout_get_cell_value (reg->table->layout, MXFRM_CELL);
|
||||
|
||||
DEBUG ("MXFRM: %s", name ? name : "(null)");
|
||||
|
||||
other_split = xaccSplitGetOtherSplit (split);
|
||||
|
||||
/* other_split may be null for two very different reasons:
|
||||
* (1) the parent transaction has three or more splits in it,
|
||||
* and so the "other" split is ambiguous, and thus null.
|
||||
* (2) the parent transaction has only this one split as a child.
|
||||
* and "other" is null because there is no other.
|
||||
*
|
||||
* In the case (2), we want to create the other split, so that
|
||||
* the user's request to transfer actually works out.
|
||||
*/
|
||||
|
||||
if (!other_split)
|
||||
{
|
||||
other_split = xaccTransGetSplit (trans, 1);
|
||||
if (!other_split)
|
||||
{
|
||||
other_split = xaccMallocSplit ();
|
||||
xaccTransAppendSplit (trans, other_split);
|
||||
}
|
||||
}
|
||||
|
||||
if (other_split)
|
||||
{
|
||||
Account *old_acc, *new_acc;
|
||||
|
||||
/* do some reparenting. Insertion into new account will automatically
|
||||
* delete from the old account */
|
||||
old_acc = xaccSplitGetAccount (other_split);
|
||||
new_acc = xaccGetAccountFromFullName (gncGetCurrentGroup (),
|
||||
name,
|
||||
gnc_get_account_separator ());
|
||||
|
||||
if ((new_acc != NULL) && (old_acc != new_acc))
|
||||
xaccAccountInsertSplit (new_acc, other_split);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have a stock, currency or portfolio register type, and
|
||||
* changes have been made to the number of shares, the price, or the
|
||||
* value, then we need to do some calculations to make sure it all
|
||||
* balances properly.*/
|
||||
if ((gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DEBT_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
CRED_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
PRIC_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
SHRS_CELL, TRUE)) &&
|
||||
((STOCK_REGISTER == (reg->type)) ||
|
||||
(CURRENCY_REGISTER == (reg->type)) ||
|
||||
(PORTFOLIO_LEDGER == (reg->type))))
|
||||
sr_split_auto_calc (reg, split);
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, SHRS_CELL, TRUE))
|
||||
{
|
||||
PriceCell *cell;
|
||||
gnc_numeric amount;
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
SHRS_CELL);
|
||||
amount = gnc_price_cell_get_value (cell);
|
||||
|
||||
DEBUG ("SHRS");
|
||||
|
||||
xaccSplitSetAmount (split, amount);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, PRIC_CELL, TRUE))
|
||||
{
|
||||
PriceCell *cell;
|
||||
gnc_numeric price;
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
PRIC_CELL);
|
||||
price = gnc_price_cell_get_value (cell);
|
||||
|
||||
DEBUG ("PRIC");
|
||||
|
||||
xaccSplitSetSharePrice (split, price);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DEBT_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
CRED_CELL, TRUE))
|
||||
{
|
||||
PriceCell *cell;
|
||||
gnc_numeric new_amount;
|
||||
gnc_numeric credit;
|
||||
gnc_numeric debit;
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
CRED_CELL);
|
||||
credit = gnc_price_cell_get_value (cell);
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
DEBT_CELL);
|
||||
debit = gnc_price_cell_get_value (cell);
|
||||
|
||||
new_amount = gnc_numeric_sub_fixed (debit, credit);
|
||||
|
||||
xaccSplitSetValue (split, new_amount);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DEBT_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
CRED_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
PRIC_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
SHRS_CELL, TRUE))
|
||||
{
|
||||
xaccSplitScrub (split);
|
||||
|
||||
if (other_split)
|
||||
{
|
||||
gnc_numeric value = xaccSplitGetValue (split);
|
||||
|
||||
value = gnc_numeric_neg (value);
|
||||
|
||||
xaccSplitSetValue (other_split, value);
|
||||
|
||||
xaccSplitScrub (other_split);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split)
|
||||
{
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Split *other_split = NULL;
|
||||
|
||||
xaccSRActuallySaveChangedCells (reg, trans, split);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GNCAccountType
|
||||
@ -2392,8 +1918,6 @@ recn_cell_confirm (char old_flag, gpointer data)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
G_INLINE_FUNC void
|
||||
sr_add_transaction (SplitRegister *reg,
|
||||
Transaction *trans,
|
||||
@ -2501,8 +2025,6 @@ sr_add_transaction (SplitRegister *reg,
|
||||
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRLoadRegister (SplitRegister *reg, GList * slist,
|
||||
Account *default_account)
|
||||
@ -2880,8 +2402,6 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist,
|
||||
xaccSRLoadXferCells (reg, default_account);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static void
|
||||
LoadXferCell (ComboCell * cell, AccountGroup * grp)
|
||||
{
|
||||
@ -2914,8 +2434,6 @@ LoadXferCell (ComboCell * cell, AccountGroup * grp)
|
||||
LEAVE ("\n");
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRLoadXferCells (SplitRegister *reg, Account *base_account)
|
||||
{
|
||||
@ -2940,8 +2458,6 @@ xaccSRLoadXferCells (SplitRegister *reg, Account *base_account)
|
||||
LoadXferCell (cell, group);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
gboolean
|
||||
xaccSRHasPendingChanges (SplitRegister *reg)
|
||||
{
|
||||
@ -2957,8 +2473,6 @@ xaccSRHasPendingChanges (SplitRegister *reg)
|
||||
return xaccTransIsOpen (pending_trans);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
xaccSRShowPresentDivider (SplitRegister *reg, gboolean show_present)
|
||||
{
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "messages.h"
|
||||
#include "pricecell.h"
|
||||
#include "split-register-control.h"
|
||||
#include "split-register-model-save.h"
|
||||
#include "split-register-p.h"
|
||||
#include "splitreg.h"
|
||||
#include "table-allgui.h"
|
||||
@ -667,10 +668,13 @@ gnc_split_register_auto_completion (SplitRegister *reg,
|
||||
|
||||
info->blank_split_edited = TRUE;
|
||||
|
||||
if (reg->template)
|
||||
xaccSRSaveChangedTemplateCells (reg, trans, blank_split);
|
||||
else
|
||||
xaccSRSaveChangedCells (reg, trans, blank_split);
|
||||
{
|
||||
SRSaveData *sd;
|
||||
|
||||
sd = gnc_split_register_save_data_new (trans, blank_split);
|
||||
gnc_table_save_cells (reg->table, sd);
|
||||
gnc_split_register_save_data_destroy (sd);
|
||||
}
|
||||
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
|
460
src/register/ledger-core/split-register-model-save.c
Normal file
460
src/register/ledger-core/split-register-model-save.c
Normal file
@ -0,0 +1,460 @@
|
||||
/********************************************************************\
|
||||
* split-register-model.c -- split register model object *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "Scrub.h"
|
||||
#include "datecell.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "numcell.h"
|
||||
#include "pricecell.h"
|
||||
#include "recncell.h"
|
||||
#include "split-register-model-save.h"
|
||||
#include "split-register-p.h"
|
||||
|
||||
|
||||
struct sr_save_data
|
||||
{
|
||||
Transaction *trans;
|
||||
Split *split;
|
||||
};
|
||||
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
static short module = MOD_LEDGER;
|
||||
|
||||
|
||||
static void
|
||||
gnc_split_register_save_cells (gpointer save_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
SRSaveData *sd = save_data;
|
||||
SplitRegister *reg = user_data;
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Transaction *trans;
|
||||
Split *other_split = NULL;
|
||||
Split *split;
|
||||
|
||||
g_return_if_fail (sd != NULL);
|
||||
|
||||
trans = sd->trans;
|
||||
split = sd->split;
|
||||
|
||||
/* copy the contents from the cursor to the split */
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, DATE_CELL, TRUE))
|
||||
{
|
||||
BasicCell *cell;
|
||||
const char *value;
|
||||
Timespec ts;
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, DATE_CELL);
|
||||
value = gnc_basic_cell_get_value (cell);
|
||||
|
||||
/* commit any pending changes */
|
||||
gnc_date_cell_commit ((DateCell *) cell);
|
||||
|
||||
DEBUG ("DATE: %s", value ? value : "(null)");
|
||||
|
||||
gnc_date_cell_get_date ((DateCell *) cell, &ts);
|
||||
|
||||
xaccTransSetDatePostedTS (trans, &ts);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, NUM_CELL, TRUE))
|
||||
{
|
||||
BasicCell *cell;
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, NUM_CELL);
|
||||
|
||||
DEBUG ("NUM: %s\n", value ? value : "(null)");
|
||||
|
||||
xaccTransSetNum (trans, value);
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, NUM_CELL);
|
||||
|
||||
if (gnc_num_cell_set_last_num ((NumCell *) cell, value))
|
||||
{
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Split *blank_split = xaccSplitLookup(&info->blank_split_guid);
|
||||
Transaction *blank_trans = xaccSplitGetParent (blank_split);
|
||||
|
||||
if (trans != blank_trans)
|
||||
sr_set_last_num (reg, gnc_basic_cell_get_value (cell));
|
||||
}
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, DESC_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, DESC_CELL);
|
||||
|
||||
DEBUG ("DESC: %s", value ? value : "(null)");
|
||||
|
||||
xaccTransSetDescription (trans, value);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, NOTES_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, NOTES_CELL);
|
||||
|
||||
DEBUG ("NOTES: %s", value ? value : "(null)");
|
||||
|
||||
xaccTransSetNotes (trans, value);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, RECN_CELL, TRUE))
|
||||
{
|
||||
RecnCell *cell;
|
||||
|
||||
cell = (RecnCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
RECN_CELL);
|
||||
|
||||
DEBUG ("RECN: %c", gnc_recn_cell_get_flag (cell));
|
||||
|
||||
xaccSplitSetReconcile (split, gnc_recn_cell_get_flag (cell));
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, ACTN_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, ACTN_CELL);
|
||||
|
||||
DEBUG ("ACTN: %s", value ? value : "(null)");
|
||||
|
||||
xaccSplitSetAction (split, value);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, MEMO_CELL, TRUE))
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
|
||||
|
||||
DEBUG ("MEMO: %s", value ? value : "(null)");
|
||||
|
||||
xaccSplitSetMemo (split, value);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* OK, the handling of transfers gets complicated because it depends
|
||||
* on what was displayed to the user. For a multi-line display, we
|
||||
* just reparent the indicated split, its it, and that's that. For
|
||||
* a two-line display, we want to reparent the "other" split, but
|
||||
* only if there is one. XFRM is the straight split, MXFRM is the
|
||||
* mirrored split. */
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, XFRM_CELL, TRUE))
|
||||
{
|
||||
Account *old_acc;
|
||||
Account *new_acc;
|
||||
|
||||
old_acc = xaccSplitGetAccount (split);
|
||||
|
||||
new_acc = gnc_split_register_get_account (reg, XFRM_CELL);
|
||||
|
||||
if ((new_acc != NULL) && (old_acc != new_acc))
|
||||
xaccAccountInsertSplit (new_acc, split);
|
||||
}
|
||||
|
||||
if (reg->style == REG_STYLE_LEDGER && !info->trans_expanded)
|
||||
other_split = xaccSplitGetOtherSplit (split);
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, MXFRM_CELL, TRUE))
|
||||
{
|
||||
other_split = xaccSplitGetOtherSplit (split);
|
||||
|
||||
/* other_split may be null for two very different reasons:
|
||||
* (1) the parent transaction has three or more splits in it,
|
||||
* and so the "other" split is ambiguous, and thus null.
|
||||
* (2) the parent transaction has only this one split as a child.
|
||||
* and "other" is null because there is no other.
|
||||
*
|
||||
* In the case (2), we want to create the other split, so that
|
||||
* the user's request to transfer actually works out.
|
||||
*/
|
||||
|
||||
if (!other_split)
|
||||
{
|
||||
other_split = xaccTransGetSplit (trans, 1);
|
||||
if (!other_split)
|
||||
{
|
||||
other_split = xaccMallocSplit ();
|
||||
xaccTransAppendSplit (trans, other_split);
|
||||
}
|
||||
}
|
||||
|
||||
if (other_split)
|
||||
{
|
||||
Account *old_acc, *new_acc;
|
||||
|
||||
/* do some reparenting. Insertion into new account will automatically
|
||||
* delete from the old account */
|
||||
old_acc = xaccSplitGetAccount (other_split);
|
||||
new_acc = gnc_split_register_get_account (reg, MXFRM_CELL);
|
||||
|
||||
if ((new_acc != NULL) && (old_acc != new_acc))
|
||||
xaccAccountInsertSplit (new_acc, other_split);
|
||||
}
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, SHRS_CELL, TRUE))
|
||||
{
|
||||
PriceCell *cell;
|
||||
gnc_numeric amount;
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
SHRS_CELL);
|
||||
amount = gnc_price_cell_get_value (cell);
|
||||
|
||||
DEBUG ("SHRS");
|
||||
|
||||
xaccSplitSetAmount (split, amount);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout, PRIC_CELL, TRUE))
|
||||
{
|
||||
PriceCell *cell;
|
||||
gnc_numeric price;
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
PRIC_CELL);
|
||||
price = gnc_price_cell_get_value (cell);
|
||||
|
||||
DEBUG ("PRIC");
|
||||
|
||||
xaccSplitSetSharePrice (split, price);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DEBT_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
CRED_CELL, TRUE))
|
||||
{
|
||||
PriceCell *cell;
|
||||
gnc_numeric new_amount;
|
||||
gnc_numeric credit;
|
||||
gnc_numeric debit;
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
CRED_CELL);
|
||||
credit = gnc_price_cell_get_value (cell);
|
||||
|
||||
cell = (PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
|
||||
DEBT_CELL);
|
||||
debit = gnc_price_cell_get_value (cell);
|
||||
|
||||
new_amount = gnc_numeric_sub_fixed (debit, credit);
|
||||
|
||||
xaccSplitSetValue (split, new_amount);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DEBT_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
CRED_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
PRIC_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
SHRS_CELL, TRUE))
|
||||
{
|
||||
xaccSplitScrub (split);
|
||||
|
||||
if (other_split)
|
||||
{
|
||||
gnc_numeric value = xaccSplitGetValue (split);
|
||||
|
||||
value = gnc_numeric_neg (value);
|
||||
|
||||
xaccSplitSetValue (other_split, value);
|
||||
|
||||
xaccSplitScrub (other_split);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_split_register_save_template_cells (gpointer save_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
SRSaveData *sd = save_data;
|
||||
SplitRegister *reg = user_data;
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Transaction *trans;
|
||||
Split *split;
|
||||
Split *other_split = NULL;
|
||||
kvp_frame *kvpf;
|
||||
AccountGroup *template_ag;
|
||||
Account *template_acc;
|
||||
kvp_value *tag_val;
|
||||
BasicCell *cell;
|
||||
|
||||
DEBUG (" ");
|
||||
|
||||
g_return_if_fail (sd != NULL);
|
||||
|
||||
trans = sd->trans;
|
||||
split = sd->split;
|
||||
|
||||
template_acc = reg->templateAcct;
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
DATE_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
NUM_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
RECN_CELL, TRUE) )
|
||||
{
|
||||
PERR( "unexpected changed fields in a template register\n" );
|
||||
}
|
||||
|
||||
/* We'll be using the Split's KVP frame a lot */
|
||||
kvpf = xaccSplitGetSlots (split);
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
XFRM_CELL, TRUE) )
|
||||
{
|
||||
Account *acct;
|
||||
const GUID *acctGUID;
|
||||
|
||||
/* save the account GUID into the kvp_data. */
|
||||
acct = gnc_split_register_get_account (reg, XFRM_CELL);
|
||||
if (!acct)
|
||||
{
|
||||
PERR ("unknown account");
|
||||
return;
|
||||
}
|
||||
|
||||
acctGUID = xaccAccountGetGUID (acct);
|
||||
kvp_frame_set_slot (kvpf, "sched-xaction/xfrm",
|
||||
kvp_value_new_guid(acctGUID));
|
||||
kvpf = xaccSplitGetSlots (split);
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
|
||||
/* set the actual account to the fake account for these templates */
|
||||
xaccAccountInsertSplit (template_acc, split);
|
||||
}
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
MXFRM_CELL, TRUE) )
|
||||
{
|
||||
DEBUG( "Template: Got MXFRM changed\n" );
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, MXFRM_CELL);
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
}
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
FCRED_CELL, TRUE) ||
|
||||
gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
FDEBT_CELL, TRUE) )
|
||||
{
|
||||
const char *value;
|
||||
char *amountStr = "x + y/42";
|
||||
gnc_numeric new_amount;
|
||||
gnc_numeric credit;
|
||||
gnc_numeric debit;
|
||||
|
||||
DEBUG( "kvp_frame before: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
|
||||
/* amountStr = gnc_numeric_to_string( new_amount ); */
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, FCRED_CELL);
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/credit_formula",
|
||||
kvp_value_new_string( value ) );
|
||||
|
||||
value = gnc_table_layout_get_cell_value (reg->table->layout, FDEBT_CELL);
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/debit_formula",
|
||||
kvp_value_new_string( value ) );
|
||||
|
||||
DEBUG( "kvp_frame after: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
|
||||
/* set the amount to an innocuous value */
|
||||
xaccSplitSetValue (split, gnc_numeric_create(0, 1) );
|
||||
}
|
||||
|
||||
if ( gnc_table_layout_get_cell_changed (reg->table->layout,
|
||||
SHRS_CELL, TRUE) )
|
||||
{
|
||||
char *sharesStr = "(x + y)/42";
|
||||
|
||||
/* FIXME: shares cells are numeric by definition. */
|
||||
DEBUG( "kvp_frame before: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
|
||||
/* sharesStr = gnc_numeric_to_string( sharesStr ); */
|
||||
kvp_frame_set_slot( kvpf, "sched-xaction/shares",
|
||||
kvp_value_new_string( sharesStr ) );
|
||||
DEBUG( "kvp_frame after: %s\n", kvp_frame_to_string( kvpf ) );
|
||||
/* set the shares to an innocuous value */
|
||||
xaccSplitSetSharePriceAndAmount (split,
|
||||
gnc_numeric_create(0, 1),
|
||||
gnc_numeric_create(0, 1) );
|
||||
|
||||
cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
|
||||
gnc_basic_cell_set_changed (cell, FALSE);
|
||||
}
|
||||
|
||||
gnc_split_register_save_cells (save_data, user_data);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_split_register_model_add_save_handlers (TableModel *model)
|
||||
{
|
||||
g_return_if_fail (model != NULL);
|
||||
model->save_handler = gnc_split_register_save_cells;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_template_register_model_add_save_handlers (TableModel *model)
|
||||
{
|
||||
g_return_if_fail (model != NULL);
|
||||
model->save_handler = gnc_split_register_save_template_cells;
|
||||
}
|
||||
|
||||
SRSaveData *
|
||||
gnc_split_register_save_data_new (Transaction *trans, Split *split)
|
||||
{
|
||||
SRSaveData *sd;
|
||||
|
||||
g_return_val_if_fail (trans != NULL, NULL);
|
||||
g_return_val_if_fail (split != NULL, NULL);
|
||||
|
||||
sd = g_new0 (SRSaveData, 1);
|
||||
|
||||
sd->trans = trans;
|
||||
sd->split = split;
|
||||
|
||||
return sd;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_split_register_save_data_destroy (SRSaveData *sd)
|
||||
{
|
||||
g_free (sd);
|
||||
}
|
40
src/register/ledger-core/split-register-model-save.h
Normal file
40
src/register/ledger-core/split-register-model-save.h
Normal file
@ -0,0 +1,40 @@
|
||||
/********************************************************************\
|
||||
* split-register-model-save.h -- split register model object *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef SPLIT_REGISTER_MODEL_SAVE_H
|
||||
#define SPLIT_REGISTER_MODEL_SAVE_H
|
||||
|
||||
#include "Transaction.h"
|
||||
#include "table-model.h"
|
||||
|
||||
|
||||
void gnc_split_register_model_add_save_handlers (TableModel *model);
|
||||
void gnc_template_register_model_add_save_handlers (TableModel *model);
|
||||
|
||||
typedef struct sr_save_data SRSaveData;
|
||||
|
||||
SRSaveData * gnc_split_register_save_data_new (Transaction *trans,
|
||||
Split *split);
|
||||
|
||||
void gnc_split_register_save_data_destroy (SRSaveData *sd);
|
||||
|
||||
#endif
|
@ -34,6 +34,7 @@
|
||||
#include "pricecell.h"
|
||||
#include "recncell.h"
|
||||
#include "split-register-model.h"
|
||||
#include "split-register-model-save.h"
|
||||
#include "split-register-p.h"
|
||||
#include "messages.h"
|
||||
|
||||
@ -1059,6 +1060,8 @@ gnc_split_register_model_new (void)
|
||||
model->cell_data_deallocator = gnc_split_register_guid_free;
|
||||
model->cell_data_copy = gnc_split_register_guid_copy;
|
||||
|
||||
gnc_split_register_model_add_save_handlers (model);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@ -1069,7 +1072,9 @@ gnc_template_register_model_new (void)
|
||||
|
||||
model = gnc_split_register_model_new ();
|
||||
|
||||
model->entry_handler = gnc_template_register_get_entry;
|
||||
model->entry_handler = gnc_template_register_get_entry;
|
||||
|
||||
gnc_template_register_model_add_save_handlers (model);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@ -135,12 +135,8 @@ void sr_set_cell_fractions (SplitRegister *reg, Split *split);
|
||||
CellBlock * sr_get_passive_cursor (SplitRegister *reg);
|
||||
CellBlock * sr_get_active_cursor (SplitRegister *reg);
|
||||
|
||||
void xaccSRSaveChangedCells (SplitRegister *reg,
|
||||
Transaction *trans,
|
||||
Split *split);
|
||||
void sr_set_last_num (SplitRegister *reg, const char *num);
|
||||
|
||||
void xaccSRSaveChangedTemplateCells (SplitRegister *reg,
|
||||
Transaction *trans,
|
||||
Split *split);
|
||||
Account * gnc_split_register_get_account (SplitRegister *reg, int cell_type);
|
||||
|
||||
#endif
|
||||
|
@ -403,3 +403,15 @@ sr_get_active_cursor (SplitRegister *reg)
|
||||
|
||||
return gnc_table_layout_get_cursor (reg->table->layout, cursor_name);
|
||||
}
|
||||
|
||||
void
|
||||
sr_set_last_num (SplitRegister *reg, const char *num)
|
||||
{
|
||||
Account *account;
|
||||
|
||||
account = sr_get_default_account (reg);
|
||||
if (!account)
|
||||
return;
|
||||
|
||||
xaccAccountSetLastNum (account, num);
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ gnc_table_get_entry (Table *table, VirtualLocation virt_loc)
|
||||
CellIOFlags
|
||||
gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc)
|
||||
{
|
||||
if (!table->model->io_flag_handler)
|
||||
if (!table || !table->model->io_flag_handler)
|
||||
return XACC_CELL_ALLOW_NONE;
|
||||
|
||||
return table->model->io_flag_handler (virt_loc,
|
||||
@ -282,7 +282,7 @@ gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc)
|
||||
const char *
|
||||
gnc_table_get_label (Table *table, VirtualLocation virt_loc)
|
||||
{
|
||||
if (!table->model->label_handler)
|
||||
if (!table || !table->model->label_handler)
|
||||
return "";
|
||||
|
||||
return table->model->label_handler (virt_loc,
|
||||
@ -292,7 +292,7 @@ gnc_table_get_label (Table *table, VirtualLocation virt_loc)
|
||||
guint32
|
||||
gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc)
|
||||
{
|
||||
if (!table->model->fg_color_handler)
|
||||
if (!table || !table->model->fg_color_handler)
|
||||
return 0x0; /* black */
|
||||
|
||||
return table->model->fg_color_handler (virt_loc,
|
||||
@ -303,7 +303,7 @@ guint32
|
||||
gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc,
|
||||
gboolean *hatching)
|
||||
{
|
||||
if (!table->model->bg_color_handler)
|
||||
if (!table || !table->model->bg_color_handler)
|
||||
return 0xffffff; /* white */
|
||||
|
||||
return table->model->bg_color_handler (virt_loc, hatching,
|
||||
@ -314,7 +314,7 @@ void
|
||||
gnc_table_get_borders (Table *table, VirtualLocation virt_loc,
|
||||
PhysicalCellBorders *borders)
|
||||
{
|
||||
if (!table->model->cell_border_handler)
|
||||
if (!table || !table->model->cell_border_handler)
|
||||
return;
|
||||
|
||||
table->model->cell_border_handler (virt_loc, borders,
|
||||
@ -440,6 +440,15 @@ gnc_table_get_cell_location (Table *table,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_table_save_cells (Table *table, gpointer save_data)
|
||||
{
|
||||
if (!table || !table->model->save_handler)
|
||||
return;
|
||||
|
||||
table->model->save_handler (save_data, table->model->handler_user_data);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_table_set_size (Table * table, int virt_rows, int virt_cols)
|
||||
{
|
||||
|
@ -211,6 +211,8 @@ gboolean gnc_table_get_cell_location (Table *table,
|
||||
VirtualCellLocation vcell_loc,
|
||||
VirtualLocation *virt_loc);
|
||||
|
||||
void gnc_table_save_cells (Table *table, gpointer save_data);
|
||||
|
||||
|
||||
/* Return the virtual cell of the header */
|
||||
VirtualCell * gnc_table_get_header_cell (Table *table);
|
||||
|
@ -81,6 +81,9 @@ typedef void (*TableGetCellBorderHandler) (VirtualLocation virt_loc,
|
||||
typedef gboolean (*TableConfirmHandler) (VirtualLocation virt_loc,
|
||||
gpointer user_data);
|
||||
|
||||
typedef void (*TableSaveHandler) (gpointer save_data,
|
||||
gpointer user_data);
|
||||
|
||||
typedef gpointer (*VirtCellDataAllocator) (void);
|
||||
typedef void (*VirtCellDataDeallocator) (gpointer cell_data);
|
||||
typedef void (*VirtCellDataCopy) (gpointer to, gconstpointer from);
|
||||
@ -94,6 +97,7 @@ typedef struct
|
||||
TableGetBGColorHandler bg_color_handler;
|
||||
TableGetCellBorderHandler cell_border_handler;
|
||||
TableConfirmHandler confirm_handler;
|
||||
TableSaveHandler save_handler;
|
||||
|
||||
gpointer handler_user_data;
|
||||
|
||||
|
@ -405,7 +405,7 @@
|
||||
;; returns 'html if html is chosen, 'txf if txf is chosen,
|
||||
;; and #f otherwise
|
||||
(define (choose-export-format)
|
||||
(let ((choice (gnc:choose_radio_option_dialog_parented
|
||||
(let ((choice (gnc:choose-radio-option-dialog-parented
|
||||
#f
|
||||
(_ "Choose export format")
|
||||
(_ "Choose the export format for this report:")
|
||||
|
Loading…
Reference in New Issue
Block a user