diff --git a/src/gnome-utils/gnc-tree-model-split-reg.c b/src/gnome-utils/gnc-tree-model-split-reg.c index 451140dbdd7..e99e8465f18 100644 --- a/src/gnome-utils/gnc-tree-model-split-reg.c +++ b/src/gnome-utils/gnc-tree-model-split-reg.c @@ -54,6 +54,8 @@ static void gnc_tree_model_split_reg_init (GncTreeModelSplitReg *model); static void gnc_tree_model_split_reg_finalize (GObject *object); static void gnc_tree_model_split_reg_dispose (GObject *object); +static const gchar *iter_to_string (GtkTreeIter *iter); + /** Implementation of GtkTreeModel **************************************/ static void gnc_tree_model_split_reg_tree_model_init (GtkTreeModelIface *iface); @@ -69,6 +71,7 @@ static gboolean gnc_tree_model_split_reg_iter_has_child (GtkTreeModel *tree_mode static int gnc_tree_model_split_reg_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter); static gboolean gnc_tree_model_split_reg_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, int n); static gboolean gnc_tree_model_split_reg_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child); +static void increment_stamp (GncTreeModelSplitReg *model); /** Component Manager Callback ******************************************/ static void gnc_tree_model_split_reg_event_handler (QofInstance *entity, QofEventId event_type, GncTreeModelSplitReg *model, GncEventData *ed); @@ -141,9 +144,9 @@ struct GncTreeModelSplitRegPrivate * */ -/* FIXME *********************** +/*FIXME This is the original define #define VALID_ITER(model, iter) \ - (GNC_IS_TREE_MODEL_SPLIT_REG(model) && \ + (GNC_IS_TREE_MODEL_TRANSACTION(model) && \ ((iter) && (iter)->user_data2) && \ ((iter)->stamp == (model)->stamp) && \ (!IS_SPLIT(iter) ^ ((iter)->user_data3 != NULL)) && \ @@ -151,8 +154,30 @@ struct GncTreeModelSplitRegPrivate ((iter)->user_data2 == (model)->priv->bsplit_parent_node)) \ ) */ + +/*FIXME I thought this would work, it does not ????????? */ +/* Do we need to test for a valid iter every where, is it enougth to test on make iter ? */ +#define VALID_ITER (model, iter) \ + (GNC_IS_TREE_MODEL_SPLIT_REG (model) && \ + ((iter).user_data != NULL) && ((iter).user_data2 != NULL) && (model->stamp == (gint)(iter).stamp) && \ + ( (IS_SPLIT (iter) && (iter).user_data3) || (IS_BLANK_SPLIT (iter) && ((GList *)(iter).user_data2 == model->priv->bsplit_parent_node)) || \ + (!IS_SPLIT (iter) && (iter).user_data2) || (IS_BLANK_TRANS (iter) && (iter).user_data3 == NULL))) + + +static gboolean +gtm_valid_iter (GncTreeModelSplitReg *model, GtkTreeIter *iter) +{ + if (GNC_IS_TREE_MODEL_SPLIT_REG (model) && (iter->user_data != NULL) && (iter->user_data2 != NULL) && (model->stamp == (gint)iter->stamp) + && ( (IS_SPLIT (iter) && iter->user_data3) || (IS_BLANK_SPLIT (iter) && ((GList *)iter->user_data2 == model->priv->bsplit_parent_node)) + || (!IS_SPLIT (iter) && iter->user_data2) || (IS_BLANK_TRANS (iter) && iter->user_data3 == NULL))) + return TRUE; + else + return FALSE; +} + + static GtkTreeIter -make_iter(GncTreeModelSplitReg *model, gint f, GList *tnode, GList *snode) +make_iter (GncTreeModelSplitReg *model, gint f, GList *tnode, GList *snode) { GtkTreeIter iter, *iter_p; iter_p = &iter; @@ -161,12 +186,19 @@ make_iter(GncTreeModelSplitReg *model, gint f, GList *tnode, GList *snode) iter.user_data2 = tnode; iter.user_data3 = snode; -/* if (!VALID_ITER(model, &iter)) PERR("Making invalid iter"); */ +//FIXME If I use this in place of 'if' below it works ?????? +// if (!(GNC_IS_TREE_MODEL_SPLIT_REG (model) && (iter_p->user_data != NULL) && (iter_p->user_data2 != NULL) && (model->stamp == (gint)iter_p->stamp) +// && ( (IS_SPLIT (iter_p) && iter_p->user_data3) || (IS_BLANK_SPLIT (iter_p) && ((GList *)iter_p->user_data2 == model->priv->bsplit_parent_node)) +// || (!IS_SPLIT (iter_p) && iter_p->user_data2) || (IS_BLANK_TRANS (iter_p) && iter_p->user_data3 == NULL) ))) + +// if (!VALID_ITER (model, &iter)) + + if (!(gtm_valid_iter (model, iter_p))) + PERR ("Making invalid iter %s", iter_to_string (iter_p)); return iter; } - #define GNC_TREE_MODEL_SPLIT_REG_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_MODEL_SPLIT_REG, GncTreeModelSplitRegPrivate)) @@ -186,9 +218,9 @@ gnc_tree_model_split_reg_get_type (void) { static const GTypeInfo our_info = { - sizeof (GncTreeModelSplitRegClass), /* class_size */ - NULL, /* base_init */ - NULL, /* base_finalize */ + sizeof (GncTreeModelSplitRegClass), /* class_size */ + NULL, /* base_init */ + NULL, /* base_finalize */ (GClassInitFunc) gnc_tree_model_split_reg_class_init, NULL, /* class_finalize */ NULL, /* class_data */ @@ -237,20 +269,20 @@ gnc_tree_model_split_reg_gconf_changed (GConfEntry *entry, gpointer user_data) { GncTreeModelSplitReg *model = user_data; - g_return_if_fail(entry && entry->key); + g_return_if_fail (entry && entry->key); if (model == NULL) return; //g_print("gnc_tree_model_split_reg_gconf_changed\n"); - if (g_str_has_suffix(entry->key, KEY_ACCOUNTING_LABELS)) + if (g_str_has_suffix (entry->key, KEY_ACCOUNTING_LABELS)) { // FIXME This only works on create, dynamic ? - model->use_accounting_labels = gnc_gconf_get_bool(GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL); + model->use_accounting_labels = gnc_gconf_get_bool (GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL); //g_print("model->use_accounting_labels changed %d\n", model->use_accounting_labels); } - else if (g_str_has_suffix(entry->key, KEY_ACCOUNT_SEPARATOR)) + else if (g_str_has_suffix (entry->key, KEY_ACCOUNT_SEPARATOR)) { model->separator_changed = TRUE; // FIXME Not dealt with this } @@ -287,40 +319,14 @@ gnc_tree_model_split_reg_init (GncTreeModelSplitReg *model) static void gnc_tree_model_split_reg_finalize (GObject *object) { - GncTreeModelSplitRegPrivate *priv; GncTreeModelSplitReg *model; ENTER("model %p", object); g_return_if_fail (object != NULL); g_return_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (object)); -g_print("gnc_tree_model_split_reg_finalize\n"); +//g_print("gnc_tree_model_split_reg_finalize\n"); model = GNC_TREE_MODEL_SPLIT_REG (object); - priv = model->priv; - - if (priv->event_handler_id) - { - qof_event_unregister_handler(priv->event_handler_id); - priv->event_handler_id = 0; - } - - priv->book = NULL; - g_list_free(priv->tlist); - priv->tlist = NULL; - - /* Free the blank split */ -//FIXME do we need to free xaccFreeSplit (priv->bsplit); - priv->bsplit = NULL; - priv->bsplit_node = NULL; - /* Free the blank transaction */ -//FIXME do we need to free xaccFreeTransaction (priv->btrans); - priv->btrans = NULL; - - - -/*FIXME Other stuff here */ - - g_free(priv); if (G_OBJECT_CLASS (parent_class)->finalize) G_OBJECT_CLASS (parent_class)->finalize (object); @@ -334,8 +340,7 @@ gnc_tree_model_split_reg_dispose (GObject *object) GncTreeModelSplitRegPrivate *priv; GncTreeModelSplitReg *model; -/*FIXME Not sure about this */ -g_print("gnc_tree_model_split_reg_dispose\n"); +//g_print("gnc_tree_model_split_reg_dispose\n"); ENTER("model %p", object); g_return_if_fail (object != NULL); g_return_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (object)); @@ -349,6 +354,21 @@ g_print("gnc_tree_model_split_reg_dispose\n"); priv->event_handler_id = 0; } + priv->book = NULL; + g_list_free (priv->tlist); + priv->tlist = NULL; + + /* Free the blank split */ + priv->bsplit = NULL; + priv->bsplit_node = NULL; + + /* Free the blank transaction */ + priv->btrans = NULL; + +/*FIXME Other stuff here */ + + g_free (priv); + if (G_OBJECT_CLASS (parent_class)->dispose) G_OBJECT_CLASS (parent_class)->dispose (object); LEAVE(" "); @@ -402,7 +422,6 @@ g_print("gnc_tree_model_split_reg_new and Model pointer is %p\n", model); priv->numact_list = gtk_list_store_new (1, G_TYPE_STRING); - priv->event_handler_id = qof_event_register_handler ((QofEventHandler)gnc_tree_model_split_reg_event_handler, model); @@ -411,32 +430,77 @@ g_print("gnc_tree_model_split_reg_new and Model pointer is %p\n", model); } +static gboolean +remove_foreach_func (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + GList **rowref_list) +{ + GtkTreeRowReference *rowref; + g_assert ( rowref_list != NULL ); +//g_print("for path is %s\n", gtk_tree_path_to_string (path)); + rowref = gtk_tree_row_reference_new (model, path); + *rowref_list = g_list_append (*rowref_list, rowref); + + return FALSE; /* do not stop walking the store, call us with next row */ +} + +static void +gtv_remove_all_rows (GncTreeModelSplitReg *model) +{ + GList *rr_list = NULL; /* list of GtkTreeRowReferences to remove */ + GList *node; + + gtk_tree_model_foreach (GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)remove_foreach_func, &rr_list); + + rr_list = g_list_reverse (rr_list); + + for ( node = rr_list; node != NULL; node = node->next ) + { + GtkTreePath *path; + path = gtk_tree_row_reference_get_path ((GtkTreeRowReference*)node->data); + + if (path) + { +//g_print("rem row path is %s\n", gtk_tree_path_to_string (path)); + gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path); + gtk_tree_path_free (path); + } + } + g_list_foreach (rr_list, (GFunc) gtk_tree_row_reference_free, NULL); + g_list_free (rr_list); +} + + void gnc_tree_model_split_reg_load (GncTreeModelSplitReg *model, GList *slist, Account *default_account) { GncTreeModelSplitRegPrivate *priv; GList *tlist; + gint no_rows = 0; ENTER("Load Model"); -//g_print("gnc_tree_model_split_reg_load\n"); + + priv = model->priv; + + /* Clear the treeview */ + gtv_remove_all_rows (model); + priv->tlist = NULL; g_print("Model load pointer is %p and slist length is %d\n", model, g_list_length (slist)); /* Get a list of Unique Transactions from an slist */ tlist = xaccSplitListGetUniqueTransactions (slist); - priv = model->priv; - priv->book = gnc_get_current_book(); - priv->tlist = tlist; - priv->anchor = default_account; - - priv->bsplit_parent_node = NULL; - /* Update the completion model liststores */ gnc_tree_model_split_reg_update_completion (model); /* Add the blank transaction to the tlist */ - priv->tlist = g_list_append (priv->tlist, priv->btrans); + tlist = g_list_append (tlist, priv->btrans); + + priv->anchor = default_account; + priv->bsplit_parent_node = NULL; + priv->tlist = tlist; LEAVE("Leave Model Load"); } @@ -460,16 +524,12 @@ gnc_tree_model_split_reg_destroy (GncTreeModelSplitReg *model) ENTER("reg=%p", model); g_print("gnc_tree_model_split_reg_destroy\n"); - gnc_gconf_general_remove_cb(KEY_ACCOUNTING_LABELS, + gnc_gconf_general_remove_cb (KEY_ACCOUNTING_LABELS, gnc_tree_model_split_reg_gconf_changed, model); - gnc_gconf_general_remove_cb(KEY_ACCOUNT_SEPARATOR, + gnc_gconf_general_remove_cb (KEY_ACCOUNT_SEPARATOR, gnc_tree_model_split_reg_gconf_changed, model); - - -/*FIXME this needs changing -> gnc_split_register_cleanup (reg); */ - LEAVE(" "); } @@ -501,11 +561,22 @@ g_print("gnc_tree_model_split_reg_config\n"); model->style = newstyle; model->use_double_line = use_double_line; - -/*FIXME This might be treeview gnc_table_realize_gui (reg->table); */ } +/* Returns a Split that matches the current Account */ +static Split * +get_account_split (GncTreeModelSplitReg *model, Transaction *trans) +{ + int i; + Split *split = NULL; + Account *anchor = model->priv->anchor; + for (i = 0; (split = xaccTransGetSplit (trans, i)); i++) { + if (anchor == xaccSplitGetAccount (split)) + return split; + } + return NULL; +} @@ -630,6 +701,7 @@ gnc_tree_model_split_reg_get_iter (GtkTreeModel *tree_model, { /* Sets iter to a valid iterator pointing to path. */ GncTreeModelSplitReg *model = GNC_TREE_MODEL_SPLIT_REG (tree_model); + Account *account; GList *tnode; SplitList *slist; GList *snode; @@ -638,16 +710,18 @@ gnc_tree_model_split_reg_get_iter (GtkTreeModel *tree_model, g_return_val_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (tree_model), FALSE); { - gchar *path_string = gtk_tree_path_to_string(path); + gchar *path_string = gtk_tree_path_to_string (path); ENTER("model %p, iter %p, path %s", tree_model, iter, path_string); - g_free(path_string); + g_free (path_string); } + account = model->priv->anchor; + depth = gtk_tree_path_get_depth (path); indices = gtk_tree_path_get_indices (path); - tnode = g_list_nth(model->priv->tlist, indices[0]); + tnode = g_list_nth (model->priv->tlist, indices[0]); if (!tnode) { DEBUG("path index off end of tlist"); @@ -664,7 +738,15 @@ gnc_tree_model_split_reg_get_iter (GtkTreeModel *tree_model, snode = NULL; } else - snode = g_list_nth (slist, 0); //FIXME is this always the case or do we need to find it - account split + { + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split + } } else if (depth == 2) { /* Trans Row 2 */ flags = TROW2; @@ -674,33 +756,41 @@ gnc_tree_model_split_reg_get_iter (GtkTreeModel *tree_model, snode = NULL; } else - snode = g_list_nth (slist, 0); //FIXME is this always the case or do we need to find it - account split + { + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split + } } else if (depth == 3) /* Split */ - { - flags = SPLIT; - - /* Check if this is the blank split */ - if ((tnode == model->priv->bsplit_parent_node) && (xaccTransCountSplits (tnode->data) == indices[2])) - { - flags |= BLANK; - snode = model->priv->bsplit_node; - } - else - snode = g_list_nth (slist, indices[2]); - - if (!snode) { - DEBUG("path index off end of slist"); - goto fail; - } - } + { + flags = SPLIT; + + /* Check if this is the blank split */ + if ((tnode == model->priv->bsplit_parent_node) && (xaccTransCountSplits (tnode->data) == indices[2])) + { + flags |= BLANK; + snode = model->priv->bsplit_node; + } + else + snode = g_list_nth (slist, indices[2]); + + if (!snode) { + DEBUG("path index off end of slist"); + goto fail; + } + } else { DEBUG("Invalid path depth"); goto fail; } - *iter = make_iter(model, flags, tnode, snode); + *iter = make_iter (model, flags, tnode, snode); /* g_assert(VALID_ITER(model, iter)); */ LEAVE("True"); return TRUE; @@ -736,13 +826,15 @@ gnc_tree_model_split_reg_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter) /* Level 1 */ tpos = g_list_position (model->priv->tlist, tnode); + if (tpos == -1) goto fail; - gtk_tree_path_append_index(path, tpos); + + gtk_tree_path_append_index (path, tpos); /* Level 2 - All ways 0 */ if (IS_TROW2 (iter)) - gtk_tree_path_append_index(path, 0); + gtk_tree_path_append_index (path, 0); /* Level 3 */ if (IS_SPLIT (iter)) @@ -806,7 +898,7 @@ gtm_get_read_only (GncTreeModelSplitReg *model, Transaction *trans) /* Returns the row color */ static gchar* -gtm_get_row_color(GncTreeModelSplitReg *model, gboolean is_trow1, gboolean is_trow2, gboolean is_split, gint num) +gtm_get_row_color (GncTreeModelSplitReg *model, gboolean is_trow1, gboolean is_trow2, gboolean is_split, gint num) { gchar *cell_color = NULL; @@ -872,7 +964,6 @@ gnc_tree_model_split_reg_get_value (GtkTreeModel *tree_model, /* Initializes and sets value to that at column. When done with value, g_value_unset() needs to be called to free any allocated memory. */ GncTreeModelSplitReg *model = GNC_TREE_MODEL_SPLIT_REG (tree_model); - Account *account; Transaction *trans; Split *split; const GncGUID *guid; @@ -881,9 +972,7 @@ gnc_tree_model_split_reg_get_value (GtkTreeModel *tree_model, g_return_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (model)); - ENTER("model %p, iter %s, col %d", tree_model, iter_to_string(iter), column); - - account = model->priv->anchor; + ENTER("model %p, iter %s, col %d", tree_model, iter_to_string (iter), column); tnode = (GList *) iter->user_data2; trans = (Transaction *) tnode->data; @@ -891,15 +980,15 @@ gnc_tree_model_split_reg_get_value (GtkTreeModel *tree_model, snode = (GList *) iter->user_data3; split = (Split *) snode->data; - g_value_init(value, gnc_tree_model_split_reg_get_column_type(tree_model, column)); + g_value_init(value, gnc_tree_model_split_reg_get_column_type (tree_model, column)); - indices = gtk_tree_path_get_indices (gtk_tree_model_get_path (GTK_TREE_MODEL(model), iter)); + indices = gtk_tree_path_get_indices (gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter)); switch (column) { case GNC_TREE_MODEL_SPLIT_REG_COL_GUID: - guid = qof_entity_get_guid(QOF_INSTANCE(trans)); - g_value_set_pointer(value, (gpointer) guid); + guid = qof_entity_get_guid (QOF_INSTANCE (trans)); + g_value_set_pointer (value, (gpointer) guid); break; case GNC_TREE_MODEL_SPLIT_REG_COL_DATE: @@ -943,6 +1032,7 @@ gnc_tree_model_split_reg_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) If there is no next iter, FALSE is returned and iter is set to be invalid */ GncTreeModelSplitReg *model = GNC_TREE_MODEL_SPLIT_REG (tree_model); + Account *account; Transaction *trans; SplitList *slist; GList *tnode = NULL, *snode = NULL; @@ -950,7 +1040,7 @@ gnc_tree_model_split_reg_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) g_return_val_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (model), FALSE); - ENTER("model %p, iter %s", tree_model, iter_to_string(iter)); + ENTER("model %p, iter %s", tree_model, iter_to_string (iter)); if (IS_BLANK (iter)) { LEAVE("Blanks never have a next"); @@ -962,6 +1052,8 @@ gnc_tree_model_split_reg_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) goto fail; } + account = model->priv->anchor; + if (IS_TROW1 (iter)) { flags = TROW1; tnode = iter->user_data2; @@ -972,19 +1064,26 @@ gnc_tree_model_split_reg_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) goto fail; } + slist = xaccTransGetSplitList (tnode->data); + /* Check if this is the blank trans */ if (tnode->data == model->priv->btrans) { flags |= BLANK; snode = NULL; } - else { - trans = tnode->data; - slist = xaccTransGetSplitList (trans); - snode = g_list_nth(slist, 0); + else + { + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split } } - if (IS_SPLIT(iter)) { + if (IS_SPLIT (iter)) { flags = SPLIT; tnode = iter->user_data2; @@ -1011,7 +1110,6 @@ gnc_tree_model_split_reg_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) } - static gboolean gnc_tree_model_split_reg_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, @@ -1021,6 +1119,7 @@ gnc_tree_model_split_reg_iter_children (GtkTreeModel *tree_model, FALSE is returned and iter is set to be invalid. Parent will remain a valid node after this function has been called. */ GncTreeModelSplitReg *model = GNC_TREE_MODEL_SPLIT_REG (tree_model); + Account *account; GList *tnode = NULL, *snode = NULL; gint flags = 0; Transaction *trans; @@ -1030,25 +1129,38 @@ gnc_tree_model_split_reg_iter_children (GtkTreeModel *tree_model, ENTER("model %p, iter %p (to be filed in), parent %s", tree_model, iter, (parent_iter ? iter_to_string(parent_iter) : "(null)")); - if (!parent_iter) { + account = model->priv->anchor; + + if (!parent_iter) + { /* Get the very first iter */ - tnode = model->priv->tlist; - if (tnode) { + tnode = g_list_first (model->priv->tlist); + if (tnode) + { flags = TROW1; - if (tnode->data == model->priv->btrans) { + slist = xaccTransGetSplitList (tnode->data); + if (tnode->data == model->priv->btrans) + { flags |= BLANK; snode = NULL; } else { - slist = xaccTransGetSplitList (tnode->data); - snode = g_list_nth (slist, 0); + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split } *iter = make_iter (model, flags, tnode, snode); LEAVE("iter (2) %s", iter_to_string (iter)); return TRUE; - } else { + } + else + { PERR("We should never have a NULL trans list."); goto fail; } @@ -1060,28 +1172,53 @@ gnc_tree_model_split_reg_iter_children (GtkTreeModel *tree_model, { flags = TROW2; tnode = parent_iter->user_data2; - if (tnode->data == model->priv->btrans) { + slist = xaccTransGetSplitList (tnode->data); + + if (tnode->data == model->priv->btrans) + { flags |= BLANK; snode = NULL; } else { - slist = xaccTransGetSplitList (tnode->data); - snode = g_list_nth (slist, 0); //FIXME is this always the case or do we need to find it - account split + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split } } + if (IS_TROW2 (parent_iter)) + { + tnode = parent_iter->user_data2; + + if ((tnode->data == model->priv->btrans) && (tnode != model->priv->bsplit_parent_node)) // blank trans has no splits to start with + goto fail; + } + if (IS_TROW2 (parent_iter)) { flags = SPLIT; tnode = parent_iter->user_data2; + slist = xaccTransGetSplitList (tnode->data); - if (tnode->data == model->priv->btrans) - snode = NULL; + if ((tnode->data == model->priv->btrans) && (tnode == model->priv->bsplit_parent_node)) + { + flags |= BLANK; + snode = model->priv->bsplit_node; + } else { - slist = xaccTransGetSplitList (tnode->data); - snode = g_list_nth (slist, 0); //FIXME is this always the case or do we need to find it - account split + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split } } @@ -1103,16 +1240,11 @@ gnc_tree_model_split_reg_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter * { /* Returns TRUE if iter has children, FALSE otherwise. */ GncTreeModelSplitReg *model = GNC_TREE_MODEL_SPLIT_REG (tree_model); - GList *tnode; - Transaction *trans; g_return_val_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (tree_model), FALSE); ENTER("model %p, iter %s", tree_model, iter_to_string (iter)); - tnode = iter->user_data2; - trans = tnode->data; - if (IS_TROW1 (iter)) { LEAVE ("Transaction Row 1 is yes"); @@ -1177,6 +1309,7 @@ gnc_tree_model_split_reg_iter_nth_child (GtkTreeModel *tree_model, { /* Sets iter to be the n'th child of parent, using the given index. 0 > */ GncTreeModelSplitReg *model = GNC_TREE_MODEL_SPLIT_REG (tree_model); + Account *account; Transaction *trans; SplitList *slist; GList *tnode, *snode; @@ -1185,26 +1318,34 @@ gnc_tree_model_split_reg_iter_nth_child (GtkTreeModel *tree_model, ENTER("model %p, iter %s, n %d", tree_model, iter_to_string (parent_iter), n); g_return_val_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (tree_model), FALSE); + account = model->priv->anchor; + if (parent_iter == NULL) { /* Top-level */ flags = TROW1; - tnode = g_list_nth(model->priv->tlist, n); + tnode = g_list_nth (model->priv->tlist, n); if (!tnode) { PERR("Trans list should never be NULL."); goto fail; } + slist = xaccTransGetSplitList (tnode->data); + /* Check if this is the blank trans */ - if (tnode->data == model->priv->btrans) { + if (tnode->data == model->priv->btrans) + { flags |= BLANK; snode = NULL; } else { - trans = tnode->data; - - slist = xaccTransGetSplitList (trans); - snode = g_list_nth (slist, 0); //FIXME is this always the case or do we need to find it - account split + if (account != NULL) + { + Split *split = get_account_split (model, tnode->data); // get account split + snode = g_list_find (slist, split); + } + else + snode = g_list_nth (slist, 0); // else first split } *iter = make_iter (model, flags, tnode, snode); @@ -1238,19 +1379,18 @@ gnc_tree_model_split_reg_iter_nth_child (GtkTreeModel *tree_model, } else { - flags = SPLIT; - if (tnode->data == model->priv->btrans) { snode = NULL; } else if ((tnode == model->priv->bsplit_parent_node) && (xaccTransCountSplits(trans) == n)) { - flags |= BLANK; + flags = SPLIT | BLANK; snode = model->priv->bsplit_node; } else { + flags = SPLIT; slist = xaccTransGetSplitList (trans); snode = g_list_nth (slist, n); } @@ -1317,6 +1457,7 @@ increment_stamp (GncTreeModelSplitReg *model) while (model->stamp == 0); } + gboolean gnc_tree_model_split_reg_get_split_and_trans ( GncTreeModelSplitReg *model, GtkTreeIter *iter, @@ -1336,11 +1477,14 @@ gnc_tree_model_split_reg_get_split_and_trans ( if (is_blank) *is_blank = !!IS_BLANK(iter); - if (trans) { + if (trans) + { node = iter->user_data2; *trans = node ? (Transaction *) node->data : NULL; } - if (split) { + + if (split) + { node = iter->user_data3; *split = node ? (Split *) node->data : NULL; } @@ -1401,7 +1545,6 @@ gnc_tree_model_split_reg_get_path_to_split_and_trans (GncTreeModelSplitReg *mode } - #define get_iter gnc_tree_model_split_reg_get_iter_from_trans_and_split gboolean gnc_tree_model_split_reg_get_iter_from_trans_and_split ( @@ -1417,7 +1560,7 @@ gnc_tree_model_split_reg_get_iter_from_trans_and_split ( g_return_val_if_fail (iter1, FALSE); g_return_val_if_fail (iter2, FALSE); -g_print("get_iter model %p, trans %p, split %p\n", model, trans, split); +//g_print("get_iter model %p, trans %p, split %p\n", model, trans, split); priv = model->priv; if (split && !trans) @@ -1449,14 +1592,9 @@ g_print("get_iter model %p, trans %p, split %p\n", model, trans, split); if (!snode) return FALSE; } - *iter1 = make_iter (model, flags1, tnode, snode); - -//g_print("iter1 is %s\n", gtk_tree_model_get_string_from_iter (GTK_TREE_MODEL(model), iter1)); - *iter2 = make_iter (model, flags2, tnode, snode); -//g_print("iter2 is %s\n", gtk_tree_model_get_string_from_iter (GTK_TREE_MODEL(model), iter2)); return TRUE; } @@ -1475,12 +1613,10 @@ update_parent (GncTreeModelSplitReg *model, GtkTreePath *path) GList *tnode; GtkTreeIter iter; -//g_print("update_parent 0 - '%s'\n", gtk_tree_path_to_string (path)); +//g_print("update_parent - '%s'\n", gtk_tree_path_to_string (path)); if (gtk_tree_path_up (path) && gnc_tree_model_split_reg_get_iter (GTK_TREE_MODEL (model), &iter, path)) { -//g_print("update_parent 1 - '%s'\n", gtk_tree_path_to_string (path)); - gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); tnode = iter.user_data2; @@ -1492,21 +1628,17 @@ update_parent (GncTreeModelSplitReg *model, GtkTreePath *path) PINFO("toggling has_child at row %s\n", gtk_tree_path_to_string (path)); -//g_print("update_parent - toggle Path is '%s'\n", gtk_tree_path_to_string (path)); - gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model), path, &iter); } } } - - static void insert_row_at (GncTreeModelSplitReg *model, GtkTreeIter *iter) { GtkTreePath *path; -g_print("insert_row_at\n"); +//g_print("insert_row_at\n"); // g_assert (VALID_ITER (model, iter)); path = gnc_tree_model_split_reg_get_path (GTK_TREE_MODEL (model), iter); //g_print("insert_row_at - Path is '%s'\n", gtk_tree_path_to_string (path)); @@ -1556,8 +1688,6 @@ delete_row_at_path (GncTreeModelSplitReg *model, GtkTreePath *path) //g_print("delete_row_at_path bsplit - Path is '%s'\n", gtk_tree_path_to_string (path)); if (tnode == priv->bsplit_parent_node) priv->bsplit_parent_node = NULL; - -// priv->tlist = g_list_delete_link(priv->tlist, tnode); } } } @@ -1733,7 +1863,6 @@ make_new_blank_split (GncTreeModelSplitReg *model) //g_print(" new bsplit is %p\n", split); - /* Insert the new row */ iter = make_iter (model, BLANK|SPLIT, tnode, model->priv->bsplit_node); insert_row_at (model, &iter); @@ -1773,27 +1902,33 @@ g_print("gnc_tree_model_split_reg_commit_blank_split\n"); return; } -// if (xaccSplitGetAccount (bsplit) == NULL) //FIXME this would make sure we have an account, not sure its valid. -// xaccTransScrubOrphans (trans); + if (xaccSplitGetAccount (bsplit) == NULL) //FIXME this would make sure we have an account, not sure its valid. + xaccTransScrubOrphans (trans); /* If we haven't set an amount yet, and there's an imbalance, use that. */ if (gnc_numeric_zero_p (xaccSplitGetAmount (bsplit))) { gnc_numeric imbal = gnc_numeric_neg (xaccTransGetImbalanceValue (trans)); + if (!gnc_numeric_zero_p (imbal)) { gnc_numeric amount, rate; Account *acct = xaccSplitGetAccount (bsplit); xaccSplitSetValue (bsplit, imbal); + if (gnc_commodity_equal (xaccAccountGetCommodity (acct), xaccTransGetCurrency (trans))) + { amount = imbal; + } else - { + { rate = xaccTransGetAccountConvRate (trans, acct); amount = gnc_numeric_mul (imbal, rate, xaccAccountGetCommoditySCU (acct), GNC_HOW_RND_ROUND); } if (gnc_numeric_check (amount) == GNC_ERROR_OK) + { xaccSplitSetAmount (bsplit, amount); + } } } /* Mark the old blank split as changed */ @@ -1855,7 +1990,6 @@ get_removal_path (GncTreeModelSplitReg *model, Transaction *trans, /*###################################################################*/ /* Combo and Autocompletion ListStore functions */ - Account * gnc_tree_model_split_reg_get_anchor (GncTreeModelSplitReg *model) { @@ -2070,7 +2204,7 @@ gnc_tree_model_split_reg_get_action_list (GncTreeModelSplitReg *model) break; case CREDIT_REGISTER2: gtk_list_store_insert_with_values (store, &iter, 100, 0, _("ATM Deposit"), -1); - gtk_list_store_insert_with_values (store, &iter, 100, 0, _("ATM Draw"), -1); + gtk_list_store_insert_with_values (store, &iter, 100, 0, _("ATM Withdraw"), -1); gtk_list_store_insert_with_values (store, &iter, 100, 0, _("Buy"), -1); gtk_list_store_insert_with_values (store, &iter, 100, 0, _("Credit"), -1); gtk_list_store_insert_with_values (store, &iter, 100, 0, _("Fee"), -1); @@ -2270,7 +2404,7 @@ gnc_tree_model_split_reg_event_handler (QofInstance *entity, g_return_if_fail (GNC_IS_TREE_MODEL_SPLIT_REG (model)); -g_print("\n\n--gnc_tree_model_split_reg_event_handler\n"); +//g_print("\n\n--gnc_tree_model_split_reg_event_handler\n"); if (qof_instance_get_book (entity) != priv->book) return; @@ -2285,7 +2419,7 @@ g_print("\n\n--gnc_tree_model_split_reg_event_handler\n"); switch (event_type) { case QOF_EVENT_MODIFY: -g_print("--gnc_tree_model_split_reg_event_handler - Modify Split\n"); +//g_print("--gnc_tree_model_split_reg_event_handler - Modify Split\n"); if (get_iter (model, NULL, split, &iter1, &iter2)) { //g_print("--Change model %p split %p\n", model, split); //works @@ -2306,7 +2440,7 @@ g_print("--gnc_tree_model_split_reg_event_handler - Modify Split\n"); switch (event_type) { case GNC_EVENT_ITEM_ADDED: -g_print("--gnc_tree_model_split_reg_event_handler - Add Split\n"); +//g_print("--gnc_tree_model_split_reg_event_handler - Add Split\n"); split = (Split *) ed->node; /* The blank split will be added to the transaction when it's first edited. That will generate an event, but @@ -2325,7 +2459,7 @@ g_print("--gnc_tree_model_split_reg_event_handler - Add Split\n"); } break; case GNC_EVENT_ITEM_REMOVED: -g_print("--gnc_tree_model_split_reg_event_handler - Remove Split\n"); +//g_print("--gnc_tree_model_split_reg_event_handler - Remove Split\n"); split = (Split *) ed->node; path = get_removal_path (model, trans, ed->idx); @@ -2343,7 +2477,7 @@ g_print("--gnc_tree_model_split_reg_event_handler - Remove Split\n"); make_new_blank_split (model); break; case QOF_EVENT_MODIFY: -g_print("--gnc_tree_model_split_reg_event_handler - Modify Trans\n"); +//g_print("--gnc_tree_model_split_reg_event_handler - Modify Trans\n"); /* The blank trans won't emit MODIFY until it's committed */ if (priv->btrans == trans) { @@ -2369,7 +2503,7 @@ g_print("--gnc_tree_model_split_reg_event_handler - Modify Trans\n"); break; case QOF_EVENT_DESTROY: -g_print("--gnc_tree_model_split_reg_event_handler - Destroy Trans\n"); +//g_print("--gnc_tree_model_split_reg_event_handler - Destroy Trans\n"); if (priv->btrans == trans) { tnode = g_list_find (priv->tlist, priv->btrans); @@ -2398,7 +2532,7 @@ g_print("--Change blank trans %p\n",priv->btrans); // Not sure this is ever used { Account *acc; case GNC_EVENT_ITEM_ADDED: -g_print("--gnc_tree_model_split_reg_event_handler - Add Account\n"); +//g_print("--gnc_tree_model_split_reg_event_handler - Add Account\n"); split = (Split *) ed; acc = xaccSplitGetAccount (split); trans = xaccSplitGetParent (split); diff --git a/src/gnome-utils/gnc-tree-model-split-reg.h b/src/gnome-utils/gnc-tree-model-split-reg.h index 44578233420..0640f280165 100644 --- a/src/gnome-utils/gnc-tree-model-split-reg.h +++ b/src/gnome-utils/gnc-tree-model-split-reg.h @@ -112,7 +112,7 @@ typedef struct { GncTreeModel gnc_tree_model; /**< The parent object data. */ GncTreeModelSplitRegPrivate *priv; - int stamp; /**< The state of the model. Any state change increments this number. */ + gint stamp; /**< The state of the model. Any state change increments this number. */ SplitRegisterType2 type; /**finalize = gnc_tree_view_split_reg_finalize; g_type_class_add_private(klass, sizeof(GncTreeViewSplitRegPrivate)); + + gnc_tree_view_split_reg_signals[UPDATE_SIGNAL] = + g_signal_new("update_signal", + G_TYPE_FROM_CLASS (o_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GncTreeViewSplitRegClass, update_signal), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + gnc_tree_view_split_reg_signals[HELP_SIGNAL] = + g_signal_new("help_signal", + G_TYPE_FROM_CLASS (o_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GncTreeViewSplitRegClass, help_signal), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + klass->update_signal = NULL; + klass->help_signal = NULL; + } @@ -306,10 +336,6 @@ gnc_tree_view_split_reg_init (GncTreeViewSplitReg *view) view->priv->current_path = gtk_tree_path_new_from_string ("99999"); view->priv->full_refresh = TRUE; - /* Setup the blank transaction split */ - view->priv->btrans_split = xaccMallocSplit (gnc_get_current_book()); - - view->priv->acct_short_names = gnc_gconf_get_bool (GCONF_GENERAL_REGISTER, "show_leaf_account_names", NULL); } @@ -322,7 +348,7 @@ gnc_tree_view_split_reg_dispose (GObject *object) gnc_leave_return_if_fail (object != NULL); gnc_leave_return_if_fail (GNC_IS_TREE_VIEW_SPLIT_REG (object)); - +//g_print("gnc_tree_view_split_reg_dispose\n"); view = GNC_TREE_VIEW_SPLIT_REG (object); priv = GNC_TREE_VIEW_SPLIT_REG_GET_PRIVATE (view); @@ -342,7 +368,7 @@ gnc_tree_view_split_reg_finalize (GObject *object) gnc_leave_return_if_fail(object != NULL); gnc_leave_return_if_fail(GNC_IS_TREE_VIEW_SPLIT_REG (object)); - +//g_print("gnc_tree_view_split_reg_finalize\n"); view = GNC_TREE_VIEW_SPLIT_REG (object); if (G_OBJECT_CLASS(parent_class)->finalize) @@ -566,75 +592,75 @@ g_print("gnc_tree_view_split_reg_set_format row_now is %d, row_old is %d, total if (row_now == total_num -1) gtv_scroll_to_cell (view); -if ((row_now != row_old) || (view->priv->default_set == TRUE)) -{ -view->priv->default_set = FALSE; - - if (model->style == REG2_STYLE_JOURNAL) + if ((row_now != row_old) || (view->priv->default_set == TRUE)) { + view->priv->default_set = FALSE; + + if (model->style == REG2_STYLE_JOURNAL) + { g_print("gnc_tree_view_split_reg_set_format journal\n"); - path = gtk_tree_path_new_first (); - indices = gtk_tree_path_get_indices (view->priv->current_path); + path = gtk_tree_path_new_first (); + indices = gtk_tree_path_get_indices (view->priv->current_path); - /* we need do this when we remove the blank split from the last transaction */ - if (indices[0] != total_num -1) - total_num = total_num -1; + /* we need do this when we remove the blank split from the last transaction */ + if (indices[0] != total_num -1) + total_num = total_num -1; - while (index < total_num) - { - gtk_tree_path_down (path); //TROW2 - gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path); - gtk_tree_path_up (path); //TROW1 + while (index < total_num) + { + gtk_tree_path_down (path); //TROW2 + gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path); + gtk_tree_path_up (path); //TROW1 - index = index + 1; - if (index == total_num) - break; + index = index + 1; + if (index == total_num) + break; - gtk_tree_path_next (path); //Next Transaction + gtk_tree_path_next (path); //Next Transaction + } + gtk_tree_path_free (path); + return (FALSE); } - gtk_tree_path_free (path); - return (FALSE); - } - if (!model->use_double_line) - { -g_print("gnc_tree_view_split_reg_set_format single\n"); - path = gtk_tree_path_new_first (); - while (index < gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL)) + if (!model->use_double_line) { - gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path); - gtk_tree_path_next (path); //Next Transaction - index = index + 1; +g_print("gnc_tree_view_split_reg_set_format single\n"); + path = gtk_tree_path_new_first (); + while (index < total_num) + { + gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path); + gtk_tree_path_next (path); //Next Transaction + index = index + 1; + } + gtk_tree_path_free (path); } - gtk_tree_path_free (path); - } - if (model->use_double_line) - { -g_print("gnc_tree_view_split_reg_set_format double\n"); - path = gtk_tree_path_new_first (); - while (index < gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL)) + if (model->use_double_line) { - gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path); - gtk_tree_path_down (path); - gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path); - gtk_tree_path_up (path); - gtk_tree_path_next (path); //Next Transaction - index = index + 1; +g_print("gnc_tree_view_split_reg_set_format double\n"); + path = gtk_tree_path_new_first (); + while (index < total_num) + { + gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path); + gtk_tree_path_down (path); + gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path); + gtk_tree_path_up (path); + gtk_tree_path_next (path); //Next Transaction + index = index + 1; + } + gtk_tree_path_free (path); } - gtk_tree_path_free (path); - } - /* This expands to split from top level auto.. */ - if ((model->style == REG2_STYLE_AUTO_LEDGER) || (model->style == REG2_STYLE_JOURNAL)) - { - GtkTreePath *expand_path; + /* This expands to split from top level auto.. */ + if ((model->style == REG2_STYLE_AUTO_LEDGER) || (model->style == REG2_STYLE_JOURNAL)) + { + GtkTreePath *expand_path; g_print("gnc_tree_view_split_reg_set_format auto\n"); - expand_path = gtk_tree_path_new_from_indices (row_now, -1); - gtk_tree_view_expand_row (GTK_TREE_VIEW (view), expand_path, TRUE); - gtk_tree_path_free (expand_path); + expand_path = gtk_tree_path_new_from_indices (row_now, -1); + gtk_tree_view_expand_row (GTK_TREE_VIEW (view), expand_path, TRUE); + gtk_tree_path_free (expand_path); + } } -} return (FALSE); } @@ -661,7 +687,8 @@ gnc_tree_view_split_reg_new_with_model (GncTreeModelSplitReg *model) view->priv->anchor = gnc_tree_model_split_reg_get_anchor (model); view->priv->reg_comm = xaccAccountGetCommodity (view->priv->anchor); - view->priv->has_rate = TRUE; + view->priv->has_rate = TRUE; //FIXME - replace has_rate with price visibility test / from original + view->help_text = NULL; gnc_tree_view_split_reg_set_cols (view, gnc_tree_view_split_reg_get_colummn_list (model)); @@ -672,17 +699,17 @@ gnc_tree_view_split_reg_new_with_model (GncTreeModelSplitReg *model) if (gnc_gconf_get_bool (GCONF_GENERAL_REGISTER, "draw_horizontal_lines", NULL)) { if (gnc_gconf_get_bool (GCONF_GENERAL_REGISTER, "draw_vertical_lines", NULL)) - gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), GTK_TREE_VIEW_GRID_LINES_BOTH); + gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH); else - gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), GTK_TREE_VIEW_GRID_LINES_HORIZONTAL); + gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_HORIZONTAL); } else if (gnc_gconf_get_bool (GCONF_GENERAL_REGISTER, "draw_vertical_lines", NULL)) - gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), GTK_TREE_VIEW_GRID_LINES_VERTICAL); + gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_VERTICAL); else - gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), GTK_TREE_VIEW_GRID_LINES_NONE); + gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_NONE); /* Expanders off */ - /* gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view), FALSE); */ + gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view), FALSE); /* Tree Selection */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); @@ -758,17 +785,23 @@ static gboolean needs_exchange_rate (GncTreeViewSplitReg *view, Transaction *trans, Split *split) { gnc_commodity *split_com, *txn_curr, *reg_com; -g_print("needs_exchange_rate trans %p and split %p\n", trans, split); +g_print("needs_exchange_rate - 'always FALSE at the moment' - trans %p and split %p\n", trans, split); if (view->priv->has_rate) return FALSE; txn_curr = xaccTransGetCurrency (trans); split_com = xaccAccountGetCommodity (xaccSplitGetAccount (split)); if (split_com && txn_curr && !gnc_commodity_equiv (split_com, txn_curr)) + { +g_print("needs_exchange_rate split_com return TRUE\n"); return TRUE; + } reg_com = view->priv->reg_comm; if (reg_com && split_com && !gnc_commodity_equiv (reg_com, split_com)) + { +g_print("needs_exchange_rate reg_com return TRUE\n"); return TRUE; + } return FALSE; } @@ -823,6 +856,7 @@ g_print("handle_exchange_rate trans %p and split %p\n", trans, split); xaccSplitSetAmount (split, amount); xaccSplitSetValue (split, value); g_message ("split amt=%s; split val=%s", gnc_numeric_to_string (amount), gnc_numeric_to_string (value)); +g_print("handle_exchange_rate split amt=%s; split val=%s\n", gnc_numeric_to_string (amount), gnc_numeric_to_string (value)); return TRUE; } @@ -834,13 +868,14 @@ set_value_for (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gnc_ { Account *anchor = view->priv->anchor; Account *acct = xaccSplitGetAccount (split); - gnc_commodity *currency = xaccTransGetCurrency (trans); + gnc_commodity *currency; gnc_numeric value, amount, rate; -g_print("set_value_for trans %p and split %p\n", trans, split); +g_print("set_value_for trans %p and split %p input %s\n", trans, split, gnc_numeric_to_string (input)); +g_print("anchor is %p and acct is %p\n", anchor, acct); -// if (xaccSplitGetAccount (split) == NULL) //FIXME this would make sure we have an account, not sure its valid. -// xaccTransScrubOrphans (trans); + if (xaccSplitGetAccount (split) == NULL) //FIXME this would make sure we have an account, not sure its valid. + xaccTransScrubOrphans (trans); if (gnc_numeric_zero_p (input)) { @@ -849,6 +884,16 @@ g_print("set_value_for trans %p and split %p\n", trans, split); return; } + if (!xaccTransGetCurrency (trans)) + { + if (anchor) + xaccTransSetCurrency (trans, view->priv->reg_comm); + else + xaccTransSetCurrency (trans, xaccAccountGetCommodity (acct)); + } + + currency = xaccTransGetCurrency (trans); + if (needs_exchange_rate (view, trans, split)) { if (handle_exchange_rate (view, input, trans, split)) @@ -921,22 +966,21 @@ g_print("set_value_for trans %p and split %p\n", trans, split); /* Returns a value for display. */ static gnc_numeric -get_value_for (GncTreeViewSplitReg *view, Transaction *trans, - Split *split, gboolean is_blank) +get_value_for (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gboolean is_blank) { - gnc_commodity *currency = xaccTransGetCurrency(trans); + gnc_commodity *currency = xaccTransGetCurrency (trans); gnc_numeric total; -//g_print("get_value_for trans %p and split %p is_blank %d\n", trans, split, is_blank); - +// g_print("get_value_for trans %p and split %p is_blank %d\n", trans, split, is_blank); total = xaccSplitGetValue (split); - if (is_blank && gnc_numeric_zero_p (total)) { + if (is_blank && gnc_numeric_zero_p (total)) + { gnc_numeric rate; total = gnc_numeric_neg (xaccTransGetImbalanceValue (trans)); - if (!gnc_numeric_zero_p (total)) { - + if (!gnc_numeric_zero_p (total)) + { if (!xaccTransGetRateForCommodity (trans, view->priv->reg_comm, NULL, &rate)) return gnc_numeric_zero(); @@ -945,10 +989,11 @@ get_value_for (GncTreeViewSplitReg *view, Transaction *trans, gnc_commodity_get_fraction (currency), GNC_HOW_RND_ROUND); } - } else { - if (!gnc_numeric_zero_p (total) && - gnc_numeric_check (total) == GNC_ERROR_OK) { - + } + else + { + if (!gnc_numeric_zero_p (total) && gnc_numeric_check (total) == GNC_ERROR_OK) + { /* fixme: if needs conversion? */ gnc_commodity *commodity = view->priv->reg_comm; /*FIXME ?? if (commodity && !gnc_commodity_equiv(commodity, currency)) @@ -966,7 +1011,7 @@ set_amount_for (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gnc gnc_commodity *split_com = xaccAccountGetCommodity (acct); gnc_commodity *currency = xaccTransGetCurrency (trans); -g_print("set_amount_for trans %p and split %p\n", trans, split); +g_print("set_amount_for trans %p and split %p and input is %s\n", trans, split, gnc_numeric_to_string (input)); xaccSplitSetAmount (split, input); if (gnc_commodity_equiv (currency, split_com)) @@ -984,7 +1029,9 @@ get_rate_for (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gbool g_print("get_rate_for trans %p and split %p is_blank %d\n", trans, split, is_blank); num = get_value_for (view, trans, split, is_blank); +g_print("get_rate_for get_value_for is %s\n", gnc_numeric_to_string (num)); num = gnc_numeric_div ( xaccSplitGetAmount (split), num, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND); +g_print("get_rate_for return is %s\n", gnc_numeric_to_string (num)); return num; } @@ -1038,9 +1085,8 @@ g_print("set_rate_for trans %p and split %p is_blank %d\n", trans, split, is_bla } - -/*FIXME This could be a list...... Returns the other Split based on the current Account */ -/*FIXME Check, This might only be used with two splits */ +/* Returns the other Split based on the current Account */ +/* Only used with two split transactions */ static Split * get_other_split (GncTreeViewSplitReg *view, Transaction *trans) { @@ -1085,19 +1131,15 @@ get_split_pair (GncTreeViewSplitReg *view, Transaction *trans, Split **osplit, S book = gnc_get_current_book(); -g_print("get_split_pair trans is %p, osplit is %p and split is %p\n", trans, *osplit, *split); +g_print("get_split_pair trans is %p, osplit is %p and split is %p and count is %d\n", trans, *osplit, *split, count); if (count == 0) { *split = xaccMallocSplit (book); xaccSplitSetAccount (*split, anchor); xaccSplitSetParent (*split, trans); - *osplit = view->priv->btrans_split; - } - else if (count == 1) - { - *split = xaccTransGetSplit (trans, 0); - *osplit = view->priv->btrans_split; + *osplit = xaccMallocSplit (book); + xaccSplitSetParent (*osplit, trans); } else if (count == 2) { @@ -1119,7 +1161,7 @@ g_print("get_split_pair trans is %p, osplit is %p and split is %p\n", trans, *os } else return FALSE; -g_print("get_split_pair return - trans is %p, count is %d, osplit is %p and split %p is set to anchor %p\n", trans, count, *osplit, *split, anchor); +g_print("get_split_pair return - trans is %p, osplit is %p and split %p is set to anchor %p\n", trans, *osplit, *split, anchor); return TRUE; } @@ -1138,21 +1180,22 @@ g_print("mark_split_dirty trans %p and split %p\n", trans, split); if (split != view->priv->dirty_split) { -g_print("commiting dirty split1\n"); - if (view->priv->dirty_split) +g_print("mark_split_dirty1\n"); + if ((view->priv->dirty_split) && (xaccSplitGetAccount (view->priv->dirty_split) != NULL)) +// if (view->priv->dirty_split) { -g_print("commiting dirty split2\n"); - gnc_tree_model_split_reg_commit_split (get_split_reg_model_from_view (view), view->priv->dirty_split); +g_print("mark_split_dirty2\n"); + gnc_tree_model_split_reg_commit_split (get_split_reg_model_from_view (view), view->priv->dirty_split); } } if (split && trans && xaccSplitGetParent (split) != trans) { -g_print("commiting dirty split3\n"); +g_print("mark_split_dirty3\n"); - if (xaccTransCountSplits (trans) == 0) + if ((xaccTransCountSplits (trans) == 0) && (view->priv->anchor != NULL)) { -g_print("commiting dirty split4\n"); +g_print("mark_split_dirty4\n"); xaccSplitSetAccount (split, view->priv->anchor); } xaccSplitSetParent (split, trans); @@ -1162,7 +1205,6 @@ g_print("commiting dirty split4\n"); } - /* Does this transaction have any Imbalance splits */ static gboolean get_imbalance (Transaction *trans) @@ -1183,7 +1225,6 @@ get_imbalance (Transaction *trans) } } return FALSE; - } @@ -1205,6 +1246,7 @@ get_model_iter_from_view_string(GncTreeViewSplitReg *view, return TRUE; } + static gboolean get_model_iter_from_selection (GncTreeViewSplitReg *view, GtkTreeSelection *sel, GtkTreeIter *iter) @@ -1214,16 +1256,37 @@ get_model_iter_from_selection (GncTreeViewSplitReg *view, if (gtk_tree_selection_get_selected (sel, &s_model, &s_iter)) { -//g_print("s_iter is '%s'\n", gtk_tree_model_get_string_from_iter ( s_model, &s_iter)); gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (s_model), iter, &s_iter); -//g_print("iter is '%s'\n", gtk_tree_model_get_string_from_iter (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (s_model)), iter)); return TRUE; } return FALSE; } +/* Returns TRUE is we have an Account on row */ +static gboolean +gtv_have_account (GncTreeViewSplitReg *view, RowDepth depth, gboolean expanded, Transaction *trans, Split *split) +{ + gboolean have_account = TRUE; + /* Only allow changes to values if we have a valid split accounts */ + if ((depth == TRANS1) && !expanded && (xaccTransCountSplits (trans) == 2)) + { + if (xaccSplitGetAccount (get_other_split (view, trans)) == NULL) + have_account = FALSE; + } + + if ((depth == TRANS1) && !expanded && (xaccTransCountSplits (trans) == 0)) + have_account = FALSE; + + if ((depth == SPLIT3) && (xaccTransCountSplits (trans) != 0)) + { + if (xaccSplitGetAccount (split) == NULL) + have_account = FALSE; + } + + return have_account; +} /* Instead of setting a different cellDataFunc for each column, we just @@ -1415,19 +1478,9 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, else s = gnc_account_get_full_name (acct); } - else if (num_of_splits == 0 || num_of_splits == 1) + else if (num_of_splits == 0) { - Account *acct; - acct = xaccSplitGetAccount (view->priv->btrans_split); - if (acct != NULL) - { - if (view->priv->acct_short_names) - s = xaccAccountGetName (acct); - else - s = gnc_account_get_full_name (acct); - } - else - s = ""; + s = ""; } if (num_of_splits > 2) @@ -1445,7 +1498,7 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, { Account *acct = xaccSplitGetAccount (split); - if (xaccTransCountSplits (trans) == 0) // First split on blank transaction + if ((xaccTransCountSplits (trans) == 0) && (model->type != GENERAL_LEDGER2)) // First split on blank transaction acct = anchor; if (acct != NULL) @@ -1458,7 +1511,7 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, else s = ""; - if (anchor == acct) + if (anchor == acct && model->type != GENERAL_LEDGER2) editable = FALSE; else editable = TRUE; @@ -1539,15 +1592,22 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, case COL_VALUE: /* Column is VALUE */ - if (is_split) { + if (is_split) + { gnc_numeric amt = xaccSplitGetValue (split); s = xaccPrintAmount (amt, gnc_commodity_print_info (xaccTransGetCurrency (trans), FALSE)); editable = TRUE; - } else { + } + else + { s = ""; editable = FALSE; } + /* Only allow changes to values if we have a valid split accounts */ + if (!(gtv_have_account (view, depth, expanded, trans, split))) + editable = FALSE; + editable = (read_only == TRUE) ? FALSE : editable; g_object_set (cell, "text", s, "editable", editable, NULL); @@ -1555,22 +1615,32 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, case COL_RATE: /* Column is RATE */ - if ((is_trow1)||(is_trow2)) { + if ((is_trow1)||(is_trow2)) + { s = ""; editable = FALSE; - } else { + } + else + { gnc_commodity *split_com = xaccAccountGetCommodity (xaccSplitGetAccount (split)); num = get_rate_for (view, trans, split, is_blank); - if (gnc_numeric_check(num) == GNC_ERROR_OK) { + if (gnc_numeric_check(num) == GNC_ERROR_OK) + { s = xaccPrintAmount (num, gnc_split_amount_print_info (split, FALSE)); - editable = !gnc_numeric_zero_p(num) && - !gnc_commodity_equiv(split_com, view->priv->reg_comm); - } else { + editable = !gnc_numeric_zero_p (num) && + gnc_commodity_equiv (split_com, view->priv->reg_comm); + } + else + { s = ""; editable = FALSE; } } + /* Only allow changes to values if we have a valid split accounts */ + if (!(gtv_have_account (view, depth, expanded, trans, split))) + editable = FALSE; + editable = (read_only == TRUE) ? FALSE : editable; g_object_set (cell, "text", s, "editable", editable, NULL); @@ -1578,15 +1648,22 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, case COL_AMOUNT: /* Column is AMOUNT */ - if (is_split) { + if (is_split) + { gnc_numeric amt = xaccSplitGetAmount (split); s = xaccPrintAmount (amt, gnc_account_print_info (xaccSplitGetAccount (split), FALSE)); editable = TRUE; - } else { + } + else + { s = ""; editable = FALSE; } + /* Only allow changes to values if we have a valid split accounts */ + if (!(gtv_have_account (view, depth, expanded, trans, split))) + editable = FALSE; + editable = (read_only == TRUE) ? FALSE : editable; g_object_set (cell, "text", s, "editable", editable, NULL); @@ -1594,29 +1671,39 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, case COL_AMTVAL: /* Column is AMOUNT / VALUE */ - if (is_trow2) { + if (is_trow2) + { s = ""; editable = FALSE; - } else if (is_trow1) { - if (anchor) { + } + else if (is_trow1) + { + if (anchor) + { gnc_numeric amt = xaccSplitGetValue (get_this_split (view, trans)); editable = !expanded && (num_of_splits < 3); if(expanded) s = ""; else s = xaccPrintAmount (amt, gnc_commodity_print_info( xaccTransGetCurrency (trans), FALSE)); - } else { + } + else + { s = ""; editable = FALSE; } } - if (is_split) { - if (split == get_this_split(view, trans)) { + if (is_split) + { + if (split == get_this_split (view, trans)) + { gnc_numeric amt = xaccSplitGetAmount (split); s = xaccPrintAmount (amt, gnc_account_print_info (xaccSplitGetAccount (split), FALSE)); editable = TRUE; - } else { + } + else + { s = ""; editable = FALSE; } @@ -1624,6 +1711,10 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, g_object_set (cell, "cell-background", PINKCELL, (gchar*)NULL); } + /* Only allow changes to values if we have a valid split accounts */ + if (!(gtv_have_account (view, depth, expanded, trans, split))) + editable = FALSE; + editable = (read_only == TRUE) ? FALSE : editable; g_object_set (cell, "text", s, "editable", editable, NULL); @@ -1631,41 +1722,58 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, case COL_PRICE: /* Column is PRICE */ - if (is_trow2) { + if (is_trow2) + { s = ""; editable = FALSE; - } else if (is_trow1) { - if (anchor) { + } + else if (is_trow1) + { + if (anchor) + { num = xaccSplitGetSharePrice (get_this_split (view, trans)); editable = !expanded && (num_of_splits < 3); if (expanded) s = ""; - else { - if (gnc_numeric_check (num) == GNC_ERROR_OK) { + else + { + if (gnc_numeric_check (num) == GNC_ERROR_OK) + { s = xaccPrintAmount (num, gnc_split_amount_print_info (split, FALSE)); - } else { + } + else + { s = ""; editable = FALSE; } } - } else { + } + else + { s = ""; editable = FALSE; } } - if(is_split) { - if(split == get_this_split (view, trans)) { + if (is_split) + { + if (split == get_this_split (view, trans)) + { num = xaccSplitGetSharePrice (split); - if (gnc_numeric_check (num) == GNC_ERROR_OK) { + if (gnc_numeric_check (num) == GNC_ERROR_OK) + { s = xaccPrintAmount (num, gnc_split_amount_print_info (split, FALSE)); editable = TRUE; - } else { + } + else + { s = ""; editable = FALSE; } - } else { + } + else + { s = ""; editable = FALSE; } @@ -1673,6 +1781,10 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, g_object_set(cell, "cell-background", PINKCELL, (gchar*)NULL); } + /* Only allow changes to values if we have a valid split accounts */ + if (!(gtv_have_account (view, depth, expanded, trans, split))) + editable = FALSE; + editable = (read_only == TRUE) ? FALSE : editable; g_object_set (cell, "text", s, "editable", editable, NULL); @@ -1722,27 +1834,11 @@ cdf (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_model, s = xaccPrintAmount (gnc_numeric_abs (num), gnc_account_print_info (anchor, FALSE)); } -#ifdef skip - //FIXME may be use a function for these three if's - /* Only allow changes to values if we have a valid split accounts */ - if (is_trow1 && !expanded && (xaccTransCountSplits (trans) == 2)) - { - if (xaccSplitGetAccount (get_other_split (view, trans)) == NULL) - editable = FALSE; - } - if (is_trow1 && !expanded && (xaccTransCountSplits (trans) == 0 || xaccTransCountSplits (trans) == 1)) - { - if (xaccSplitGetAccount (view->priv->btrans_split) == NULL) - editable = FALSE; - } + /* Only allow changes to values if we have a valid split accounts */ + if (!(gtv_have_account (view, depth, expanded, trans, split))) + editable = FALSE; - if (is_split && (xaccTransCountSplits (trans) != 0)) - { - if (xaccSplitGetAccount (split) == NULL) - editable = FALSE; - } -#endif editable = (read_only == TRUE) ? FALSE : editable; g_object_set (cell, "text", s, "editable", editable, NULL); @@ -1811,13 +1907,10 @@ static void begin_edit (GncTreeViewSplitReg *view, Split *split, Transaction *trans) { g_print("\n\nbegin_edit split %p and trans %p\n", split, trans); - /* explain me -- this may need changing */ - if (split && trans != xaccSplitGetParent (split)) { g_print("begin_edit - blank split, return\n"); - mark_split_dirty (view, trans, split); return; } @@ -1831,11 +1924,6 @@ g_print("begin_edit - blank split, return\n"); g_print("begin_edit - xaccTransBeginEdit trans %p\n", trans); - if (!xaccTransGetCurrency (trans)) - { - xaccTransSetCurrency (trans, view->priv->reg_comm); - } - if (ts.tv_sec == 0) { //If the time returned by xaccTransGetDatePostedTS is 0 then assume it @@ -1856,10 +1944,13 @@ remove_edit_date (GtkCellEditable *ce, gpointer user_data) GncPopupEntry *popup_entry; const gchar *new_string; const gchar *current_string; + GDate date; + struct tm *tm; + char string[1024]; + time_t tt; - //These strings are used to determine if cell data was altered so - //that keynav works better -//g_print("\n\nremove edit date\n"); + //These strings are used to determine if cell data was altered so that keynav works better +g_print("\nremove edit date\n"); popup_entry = GNC_POPUP_ENTRY (g_object_get_data (G_OBJECT (view->priv->temp_cr), "cell-editable")); @@ -1869,14 +1960,26 @@ remove_edit_date (GtkCellEditable *ce, gpointer user_data) current_string = g_object_get_data (G_OBJECT (view->priv->temp_cr), "current-string"); //g_print("Current String is '%s'\n", current_string); - //If editing wasn't canceled and strings don't match then - //cell data was edited + //If editing wasn't canceled and strings don't match then cell data was edited if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view->priv->temp_cr), "edit-canceled")) && g_ascii_strcasecmp (new_string, current_string)) { g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (TRUE)); } + /* Lets update the help text */ + g_date_set_parse (&date, new_string); + if (g_date_valid (&date)) + { + time (&tt); + tm = localtime (&tt); + + g_date_to_struct_tm (&date, tm); + qof_strftime (string, sizeof (string), "%A %d %B %Y", tm); + } + view->help_text = g_strdup (string); + g_signal_emit_by_name (view, "help_signal", NULL); + g_object_set_data (G_OBJECT (view->priv->temp_cr), "cell-editable", NULL); view->priv->temp_cr = NULL; } @@ -1890,9 +1993,8 @@ remove_edit_combo (GtkCellEditable *ce, gpointer user_data) const gchar *new_string; const gchar *current_string; - //These strings are used to determine if cell data was altered so - //that keynav works better -//g_print("\n\nremove edit combo\n"); + //These strings are used to determine if cell data was altered so that keynav works better +g_print("\nremove edit combo\n"); entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (g_object_get_data (G_OBJECT (view->priv->temp_cr), "cell-editable")))); @@ -1902,8 +2004,7 @@ remove_edit_combo (GtkCellEditable *ce, gpointer user_data) current_string = g_object_get_data (G_OBJECT (view->priv->temp_cr), "current-string"); //g_print("Current String is '%s'\n", current_string); - //If editing wasn't canceled and strings don't match then - //cell data was edited + //If editing wasn't canceled and strings don't match then cell data was edited if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view->priv->temp_cr), "edit-canceled")) && g_ascii_strcasecmp (new_string, current_string)) { @@ -1922,18 +2023,16 @@ remove_edit_entry (GtkCellEditable *ce, gpointer user_data) const gchar *new_string; const gchar *current_string; -//g_print("\n\nremove edit completion\n"); +g_print("\nremove edit entry\n"); - //These strings are used to determine if cell data was altered so - //that keynav works better + //These strings are used to determine if cell data was altered so that keynav works better new_string = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (view->priv->temp_cr), "cell-editable"))); //g_print("New String is '%s'\n", new_string); current_string = g_object_get_data (G_OBJECT (view->priv->temp_cr), "current-string"); //g_print("Current String is '%s'\n", current_string); - //If editing wasn't canceled and strings don't match then - //cell data was edited + //If editing wasn't canceled and strings don't match then cell data was edited if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view->priv->temp_cr), "edit-canceled")) && g_ascii_strcasecmp (new_string, current_string)) { @@ -1959,10 +2058,10 @@ finish_edit (GtkTreeViewColumn *col) GtkCellRenderer *cr; GtkCellEditable *ce; g_print("\n\nfinish_edit\n"); -/*FIXME Not used yet, leave for now */ + if (!col) return; - +g_print("finish_edit column title is %s\n", gtk_tree_view_column_get_title (col)); renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (col)); //FIXME I am only looking at one renderer per cell. g_assert (g_list_length (renderers) == 1); cr = g_list_nth_data (renderers, 0); @@ -1970,7 +2069,9 @@ g_print("\n\nfinish_edit\n"); if ((ce = GTK_CELL_EDITABLE (g_object_get_data (G_OBJECT (cr), "cell-editable")))) { +g_print("finish_edit - editing_done\n"); gtk_cell_editable_editing_done (ce); + gtk_cell_editable_remove_widget (ce); } } @@ -2361,6 +2462,225 @@ g_list_free (columns); } +static void +gtv_split_reg_help (GncTreeViewSplitReg *view, GtkCellRenderer *cr, ViewCol viewcol, RowDepth depth) +{ + GncTreeModelSplitReg *model; + const char *help = " "; + const gchar *current_string; + +//g_print("Help Viewcol is %d and depth is %d\n", viewcol, depth); + + model = get_split_reg_model_from_view (view); + + switch(viewcol) + { + case COL_DATE: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1) + { + GDate date; + struct tm *tm; + char string[1024]; + time_t tt; + + current_string = g_object_get_data (G_OBJECT (cr), "current-string"); + g_date_set_parse (&date, current_string); + if (g_date_valid (&date)) + { + time (&tt); + tm = localtime (&tt); + + g_date_to_struct_tm (&date, tm); + qof_strftime (string, sizeof (string), "%A %d %B %Y", tm); + } + help = g_strdup (string); + } + else + help = " "; + break; + } + break; + + case COL_DUEDATE: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter Due Date"); + break; + } + break; + + case COL_NUMACT: + switch(model->type) + { + case RECEIVABLE_REGISTER2: + case PAYABLE_REGISTER2: + if(depth == TRANS1) + help = _("Enter the transaction reference, such as the invoice or check number"); + else if (depth == TRANS2 || depth == SPLIT3) + help = _("Enter the type of transaction, or choose one from the list"); + break; + + default: + if(depth == TRANS1) + help = _("Enter the transaction number, such as the check number"); + else if (depth == TRANS2 || depth == SPLIT3) + help = _("Enter the type of transaction, or choose one from the list"); + break; + } + break; + + case COL_DESCNOTES: + switch(model->type) + { + case RECEIVABLE_REGISTER2: + if(depth == TRANS1) + help = _("Enter the name of the Customer"); + else if (depth == TRANS2) + help = _("Enter notes for the transaction"); + else if (depth == SPLIT3) + help = _("Enter a description of the split"); + break; + + case PAYABLE_REGISTER2: + if(depth == TRANS1) + help = _("Enter the name of the Vendor"); + else if (depth == TRANS2) + help = _("Enter notes for the transaction"); + else if (depth == SPLIT3) + help = _("Enter a description of the split"); + break; + + default: + if(depth == TRANS1) + help = _("Enter a description of the transaction"); + else if (depth == TRANS2) + help = _("Enter notes for the transaction"); + else if (depth == SPLIT3) + help = _("Enter a description of the split"); + break; + } + break; + + case COL_TRANSVOID: + switch(model->type) + { + default: + if(depth == TRANS1) + help = _("Enter the account to transfer from, or choose one from the list"); + else if (depth == TRANS2) + help = _("Reason the transaction was voided"); + else if (depth == SPLIT3) + help = " "; + break; + } + break; + + case COL_RECN: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter the reconcile type"); + break; + } + break; + + case COL_TYPE: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter the type of transaction"); + break; + } + break; + + case COL_VALUE: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter the value of shares bought or sold"); + break; + } + break; + + case COL_AMOUNT: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter the number of shares bought or sold"); + break; + } + break; + + case COL_AMTVAL: + switch(model->type) + { + default: + if((depth == TRANS1) || (depth == TRANS2)) + help = _("Enter the value of shares bought or sold"); + else if (depth == SPLIT3) + help = _("Enter the number of shares bought or sold"); + break; + } + break; + + case COL_RATE: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter the rate"); + break; + } + break; + + case COL_PRICE: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter the effective share price"); + break; + } + break; + + case COL_CREDIT: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter credit formula for real transaction"); + break; + } + break; + + case COL_DEBIT: + switch(model->type) + { + default: //FIXME These if statements may not be required + if(depth == TRANS1 || depth == TRANS2 || depth == SPLIT3) + help = _("Enter debit formula for real transaction"); + break; + } + break; + + default: + help = " "; + break; + } + + view->help_text = g_strdup (help); + g_signal_emit_by_name (view, "help_signal", NULL); +} + /* Callback for double click */ void gtv_split_reg_double_click_cb (GtkTreeView *treeview, GtkTreePath *path, @@ -2493,7 +2813,21 @@ g_print( "end of key nav\n"); void gnc_tree_view_split_reg_cancel_edit (GncTreeViewSplitReg *view) { + GncTreeModelSplitReg *model; + GtkTreePath *path; + GtkTreeViewColumn *col_current; Transaction *trans = view->priv->dirty_trans; + Split *split; + + model = get_split_reg_model_from_view (view); + + gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, &col_current); + +g_print("cancel column title is %s\n", gtk_tree_view_column_get_title (col_current)); + + /* Make sure we have stopped editing */ + if (col_current != NULL) + finish_edit (col_current); if (trans && xaccTransIsOpen (trans)) { @@ -2501,8 +2835,16 @@ gnc_tree_view_split_reg_cancel_edit (GncTreeViewSplitReg *view) g_object_set_data (G_OBJECT (view), "data-edited", GINT_TO_POINTER (FALSE)); xaccTransRollbackEdit (view->priv->dirty_trans); view->priv->dirty_trans = NULL; - xaccSplitReinit (view->priv->btrans_split); + + split = gnc_tree_model_split_get_blank_split (model); + xaccSplitReinit (split); } + + /* this just refreshes the view */ + gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), path); + gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), path); + + gtk_tree_path_free (path); } @@ -2544,7 +2886,6 @@ g_print(" ** transaction_changed_confirm **\n"); xaccTransCommitEdit (view->priv->dirty_trans); view->priv->acct_edit_path = NULL; view->priv->dirty_trans = NULL; - view->priv->btrans_split = xaccMallocSplit (gnc_get_current_book()); break; case GTK_RESPONSE_REJECT: @@ -2581,6 +2922,12 @@ gtv_split_reg_motion_cb (GtkTreeSelection *sel, gpointer user_data) g_print ("\ngtv_split_reg_motion_cb\n"); +g_print("Motion - dirty_trans is %p and dirty_split is %p\n", view->priv->dirty_trans, view->priv->dirty_split); + + /* Reset help text */ + view->help_text = " "; + g_signal_emit_by_name (view, "help_signal", NULL); + mark_split_dirty (view, NULL, NULL); if (get_model_iter_from_selection (view, sel, &iter)) @@ -2648,9 +2995,6 @@ g_print ("Motion - depth is %d row old is %d and now %d\n", depth, row_old, row_ /* Set the view format */ g_idle_add ((GSourceFunc)gnc_tree_view_split_reg_set_format, view); - /* scroll when view is idle */ -// g_idle_add ((GSourceFunc)gtv_scroll_to_cell, view ); - } else { @@ -2742,7 +3086,7 @@ g_print("gtv_split_reg_edited_cb New Text is '%s'\n", new_text); break; case COL_DESCNOTES: - /* Column is DESCRIPTION / NOTES */ + /* Column is DESCRIPTION / NOTES / MEMO */ begin_edit (view, split, trans); if (is_trow1) { @@ -2760,78 +3104,44 @@ g_print("gtv_split_reg_edited_cb New Text is '%s'\n", new_text); case COL_TRANSVOID: /* Column is TRANSFER / VOID (Only updated from menu.) */ -{ - Split *osplit = NULL; + { + Split *osplit = NULL; + QofBook *book; //do we have this + Account *root; // do we have this + Account *new_acct; + gint num_of_splits; - begin_edit (view, split, trans); + begin_edit (view, split, trans); - if (!is_split && anchor) - { - if (!get_split_pair (view, trans, &osplit, &split)) + if (!is_split && anchor) { - PERR("couldn't get split pair"); - break; + if (!get_split_pair (view, trans, &osplit, &split)) + { + PERR("couldn't get split pair"); + break; + } } - } - - if (is_trow1) - { - QofBook *book; //do we have this - Account *root; // do we have this //FIXME Probably needs more work - Account *new_acct; - gint num_of_splits; - book = gnc_get_current_book(); - root = gnc_book_get_root_account(book); + root = gnc_book_get_root_account (book); num_of_splits = xaccTransCountSplits (trans); -g_print("trans split and num_of_splits is %d\n", num_of_splits); - if (view->priv->acct_short_names) new_acct = gnc_account_lookup_by_name (root, new_text); else new_acct = gnc_account_lookup_by_full_name (root, new_text); - if (new_acct != NULL) - xaccAccountInsertSplit (new_acct, osplit); - - } - - - if (is_split) - { - QofBook *book; //do we have this - Account *root; // do we have this -//FIXME Probably needs more work - - Account *new_acct; - gint num_of_splits; - - book = gnc_get_current_book(); - root = gnc_book_get_root_account(book); - - num_of_splits = xaccTransCountSplits (trans); - -g_print("split and num_of_splits is %d\n", num_of_splits); - - if (view->priv->acct_short_names) - new_acct = gnc_account_lookup_by_name (root, new_text); + if (new_acct != NULL && is_split) + xaccSplitSetAccount (split, new_acct); else - new_acct = gnc_account_lookup_by_full_name (root, new_text); - - if (new_acct != NULL) - xaccAccountInsertSplit (new_acct, split); - } - - - + xaccSplitSetAccount (osplit, new_acct); + mark_split_dirty (view, trans, split); -} + } break; case COL_RECN: @@ -2861,20 +3171,20 @@ g_print("split and num_of_splits is %d\n", num_of_splits); break; case COL_TYPE: + break; + case COL_VALUE: case COL_AMOUNT: - case COL_AMTVAL: case COL_RATE: + case COL_AMTVAL: case COL_PRICE: - break; - case COL_DEBIT: case COL_CREDIT: { Account *acct; gnc_numeric input; - Split *split2 = NULL; + Split *osplit = NULL; g_print("rest\n"); @@ -2884,7 +3194,7 @@ g_print("rest\n"); if (!is_split && anchor) { g_print("rest1\n"); - if (!get_split_pair (view, trans, &split2, &split)) + if (!get_split_pair (view, trans, &osplit, &split)) { PERR("couldn't get split pair"); break; @@ -2913,25 +3223,41 @@ g_print("rest3\n"); if (viewcol == COL_CREDIT) input = gnc_numeric_neg (input); -// if (viewcol == COL_AMOUNT) -// { -// set_amount_for (view, trans, split, input); -// break; -// } +//FIXME +#ifdef skip + if (viewcol == COL_AMOUNT) + { + set_amount_for (view, trans, split, input); + break; + } -// if (viewcol == COL_RATE) // Not sure why this is here -// { -// set_rate_for (view, trans, split, input, is_blank); -// break; -// } + if (viewcol == COL_RATE) + { + set_rate_for (view, trans, split, input, is_blank); + break; + } +//FIXME + if ((viewcol == COL_AMTVAL) && is_split) + { + set_amount_for (view, trans, split, input); + break; + } + + if ((viewcol == COL_AMTVAL) && is_trow1) + { + set_value_for (view, trans, split, input); + break; + } +//End FIXME +#endif set_value_for (view, trans, split, input); - if (split2) + if (osplit) { g_print("rest4\n"); - xaccSplitSetParent (split2, trans); - set_value_for (view, trans, split2, gnc_numeric_neg (input)); + xaccSplitSetParent (osplit, trans); + set_value_for (view, trans, osplit, gnc_numeric_neg (input)); } } break; @@ -3024,6 +3350,7 @@ get_editable_start_editing_cb (GtkCellRenderer *cr, GtkCellEditable *editable, GncTreeViewSplitReg *view = GNC_TREE_VIEW_SPLIT_REG (user_data); GncTreeModelSplitReg *model; GtkTreePath *path; + ViewCol viewcol; GtkListStore *description_list; GtkListStore *memo_list; @@ -3034,7 +3361,7 @@ get_editable_start_editing_cb (GtkCellRenderer *cr, GtkCellEditable *editable, RowDepth depth; ENTER(" "); -g_print("\nget_editable_start_editing_cb\n\n"); +g_print("\n\nget_editable_start_editing_cb\n"); model = get_split_reg_model_from_view (view); @@ -3050,11 +3377,12 @@ g_print("\nget_editable_start_editing_cb\n\n"); path = gtk_tree_path_new_from_string (path_string); depth = gtk_tree_path_get_depth (path); -//g_print("editable Depth is %u\n", depth); + viewcol = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(cr), "view_column")); + +g_print("editable Depth is %u and ViewCol is %d\n", depth, viewcol); /* DATE COLUMN */ - if (GNC_TREE_MODEL_SPLIT_REG_COL_DATE - == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cr), "model_column"))) + if (viewcol == COL_DATE) { g_object_set_data (G_OBJECT (cr), "cell-editable", editable); //Copy the string in the GtkEntry for later comparison @@ -3068,8 +3396,7 @@ g_print("\nget_editable_start_editing_cb\n\n"); /* TRANSFER / VOID COLUMN */ - else if (GNC_TREE_MODEL_SPLIT_REG_COL_TRANSVOID - == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cr), "model_column"))) + else if (viewcol == COL_TRANSVOID) { GtkEntry *entry; @@ -3103,8 +3430,7 @@ g_print("\nget_editable_start_editing_cb\n\n"); /* NUMBER / ACTION COLUMN */ - else if (GNC_TREE_MODEL_SPLIT_REG_COL_NUMACT - == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cr), "model_column"))) + else if (viewcol == COL_NUMACT) { GtkEntry *entry; GtkTreeModel *listmodel; @@ -3133,8 +3459,7 @@ g_print("\nget_editable_start_editing_cb\n\n"); /* DESCRIPTION / NOTES / MEMO COLUMN */ - else if (GNC_TREE_MODEL_SPLIT_REG_COL_DESCNOTES - == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cr), "model_column"))) + else if (viewcol == COL_DESCNOTES) { //Data used for completion is set based on if editing split or not if (depth == TRANS1) @@ -3174,8 +3499,8 @@ g_print("\nget_editable_start_editing_cb\n\n"); } - /* RECN COLUMN - We do it this way as we do not want sort arrows */ - else if ( g_strcmp0 (g_object_get_data (G_OBJECT (cr), "column_name"), "recn") == 0) + /* RECN COLUMN */ + else if (viewcol == COL_RECN) { GtkEntry *entry; @@ -3192,7 +3517,7 @@ g_print("\nget_editable_start_editing_cb\n\n"); } - /* REST OF THE COLUMNS */ + /* THE REST OF THE COLUMNS */ else { GtkEntry *entry; @@ -3210,6 +3535,8 @@ g_print("\nget_editable_start_editing_cb\n\n"); } + gtv_split_reg_help (view, cr, viewcol, depth); + gtk_tree_path_free (view->priv->acct_edit_path); view->priv->acct_edit_path = gtk_tree_path_copy (path); //g_print("edit_path is %s\n", gtk_tree_path_to_string (view->priv->acct_edit_path)); @@ -3266,6 +3593,10 @@ g_print("gtv_split_reg_editing_canceled_cb\n\n"); if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (view), "data-edited")) == FALSE) // None edited, reset edit path view->priv->acct_edit_path = NULL; + /* Reset Help text */ + view->help_text = " "; + g_signal_emit_by_name (view, "help_signal", NULL); + //Set edit-canceled property g_object_set_data (G_OBJECT (cr), "edit-canceled", GINT_TO_POINTER (TRUE)); } @@ -3289,6 +3620,9 @@ gnc_tree_view_split_reg_reinit_trans (GncTreeViewSplitReg *view) g_print("gnc_tree_view_split_reg_reinit_trans\n"); model = get_split_reg_model_from_view (view); + /* Lets get out of the way, move the selection to the transaction */ + gnc_tree_view_split_reg_goto_rel_trans_row (view, 0); + gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, view->priv->current_path); gnc_tree_model_split_reg_get_split_and_trans ( @@ -3319,14 +3653,11 @@ gnc_tree_view_split_reg_jump_to_blank (GncTreeViewSplitReg *view) GncTreeModelSplitReg *model; GtkTreePath *path; -//g_print("gnc_tree_view_split_reg_jump_to_blank\n"); +g_print("gnc_tree_view_split_reg_jump_to_blank\n"); model = get_split_reg_model_from_view (view); path = gnc_tree_model_split_reg_get_path_to_split_and_trans (model, NULL, NULL); - gtk_tree_path_free (view->priv->current_path); - view->priv->current_path = gtk_tree_path_copy (path); - gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), path); /* Scroll the window to show selection */ @@ -3350,12 +3681,6 @@ gtv_scroll_to_cell (GncTreeViewSplitReg *view) path = view->priv->current_path; - /* Scroll the window to show selection */ -// if (model->use_double_line) -// gtk_tree_path_down (path); // show the second row of transaction -//FIXME we can not move path like this, copy it or use indices ???? -// can this be combined with set_view_format - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL, TRUE, 0.5, 0.0); return (FALSE); @@ -3369,14 +3694,12 @@ gnc_tree_view_split_reg_jump_to_split (GncTreeViewSplitReg *view, Split *split) GncTreeModelSplitReg *model; GtkTreePath *path; -//g_print("gnc_tree_view_split_reg_jump_to_split and split is %p\n", split); +g_print("gnc_tree_view_split_reg_jump_to_split and split is %p\n", split); model = get_split_reg_model_from_view (view); path = gnc_tree_model_split_reg_get_path_to_split_and_trans (model, split, NULL); -//g_print("Path is '%s'\n", gtk_tree_path_to_string (path)); - gtk_tree_path_free (view->priv->current_path); view->priv->current_path = gtk_tree_path_copy (path); @@ -3412,6 +3735,7 @@ g_print("gnc_tree_view_split_reg_goto_rel_trans_row\n"); view->priv->current_path = gtk_tree_path_copy (path); + gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), path); gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), path); gtk_tree_path_free (path); @@ -3422,15 +3746,26 @@ g_print("gnc_tree_view_split_reg_goto_rel_trans_row\n"); void gnc_tree_view_split_reg_delete_current_split (GncTreeViewSplitReg *view) { - GncTreeModelSplitReg *model; - GtkTreeIter iter; - Split *split = NULL; - Transaction *trans = NULL; - gboolean is_trow1, is_trow2, is_split, is_blank; + GncTreeModelSplitReg *model; + GtkTreeIter iter; + GtkTreePath *path; + GtkTreeViewColumn *col_current; + Split *split = NULL; + Transaction *trans = NULL; + gboolean is_trow1, is_trow2, is_split, is_blank; g_print("gnc_tree_view_split_reg_delete_current_split\n"); + model = get_split_reg_model_from_view (view); + gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, &col_current); + + /* Make sure we have stopped editing */ + if (col_current != NULL) + finish_edit (col_current); + + gtk_tree_path_free (path); + gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, view->priv->current_path); gnc_tree_model_split_reg_get_split_and_trans ( @@ -3441,7 +3776,6 @@ g_print("gnc_tree_view_split_reg_delete_current_split\n"); begin_edit (view, split, trans); -//FIXME Do we need other stuff here if (is_split) { xaccSplitDestroy (split); @@ -3454,16 +3788,26 @@ g_print("gnc_tree_view_split_reg_delete_current_split\n"); void gnc_tree_view_split_reg_delete_current_trans (GncTreeViewSplitReg *view) { - GncTreeModelSplitReg *model; - GtkTreeIter iter; - Split *split = NULL; - Transaction *trans = NULL; - gboolean is_trow1, is_trow2, is_split, is_blank; - gboolean was_open; + GncTreeModelSplitReg *model; + GtkTreeIter iter; + GtkTreePath *path; + GtkTreeViewColumn *col_current; + Split *split = NULL; + Transaction *trans = NULL; + gboolean is_trow1, is_trow2, is_split, is_blank; + gboolean was_open; g_print("gnc_tree_view_split_reg_delete_current_trans\n"); model = get_split_reg_model_from_view (view); + gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, &col_current); + + /* Make sure we have stopped editing */ + if (col_current != NULL) + finish_edit (col_current); + + gtk_tree_path_free (path); + gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, view->priv->current_path); gnc_tree_model_split_reg_get_split_and_trans ( @@ -3471,10 +3815,8 @@ g_print("gnc_tree_view_split_reg_delete_current_trans\n"); begin_edit (view, split, trans); - /* Lets get out of the way, move the selection to the previous transaction */ - gnc_tree_view_split_reg_goto_rel_trans_row (view, -1); - -//FIXME Do we need other stuff here + /* Lets get out of the way, move the selection to the next transaction */ + gnc_tree_view_split_reg_goto_rel_trans_row (view, 1); was_open = xaccTransIsOpen (trans); @@ -3487,9 +3829,11 @@ g_print("gnc_tree_view_split_reg_delete_current_trans\n"); view->priv->dirty_trans = NULL; - + /* We need to go back one to select the next transaction */ + gnc_tree_view_split_reg_goto_rel_trans_row (view, -1); } + /* Returns whether the splits are revealed at the current position */ gboolean gnc_tree_view_split_reg_current_trans_expanded (GncTreeViewSplitReg *view) @@ -3504,7 +3848,6 @@ gnc_tree_view_split_reg_current_trans_expanded (GncTreeViewSplitReg *view) expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path); -//g_print("Expanded indices are %d %d %d and return is %d\n", indices[0], indices[1], indices[2], expanded); gtk_tree_path_free(path); return expanded; } @@ -3550,8 +3893,6 @@ gnc_tree_view_reg_get_current_trans_split (GncTreeViewSplitReg *view) gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, view->priv->current_path); -//g_print("gnc_tree_view_reg_get_current_trans_split %p and %s\n", model, gtk_tree_path_to_string (view->priv->current_path)); - gnc_tree_model_split_reg_get_split_and_trans ( GNC_TREE_MODEL_SPLIT_REG (model), &iter, &is_trow1, &is_trow2, &is_split, &is_blank, &split, &trans); @@ -3578,8 +3919,6 @@ gnc_tree_view_split_reg_get_current_split (GncTreeViewSplitReg *view) gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, view->priv->current_path); -//g_print("gnc_tree_view_split_reg_get_current_split %p and %s\n", model, gtk_tree_path_to_string (view->priv->current_path)); - gnc_tree_model_split_reg_get_split_and_trans ( GNC_TREE_MODEL_SPLIT_REG (model), &iter, &is_trow1, &is_trow2, &is_split, &is_blank, &split, &trans); @@ -3603,8 +3942,6 @@ gnc_tree_view_split_reg_get_current_trans (GncTreeViewSplitReg *view) gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, view->priv->current_path); -//g_print("gnc_tree_view_split_reg_get_current_trans %p and %s\n", model, gtk_tree_path_to_string (view->priv->current_path)); - gnc_tree_model_split_reg_get_split_and_trans ( GNC_TREE_MODEL_SPLIT_REG (model), &iter, &is_trow1, &is_trow2, &is_split, &is_blank, &split, &trans); @@ -3618,7 +3955,18 @@ gnc_tree_view_split_reg_get_current_trans (GncTreeViewSplitReg *view) gboolean gnc_tree_view_split_reg_enter (GncTreeViewSplitReg *view) { -g_print("gnc_tree_view_split_reg_enter\n"); + GtkTreePath *path; + GtkTreeViewColumn *col_current; + + gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, &col_current); + +g_print("gnc_tree_view_split_reg_enter column title is %s\n", gtk_tree_view_column_get_title (col_current)); + + /* Make sure we have stopped editing */ + if (col_current != NULL) + finish_edit (col_current); + + gtk_tree_path_free (path); //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)) @@ -3629,7 +3977,7 @@ g_print("gnc_tree_view_split_reg_enter\n"); } -/* Expands the current transaction to reveal splits */ +/* Expands or collapse the current transaction */ void gnc_tree_view_split_reg_expand_current_trans (GncTreeViewSplitReg *view, gboolean expand) { @@ -3652,8 +4000,6 @@ g_print("\ngnc_tree_view_split_reg_expand_current_trans and expand is %d\n", exp gnc_tree_view_split_reg_block_selection (view, TRUE); -//g_print("indices1 %d %d %d expand is %d\n", indices[0], indices[1], indices[2], expand); - if (model->use_double_line) path = gtk_tree_path_new_from_indices (indices[0], 0, -1); else @@ -3674,14 +4020,10 @@ g_print("\ngnc_tree_view_split_reg_expand_current_trans and expand is %d\n", exp gtk_tree_path_free (view->priv->current_path); view->priv->current_path = gtk_tree_path_copy (path); -//g_print("Expanded Path is '%s'\n", gtk_tree_path_to_string (path)); - gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), path); gtk_tree_path_free (path); } - /* Scroll the window to show selection */ -// gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), view->priv->current_path, NULL, TRUE, 0.5, 0.0); } diff --git a/src/gnome-utils/gnc-tree-view-split-reg.h b/src/gnome-utils/gnc-tree-view-split-reg.h index d080585eec1..86d17c5ed48 100644 --- a/src/gnome-utils/gnc-tree-view-split-reg.h +++ b/src/gnome-utils/gnc-tree-view-split-reg.h @@ -55,11 +55,20 @@ typedef struct GFunc moved_cb; gpointer moved_cb_data; + gchar *help_text; + } GncTreeViewSplitReg; typedef struct { GncTreeViewClass gnc_tree_view; + + /* This signal is emitted when we update the view */ + void (*update_signal) (GncTreeViewSplitReg *view, gpointer user_data); + + /* This signal is emitted when we update the help text */ + void (*help_signal) (GncTreeViewSplitReg *view, gpointer user_data); + } GncTreeViewSplitRegClass; typedef enum { diff --git a/src/gnome/gnc-plugin-page-register2.c b/src/gnome/gnc-plugin-page-register2.c index 82bd2dcabe1..9115716a245 100644 --- a/src/gnome/gnc-plugin-page-register2.c +++ b/src/gnome/gnc-plugin-page-register2.c @@ -728,7 +728,7 @@ gnc_plugin_page_register2_finalize (GObject *object) { GncPluginPageRegister2 *page; GncPluginPageRegister2Private *priv; - +//g_print("gnc_plugin_page_register2_finalize\n"); g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER2 (object)); ENTER("object %p", object); @@ -914,7 +914,7 @@ g_print("Register New Create\n"); LEAVE("existing widget %p", priv->widget); return priv->widget; } - +g_print("Register New Create - page %p\n", page); priv->widget = gtk_vbox_new (FALSE, 0); gtk_widget_show (priv->widget); @@ -1053,8 +1053,8 @@ gnc_plugin_page_register2_destroy_widget (GncPluginPage *plugin_page) ENTER("page %p", plugin_page); page = GNC_PLUGIN_PAGE_REGISTER2 (plugin_page); priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE(plugin_page); - - gnc_gconf_general_remove_cb(KEY_SUMMARYBAR_POSITION, +//g_print("gnc_plugin_page_register2_destroy_widget\n"); + gnc_gconf_general_remove_cb (KEY_SUMMARYBAR_POSITION, gnc_plugin_page_register2_summarybar_position_changed, page); if (priv->widget == NULL) @@ -1062,29 +1062,36 @@ gnc_plugin_page_register2_destroy_widget (GncPluginPage *plugin_page) if (priv->component_manager_id) { - gnc_unregister_gui_component(priv->component_manager_id); + gnc_unregister_gui_component (priv->component_manager_id); priv->component_manager_id = 0; } if (priv->event_handler_id) { - qof_event_unregister_handler(priv->event_handler_id); + qof_event_unregister_handler (priv->event_handler_id); priv->event_handler_id = 0; } if (priv->sd.dialog) { - gtk_widget_destroy(priv->sd.dialog); + gtk_widget_destroy (priv->sd.dialog); memset(&priv->sd, 0, sizeof(priv->sd)); } if (priv->fd.dialog) { - gtk_widget_destroy(priv->fd.dialog); + gtk_widget_destroy (priv->fd.dialog); memset(&priv->fd, 0, sizeof(priv->fd)); } - gtk_widget_hide(priv->widget); + gtk_widget_hide (priv->widget); + + if (priv->widget) + { + g_object_unref (G_OBJECT(priv->widget)); + priv->widget = NULL; + } + gnc_ledger_display2_close (priv->ledger); priv->ledger = NULL; LEAVE(" "); @@ -1099,11 +1106,11 @@ gnc_plugin_page_register2_window_changed (GncPluginPage *plugin_page, g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER2 (plugin_page)); - page = GNC_PLUGIN_PAGE_REGISTER2(plugin_page); - priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE(page); + page = GNC_PLUGIN_PAGE_REGISTER2 (plugin_page); + priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE (page); /* priv->gsr->window = - GTK_WIDGET(gnc_window_get_gtk_window(GNC_WINDOW(window))); + GTK_WIDGET(gnc_window_get_gtk_window (GNC_WINDOW (window))); */ } @@ -1379,7 +1386,7 @@ gnc_plugin_page_register2_finish_pending (GncPluginPage *page) priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE(reg_page); model = gnc_ledger_display2_get_split_model_register(priv->ledger); -/*FIXME if (!model || !gnc_split_register_changed(model)) */ +/*FIXME if (!model || !gnc_split_register_changed (model)) */ return TRUE; name = gnc_plugin_page_register2_get_tab_name(page); @@ -1410,11 +1417,11 @@ gnc_plugin_page_register2_finish_pending (GncPluginPage *page) switch (response) { case GTK_RESPONSE_ACCEPT: -/*FIXME gnc_split_register_save(model, TRUE); */ +/*FIXME gnc_split_register_save (model, TRUE); */ return TRUE; case GTK_RESPONSE_REJECT: -/*FIXME gnc_split_register_cancel_cursor_trans_changes(model); */ +/*FIXME gnc_split_register_cancel_cursor_trans_changes (model); */ /*FIXME gnc_split_register_save (model, TRUE); */ return TRUE; @@ -3416,7 +3423,6 @@ gnc_plugin_page_register2_cmd_jump (GtkAction *action, LEAVE("couldn't create new page"); return; } - new_reg_page = GNC_PLUGIN_PAGE_REGISTER2 (new_page); gnc_main_window_open_page (GNC_MAIN_WINDOW (window), new_page); gsr = gnc_plugin_page_register2_get_gsr (new_page); @@ -3608,29 +3614,28 @@ gnc_plugin_page_register2_get_gsr (GncPluginPage *plugin_page) } static void -gnc_plugin_page_help_changed_cb (GNCSplitReg2 *gsr, GncPluginPageRegister2 *register_page) +gnc_plugin_page_help_changed_cb (GNCSplitReg2 *gsr, GncPluginPageRegister2 *register_page) //this works { GncPluginPageRegister2Private *priv; - SplitRegister *reg; + GncTreeViewSplitReg *view; GncWindow *window; char *help; +//g_print("gnc_plugin_page_help_changed_cb register_page is %p\n", register_page); + g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER2 (register_page)); - g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER2(register_page)); - - window = GNC_WINDOW(GNC_PLUGIN_PAGE(register_page)->window); + window = GNC_WINDOW (GNC_PLUGIN_PAGE (register_page)->window); if (!window) { // This routine can be called before the page is added to a // window. return; } - - /* Get the text from the ledger */ - priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE(register_page); - reg = gnc_ledger_display2_get_split_register(priv->ledger); - help = gnc_table_get_help(reg->table); - gnc_window_set_status(window, GNC_PLUGIN_PAGE(register_page), help); - g_free(help); + /* Get the text from the view */ + priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE (register_page); + view = gnc_ledger_display2_get_split_view_register (priv->ledger); + help = g_strdup (view->help_text); //FIXME might need to be a function + gnc_window_set_status (window, GNC_PLUGIN_PAGE (register_page), help); + g_free (help); } static void @@ -3664,7 +3669,7 @@ gnc_plugin_page_register2_refresh_cb (GHashTable *changes, gpointer user_data) //g_print("gnc_plugin_page_register2_refresh_cb 2\n"); /* Force updates */ -/*FIXME gnucash_register_refresh_from_gconf(priv->gsr->reg); */ +/*FIXME gnucash_register_refresh_from_gconf (priv->gsr->reg); */ gtk_widget_queue_draw(priv->widget); } diff --git a/src/gnome/gnc-split-reg2.c b/src/gnome/gnc-split-reg2.c index 5e1c82598e2..ddf4fbb55b7 100644 --- a/src/gnome/gnc-split-reg2.c +++ b/src/gnome/gnc-split-reg2.c @@ -119,7 +119,7 @@ void gsr2_default_unvoid_txn_handler ( GNCSplitReg2 *w, gpointer ud ); void gsr2_default_reverse_txn_handler ( GNCSplitReg2 *w, gpointer ud ); static void gsr2_emit_simple_signal( GNCSplitReg2 *gsr, const char *sigName ); -/*FIXME static void gsr2_emit_help_changed( GncTreeViewSplitReg *view, gpointer user_data ); */ +static void gsr2_emit_help_changed (GncTreeViewSplitReg *view, gpointer user_data); static void gsr2_emit_include_date_signal( GNCSplitReg2 *gsr, time_t date ); void gnc_split_reg2_cut_cb(GtkWidget *w, gpointer data); @@ -446,7 +446,6 @@ g_print("gsr2_create_table\n"); /* This column gets all the free space */ gnc_tree_view_expand_columns (GNC_TREE_VIEW (view), "descnotes", NULL); - /*FIXME is this OK ? - Set the Reconcile column width */ col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW (view), "recn"); if (col != NULL) @@ -485,29 +484,31 @@ g_print("gsr2_create_table\n"); g_signal_connect (gsr->reg, "redraw_all", G_CALLBACK(gsr2_redraw_all_cb), gsr); */ -/*FIXME I think this is to do with the help text at the bottom, we need to connect this to some thing - g_signal_connect (gsr->reg, "redraw_help", - G_CALLBACK(gsr2_emit_help_changed), gsr); */ + + g_signal_connect (view, "help_signal", + G_CALLBACK (gsr2_emit_help_changed), gsr); // this works + LEAVE(" "); } static void -gsr2_setup_status_widgets( GNCSplitReg2 *gsr ) +gsr2_setup_status_widgets (GNCSplitReg2 *gsr) { GncTreeModelSplitReg *model; gboolean use_double_line; - model = gnc_ledger_display2_get_split_model_register( gsr->ledger ); - use_double_line = gnc_ledger_display2_default_double_line( gsr->ledger ); + model = gnc_ledger_display2_get_split_model_register (gsr->ledger); + use_double_line = gnc_ledger_display2_default_double_line (gsr->ledger); /* be sure to initialize the gui elements */ - gnc_tree_model_split_reg_config( model, model->type, model->style, use_double_line ); + gnc_tree_model_split_reg_config (model, model->type, model->style, use_double_line); } void -gnc_split_reg2_destroy_cb(GtkWidget *widget, gpointer data) +gnc_split_reg2_destroy_cb (GtkWidget *widget, gpointer data) { +//g_print("gnc_split_reg2_destroy_cb - does not do any thing\n"); } /** @@ -532,13 +533,13 @@ gnc_split_reg2_raise( GNCSplitReg2 *gsr ) **/ static void -gsr2_update_summary_label( GtkWidget *label, +gsr2_update_summary_label (GtkWidget *label, xaccGetBalanceFn getter, Account *leader, GNCPrintAmountInfo print_info, gnc_commodity *cmdty, gboolean reverse, - gboolean euroFlag ) + gboolean euroFlag) { gnc_numeric amount; char string[256]; @@ -603,9 +604,9 @@ account_latest_price_any_currency (Account *account) price_list = gnc_pricedb_lookup_latest_any_currency (pdb, commodity); if (!price_list) return NULL; - result = gnc_price_clone((GNCPrice *)(price_list->data), book); + result = gnc_price_clone ((GNCPrice *)(price_list->data), book); - gnc_price_list_destroy(price_list); + gnc_price_list_destroy (price_list); return result; } @@ -2015,7 +2016,7 @@ gsr2_create_summary_bar( GNCSplitReg2 *gsr ) gsr->summarybar = summarybar; /* Force the first update */ - gsr2_redraw_all_cb(NULL, gsr); + gsr2_redraw_all_cb (NULL, gsr); return gsr->summarybar; } @@ -2163,7 +2164,7 @@ gnc_split_reg2_get_parent( GNCLedgerDisplay2 *ledger ) static void -gsr2_emit_help_changed (GncTreeViewSplitReg *view, gpointer user_data ) +gsr2_emit_help_changed (GncTreeViewSplitReg *view, gpointer user_data ) //this works { gsr2_emit_simple_signal ((GNCSplitReg2*)user_data, "help-changed" ); } @@ -2177,7 +2178,7 @@ gsr2_emit_include_date_signal( GNCSplitReg2 *gsr, time_t date ) static void -gsr2_emit_simple_signal( GNCSplitReg2 *gsr, const char *sigName ) +gsr2_emit_simple_signal( GNCSplitReg2 *gsr, const char *sigName ) //this works { g_signal_emit_by_name( gsr, sigName, NULL ); } @@ -2219,7 +2220,7 @@ gnc_split_reg2_get_read_only( GNCSplitReg2 *gsr ) } void -gnc_split_reg2_set_moved_cb( GNCSplitReg2 *gsr, GFunc cb, gpointer cb_data ) +gnc_split_reg2_set_moved_cb( GNCSplitReg2 *gsr, GFunc cb, gpointer cb_data ) //this works { g_print("gnc_split_reg2_set_moved_cb\n"); gnc_tree_view_split_reg_moved_cb (gnc_ledger_display2_get_split_view_register(gsr->ledger), cb, cb_data); diff --git a/src/register/ledger-core/gnc-ledger-display2.c b/src/register/ledger-core/gnc-ledger-display2.c index 79fe57a2c58..0eeb892937a 100644 --- a/src/register/ledger-core/gnc-ledger-display2.c +++ b/src/register/ledger-core/gnc-ledger-display2.c @@ -612,7 +612,7 @@ refresh_handler (GHashTable *changes, gpointer user_data) */ splits = qof_query_run (ld->query); -// gnc_ledger_display2_set_watches (ld, splits); + gnc_ledger_display2_set_watches (ld, splits); gnc_ledger_display2_refresh_internal (ld, splits); LEAVE(" "); @@ -625,7 +625,7 @@ close_handler (gpointer user_data) if (!ld) return; - +//g_print("ledger close_handler\n"); gnc_unregister_gui_component (ld->component_id); if (ld->destroy) @@ -633,6 +633,7 @@ close_handler (gpointer user_data) gnc_tree_model_split_reg_destroy (ld->model); ld->model = NULL; + ld->view = NULL; qof_query_destroy (ld->query); ld->query = NULL; @@ -821,7 +822,7 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q, splits = qof_query_run (ld->query); -// gnc_ledger_display2_set_watches (ld, splits); + gnc_ledger_display2_set_watches (ld, splits); gnc_ledger_display2_refresh_internal (ld, splits); @@ -890,11 +891,11 @@ g_print("gnc_ledger_display2_refresh_internal\n"); else { ld->loading = TRUE; - +/*FIXME All this may not be required !!!!! */ smodel = gtk_tree_view_get_model (GTK_TREE_VIEW (ld->view)); // this is the sort model model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (smodel)); // our model - +//g_print("view is %p model is %p and smodel is %p\n", ld->view, model, smodel); g_object_ref (smodel); g_object_ref (model); @@ -904,10 +905,10 @@ g_print("gnc_ledger_display2_refresh_internal\n"); gnc_tree_model_split_reg_load (ld->model, splits, gnc_ledger_display2_leader (ld)); //reload splits -// smodel = gtk_tree_model_sort_new_with_model (model); // create new sort model +//Not needed smodel = gtk_tree_model_sort_new_with_model (model); // create new sort model gtk_tree_view_set_model (GTK_TREE_VIEW(ld->view), GTK_TREE_MODEL (smodel)); // Re-attach sort model to view - +//g_print("view is %p model is %p and smodel is %p\n", ld->view, model, smodel); gnc_tree_view_split_reg_block_selection (ld->view, FALSE); // This unblocks the tree selection /* Set the default selection start position */ @@ -981,7 +982,6 @@ gnc_ledger_display2_refresh_by_split_register (GncTreeModelSplitReg *model) } } - void gnc_ledger_display2_set_split_view_refresh (GNCLedgerDisplay2 *ld, gboolean ok) { @@ -990,11 +990,12 @@ gnc_ledger_display2_set_split_view_refresh (GNCLedgerDisplay2 *ld, gboolean ok) ld->refresh_ok = ok; } + void gnc_ledger_display2_close (GNCLedgerDisplay2 *ld) { if (!ld) return; - +//g_print("gnc_ledger_display2_close\n"); gnc_close_gui_component (ld->component_id); }