Register rewrite Update, adds date accelerator and fixes duplicate transaction. This update adds the date accelerator keys to the date column and fixes the duplicate transaction option. Author: Robert Fewell

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22886 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls 2013-04-07 22:14:44 +00:00
parent e6f6bcd87c
commit c55362b090
8 changed files with 269 additions and 148 deletions

View File

@ -91,12 +91,12 @@ static void gcrd_hide (GncCellRendererPopup *cell);
/* These two functions are used internally */
gboolean gcrd_time2dmy ( time64 raw_time, gint *day, gint *month, gint *year);
static time64 gcrd_dmy2time ( gint day, gint month, gint year);
gboolean gcrd_time2dmy (time64 raw_time, gint *day, gint *month, gint *year);
static time64 gcrd_dmy2time (gint day, gint month, gint year);
/* These two functions convert string to date to string */
static gchar * gcrd_time2dmy_string ( time64 raw_time);
static time64 gcrd_string_dmy2time ( char *date_string);
static gchar * gcrd_time2dmy_string (time64 raw_time);
static time64 gcrd_string_dmy2time (const gchar *date_string);
static GncCellRendererPopupClass *parent_class;
@ -306,12 +306,12 @@ gcrd_show (GncCellRendererPopup *cell,
gint x2,
gint y2)
{
GncCellRendererDate *date;
GncCellRendererDate *date;
gint year;
gint month;
gint day;
gint index;
gchar *text;
const gchar *text;
if (parent_class->show_popup) {
parent_class->show_popup (cell,
@ -322,14 +322,16 @@ gcrd_show (GncCellRendererPopup *cell,
date = GNC_CELL_RENDERER_DATE (cell);
if (!(g_strcmp0(cell->cell_text, "")))
text = gnc_popup_entry_get_text (GNC_POPUP_ENTRY (GNC_CELL_RENDERER_POPUP (cell)->editable));
if (!(g_strcmp0(text, "")))
{
date->time = gnc_time (NULL);
gcrd_time2dmy ( date->time, &day, &month, &year);
}
else
{
date->time = gcrd_string_dmy2time (cell->cell_text);
date->time = gcrd_string_dmy2time (text);
gcrd_time2dmy ( date->time, &day, &month, &year);
}
@ -452,7 +454,7 @@ gcrd_grab_on_window (GdkWindow *window,
/* This function converts a time64 value date to separate entities */
gboolean
gcrd_time2dmy ( time64 raw_time, gint *day, gint *month, gint *year)
gcrd_time2dmy (time64 raw_time, gint *day, gint *month, gint *year)
{
struct tm * timeinfo;
@ -467,7 +469,7 @@ gcrd_time2dmy ( time64 raw_time, gint *day, gint *month, gint *year)
/* This function converts separate entities to a time64 value */
static time64
gcrd_dmy2time ( gint day, gint month, gint year)
gcrd_dmy2time (gint day, gint month, gint year)
{
struct tm when;
@ -482,7 +484,7 @@ gcrd_dmy2time ( gint day, gint month, gint year)
/* This function converts a time64 value date to a string */
static gchar *
gcrd_time2dmy_string ( time64 raw_time)
gcrd_time2dmy_string (time64 raw_time)
{
return qof_print_date (raw_time);
}
@ -490,7 +492,7 @@ gcrd_time2dmy_string ( time64 raw_time)
/* This function converts a string date to a time64 value */
static time64
gcrd_string_dmy2time (char *date_string)
gcrd_string_dmy2time (const gchar *date_string)
{
gint year = 0, month = 0, day = 0;

View File

@ -34,6 +34,8 @@
#include <string.h>
#include "gnc-cell-renderer-popup-entry.h"
#include "dialog-utils.h"
#include "gnc-date.h"
static void gnc_popup_entry_init (GncPopupEntry *entry);
static void gnc_popup_entry_class_init (GncPopupEntryClass *class);
@ -163,16 +165,37 @@ gtk_cell_editable_key_press_event (GtkEntry *entry,
GdkEventKey *key_event,
GncPopupEntry *widget)
{
if (key_event->keyval == GDK_Escape) {
widget->editing_canceled = TRUE;
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (widget));
return TRUE;
}
const char *date_string;
gint year = 0, month = 0, day = 0;
struct tm when;
return FALSE;
if (key_event->keyval == GDK_Escape)
{
widget->editing_canceled = TRUE;
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (widget));
return TRUE;
}
date_string = gtk_entry_get_text (entry);
memset (&when, 0, sizeof (when));
if (qof_scan_date (date_string, &day, &month, &year))
{
when.tm_year = year - 1900;
when.tm_mon = month - 1 ;
when.tm_mday = day;
if (!gnc_handle_date_accelerator (key_event, &when, date_string))
return FALSE;
gtk_entry_set_text (entry, qof_print_date (gnc_mktime (&when)));
return TRUE;
}
return FALSE;
}
static gboolean

View File

@ -28,7 +28,6 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libguile.h>
#include <string.h>
#include "gnc-tree-control-split-reg.h"
@ -39,7 +38,6 @@
#include "gnc-gconf-utils.h"
#include "gnc-gdate-utils.h"
#include "dialog-utils.h"
#include "guile-util.h"
#include "dialog-dup-trans.h"
#include "dialog-account.h"
@ -51,46 +49,6 @@
/** Static Globals *******************************************************/
static QofLogModule log_module = GNC_MOD_LEDGER;
static SCM copied_item = SCM_UNDEFINED;
/** implementations *******************************************************/
/* Uses the scheme split copying routines */
static void
gtc_copy_split_onto_split (Split *from, Split *to, gboolean use_cut_semantics)
{
SCM split_scm;
if ((from == NULL) || (to == NULL))
return;
split_scm = gnc_copy_split(from, use_cut_semantics);
if (split_scm == SCM_UNDEFINED)
return;
gnc_copy_split_scm_onto_split (split_scm, to, gnc_get_current_book ());
}
/* Uses the scheme transaction copying routines */
static void
gtc_copy_trans_onto_trans (Transaction *from, Transaction *to,
gboolean use_cut_semantics,
gboolean do_commit)
{
SCM trans_scm;
if ((from == NULL) || (to == NULL))
return;
trans_scm = gnc_copy_trans(from, use_cut_semantics);
if (trans_scm == SCM_UNDEFINED)
return;
gnc_copy_trans_scm_onto_trans (trans_scm, to, do_commit,
gnc_get_current_book ());
}
/*****************************************************************************/
/*****************************************************************************/
@ -227,10 +185,60 @@ gtc_trans_test_for_edit (GncTreeViewSplitReg *view, Transaction *trans)
return FALSE;
}
/*****************************************************************************/
/*****************************************************************************/
void
gnc_tree_control_split_reg_parse_date (GDate *parsed, const char *datestr)
{
int day, month, year;
gboolean use_autoreadonly = qof_book_uses_autoreadonly (gnc_get_current_book ());
if (!parsed) return;
if (!datestr) return;
if (!qof_scan_date (datestr, &day, &month, &year))
{
// Couldn't parse date, use today
struct tm tm_today;
gnc_tm_get_today_start (&tm_today);
day = tm_today.tm_mday;
month = tm_today.tm_mon + 1;
year = tm_today.tm_year + 1900;
}
// If we have an auto-read-only threshold, do not accept a date that is
// older than the threshold.
if (use_autoreadonly)
{
GDate *d = g_date_new_dmy (day, month, year);
GDate *readonly_threshold = qof_book_get_autoreadonly_gdate (gnc_get_current_book());
if (g_date_compare (d, readonly_threshold) < 0)
{
g_warning("Entered date %s is before the \"auto-read-only threshold\"; resetting to the threshold.", datestr);
#if 0
GtkWidget *dialog = gtk_message_dialog_new (NULL,
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s", _("Cannot store a transaction at this date"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", _("The entered date of the new transaction is older than the \"Read-Only Threshold\" set for this book. "
"This setting can be changed in File -> Properties -> Accounts."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
#endif
// Reset the date to the threshold date
day = g_date_get_day (readonly_threshold);
month = g_date_get_month (readonly_threshold);
year = g_date_get_year (readonly_threshold);
}
g_date_free (d);
g_date_free (readonly_threshold);
}
g_date_set_dmy (parsed, day, month, year);
}
gboolean
gnc_tree_control_split_reg_balance_trans (GncTreeViewSplitReg *view, Transaction *trans)
@ -711,22 +719,24 @@ gnc_tree_control_split_reg_jump_to_blank (GncTreeViewSplitReg *view)
}
/* Jump to split */
/* Jump to transaction or split */
void
gnc_tree_control_split_reg_jump_to_split (GncTreeViewSplitReg *view, Split *split, gboolean amount)
gnc_tree_control_split_reg_jump_to (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gboolean amount)
{
GncTreeModelSplitReg *model;
GtkTreePath *mpath, *spath;
model = gnc_tree_view_split_reg_get_model_from_view (view);
mpath = gnc_tree_model_split_reg_get_path_to_split_and_trans (model, split, NULL);
if (split)
trans = NULL;
mpath = gnc_tree_model_split_reg_get_path_to_split_and_trans (model, split, trans);
spath = gnc_tree_view_split_reg_get_sort_path_from_model_path (view, mpath);
// gnc_tree_view_split_reg_set_current_path (view, spath);
gnc_tree_view_split_reg_expand_trans (view, xaccSplitGetParent (split));
if (split)
gnc_tree_view_split_reg_expand_trans (view, xaccSplitGetParent (split));
gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath);
@ -849,13 +859,18 @@ gnc_tree_control_split_reg_goto_rel_trans_row (GncTreeViewSplitReg *view, gint r
new_spath = gtk_tree_path_new_from_indices (indices[0] + (relative * view->sort_direction), -1);
// gnc_tree_view_split_reg_set_current_path (view, new_spath);
// if relative == 0 we block all selection changes
gnc_tree_view_split_reg_block_selection (view, TRUE);
gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath);
gnc_tree_view_split_reg_block_selection (view, FALSE);
if (relative != 0)
gnc_tree_view_split_reg_block_selection (view, FALSE);
gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), new_spath);
if (relative == 0)
gnc_tree_view_split_reg_block_selection (view, FALSE);
/* Set cursor to new spath */
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), new_spath, NULL, FALSE);
@ -1240,7 +1255,7 @@ gnc_tree_control_split_reg_reverse_current (GncTreeViewSplitReg *view)
gtk_main_iteration ();
/* Now jump to new trans */
gnc_tree_control_split_reg_jump_to_split (view, xaccTransGetSplit (new_trans, 0), FALSE);
gnc_tree_control_split_reg_jump_to (view, NULL, xaccTransGetSplit (new_trans, 0), FALSE);
LEAVE("Reverse transaction created");
}
@ -1314,7 +1329,6 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
window = gnc_tree_view_split_reg_get_parent (view);
/* Ok, we are now ready to make the copy. */
if (depth == SPLIT3)
{
Split *new_split;
@ -1360,8 +1374,8 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
xaccTransBeginEdit (trans);
gnc_tree_view_split_reg_set_dirty_trans (view, trans);
xaccSplitCopyOnto (split, new_split);
xaccSplitSetParent (new_split, trans);
gtc_copy_split_onto_split (split, new_split, FALSE);
// Add the blank split
gnc_tree_model_split_reg_set_blank_split_parent (model, trans, FALSE);
@ -1404,19 +1418,20 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
/* We are on a transaction row. Copy the whole transaction. */
date = time (0);
if (gnc_strisnum (xaccTransGetNum (trans)))
if (gnc_strisnum (gnc_get_num_action (trans, trans_split)))
{
Account *account = gnc_tree_model_split_reg_get_anchor (model);
if (account)
in_num = xaccAccountGetLastNum (account);
else
in_num = gnc_get_num_action (trans, trans_split);
in_tnum = (!use_split_action_for_num_field
? NULL
: gnc_get_num_action (trans, NULL));
}
in_tnum = (use_split_action_for_num_field
? gnc_get_num_action (trans, NULL)
: NULL);
if (!gnc_dup_trans_dialog (window, NULL, TRUE,
&date, in_num, &out_num, in_tnum, &out_tnum))
{
@ -1449,18 +1464,29 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
g_date_free (readonly_threshold);
}
split_index = xaccTransGetSplitIndex (trans, split);
trans_split_index = xaccTransGetSplitIndex (trans, trans_split);
new_trans = xaccMallocTransaction (gnc_get_current_book ());
xaccTransBeginEdit (new_trans);
gtc_copy_trans_onto_trans (trans, new_trans, FALSE, FALSE);
xaccTransCopyOnto (trans, new_trans);
xaccTransSetDatePostedSecs (new_trans, date);
/* set per book option */
gnc_set_num_action (new_trans, NULL, out_num, out_tnum);
if (!use_split_action_for_num_field)
if (gnc_strisnum (out_num))
{
Account *account = gnc_tree_model_split_reg_get_anchor (model);
/* If current register is for account, set last num */
if (account)
xaccAccountSetLastNum (account, out_num);
}
if (use_split_action_for_num_field)
{
/* find split in new_trans that equals trans_split and set
* split_action to out_num */
@ -1471,11 +1497,13 @@ gnc_tree_control_split_reg_duplicate_current (GncTreeViewSplitReg *view)
* account, only the anchor split will be set with user input. The
* user will have to adjust other splits manually. */
}
xaccTransCommitEdit (new_trans);
g_free (out_num);
if (out_num != NULL)
g_free (out_num);
if (!use_split_action_for_num_field)
if (use_split_action_for_num_field && out_tnum != NULL)
g_free (out_tnum);
}
LEAVE(" ");

View File

@ -24,7 +24,6 @@
* *
\********************************************************************/
#ifndef __GNC_TREE_CONTROL_SPLIT_REG_H
#define __GNC_TREE_CONTROL_SPLIT_REG_H
@ -51,7 +50,7 @@ void gnc_tree_control_split_reg_unvoid_current_trans (GncTreeViewSplitReg *view)
void gnc_tree_control_split_reg_jump_to_blank (GncTreeViewSplitReg *view);
void gnc_tree_control_split_reg_jump_to_split (GncTreeViewSplitReg *view, Split *split, gboolean amount);
void gnc_tree_control_split_reg_jump_to (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gboolean amount);
void gnc_tree_control_split_reg_cancel_edit (GncTreeViewSplitReg *view, gboolean reg_closing);
@ -81,6 +80,8 @@ gboolean gnc_tree_control_split_reg_recn_test (GncTreeViewSplitReg *view);
gboolean gnc_tree_control_split_reg_balance_trans (GncTreeViewSplitReg *view, Transaction *trans);
void gnc_tree_control_split_reg_parse_date (GDate *parsed, const char *datestr);
Account * gnc_tree_control_split_reg_get_account_by_name (GncTreeViewSplitReg *view, const char *name);
/*****************************************************************************/

View File

@ -2962,7 +2962,7 @@ remove_edit_date (GtkCellEditable *ce, gpointer user_data)
}
/* Lets update the help text */
g_date_set_parse (&date, new_string);
gnc_tree_control_split_reg_parse_date (&date, new_string);
if (g_date_valid (&date))
{
struct tm tm;
@ -3164,14 +3164,13 @@ transaction_changed_confirm (GncTreeViewSplitReg *view,
case GTK_RESPONSE_REJECT:
if (view->priv->dirty_trans && xaccTransIsOpen (view->priv->dirty_trans))
{
// Remove the split before rollback.
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, TRUE);
// Move selection to trans - selection is blocked
if (new_trans == NULL) // This is NULL for keyboard and enter...
gnc_tree_control_split_reg_goto_rel_trans_row (view, 0);
g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (FALSE));
xaccTransRollbackEdit (view->priv->dirty_trans);
// Add the split after rollback so it is last in list.
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, FALSE);
view->priv->dirty_trans = NULL;
split = gnc_tree_model_split_get_blank_split (model);
@ -4079,7 +4078,7 @@ gtv_split_reg_button_cb (GtkWidget *widget, GdkEventButton *event, gpointer user
if (gtk_tree_selection_path_is_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath))
{
/* Set cursor to column */
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, col, FALSE);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, col, TRUE);
// Reconcile tests
if (gtv_split_reg_recn_tests (view, col))
@ -4117,6 +4116,13 @@ gtv_split_reg_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer user
switch (event->keyval)
{
case GDK_KEY_plus:
case GDK_KEY_minus:
case GDK_KEY_KP_Add:
case GDK_KEY_KP_Subtract:
return TRUE; //FIXME I may use these to expand/collapse to splits later...
break;
case GDK_KEY_space:
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
@ -4164,29 +4170,36 @@ gtv_split_reg_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer user
//Ask for confirmation if data has been edited, transaction_changed_confirm return TRUE if canceled
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view), "data-edited")) && transaction_changed_confirm (view, NULL))
{
Transaction *dirty_trans;
/* Restore position - Cancel / Discard */
if (view->priv->current_ref != NULL)
{
gtk_tree_row_reference_free (view->priv->current_ref);
view->priv->current_ref = NULL;
}
view->priv->current_ref = gtk_tree_row_reference_copy (view->priv->edit_ref);
if (gtk_tree_row_reference_valid (view->priv->edit_ref))
view->priv->current_ref = gtk_tree_row_reference_copy (view->priv->edit_ref);
// Jump to the first split of dirty_trans.
gnc_tree_control_split_reg_jump_to_split (view, xaccTransGetSplit (view->priv->dirty_trans, 0), FALSE);
dirty_trans = gnc_tree_view_split_reg_get_dirty_trans_by_ref (view);
// Expand trans on split-trans (We only expand on cancel, view->priv->dirty_trans is not NULL on cancel)
if ((xaccTransCountSplits (dirty_trans) > 2) && view->priv->dirty_trans != NULL)
{
// Jump to the first split of dirty_trans.
gnc_tree_control_split_reg_jump_to (view, NULL, xaccTransGetSplit (dirty_trans, 0), FALSE);
}
else
// Jump to the dirty_trans.
gnc_tree_control_split_reg_jump_to (view, dirty_trans, NULL, FALSE);
/* Remove the blank split and re-add - done so we keep it last in list */
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, TRUE);
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, FALSE);
gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, TRUE);
gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, FALSE);
// if (xaccTransCountSplits (view->priv->dirty_trans) > 2) //FIXME Maybe we should just expand for split-trans
// {
/* give gtk+ a chance to handle pending events */
while (gtk_events_pending ())
gtk_main_iteration ();
gnc_tree_view_split_reg_expand_trans (view, NULL);
// }
}
}
else
@ -4245,9 +4258,9 @@ gtv_split_reg_motion_cb (GtkTreeSelection *sel, gpointer user_data)
// gtk_tree_row_reference_valid (view->priv->edit_ref));
//if(gtk_tree_row_reference_valid (view->priv->current_ref))
//g_print("Motion - Old Current Path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->current_ref)));
// g_print("Motion - Old Current Path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->current_ref)));
//if(gtk_tree_row_reference_valid (view->priv->edit_ref))
//g_print("Motion - Old Edit path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->edit_ref)));
// g_print("Motion - Old Edit path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->edit_ref)));
/* save the current path */
if(view->priv->current_ref != NULL)
@ -4266,47 +4279,54 @@ gtv_split_reg_motion_cb (GtkTreeSelection *sel, gpointer user_data)
gtk_tree_path_free (mpath);
//if(gtk_tree_row_reference_valid (view->priv->current_ref))
//g_print("Motion - Current Path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->current_ref)));
// g_print("Motion - Current Path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->current_ref)));
//if(gtk_tree_row_reference_valid (view->priv->edit_ref))
//g_print("Motion - Edit path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->edit_ref)));
// g_print("Motion - Edit path is '%s'\n", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->edit_ref)));
gnc_tree_model_split_reg_get_split_and_trans (
GNC_TREE_MODEL_SPLIT_REG (model), &m_iter, &is_trow1, &is_trow2, &is_split, &is_blank, &split, &trans);
//g_print("Motion - get model split %p, trans %p, is_split %d, is_blank %d\n", split, trans, is_split, is_blank);
//Ask for confirmation if data has been edited, transaction_changed_confirm return TRUE if canceled
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view), "data-edited")) && transaction_changed_confirm (view, trans))
{
Transaction *dirty_trans;
//g_print("Restore position - Cancel / Discard\n");
/* Restore position - Cancel / Discard */
if(view->priv->current_ref != NULL)
if (view->priv->current_ref != NULL)
{
gtk_tree_row_reference_free (view->priv->current_ref);
view->priv->current_ref = NULL;
}
view->priv->current_ref = gtk_tree_row_reference_copy (view->priv->edit_ref);
if (gtk_tree_row_reference_valid (view->priv->edit_ref))
view->priv->current_ref = gtk_tree_row_reference_copy (view->priv->edit_ref);
// Jump to the first split of dirty_trans.
gnc_tree_control_split_reg_jump_to_split (view, xaccTransGetSplit (view->priv->dirty_trans, 0), FALSE);
dirty_trans = gnc_tree_view_split_reg_get_dirty_trans_by_ref (view);
// Expand trans on split-trans (We only expand on cancel, view->priv->dirty_trans is not NULL on cancel)
if ((xaccTransCountSplits (dirty_trans) > 2) && view->priv->dirty_trans != NULL)
{
// Jump to the first split of dirty_trans.
gnc_tree_control_split_reg_jump_to (view, NULL, xaccTransGetSplit (dirty_trans, 0), FALSE);
}
else
// Jump to the dirty_trans.
gnc_tree_control_split_reg_jump_to (view, dirty_trans, NULL, FALSE);
/* Remove the blank split and re-add - done so we keep it last in list */
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, TRUE);
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, FALSE);
gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, TRUE);
gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, FALSE);
// if (xaccTransCountSplits (view->priv->dirty_trans) > 2) //FIXME Maybe we should just expand for split-trans
// {
/* give gtk+ a chance to handle pending events */
while (gtk_events_pending ())
gtk_main_iteration ();
/* give gtk+ a chance to handle pending events */
while (gtk_events_pending ())
gtk_main_iteration ();
gnc_tree_view_split_reg_expand_trans (view, NULL);
// }
return;
}
else
{
{
//g_print("Commit and skip\n");
/* Commit and skip */
/* Move the blank split */
@ -4345,7 +4365,7 @@ gtv_split_reg_motion_cb (GtkTreeSelection *sel, gpointer user_data)
}
gtk_tree_path_free (spath);
// Check to see if current trans is expanded and set appropiately
// Check to see if current trans is expanded and remember
if (gnc_tree_view_split_reg_trans_expanded (view, trans))
view->priv->expanded = TRUE;
else
@ -4420,16 +4440,16 @@ gtv_split_reg_edited_cb (GtkCellRendererText *cell, const gchar *path_string,
/* Column is DATE */
if (is_trow1)
{
GDate date;
g_date_set_parse (&date, new_text);
if (g_date_valid (&date))
GDate parsed_date;
gnc_tree_control_split_reg_parse_date (&parsed_date, new_text);
if (g_date_valid (&parsed_date))
{
gtv_begin_edit (view, NULL, trans);
xaccTransSetDate (trans, g_date_get_day (&date), g_date_get_month (&date), g_date_get_year (&date));
xaccTransSetDate (trans, g_date_get_day (&parsed_date), g_date_get_month (&parsed_date), g_date_get_year (&parsed_date));
}
else
{
//FIXME should we default to todays date ????
// We should never get here
PERR("invalid date `%s`", new_text);
}
}
@ -5180,12 +5200,12 @@ gtv_get_editable_start_editing_cb (GtkCellRenderer *cr, GtkCellEditable *editabl
}
gtv_split_reg_help (view, cr, viewcol, depth);
//FIXME
fpath = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT (s_model), spath);
mpath = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (f_model), fpath);
if(view->priv->edit_ref != NULL)
if (view->priv->edit_ref != NULL)
{
gtk_tree_row_reference_free (view->priv->edit_ref);
view->priv->edit_ref = NULL;
@ -5195,6 +5215,7 @@ gtv_get_editable_start_editing_cb (GtkCellRenderer *cr, GtkCellEditable *editabl
DEBUG("edit_path is %s", gtk_tree_path_to_string (gtk_tree_row_reference_get_path (view->priv->edit_ref)));
gtk_tree_path_free (mpath);
gtk_tree_path_free (fpath);
//FIXME
gtk_tree_path_free (spath);
view->priv->temp_cr = cr;
@ -5331,6 +5352,35 @@ gnc_tree_view_split_reg_get_dirty_trans (GncTreeViewSplitReg *view)
return view->priv->dirty_trans;
}
Transaction *
gnc_tree_view_split_reg_get_dirty_trans_by_ref (GncTreeViewSplitReg *view)
{
GncTreeModelSplitReg *model;
GtkTreePath *mpath;
Split *split = NULL;
Transaction *trans = NULL;
gboolean is_trow1, is_trow2, is_split, is_blank;
GtkTreeIter m_iter;
gboolean valid;
model = gnc_tree_view_split_reg_get_model_from_view (view);
mpath = gtk_tree_row_reference_get_path (view->priv->edit_ref);
// this can be NULL when tabbing off the end of the list.
if (mpath == NULL)
trans = view->priv->current_trans;
else
{
valid = gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &m_iter, mpath);
if (valid)
gnc_tree_model_split_reg_get_split_and_trans (
GNC_TREE_MODEL_SPLIT_REG (model), &m_iter, &is_trow1, &is_trow2, &is_split, &is_blank, &split, &trans);
}
return trans;
}
/* Sets dirty_trans to trans or NULL to clear */
void
@ -5409,7 +5459,7 @@ gnc_tree_view_split_reg_reinit_trans (GncTreeViewSplitReg *view)
trans = view->priv->current_trans;
/* Lets get out of the way, move the selection to the transaction */
// Lets get out of the way, move selection to trans - selection is blocked
gnc_tree_control_split_reg_goto_rel_trans_row (view, 0);
depth = view->priv->current_depth;
@ -5450,7 +5500,7 @@ gnc_tree_view_split_reg_delete_current_split (GncTreeViewSplitReg *view)
gnc_tree_view_split_reg_set_dirty_trans (view, trans);
/* Lets get out of the way, move the selection to the transaction */
// Lets get out of the way, move selection to trans - selection is blocked
gnc_tree_control_split_reg_goto_rel_trans_row (view, 0);
was_open = xaccTransIsOpen (trans);
@ -5505,21 +5555,37 @@ gnc_tree_view_split_reg_enter (GncTreeViewSplitReg *view)
/* Ask for confirmation if data has been edited, transaction_changed_confirm return TRUE if canceled */
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view), "data-edited")) && transaction_changed_confirm (view, NULL))
{
// Jump to the first split of dirty_trans.
gnc_tree_control_split_reg_jump_to_split (view, xaccTransGetSplit (view->priv->dirty_trans, 0), FALSE);
Transaction *dirty_trans;
/* Restore position - Cancel / Discard */
if (view->priv->current_ref != NULL)
{
gtk_tree_row_reference_free (view->priv->current_ref);
view->priv->current_ref = NULL;
}
if (gtk_tree_row_reference_valid (view->priv->edit_ref))
view->priv->current_ref = gtk_tree_row_reference_copy (view->priv->edit_ref);
dirty_trans = gnc_tree_view_split_reg_get_dirty_trans_by_ref (view);
// Expand trans on split-trans (We only expand on cancel, view->priv->dirty_trans is not NULL on cancel)
if ((xaccTransCountSplits (dirty_trans) > 2) && view->priv->dirty_trans != NULL)
{
// Jump to the first split of dirty_trans.
gnc_tree_control_split_reg_jump_to (view, NULL, xaccTransGetSplit (dirty_trans, 0), FALSE);
}
else
// Jump to the dirty_trans.
gnc_tree_control_split_reg_jump_to (view, dirty_trans, NULL, FALSE);
/* Remove the blank split and re-add - done so we keep it last in list */
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, TRUE);
gnc_tree_model_split_reg_set_blank_split_parent (model, view->priv->dirty_trans, FALSE);
gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, TRUE);
gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, FALSE);
// if (xaccTransCountSplits (view->priv->dirty_trans) > 2) //FIXME Maybe we should just expand for split-trans
// {
/* give gtk+ a chance to handle pending events */
while (gtk_events_pending ())
gtk_main_iteration ();
gtk_main_iteration ();
gnc_tree_view_split_reg_expand_trans (view, NULL);
// }
return FALSE;
}
return TRUE;
@ -5540,6 +5606,7 @@ gnc_tree_view_split_reg_cancel_edit (GncTreeViewSplitReg *view, gboolean reg_clo
if (trans && xaccTransIsOpen (trans))
{
// Move selection to trans - selection is blocked
gnc_tree_control_split_reg_goto_rel_trans_row (view, 0);
// Remove the split before rollback.

View File

@ -127,6 +127,8 @@ Split * gnc_tree_view_split_reg_get_current_split (GncTreeViewSplitReg *view);
Transaction * gnc_tree_view_split_reg_get_dirty_trans (GncTreeViewSplitReg *view);
Transaction * gnc_tree_view_split_reg_get_dirty_trans_by_ref (GncTreeViewSplitReg *view);
void gnc_tree_view_split_reg_set_current_path (GncTreeViewSplitReg *view, GtkTreePath *path);
GtkTreePath * gnc_tree_view_split_reg_get_current_path (GncTreeViewSplitReg *view);

View File

@ -3276,7 +3276,7 @@ gnc_plugin_page_register2_cmd_jump (GtkAction *action,
ld = gnc_plugin_page_register2_get_ledger (new_page);
new_view = gnc_ledger_display2_get_split_view_register (ld);
gnc_tree_control_split_reg_jump_to_split (new_view, split, FALSE);
gnc_tree_control_split_reg_jump_to (new_view, NULL, split, FALSE);
LEAVE(" ");
}

View File

@ -356,7 +356,7 @@ gnc_split_reg2_jump_to_split (GNCSplitReg2 *gsr, Split *split)
view = gnc_ledger_display2_get_split_view_register (gsr->ledger);
gnc_tree_control_split_reg_jump_to_split (view, split, FALSE);
gnc_tree_control_split_reg_jump_to (view, NULL, split, FALSE);
}
@ -376,9 +376,7 @@ gnc_split_reg2_jump_to_split_amount (GNCSplitReg2 *gsr, Split *split)
view = gnc_ledger_display2_get_split_view_register (gsr->ledger);
gnc_tree_control_split_reg_jump_to_split (view, split, TRUE);
//FIXME this needs more
gnc_tree_control_split_reg_jump_to (view, NULL, split, TRUE);
}
/**
@ -699,7 +697,7 @@ gnc_split_reg2_balancing_entry (GNCSplitReg2 *gsr, Account *account,
else
{
// goto balancing transaction
gnc_tree_control_split_reg_jump_to_split (view, split, FALSE);
gnc_tree_control_split_reg_jump_to (view, NULL, split, FALSE);
}
}