r14528 - gnucash/branches/register-rewrite/src/gnome-utils - Factor out code for getting the currently selected trans and split.
Chris Shoemaker
chris at cvs.gnucash.org
Sun Jul 16 20:23:57 EDT 2006
Author: chris
Date: 2006-07-16 20:23:56 -0400 (Sun, 16 Jul 2006)
New Revision: 14528
Trac: http://svn.gnucash.org/trac/changeset/14528
Modified:
gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.c
gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.h
Log:
Factor out code for getting the currently selected trans and split.
Factor code for returning the cursor to the edited trans.
Factor code for canceling an edit.
Provide functions that: move to the blank trans, reinit the current trans,
void/unvoid the current trans
Modified: gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.c
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.c 2006-07-17 00:18:13 UTC (rev 14527)
+++ gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.c 2006-07-17 00:23:56 UTC (rev 14528)
@@ -70,6 +70,7 @@
#include "gnc-exp-parser.h"
#include "dialog-transfer.h"
#include "dialog-utils.h"
+#include "gnc-gui-query.h"
#define SPLIT_TRANS_STR _("-- Split Transaction --")
@@ -306,6 +307,7 @@
}
+#define get_selected_split gnc_tree_view_transaction_get_selected_split
Split *
gnc_tree_view_transaction_get_selected_split(GncTreeViewTransaction *tv)
{
@@ -321,6 +323,22 @@
return split;
}
+#define get_selected_trans gnc_tree_view_transaction_get_selected_trans
+Transaction *
+gnc_tree_view_transaction_get_selected_trans(GncTreeViewTransaction *tv)
+{
+ GtkTreeIter iter;
+ GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
+ Transaction *trans = NULL;
+
+ if (get_model_iter_from_selection(tv, sel, &iter)) {
+ GncTreeModelTransaction *model = get_trans_model_from_view(tv);
+ gnc_tree_model_transaction_get_split_and_trans(
+ model, &iter, NULL, NULL, NULL, &trans);
+ }
+ return trans;
+}
+
static GtkTreePath *
get_view_path_from_model_iter(GncTreeViewTransaction *tv, GtkTreeIter *iter)
{
@@ -1066,6 +1084,16 @@
}
}
+void
+gnc_tree_view_transaction_cancel_edit(GncTreeViewTransaction *tv)
+{
+ Transaction *t = tv->priv->dirty_trans;
+
+ if (t && xaccTransIsOpen(t)) {
+ xaccTransRollbackEdit(tv->priv->dirty_trans);
+ tv->priv->dirty_trans = NULL;
+ }
+}
/* Returns TRUE if dialog was cancelled. Does nothing is 'new_trans'
is the dirty trans. */
static gboolean
@@ -1104,8 +1132,7 @@
break;
case GTK_RESPONSE_REJECT:
- xaccTransRollbackEdit(tv->priv->dirty_trans);
- tv->priv->dirty_trans = NULL;
+ gnc_tree_view_transaction_cancel_edit(tv);
break;
case GTK_RESPONSE_CANCEL:
default:
@@ -1116,6 +1143,21 @@
}
static void
+restore_cursor_to_dirty(GncTreeViewTransaction *tv)
+{
+ GtkTreeIter iter;
+ GncTreeModelTransaction *model = get_trans_model_from_view(tv);
+
+ /* FIXME?: restore split cursor */
+ if (gnc_tree_model_transaction_get_iter_from_trans_and_split(
+ model, tv->priv->dirty_trans, NULL, &iter)) {
+ GtkTreePath *path = get_view_path_from_model_iter(tv, &iter);
+ GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
+ gtk_tree_selection_select_path(sel, path);
+ }
+}
+
+static void
//motion_cb(GtkTreeView *tv, gpointer data)
motion_cb(GtkTreeSelection *sel, gpointer data)
{
@@ -1125,30 +1167,50 @@
GtkTreeIter iter;
GncTreeViewTransaction *tv = GNC_TREE_VIEW_TRANSACTION(data);
GncTreeModelTransaction *model; // = GNC_TREE_MODEL_TRANSACTION(data);
- Split *split;
Transaction *trans = NULL;
model = get_trans_model_from_view(tv);
mark_split_dirty(tv, NULL, NULL);
if (get_model_iter_from_selection(tv, sel, &iter)) {
- gboolean is_split, is_blank;
gnc_tree_model_transaction_get_split_and_trans (
- model, &iter, &is_split, &is_blank, &split, &trans);
+ model, &iter, NULL, NULL, NULL, &trans);
if (transaction_changed_confirm(tv, trans)) {
/* Restore cursor position */
- if (gnc_tree_model_transaction_get_iter_from_trans(
- model, tv->priv->dirty_trans, &iter)) {
- GtkTreePath *path;
- path = get_view_path_from_model_iter(tv, &iter);
- gtk_tree_selection_select_path(sel, path);
- }
+ restore_cursor_to_dirty(tv);
} else
gnc_tree_model_transaction_set_blank_split_parent(model, trans);
}
}
+void
+gnc_tree_view_transaction_select_split(GncTreeViewTransaction *tv,
+ Split *split)
+{
+ GtkTreeIter iter;
+ GncTreeModelTransaction *model = get_trans_model_from_view(tv);
+
+ if (gnc_tree_model_transaction_get_iter_from_trans_and_split(
+ model, NULL, split, &iter)) {
+ GtkTreePath *path = get_view_path_from_model_iter(tv, &iter);
+ GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
+ gtk_tree_selection_select_path(sel, path);
+ }
+}
+
+void gnc_tree_view_transaction_goto_blank_trans(GncTreeViewTransaction *tv)
+{
+ GtkTreeIter iter;
+ GncTreeModelTransaction *model = get_trans_model_from_view(tv);
+
+ if (gnc_tree_model_transaction_get_blank_trans_iter(model, &iter)) {
+ GtkTreePath *path = get_view_path_from_model_iter(tv, &iter);
+ GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
+ gtk_tree_selection_select_path(sel, path);
+ }
+}
+
/* Note: These next three functions are for handling the editable
account combo box cell. There are at least two ways of doing this:
We could just catch the "edited" signal offered by
@@ -1203,7 +1265,7 @@
old_acct = xaccSplitGetAccount(split);
if (old_acct != new_acct) {
- gnc_numeric input, reg_rate;
+ gnc_numeric input;
gnc_commodity *reg_comm = tv->priv->reg_comm;
PINFO("setting %s to %s", xaccAccountGetName(old_acct),
@@ -1215,8 +1277,8 @@
transaction currency into the register commodity. If
we allowed the loss of this info, we wouldn't know what
to display for any split. */
- if (xaccTransGetRateForCommodity(
- trans, reg_comm, split, ®_rate)) {
+ if (!old_acct ||
+ xaccTransGetRateForCommodity(trans, reg_comm, split, NULL)) {
begin_edit(tv, NULL, trans);
mark_split_dirty(tv, split, trans);
xaccSplitSetAccount(split, new_acct);
@@ -1331,6 +1393,27 @@
}
}
}
+
+void
+gnc_tree_view_transaction_reinit_trans(GncTreeViewTransaction *tv)
+{
+ Transaction *trans;
+
+ trans = get_selected_trans(tv);
+ if (trans) {
+ Split *s;
+ int i = 0;
+
+ begin_edit(tv, NULL, trans);
+ while ((s = xaccTransGetSplit(trans, i)) != NULL) {
+ if (xaccTransGetRateForCommodity(
+ trans, tv->priv->reg_comm, s, NULL))
+ xaccSplitDestroy(s);
+ else i++;
+ }
+ }
+}
+
#if 0
static gboolean
@@ -1479,7 +1562,7 @@
/* CONTROL */
static gboolean
-gtvt_key_press_cb(GtkWidget *treeview, GdkEventKey *event, gpointer userdata)
+gtvt_key_press_cb(GtkWidget *treeview, GdkEventKey *event, gpointer unused)
{
GtkTreeView *tv = GTK_TREE_VIEW(treeview);
GtkTreeViewColumn *col;
@@ -1510,8 +1593,69 @@
return TRUE;
}
+void
+gnc_tree_view_transaction_enter(GncTreeViewTransaction *tv)
+{
+ GdkEventKey event;
+ event.type = GDK_KEY_PRESS;
+ event.keyval = GDK_Return;
+ gtvt_key_press_cb(GTK_WIDGET(tv), &event, NULL);
+}
+
Account *
gnc_tree_view_transaction_get_anchor(GncTreeViewTransaction *tv)
{
return tv->priv->anchor; /* cached from model */
}
+
+void
+gnc_tree_view_transaction_void(GncTreeViewTransaction *tv)
+{
+ const char *reason;
+ GtkWidget *dialog, *entry;
+ Transaction *trans;
+ GladeXML *xml;
+ gint result;
+
+ trans = get_selected_trans(tv);
+ if (!trans || xaccTransHasSplitsInState(trans, VREC))
+ return;
+
+ if (xaccTransHasReconciledSplits(trans) ||
+ xaccTransHasSplitsInState(trans, CREC)) {
+ gnc_error_dialog(NULL, _("You cannot void a transaction with "
+ "reconciled or cleared splits."));
+ return;
+ }
+
+ xml = gnc_glade_xml_new("register.glade", "Void Transaction");
+ dialog = glade_xml_get_widget(xml, "Void Transaction");
+ entry = glade_xml_get_widget(xml, "reason");
+
+ result = gtk_dialog_run(GTK_DIALOG(dialog));
+ if (result == GTK_RESPONSE_OK) {
+ reason = gtk_entry_get_text(GTK_ENTRY(entry));
+ if (reason == NULL)
+ reason = "";
+ begin_edit(tv, NULL, trans);
+ xaccTransVoid(trans, reason);
+ }
+
+ /* All done. Get rid of it. */
+ gtk_widget_destroy(dialog);
+ g_object_unref(xml);
+}
+
+void
+gnc_tree_view_transaction_unvoid(GncTreeViewTransaction *tv)
+{
+
+ Transaction *trans = get_selected_trans(tv);
+
+ if (!trans || !xaccTransHasSplitsInState(trans, VREC))
+ return;
+
+ begin_edit(tv, NULL, trans);
+ xaccTransUnvoid(trans);
+}
+
Modified: gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.h
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.h 2006-07-17 00:18:13 UTC (rev 14527)
+++ gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-view-transaction.h 2006-07-17 00:23:56 UTC (rev 14528)
@@ -68,12 +68,29 @@
Account *
gnc_tree_view_transaction_get_anchor(GncTreeViewTransaction *tv);
-Split *
+Split *
gnc_tree_view_transaction_get_selected_split(GncTreeViewTransaction *tv);
+Transaction *
+gnc_tree_view_transaction_get_selected_trans(GncTreeViewTransaction *tv);
-void
-gnc_tree_view_transaction_delete_selected(GncTreeViewTransaction *tv);
+void gnc_tree_view_transaction_delete_selected(GncTreeViewTransaction *tv);
+void gnc_tree_view_transaction_reinit_trans(GncTreeViewTransaction *tv);
+
+void gnc_tree_view_transaction_enter(GncTreeViewTransaction *tv);
+
+void gnc_tree_view_transaction_cancel_edit(GncTreeViewTransaction *tv);
+
+void gnc_tree_view_transaction_void(GncTreeViewTransaction *tv);
+void gnc_tree_view_transaction_unvoid(GncTreeViewTransaction *tv);
+
+
+void gnc_tree_view_transaction_goto_blank_trans(GncTreeViewTransaction *tv);
+
+void gnc_tree_view_transaction_select_split(GncTreeViewTransaction *tv,
+ Split *split);
+
+
/** @} */
More information about the gnucash-changes
mailing list