Use the new account tree view widget.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gnucash-gnome2-dev@9162 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton
2003-08-24 05:50:04 +00:00
parent a6940481fb
commit 45f0153fdd

View File

@@ -32,7 +32,6 @@
#include "druid-stock-split.h"
#include "druid-utils.h"
#include "global-options.h"
#include "gnc-account-tree.h"
#include "gnc-amount-edit.h"
#include "gnc-book.h"
#include "gnc-component-manager.h"
@@ -41,13 +40,15 @@
#include "gnc-engine-util.h"
#include "gnc-exp-parser.h"
#include "gnc-gui-query.h"
#include "gnc-tree-model-account.h"
#include "gnc-tree-view-account.h"
#include "gnc-ui.h"
#include "gnc-ui-util.h"
#include "messages.h"
#define DRUID_STOCK_SPLIT_CM_CLASS "druid-stock-split"
#define NEW 1
/** structures *********************************************************/
typedef struct
@@ -74,9 +75,32 @@ typedef struct
} StockSplitInfo;
/** declarations *******************************************************/
void gnc_stock_split_druid_window_destroy_cb (GtkObject *object, gpointer data);
gboolean gnc_stock_split_druid_account_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data);
void gnc_stock_split_druid_details_prepare (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data);
gboolean gnc_stock_split_druid_details_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data);
void gnc_stock_split_druid_cash_prepare (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data);
gboolean gnc_stock_split_druid_cash_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data);
void gnc_stock_split_druid_finish (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data);
void gnc_stock_split_druid_cancel_druid (GnomeDruid *druid,
gpointer user_data);
/** implementations ****************************************************/
static void
window_destroy_cb (GtkObject *object, gpointer data)
void
gnc_stock_split_druid_window_destroy_cb (GtkObject *object, gpointer data)
{
StockSplitInfo *info = data;
@@ -197,10 +221,10 @@ refresh_details_page (StockSplitInfo *info)
xaccAccountGetCommodity (account));
}
static gboolean
account_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
gboolean
gnc_stock_split_druid_account_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
Account *account;
@@ -232,8 +256,8 @@ gnc_parse_error_dialog (StockSplitInfo *info, const char *error_string)
parse_error_string);
}
static void
details_prepare (GnomeDruidPage *druidpage,
void
gnc_stock_split_druid_details_prepare (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
@@ -242,10 +266,10 @@ details_prepare (GnomeDruidPage *druidpage,
gtk_widget_grab_focus(info->distribution_edit);
}
static gboolean
details_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
gboolean
gnc_stock_split_druid_details_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
gnc_numeric amount;
@@ -287,13 +311,23 @@ details_next (GnomeDruidPage *druidpage,
return FALSE;
}
static void
cash_prepare (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
void
gnc_stock_split_druid_cash_prepare (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
GtkTreeSelection *selection;
#ifdef NEW
gtk_tree_view_expand_all (GTK_TREE_VIEW(info->income_tree));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(info->income_tree));
gtk_tree_selection_unselect_all (selection);
gtk_tree_view_expand_all (GTK_TREE_VIEW(info->asset_tree));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(info->asset_tree));
gtk_tree_selection_unselect_all (selection);
#else
gnc_account_tree_refresh (GNC_ACCOUNT_TREE (info->income_tree));
gnc_account_tree_expand_all (GNC_ACCOUNT_TREE (info->income_tree));
gtk_clist_select_row (GTK_CLIST (info->income_tree), 0, 0);
@@ -301,14 +335,15 @@ cash_prepare (GnomeDruidPage *druidpage,
gnc_account_tree_refresh (GNC_ACCOUNT_TREE (info->asset_tree));
gnc_account_tree_expand_all (GNC_ACCOUNT_TREE (info->asset_tree));
gtk_clist_select_row (GTK_CLIST (info->asset_tree), 0, 0);
#endif
gtk_widget_grab_focus(info->cash_edit);
}
static gboolean
cash_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
gboolean
gnc_stock_split_druid_cash_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
gnc_numeric amount;
@@ -334,8 +369,13 @@ cash_next (GnomeDruidPage *druidpage,
{
Account *account;
#ifdef NEW
if (!gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->income_tree), &account))
account = NULL;
#else
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->income_tree));
#endif
if (!account)
{
const char *message = _("You must select an income account\n"
@@ -344,8 +384,13 @@ cash_next (GnomeDruidPage *druidpage,
return TRUE;
}
#ifdef NEW
if (!gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree), &account))
account = NULL;
#else
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->asset_tree));
#endif
if (!account)
{
const char *message = _("You must select an asset account\n"
@@ -358,10 +403,10 @@ cash_next (GnomeDruidPage *druidpage,
return FALSE;
}
static void
stock_split_finish (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
void
gnc_stock_split_druid_finish (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
GList *account_commits;
@@ -453,8 +498,13 @@ stock_split_finish (GnomeDruidPage *druidpage,
memo = gtk_entry_get_text (GTK_ENTRY (info->memo_entry));
/* asset split */
#ifdef NEW
if (!gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree), &account))
account = NULL;
#else
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->asset_tree));
#endif
split = xaccMallocSplit (gnc_get_current_book ());
@@ -472,8 +522,13 @@ stock_split_finish (GnomeDruidPage *druidpage,
/* income split */
#ifdef NEW
if (!gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->income_tree), &account))
account = NULL;
#else
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->income_tree));
#endif
split = xaccMallocSplit (gnc_get_current_book ());
@@ -501,41 +556,61 @@ stock_split_finish (GnomeDruidPage *druidpage,
gnc_close_gui_component_by_data (DRUID_STOCK_SPLIT_CM_CLASS, info);
}
static void
druid_cancel (GnomeDruid *druid, gpointer user_data)
void
gnc_stock_split_druid_cancel_druid (GnomeDruid *druid, gpointer user_data)
{
StockSplitInfo *info = user_data;
gnc_close_gui_component_by_data (DRUID_STOCK_SPLIT_CM_CLASS, info);
}
static gboolean
gnc_stock_split_druid_view_filter_income (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
Account *account;
GNCAccountType type;
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), iter);
type = xaccAccountGetType(account);
printf("Iter for %s, type is %d, returns %s\n",
xaccAccountGetName (account), type,
(type == INCOME) ? "TRUE" : "FALSE");
return (type == INCOME);
}
static gboolean
gnc_stock_split_druid_view_filter_asset (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
Account *account;
GNCAccountType type;
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), iter);
type = xaccAccountGetType(account);
return ((type == BANK) || (type == CASH) || (type == ASSET));
}
static void
gnc_stock_split_druid_create (StockSplitInfo *info)
{
GtkWidget *page;
GladeXML *xml;
GdkPixbuf *pixbuf;
xml = gnc_glade_xml_new ("stocks.glade", "Stock Split Druid");
info->window = glade_xml_get_widget (xml, "Stock Split Druid");
info->druid = glade_xml_get_widget (xml, "stock_split_druid");
gtk_signal_connect (GTK_OBJECT (info->window), "destroy",
GTK_SIGNAL_FUNC (window_destroy_cb), info);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, info);
gtk_signal_connect (GTK_OBJECT (info->druid), "cancel",
GTK_SIGNAL_FUNC (druid_cancel), info);
/* libglade2 is broken. It should read these from the glade file. */
gnc_druid_set_colors (GNOME_DRUID(info->druid));
gnc_druid_set_watermark_images (GNOME_DRUID(info->druid),
"stock_split_title.png",
"stock_split_watermark.png");
gnome_druid_page_edge_set_title(GNOME_DRUID_PAGE_EDGE(info->druid),
"Stock Split Druid");
gnome_druid_page_edge_set_text (GNOME_DRUID_PAGE_EDGE(info->druid),
"Enter stock split info");
pixbuf = gdk_pixbuf_new_from_file ("stock_split_watermark.png", NULL);
gnome_druid_page_edge_set_watermark (GNOME_DRUID_PAGE_EDGE(info->druid), pixbuf );
gdk_pixbuf_unref (pixbuf);
/* account list */
{
@@ -549,11 +624,6 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
gtk_signal_connect (GTK_OBJECT (clist), "select_row",
GTK_SIGNAL_FUNC (clist_select_row), info);
page = glade_xml_get_widget (xml, "account_page");
gtk_signal_connect (GTK_OBJECT (page), "next",
GTK_SIGNAL_FUNC (account_next), info);
}
/* info widgets */
@@ -587,19 +657,10 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
ce = gnc_currency_edit_new ();
gtk_box_pack_start (GTK_BOX (box), ce, TRUE, TRUE, 0);
info->price_currency_edit = ce;
page = glade_xml_get_widget (xml, "details_page");
gtk_signal_connect (GTK_OBJECT (page), "prepare",
GTK_SIGNAL_FUNC (details_prepare), info);
gtk_signal_connect (GTK_OBJECT (page), "next",
GTK_SIGNAL_FUNC (details_next), info);
}
/* Cash in Lieu page */
{
AccountViewInfo view_info;
GNCAccountType type;
GtkWidget *box;
GtkWidget *tree;
GtkWidget *amount;
@@ -613,6 +674,14 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
info->memo_entry = glade_xml_get_widget (xml, "memo_entry");
/* income tree */
#ifdef NEW
tree = GTK_WIDGET(gnc_tree_view_account_new_filterable ());
info->income_tree = tree;
gnc_tree_view_account_set_filter (GNC_TREE_VIEW_ACCOUNT (tree),
gnc_stock_split_druid_view_filter_income,
NULL /* user data */,
NULL /* destroy callback */);
#else
tree = gnc_account_tree_new ();
info->income_tree = tree;
gtk_clist_column_titles_hide (GTK_CLIST (tree));
@@ -625,6 +694,7 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
view_info.include_type[type] = (type == INCOME);
gnc_account_tree_set_view_info (GNC_ACCOUNT_TREE (tree), &view_info);
#endif
gtk_widget_show (tree);
@@ -633,6 +703,14 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
/* asset tree */
#ifdef NEW
tree = GTK_WIDGET(gnc_tree_view_account_new_filterable ());
info->asset_tree = tree;
gnc_tree_view_account_set_filter (GNC_TREE_VIEW_ACCOUNT (tree),
gnc_stock_split_druid_view_filter_asset,
NULL /* user data */,
NULL /* destroy callback */);
#else
tree = gnc_account_tree_new ();
info->asset_tree = tree;
gtk_clist_column_titles_hide (GTK_CLIST (tree));
@@ -646,25 +724,13 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
(type == BANK) || (type == CASH) || (type == ASSET);
gnc_account_tree_set_view_info (GNC_ACCOUNT_TREE (tree), &view_info);
#endif
gtk_widget_show (tree);
scroll = glade_xml_get_widget (xml, "asset_scroll");
gtk_container_add (GTK_CONTAINER (scroll), tree);
page = glade_xml_get_widget (xml, "cash_page");
gtk_signal_connect (GTK_OBJECT (page), "prepare",
GTK_SIGNAL_FUNC (cash_prepare), info);
gtk_signal_connect (GTK_OBJECT (page), "next",
GTK_SIGNAL_FUNC (cash_next), info);
}
page = glade_xml_get_widget (xml, "finish_page");
gtk_signal_connect (GTK_OBJECT (page), "finish",
GTK_SIGNAL_FUNC (stock_split_finish), info);
}
static void