r22888 - gnucash/trunk/src/gnome-utils - Register rewrite Update, changes the way the transaction changed dialog pops up. This update changes the way the transaction changed dialog pops up and also when you navigate to a cell it automaticly changes to allow input. Author: Robert Fewell

John Ralls jralls at code.gnucash.org
Sun Apr 7 18:15:06 EDT 2013


Author: jralls
Date: 2013-04-07 18:15:06 -0400 (Sun, 07 Apr 2013)
New Revision: 22888
Trac: http://svn.gnucash.org/trac/changeset/22888

Modified:
   gnucash/trunk/src/gnome-utils/gnc-tree-control-split-reg.c
   gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c
   gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.h
Log:
Register rewrite Update, changes the way the transaction changed dialog pops up. This update changes the way the transaction changed dialog pops up and also when you navigate to a cell it automaticly changes to allow input. Author: Robert Fewell

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-control-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-control-split-reg.c	2013-04-07 22:14:55 UTC (rev 22887)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-control-split-reg.c	2013-04-07 22:15:06 UTC (rev 22888)
@@ -706,8 +706,6 @@
 
     spath = gnc_tree_view_split_reg_get_sort_path_from_model_path (view, mpath);
 
-    gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath);
-
     /* Set cursor to new spath */
     gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, NULL, FALSE);
 
@@ -738,8 +736,6 @@
     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);
-
     /* Set cursor to new spath, if amount, cursor is set to correct column ready for editing */
     if (amount)
     {
@@ -866,14 +862,12 @@
     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);
+    /* Set cursor to new spath */
+    gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), new_spath, NULL, FALSE);
 
     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);
-
     LEAVE("new_spath is %s", gtk_tree_path_to_string (new_spath));
 
     gtk_tree_path_free (new_spath);

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c	2013-04-07 22:14:55 UTC (rev 22887)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c	2013-04-07 22:15:06 UTC (rev 22888)
@@ -54,6 +54,14 @@
     LAST_SIGNAL
 };
 
+typedef enum {
+    RESET,  //0
+    ACCEPT, //1
+    DISCARD,//2
+    CANCEL  //3
+}TransConfirm;
+
+
 /** Static Globals *******************************************************/
 static QofLogModule log_module = GNC_MOD_GUI;
 
@@ -239,7 +247,7 @@
     GtkTreeRowReference *current_ref;         // The current model path reference
 
     Transaction         *dirty_trans;         // Set when transaction is changed
-    GtkTreeRowReference *edit_ref;            // The model edit path reference
+    TransConfirm         trans_confirm;       // This is the return value for transaction_changed_confirm
 
     GtkCellRenderer     *temp_cr;             // Pointer to Temp Cell Renderer
     gulong               fo_handler_id;       // Focus out callback id
@@ -410,11 +418,26 @@
     f_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (s_model));
 
     fpath = gtk_tree_model_filter_convert_child_path_to_path (GTK_TREE_MODEL_FILTER (f_model), mpath);
-
+//FIXME Leak fpath
     return gtk_tree_model_sort_convert_child_path_to_path (GTK_TREE_MODEL_SORT (s_model), fpath);
 }
 
 
+/* Get model path from the sort model path */
+GtkTreePath *
+gnc_tree_view_split_reg_get_model_path_from_sort_path (GncTreeViewSplitReg *view, GtkTreePath *spath)
+{
+    GtkTreeModel *f_model, *s_model;
+    GtkTreePath *fpath;
+
+    s_model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+    f_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (s_model));
+
+    fpath = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT (s_model), spath);
+//FIXME Leak fpath
+    return gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (f_model), fpath);
+}
+
 /* Forces the entire split register tree to be re-evaluated for visibility. */
 void
 gnc_tree_view_split_reg_refilter (GncTreeViewSplitReg *view)
@@ -442,6 +465,7 @@
     view->priv->fo_handler_id = 0;
     view->sort_depth = 1;
     view->priv->auto_complete = FALSE;
+    view->priv->trans_confirm = RESET;
 
     view->priv->acct_short_names = gnc_gconf_get_bool (GCONF_GENERAL_REGISTER, "show_leaf_account_names", NULL);
 }
@@ -472,12 +496,6 @@
         view->priv->current_ref = NULL;
     }
 
-    if(view->priv->edit_ref != NULL)
-    {
-        gtk_tree_row_reference_free (view->priv->edit_ref);
-        view->priv->edit_ref = NULL;
-    }
-
     if (G_OBJECT_CLASS (parent_class)->dispose)
         (* G_OBJECT_CLASS (parent_class)->dispose) (object);
 
@@ -1049,8 +1067,6 @@
     }
     view->priv->current_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), new_mpath);
 
-    gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath);
-
     /* Set cursor to new spath */
     gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, NULL, FALSE);
 
@@ -2868,12 +2884,7 @@
 //FIXME this could be the sort path instead of model path / check !!
     path = gtk_tree_path_new_from_string (path_string);
 
-    if(view->priv->edit_ref != NULL)
-    {
-        gtk_tree_row_reference_free (view->priv->edit_ref);
-        view->priv->edit_ref = NULL;
-    }
-    view->priv->edit_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), path);
+//FIXME stuff here...
 
     gtk_tree_path_free (path);
 
@@ -3148,16 +3159,12 @@
     case GTK_RESPONSE_ACCEPT:
         g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (FALSE));
         xaccTransCommitEdit (view->priv->dirty_trans);
-        if(view->priv->edit_ref != NULL)
-        {
-            gtk_tree_row_reference_free (view->priv->edit_ref);
-            view->priv->edit_ref = NULL;
-        }
         split = gnc_tree_model_split_get_blank_split (model);
         xaccSplitReinit (split); // Clear the blank split
         view->priv->dirty_trans = NULL;
         view->change_allowed = FALSE;
         view->priv->auto_complete = FALSE;
+        view->priv->trans_confirm = ACCEPT;
         return FALSE;
         break;
 
@@ -3171,24 +3178,23 @@
             g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (FALSE));
             xaccTransRollbackEdit (view->priv->dirty_trans);
 
-            view->priv->dirty_trans = NULL;
-
             split = gnc_tree_model_split_get_blank_split (model);
             xaccSplitReinit (split); // Clear the blank split
             view->change_allowed = FALSE;
             view->priv->auto_complete = FALSE;
+            view->priv->trans_confirm = DISCARD;
         }
         return TRUE;
         break;
 
     case GTK_RESPONSE_CANCEL:
+        view->priv->trans_confirm = CANCEL;
         return TRUE;
         break;
 
     default:
         return FALSE;
     }
-
     return FALSE;
 }
 
@@ -3928,7 +3934,8 @@
 
     spath = gnc_tree_view_split_reg_get_sort_path_from_model_path (view, bpath);
 
-    gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath);
+    /* Set cursor to new spath */
+    gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, NULL, FALSE);
 
     gtk_tree_path_free (bpath);
     gtk_tree_path_free (spath);
@@ -4053,15 +4060,19 @@
 }
 
 
-/* This is the callback for the mouse click on a selected row */
+/* This is the callback for the mouse click */
 static gboolean
 gtv_split_reg_button_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
 {
     GncTreeViewSplitReg  *view = GNC_TREE_VIEW_SPLIT_REG (widget);
     GncTreeModelSplitReg *model;
-    GtkTreePath          *spath;
+    GtkTreePath *mpath, *spath;
     GtkTreeViewColumn    *col;
     ViewCol viewcol;
+    GtkTreeIter m_iter;
+    Split *split = NULL;
+    Transaction *trans = NULL;
+    gboolean is_trow1, is_trow2, is_split, is_blank;
 
     model = gnc_tree_view_split_reg_get_model_from_view (view);
 
@@ -4074,21 +4085,68 @@
         if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view), (gint) event->x, (gint) event->y,
                                              &spath, &col, NULL, NULL))
         {
-            // Are we on a selected row.
-            if (gtk_tree_selection_path_is_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), spath))
+            mpath = gnc_tree_view_split_reg_get_model_path_from_sort_path (view, spath);
+
+            if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &m_iter, mpath))
             {
-                /* Set cursor to column */
-                gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, col, TRUE);
+                DEBUG("Mouse Button Press - mpath is %s, spath is %s", gtk_tree_path_to_string (mpath), gtk_tree_path_to_string (spath));
 
+                // Reset the transaction confirm flag.
+                view->priv->trans_confirm = RESET;
+
+                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);
+
+                // 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))
+                {
+                    DEBUG("MBP - Restore position - Cancel / Discard");
+
+                    /* Restore position - Cancel / Discard */
+                    if (view->priv->trans_confirm == CANCEL)
+                    {
+                        DEBUG("MBP - Cancel");
+
+                        // Expand trans on split-trans (We only expand on cancel and more than two splits)
+                        if ((xaccTransCountSplits (view->priv->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 (view->priv->dirty_trans, 0), FALSE);
+                        }
+                        else
+                            // Jump to the dirty_trans.
+                            gnc_tree_control_split_reg_jump_to (view, view->priv->dirty_trans, NULL, FALSE);
+
+                        gtk_tree_path_free (spath);
+                        gtk_tree_path_free (mpath);
+                        return TRUE;
+                    }
+
+                    if (view->priv->trans_confirm == DISCARD)
+                    {
+                        DEBUG("MBP - Discard");
+                        view->priv->dirty_trans = NULL;
+                    }
+                }
+
+                /* Skip */
                 // Reconcile tests
                 if (gtv_split_reg_recn_tests (view, col))
                 {
                     gtk_tree_path_free (spath);
+                    gtk_tree_path_free (mpath);
                     return TRUE;
                 }
+
+                /* Set cursor to column */
+                gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, col, TRUE);
+                gtk_tree_path_free (spath);
+                gtk_tree_path_free (mpath);
+                return TRUE;
             }
+            gtk_tree_path_free (spath);
+            gtk_tree_path_free (mpath);
         }
-        gtk_tree_path_free (spath);
     }
     return FALSE;
 }
@@ -4164,50 +4222,54 @@
             return TRUE;
         }
 
+        // Reset the transaction confirm flag.
+        view->priv->trans_confirm = RESET;
+
         /* Have we stepped off the end */
         if (!spath || !gnc_tree_view_path_is_valid (GNC_TREE_VIEW (view), spath)) // We have stepped off the end
         {
             //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)
+                DEBUG("KN - Restore position - Cancel / Discard");
+
+                if (view->priv->trans_confirm == CANCEL)
                 {
-                    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);
+                    DEBUG("KN - Cancel");
 
-                dirty_trans = gnc_tree_view_split_reg_get_dirty_trans_by_ref (view);
+                    // Expand trans on split-trans (We only expand on cancel)
+                    if ((xaccTransCountSplits (view->priv->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 (view->priv->dirty_trans, 0), FALSE);
+                    }
+                    else
+                        // Jump to the dirty_trans.
+                        gnc_tree_control_split_reg_jump_to (view, view->priv->dirty_trans, NULL, FALSE);
 
-                // 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);
+                    gtk_tree_path_free (spath);
+                    return TRUE;
                 }
-                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, dirty_trans, TRUE);
-                gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, FALSE);
+                if (view->priv->trans_confirm == DISCARD)
+                {
+                    DEBUG("KN - Discard");
+                    gnc_tree_view_split_reg_block_selection (view, TRUE);
 
-                /* give gtk+ a chance to handle pending events */
-                while (gtk_events_pending ())
-                    gtk_main_iteration ();
+                    // Check to see if dirty_trans expanded, collapse it.
+                    if (gnc_tree_view_split_reg_trans_expanded (view, view->priv->dirty_trans))
+                        gnc_tree_view_split_reg_collapse_trans (view, view->priv->dirty_trans);
+
+                    gnc_tree_view_split_reg_block_selection (view, FALSE);
+                    view->priv->dirty_trans = NULL;
+                }
             }
         }
-        else
-        {
-            /* Set cursor to new column, open for editing */
-            gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, col, TRUE);
-        }
 
+        /* Set cursor to new column, open for editing */
+        gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), spath, col, TRUE);
+
         gtk_tree_path_free (spath);
         return TRUE;
         break;
@@ -4254,13 +4316,10 @@
 
 //g_print ("Motion - mpath is %s spath is %s\n\n", gtk_tree_path_to_string (mpath), gtk_tree_path_to_string (spath));
 
-//g_print("Motion - current_ref is valid %d edit_ref is %d\n", gtk_tree_row_reference_valid (view->priv->current_ref),
-//                                                             gtk_tree_row_reference_valid (view->priv->edit_ref));
+//g_print("Motion - current_ref is valid %d\n", gtk_tree_row_reference_valid (view->priv->current_ref));
 
-//if(gtk_tree_row_reference_valid (view->priv->current_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)));
-//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)));
 
         /* save the current path */
         if(view->priv->current_ref != NULL)
@@ -4278,67 +4337,26 @@
 
         gtk_tree_path_free (mpath);
 
-//if(gtk_tree_row_reference_valid (view->priv->current_ref))
+//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)));
-//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)));
 
         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);
+//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");
+        /* Move the blank split */ 
+        gnc_tree_model_split_reg_set_blank_split_parent (model, trans, FALSE);
 
-            /* 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, dirty_trans, TRUE);
-            gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, FALSE);
-
-            /* give gtk+ a chance to handle pending events */
-            while (gtk_events_pending ())
-                gtk_main_iteration ();
-
-            return;
-        }
-        else
-        {
-//g_print("Commit and skip\n");
-            /* Commit and skip */
-            /* Move the blank split */ 
-            gnc_tree_model_split_reg_set_blank_split_parent (model, trans, FALSE);
-        }
-
+        /* Save trans / split / depth to the current values */
         old_trans = view->priv->current_trans;
         view->priv->current_trans = trans;
         view->priv->current_split = split;
         view->priv->current_depth = depth;
 
-//g_print("Motion - ** view->priv-> c_trans is %p c_split is %p depth %d **\n\n", view->priv->current_trans, view->priv->current_split, view->priv->current_depth);
+//g_print("Motion - ** view->priv-> c_trans is %p c_split is %p depth %d, old_trans is %p **\n\n", view->priv->current_trans,
+//             view->priv->current_split, view->priv->current_depth, old_trans);
+
         /* Auto expand transaction and collapse previous transaction */
         if (old_trans != trans)
         {
@@ -4347,8 +4365,12 @@
 
             if (model->style != REG2_STYLE_JOURNAL)
             {
+                gnc_tree_view_split_reg_block_selection (view, TRUE);
+
                 if (gnc_tree_view_split_reg_trans_expanded (view, old_trans))
                     gnc_tree_view_split_reg_collapse_trans (view, old_trans);
+
+                gnc_tree_view_split_reg_block_selection (view, FALSE);
             }
             else
                 gnc_tree_view_split_reg_expand_trans (view, NULL);
@@ -4367,9 +4389,9 @@
 
         // Check to see if current trans is expanded and remember
         if (gnc_tree_view_split_reg_trans_expanded (view, trans))
-                view->priv->expanded = TRUE;
+            view->priv->expanded = TRUE;
         else
-                view->priv->expanded = FALSE;
+            view->priv->expanded = FALSE;
     }
     else
     {
@@ -5200,22 +5222,6 @@
     }
 
     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)
-    {
-        gtk_tree_row_reference_free (view->priv->edit_ref);
-        view->priv->edit_ref = NULL;
-    }
-    view->priv->edit_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), mpath);
-
-    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;
@@ -5266,11 +5272,7 @@
 
     if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view), "data-edited")) == FALSE) // Not edited, reset edit path
     {
-        if(view->priv->edit_ref != NULL)
-        {
-            gtk_tree_row_reference_free (view->priv->edit_ref);
-            view->priv->edit_ref = NULL;
-        }
+        view->priv->dirty_trans = NULL;
     }
 
     /* Reset Help text */
@@ -5352,36 +5354,7 @@
     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
 gnc_tree_view_split_reg_set_dirty_trans (GncTreeViewSplitReg *view, Transaction *trans)
@@ -5392,22 +5365,11 @@
 
     if (trans == NULL)
     {
-        if(view->priv->edit_ref != NULL)
-        {
-            gtk_tree_row_reference_free (view->priv->edit_ref);
-            view->priv->edit_ref = NULL;
-        }
         g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (FALSE));
         view->priv->dirty_trans = NULL;
     }
     else
     {
-        if(view->priv->edit_ref != NULL)
-        {
-            gtk_tree_row_reference_free (view->priv->edit_ref);
-            view->priv->edit_ref = NULL;
-        }
-        view->priv->edit_ref = gtk_tree_row_reference_copy (view->priv->current_ref);
         g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (TRUE));
         view->priv->dirty_trans = trans;
     }
@@ -5422,31 +5384,6 @@
 }
 
 
-/* Set the Current path to path */
-void
-gnc_tree_view_split_reg_set_current_path (GncTreeViewSplitReg *view, GtkTreePath *path)
-{
-    GncTreeModelSplitReg *model;
-
-    model = gnc_tree_view_split_reg_get_model_from_view (view);
-
-//FIXME I am not sure this function is needed, it is usualy followed by set selection which
-//      will do this any way ?????
-
-    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_new (GTK_TREE_MODEL (model), path);
-
-//FIXME this is crap - not needed...
-//    view->priv->current_trans = gnc_tree_view_split_reg_get_current_trans (view);
-//    view->priv->current_split = gnc_tree_view_split_reg_get_current_split (view);
-//    view->priv->current_depth = gnc_tree_view_reg_get_selected_row_depth (view);
-}
-
-
 /* Reinit transaction / delete the splits */
 void
 gnc_tree_view_split_reg_reinit_trans (GncTreeViewSplitReg *view)
@@ -5552,41 +5489,43 @@
     /* Make sure we have stopped editing */
     gnc_tree_view_split_reg_finish_edit (view);
 
+    // Reset the transaction confirm flag.
+    view->priv->trans_confirm = RESET;
+
     /* 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)
+        DEBUG("Enter - Restore position - Cancel / Discard");
+
+        if (view->priv->trans_confirm == CANCEL)
         {
-            gtk_tree_row_reference_free (view->priv->current_ref);
-            view->priv->current_ref = NULL;
+            DEBUG("Enter - Cancel");
+
+            // Expand trans on split-trans (We only expand on cancel).
+            if ((xaccTransCountSplits (view->priv->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 (view->priv->dirty_trans, 0), FALSE);
+            }
+            else
+                // Jump to the dirty_trans.
+                gnc_tree_control_split_reg_jump_to (view, view->priv->dirty_trans, NULL, FALSE);
         }
-        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)
+        if (view->priv->trans_confirm == DISCARD)
         {
-            // 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);
+            DEBUG("Enter - Discard");
+            gnc_tree_view_split_reg_block_selection (view, TRUE);
 
-        /* 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, dirty_trans, TRUE);
-        gnc_tree_model_split_reg_set_blank_split_parent (model, dirty_trans, FALSE);
+            // Check to see if dirty_trans expanded, collapse it.
+            if (gnc_tree_view_split_reg_trans_expanded (view, view->priv->dirty_trans))
+                gnc_tree_view_split_reg_collapse_trans (view, view->priv->dirty_trans);
 
-        /* give gtk+ a chance to handle pending events */
-        while (gtk_events_pending ())
-            gtk_main_iteration ();
+            gnc_tree_view_split_reg_block_selection (view, FALSE);
 
-        return FALSE;
+            view->priv->dirty_trans = NULL;
+        }
     }
     return TRUE;
 }
@@ -5621,12 +5560,6 @@
 
         split = gnc_tree_model_split_get_blank_split (model);
         xaccSplitReinit (split); // Clear the blank split
-
-        if (view->priv->edit_ref != NULL)
-        {
-            gtk_tree_row_reference_free (view->priv->edit_ref);
-            view->priv->edit_ref = NULL;
-        }
     }
     /* Reset allow changes for reconciled transctions */
     view->change_allowed = FALSE;
@@ -5684,7 +5617,7 @@
 }
 
 
-/* Collapse the transaction, if trans is NULL,  use current_ref */
+/* Collapse the transaction, if trans is NULL, use current_ref */
 void
 gnc_tree_view_split_reg_collapse_trans (GncTreeViewSplitReg *view, Transaction *trans)
 {

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.h	2013-04-07 22:14:55 UTC (rev 22887)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.h	2013-04-07 22:15:06 UTC (rev 22888)
@@ -127,10 +127,6 @@
 
 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);
 
 RowDepth gnc_tree_view_reg_get_selected_row_depth (GncTreeViewSplitReg *view);
@@ -150,9 +146,12 @@
 const char * gnc_tree_view_split_reg_get_credit_debit_string (GncTreeViewSplitReg *view, gboolean credit);
 
 /*************************************************************************************/
-
+/* Get sort model path from the model path */
 GtkTreePath * gnc_tree_view_split_reg_get_sort_path_from_model_path (GncTreeViewSplitReg *view, GtkTreePath *mpath);
 
+/* Get model path from the sort model path */
+GtkTreePath * gnc_tree_view_split_reg_get_model_path_from_sort_path (GncTreeViewSplitReg *view, GtkTreePath *spath);
+
 GncTreeModelSplitReg * gnc_tree_view_split_reg_get_model_from_view (GncTreeViewSplitReg *view);
 
 gboolean gnc_tree_view_split_reg_scroll_to_cell (GncTreeViewSplitReg *view);



More information about the gnucash-changes mailing list