[PATCH] Updated add/edit account window
Andreas Köhler
andi5.py at gmx.net
Wed Feb 15 12:40:10 EST 2006
Hi,
On Monday, 16 Jan 2006, 16:49 CET, Eskil Bylund wrote:
> Here's a patch that updates the add/edit account window. Changes are:
>
> * src/gnome/glade/account.glade
> * src/gnome-utils/dialog-account.c: Clean up the Account dialog.
> Replace the account type clist with a GtkComboBox. Update the title
> when changing parent account.
>
> By the way. The GnomeDateEdit in the opening balance notebook allows
> one to set not only the date but also the time. Is this time ever
> used? If not, the GnomeDateEdit should be set to only display the
> date.
@Eskil:
I am sorry, I did not follow/remember this thread, so my patch
([13259]) did not make use of your work. I rather saw a CList and
thought that nobody has cared yet.
Here is a patch that tries to replace the list store with a filtered
GncTreeModelAccountTypes. If you do not want to go this way (do not
think so), there are still two open bugs in my own code ;)
What it does:
* uses a filtered GncTreeModelAccountTypes with eigher
aw->valid_types or xaccAccountTypesValid | 1<< aw->type
* adds gnc_tree_model_account_types_get_iter_from_type to set an
iter to a specific type
* some minor changes, including one to
gnc_tree_model_account_types_get_flags
What do you think?
-- andi5
-------------- next part --------------
Index: src/gnome-utils/gnc-tree-model-account-types.c
===================================================================
--- src/gnome-utils/gnc-tree-model-account-types.c (revision 13259)
+++ src/gnome-utils/gnc-tree-model-account-types.c (working copy)
@@ -199,7 +199,7 @@
void
gnc_tree_model_account_types_set_selected (GncTreeModelAccountTypes * model,
- guint32 selected)
+ guint32 selected)
{
GncTreeModelAccountTypesPrivate *priv;
@@ -248,7 +248,7 @@
{
GtkTreePath *path;
gint *path_idx;
- guint i;
+ gint i;
GtkTreeSelection *sel;
@@ -271,10 +271,10 @@
/* Static functions implementing GtkTreeModel */
-static guint
+static GtkTreeModelFlags
gnc_tree_model_account_types_get_flags (GtkTreeModel * tree_model)
{
- return 0;
+ return GTK_TREE_MODEL_ITERS_PERSIST | GTK_TREE_MODEL_LIST_ONLY;
}
static int
@@ -294,7 +294,7 @@
switch (index) {
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE:
- return G_TYPE_UINT;
+ return G_TYPE_INT;
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME:
return G_TYPE_STRING;
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_SELECTED:
@@ -327,6 +327,23 @@
return FALSE;
}
+gboolean
+gnc_tree_model_account_types_get_iter_from_type (
+ GncTreeModelAccountTypes * tree_model,
+ GtkTreeIter * iter,
+ GNCAccountType type)
+{
+ GtkTreePath *path;
+ gboolean retval;
+
+ path = gtk_tree_path_new_from_indices (type, -1);
+ retval = gnc_tree_model_account_types_get_iter (GTK_TREE_MODEL (tree_model),
+ iter, path);
+ gtk_tree_path_free (path);
+
+ return retval;
+}
+
static GtkTreePath *
gnc_tree_model_account_types_get_path (GtkTreeModel * tree_model,
GtkTreeIter * iter)
@@ -347,7 +364,7 @@
static void
gnc_tree_model_account_types_get_value (GtkTreeModel * tree_model,
- GtkTreeIter * iter, int column,
+ GtkTreeIter * iter, int column,
GValue * value)
{
GncTreeModelAccountTypes *model = GNC_TREE_MODEL_ACCOUNT_TYPES(tree_model);
@@ -400,7 +417,7 @@
static gboolean
gnc_tree_model_account_types_iter_children (GtkTreeModel * tree_model,
- GtkTreeIter * iter,
+ GtkTreeIter * iter,
GtkTreeIter * parent)
{
@@ -439,7 +456,7 @@
static gboolean
gnc_tree_model_account_types_iter_nth_child (GtkTreeModel * tree_model,
- GtkTreeIter * iter,
+ GtkTreeIter * iter,
GtkTreeIter * parent, int n)
{
GncTreeModelAccountTypes *model;
Index: src/gnome-utils/gnc-tree-model-account-types.h
===================================================================
--- src/gnome-utils/gnc-tree-model-account-types.h (revision 13259)
+++ src/gnome-utils/gnc-tree-model-account-types.h (working copy)
@@ -38,6 +38,8 @@
#ifndef __GNC_TREE_MODEL_ACCOUNT_TYPES_H
#define __GNC_TREE_MODEL_ACCOUNT_TYPES_H
+#include "Account.h"
+
G_BEGIN_DECLS
/* type macros */
@@ -94,7 +96,8 @@
/* Get the static GtkTreeModel representing the list of all possible
account types. You may not modify this model, but you can use if
- for multiple views. You probably want gnc_tree_model_types_valid(). */
+ for multiple views. You probably want
+ gnc_tree_model_account_types_valid(). */
GtkTreeModel * gnc_tree_model_account_types_master(void);
/* Returns a GtkTreeModelFilter that wraps the model. Deprecated
@@ -106,11 +109,18 @@
/* Returns a GtkTreeModelFilter that wraps the model. Only account
types specified by the 'types' bitmask are visible. To force the
visibility of deprecated account types, pass
- (xaccAccountTypesValid() & (1 << MY_DEPRECATED_ACCOUNT_TYPE)).
+ (xaccAccountTypesValid() | (1 << MY_DEPRECATED_ACCOUNT_TYPE)).
Caller is responsible for ref/unref. */
GtkTreeModel * gnc_tree_model_account_types_filter_using_mask (guint32 types);
+/* If 'type' is a type, sets 'iter' to the iterator pointing to that type and
+ returns TRUE. Otherwise returns FALSE and makes 'iter' invalid. */
+gboolean gnc_tree_model_account_types_get_iter_from_type(
+ GncTreeModelAccountTypes *model,
+ GtkTreeIter *iter,
+ GNCAccountType type);
+
/* Return the bitmask of the account type enums reflecting the state
of the tree selection */
guint32 gnc_tree_model_account_types_get_selection(GtkTreeView *view);
Index: src/gnome-utils/dialog-account.c
===================================================================
--- src/gnome-utils/dialog-account.c (revision 13259)
+++ src/gnome-utils/dialog-account.c (working copy)
@@ -41,6 +41,7 @@
#include "gnc-engine.h"
#include "gnc-gui-query.h"
#include "gnc-session.h"
+#include "gnc-tree-model-account-types.h"
#include "gnc-tree-view-account.h"
#include "gnc-ui.h"
#include "gnc-ui-util.h"
@@ -56,13 +57,6 @@
EDIT_ACCOUNT
} AccountDialogType;
-typedef enum
-{
- COL_TYPE_TEXT,
- COL_TYPE_ID,
- NUM_TYPE_COLUMNS
-} AccountTypeColumns;
-
typedef struct _AccountWindow
{
gboolean modal;
@@ -1090,7 +1084,7 @@
GtkTreeModel *model;
GtkTreeIter iter;
gboolean sensitive;
- guint type_id;
+ gint type_id;
g_return_if_fail (aw != NULL);
@@ -1100,9 +1094,11 @@
aw->type = BAD_TYPE;
} else {
- gtk_tree_model_get (model, &iter, COL_TYPE_ID, &type_id, -1);
+ gtk_tree_model_get (model, &iter,
+ GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE, &type_id,
+ -1);
aw->type = type_id;
- last_used_account_type = aw->type;
+ last_used_account_type = type_id;
gnc_account_commodity_from_type (aw, TRUE);
@@ -1120,36 +1116,6 @@
}
}
-static void
-gnc_account_type_store_fill (GtkListStore *store, GList *types)
-{
- GtkTreeIter iter;
- gint acct_type;
- gchar *text;
-
- gtk_list_store_clear (store);
-
- if (types == NULL) {
- for (acct_type = 0; acct_type < NUM_ACCOUNT_TYPES; acct_type++) {
- text = (gchar *) xaccAccountGetTypeStr (acct_type);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COL_TYPE_TEXT, text,
- COL_TYPE_ID, GINT_TO_POINTER(acct_type),
- -1);
- }
- } else {
- for ( ; types != NULL; types = types->next ) {
- text = (gchar *) xaccAccountGetTypeStr ((GNCAccountType) (types->data));
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COL_TYPE_TEXT, text,
- COL_TYPE_ID, types->data,
- -1);
- }
- }
-}
-
static GNCAccountType
gnc_account_choose_new_acct_type (AccountWindow *aw)
{
@@ -1163,40 +1129,20 @@
return ((GNCAccountType)(aw->valid_types->data));
}
-static gboolean
-gnc_account_type_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GNCAccountType type)
-{
- guint type_id;
-
- gtk_tree_model_get_iter_first (model, iter);
-
- do {
- gtk_tree_model_get (model, iter, COL_TYPE_ID, &type_id, -1);
- if (type == type_id)
- return TRUE;
- } while (gtk_tree_model_iter_next (model, iter));
-
- return FALSE;
-}
-
static void
gnc_account_type_view_create (AccountWindow *aw)
{
- GtkTreeModel *model;
- GtkTreeSelection *selection;
+ GtkTreeModel *model, *f_model;
GtkTreeIter iter;
- GtkTreePath *path;
+ GtkTreeSelection *selection;
+ GtkTreePath *path, *f_path;
GtkCellRenderer *renderer;
GtkTreeView *view;
+ GList *type_list;
+ guint32 types;
- model = GTK_TREE_MODEL (gtk_list_store_new (NUM_TYPE_COLUMNS,
- G_TYPE_STRING,
- G_TYPE_UINT));
- gnc_account_type_store_fill (GTK_LIST_STORE (model), aw->valid_types);
+ model = gnc_tree_model_account_types_master ();
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
- COL_TYPE_TEXT, GTK_SORT_ASCENDING);
-
switch (aw->dialog_type) {
case NEW_ACCOUNT:
aw->type = gnc_account_choose_new_acct_type (aw);
@@ -1206,23 +1152,41 @@
break;
}
+ if (aw->valid_types == NULL) {
+ types = xaccAccountTypesValid () | (1 << aw->type);
+ } else {
+ types = 0;
+ for (type_list=aw->valid_types; type_list; type_list=g_list_next (type_list))
+ types |= (1 << (guint)type_list->data);
+ }
+
+ f_model = gnc_tree_model_account_types_filter_using_mask (types);
+
view = GTK_TREE_VIEW (aw->type_view);
- gtk_tree_view_set_model (view, model);
+ gtk_tree_view_set_model (view, f_model);
+ g_object_unref (G_OBJECT (f_model));
+
renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (view, -1, NULL,
- renderer, "text", COL_TYPE_TEXT,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ view, -1, NULL, renderer,
+ "text", GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME,
+ NULL);
selection = gtk_tree_view_get_selection (view);
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_account_type_changed_cb), aw);
- if (gnc_account_type_get_iter (model, &iter, aw->type)) {
- gtk_tree_selection_select_iter (selection, &iter);
-
- path = gtk_tree_model_get_path (model, &iter);
- gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0.0, 0.0);
- gtk_tree_path_free (path);
+ if (gnc_tree_model_account_types_get_iter_from_type (
+ GNC_TREE_MODEL_ACCOUNT_TYPES (model), &iter, aw->type)) {
+ if ((path = gtk_tree_model_get_path (model, &iter)) != NULL) {
+ if ((f_path = gtk_tree_model_filter_convert_child_path_to_path (
+ GTK_TREE_MODEL_FILTER (f_model), path)) != NULL) {
+ gtk_tree_selection_select_path (selection, f_path);
+ gtk_tree_view_scroll_to_cell (view, f_path, NULL, FALSE, 0.0, 0.0);
+ gtk_tree_path_free (f_path);
+ }
+ gtk_tree_path_free (path);
+ }
}
}
More information about the gnucash-devel
mailing list