More work on stock split druid.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3572 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-02-02 04:04:01 +00:00
parent 11b3630d99
commit adb36f6a43
4 changed files with 354 additions and 24 deletions

View File

@ -21,6 +21,7 @@ src/gnome/dialog-transfer.c
src/gnome/dialog-utils.c
src/gnome/druid-commodity.c
src/gnome/druid-qif-import.c
src/gnome/druid-stock-split.c
src/gnome/file-history.c
src/gnome/glade-gnc-dialogs.c
src/gnome/gnc-commodity-edit.c

View File

@ -47,6 +47,7 @@
typedef struct
{
GtkWidget * window;
GtkWidget * druid;
/* account page data */
GtkWidget * account_list;
@ -55,11 +56,14 @@ typedef struct
/* info page data */
GtkWidget * date_edit;
GtkWidget * distribution_edit;
GtkWidget * description_entry;
GtkWidget * price_edit;
/* cash in lieu page data */
GtkWidget * cash_edit;
GtkWidget * description_entry;
GtkWidget * memo_entry;
GtkWidget * income_tree;
GtkWidget * asset_tree;
} StockSplitInfo;
@ -240,9 +244,201 @@ details_next (GnomeDruidPage *druidpage,
return TRUE;
}
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (info->price_edit)))
{
gnc_parse_error_dialog (info,
_("You must either enter a valid price\n"
"or leave it blank."));
return TRUE;
}
amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->price_edit));
if (gnc_numeric_negative_p (amount))
{
const char *message = _("The price must be positive.");
gnc_error_dialog_parented (GTK_WINDOW (info->window), message);
return TRUE;
}
return FALSE;
}
static void
cash_prepare (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
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);
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);
}
static gboolean
cash_next (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
gnc_numeric amount;
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (info->cash_edit)))
{
gnc_parse_error_dialog (info,
_("You must either enter a valid cash amount\n"
"or leave it blank."));
return TRUE;
}
amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->cash_edit));
if (gnc_numeric_negative_p (amount))
{
const char *message = _("The cash distribution must be positive.");
gnc_error_dialog_parented (GTK_WINDOW (info->window), message);
return TRUE;
}
if (gnc_numeric_positive_p (amount))
{
Account *account;
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->income_tree));
if (!account)
{
const char *message = _("You must select an income account\n"
"for the cash distribution.");
gnc_error_dialog_parented (GTK_WINDOW (info->window), message);
return TRUE;
}
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->asset_tree));
if (!account)
{
const char *message = _("You must select an asset account\n"
"for the cash distribution.");
gnc_error_dialog_parented (GTK_WINDOW (info->window), message);
return TRUE;
}
}
return FALSE;
}
static void
stock_split_finish (GnomeDruidPage *druidpage,
gpointer arg1,
gpointer user_data)
{
StockSplitInfo *info = user_data;
gnc_numeric amount;
Transaction *trans;
Account *account;
Split *split;
account = xaccAccountLookup (&info->account);
g_return_if_fail (account != NULL);
amount = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT (info->distribution_edit));
g_return_if_fail (!gnc_numeric_zero_p (amount));
gnc_suspend_gui_refresh ();
trans = xaccMallocTransaction ();
xaccTransBeginEdit (trans);
{
time_t date;
date = gnc_date_edit_get_date (GNC_DATE_EDIT (info->date_edit));
xaccTransSetDateSecs (trans, date);
}
{
const char *description;
description = gtk_entry_get_text (GTK_ENTRY (info->description_entry));
xaccTransSetDescription (trans, description);
}
split = xaccMallocSplit ();
xaccTransAppendSplit (trans, split);
xaccAccountBeginEdit (account);
xaccAccountInsertSplit (account, split);
xaccAccountCommitEdit (account);
xaccSplitSetShareAmount (split, amount);
xaccSplitMakeStockSplit (split);
xaccSplitSetAction (split, _("Split"));
amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->price_edit));
if (gnc_numeric_positive_p (amount))
{
const char *message = "FIXME: we need the pricedb to record.";
gnc_error_dialog_parented (GTK_WINDOW (info->window), message);
}
amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->cash_edit));
if (gnc_numeric_positive_p (amount))
{
const char *memo;
memo = gtk_entry_get_text (GTK_ENTRY (info->memo_entry));
/* asset split */
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->asset_tree));
split = xaccMallocSplit ();
xaccAccountBeginEdit (account);
xaccAccountInsertSplit (account, split);
xaccAccountCommitEdit (account);
xaccTransAppendSplit (trans, split);
xaccSplitSetShareAmount (split, amount);
xaccSplitSetValue (split, amount);
xaccSplitSetMemo (split, memo);
/* income split */
account = gnc_account_tree_get_current_account
(GNC_ACCOUNT_TREE (info->income_tree));
split = xaccMallocSplit ();
xaccAccountBeginEdit (account);
xaccAccountInsertSplit (account, split);
xaccAccountCommitEdit (account);
xaccTransAppendSplit (trans, split);
xaccSplitSetShareAmount (split, gnc_numeric_neg (amount));
xaccSplitSetValue (split, gnc_numeric_neg (amount));
xaccSplitSetMemo (split, memo);
}
xaccTransCommitEdit (trans);
gnc_resume_gui_refresh ();
gnc_close_gui_component_by_data (DRUID_STOCK_SPLIT_CM_CLASS, info);
}
static void
druid_cancel (GnomeDruid *druid, gpointer user_data)
{
@ -251,26 +447,24 @@ druid_cancel (GnomeDruid *druid, gpointer user_data)
gnc_close_gui_component_by_data (DRUID_STOCK_SPLIT_CM_CLASS, info);
}
static void
gnc_stock_split_druid_create (StockSplitInfo *info)
{
GtkWidget *druid;
GtkWidget *page;
info->window = create_Stock_Split_Druid ();
druid = lookup_widget (info->window, "stock_split_druid");
info->druid = lookup_widget (info->window, "stock_split_druid");
gtk_signal_connect (GTK_OBJECT (info->window), "destroy",
GTK_SIGNAL_FUNC (window_destroy_cb), info);
gtk_signal_connect (GTK_OBJECT (druid), "cancel",
gtk_signal_connect (GTK_OBJECT (info->druid), "cancel",
GTK_SIGNAL_FUNC (druid_cancel), info);
/* account list */
{
GtkCList *clist;
GtkWidget *page;
info->account_list = lookup_widget (info->window, "account_clist");
@ -291,9 +485,11 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
{
GtkWidget *box;
GtkWidget *amount;
GtkWidget *page;
GtkWidget *date;
info->description_entry =
lookup_widget (info->window, "description_entry");
box = lookup_widget (info->window, "date_box");
date = gnc_date_edit_new(time(NULL), FALSE, FALSE);
gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);
@ -319,26 +515,101 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
/* Cash in Lieu page */
{
AccountViewInfo view_info;
GNCAccountType type;
GtkWidget *box;
GtkWidget *tree;
GtkWidget *amount;
GtkWidget *scroll;
box = lookup_widget (info->window, "cash_box");
amount = gnc_amount_edit_new ();
gtk_box_pack_start (GTK_BOX (box), amount, TRUE, TRUE, 0);
info->cash_edit = amount;
info->description_entry = lookup_widget (info->window,
"description_entry");
info->memo_entry = lookup_widget (info->window, "memo_entry");
/* income tree */
tree = gnc_account_tree_new ();
info->income_tree = tree;
gtk_clist_column_titles_hide (GTK_CLIST (tree));
gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_BROWSE);
gnc_account_tree_hide_all_but_name (GNC_ACCOUNT_TREE (tree));
gnc_account_tree_get_view_info (GNC_ACCOUNT_TREE (tree), &view_info);
for (type = 0; type < NUM_ACCOUNT_TYPES; type++)
view_info.include_type[type] = (type == INCOME);
gnc_account_tree_set_view_info (GNC_ACCOUNT_TREE (tree), &view_info);
gtk_widget_show (tree);
scroll = lookup_widget (info->window, "income_scroll");
gtk_container_add (GTK_CONTAINER (scroll), tree);
/* asset tree */
tree = gnc_account_tree_new ();
info->asset_tree = tree;
gtk_clist_column_titles_hide (GTK_CLIST (tree));
gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_BROWSE);
gnc_account_tree_hide_all_but_name (GNC_ACCOUNT_TREE (tree));
gnc_account_tree_get_view_info (GNC_ACCOUNT_TREE (tree), &view_info);
for (type = 0; type < NUM_ACCOUNT_TYPES; type++)
view_info.include_type[type] =
(type == BANK) || (type == CASH) || (type == ASSET);
gnc_account_tree_set_view_info (GNC_ACCOUNT_TREE (tree), &view_info);
gtk_widget_show (tree);
scroll = lookup_widget (info->window, "asset_scroll");
gtk_container_add (GTK_CONTAINER (scroll), tree);
page = lookup_widget (info->window, "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 = lookup_widget (info->window, "finish_page");
gtk_signal_connect (GTK_OBJECT (page), "finish",
GTK_SIGNAL_FUNC (stock_split_finish), info);
}
static void
refresh_handler (GHashTable *changes, gpointer user_data)
{
StockSplitInfo *info = user_data;
Account *old_account;
Account *new_account;
GNCIdType id_type;
GtkWidget *page;
if (fill_account_list (info, xaccAccountLookup (&info->account)) == 0)
id_type = xaccGUIDType (&info->account);
old_account = xaccAccountLookup (&info->account);
if (fill_account_list (info, old_account) == 0)
{
gnc_close_gui_component_by_data (DRUID_STOCK_SPLIT_CM_CLASS, info);
return;
}
new_account = xaccAccountLookup (&info->account);
if (id_type == GNC_ID_NULL || old_account == new_account)
return;
page = lookup_widget (info->window, "account_page");
gnome_druid_set_page (GNOME_DRUID (info->druid), GNOME_DRUID_PAGE (page));
}
static void

View File

@ -5879,9 +5879,11 @@ create_Stock_Split_Druid (void)
GtkWidget *vbox100;
GtkWidget *label847683;
GtkWidget *label847684;
GtkWidget *label847693;
GtkWidget *vbox101;
GtkWidget *date_box;
GtkWidget *distribution_box;
GtkWidget *description_entry;
GtkWidget *hseparator2;
GtkWidget *label847691;
GtkWidget *hbox93;
@ -5900,7 +5902,7 @@ create_Stock_Split_Druid (void)
GtkWidget *label847689;
GtkWidget *vbox104;
GtkWidget *cash_box;
GtkWidget *description_entry;
GtkWidget *memo_entry;
GtkWidget *hbox88;
GtkWidget *frame43;
GtkWidget *income_scroll;
@ -6027,7 +6029,7 @@ create_Stock_Split_Druid (void)
gtk_widget_show (druid_vbox32);
gtk_container_set_border_width (GTK_CONTAINER (druid_vbox32), 5);
label847681 = gtk_label_new (_("Enter the date and the number of shares you gained or lost from the stock split or merger.\nFor stock mergers (negative splits) use a negative value for the share distribution."));
label847681 = gtk_label_new (_("Enter the date and the number of shares you gained or lost from the stock split or merger.\nFor stock mergers (negative splits) use a negative value for the share distribution.\nYou can also enter a description of the transaction, or accept the default one."));
gtk_widget_ref (label847681);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "label847681", label847681,
(GtkDestroyNotify) gtk_widget_unref);
@ -6048,6 +6050,7 @@ create_Stock_Split_Druid (void)
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (vbox100);
gtk_box_pack_start (GTK_BOX (hbox86), vbox100, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox100), 2);
label847683 = gtk_label_new (_("Date:"));
gtk_widget_ref (label847683);
@ -6065,6 +6068,14 @@ create_Stock_Split_Druid (void)
gtk_box_pack_start (GTK_BOX (vbox100), label847684, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label847684), 1, 0.5);
label847693 = gtk_label_new (_("Description:"));
gtk_widget_ref (label847693);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "label847693", label847693,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (label847693);
gtk_box_pack_start (GTK_BOX (vbox100), label847693, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label847693), 1, 0.5);
vbox101 = gtk_vbox_new (TRUE, 4);
gtk_widget_ref (vbox101);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "vbox101", vbox101,
@ -6086,6 +6097,14 @@ create_Stock_Split_Druid (void)
gtk_widget_show (distribution_box);
gtk_box_pack_start (GTK_BOX (vbox101), distribution_box, FALSE, FALSE, 0);
description_entry = gtk_entry_new ();
gtk_widget_ref (description_entry);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "description_entry", description_entry,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (description_entry);
gtk_box_pack_start (GTK_BOX (vbox101), description_entry, FALSE, FALSE, 0);
gtk_entry_set_text (GTK_ENTRY (description_entry), _("Stock Split"));
hseparator2 = gtk_hseparator_new ();
gtk_widget_ref (hseparator2);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "hseparator2", hseparator2,
@ -6149,7 +6168,7 @@ create_Stock_Split_Druid (void)
gtk_box_pack_start (GTK_BOX (druid_vbox33), label847687, FALSE, FALSE, 0);
gtk_label_set_justify (GTK_LABEL (label847687), GTK_JUSTIFY_LEFT);
vbox102 = gtk_vbox_new (FALSE, 8);
vbox102 = gtk_vbox_new (FALSE, 10);
gtk_widget_ref (vbox102);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "vbox102", vbox102,
(GtkDestroyNotify) gtk_widget_unref);
@ -6179,7 +6198,7 @@ create_Stock_Split_Druid (void)
gtk_box_pack_start (GTK_BOX (vbox103), label847688, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label847688), 1, 0.5);
label847689 = gtk_label_new (_("Description:"));
label847689 = gtk_label_new (_("Memo:"));
gtk_widget_ref (label847689);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "label847689", label847689,
(GtkDestroyNotify) gtk_widget_unref);
@ -6201,12 +6220,13 @@ create_Stock_Split_Druid (void)
gtk_widget_show (cash_box);
gtk_box_pack_start (GTK_BOX (vbox104), cash_box, FALSE, FALSE, 0);
description_entry = gtk_entry_new ();
gtk_widget_ref (description_entry);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "description_entry", description_entry,
memo_entry = gtk_entry_new ();
gtk_widget_ref (memo_entry);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "memo_entry", memo_entry,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (description_entry);
gtk_box_pack_start (GTK_BOX (vbox104), description_entry, FALSE, FALSE, 0);
gtk_widget_show (memo_entry);
gtk_box_pack_start (GTK_BOX (vbox104), memo_entry, FALSE, FALSE, 0);
gtk_entry_set_text (GTK_ENTRY (memo_entry), _("Cash In Lieu"));
hbox88 = gtk_hbox_new (TRUE, 2);
gtk_widget_ref (hbox88);
@ -6228,6 +6248,7 @@ create_Stock_Split_Druid (void)
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (income_scroll);
gtk_container_add (GTK_CONTAINER (frame43), income_scroll);
gtk_container_set_border_width (GTK_CONTAINER (income_scroll), 3);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (income_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
frame44 = gtk_frame_new (_("Asset Account"));
@ -6243,6 +6264,7 @@ create_Stock_Split_Druid (void)
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (asset_scroll);
gtk_container_add (GTK_CONTAINER (frame44), asset_scroll);
gtk_container_set_border_width (GTK_CONTAINER (asset_scroll), 3);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (asset_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
finish_page = gnome_druid_page_finish_new ();

View File

@ -8742,7 +8742,8 @@ words.
<class>GtkLabel</class>
<name>label847681</name>
<label>Enter the date and the number of shares you gained or lost from the stock split or merger.
For stock mergers (negative splits) use a negative value for the share distribution.</label>
For stock mergers (negative splits) use a negative value for the share distribution.
You can also enter a description of the transaction, or accept the default one.</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
@ -8771,6 +8772,7 @@ For stock mergers (negative splits) use a negative value for the share distribut
<widget>
<class>GtkVBox</class>
<name>vbox100</name>
<border_width>2</border_width>
<homogeneous>True</homogeneous>
<spacing>4</spacing>
<child>
@ -8812,6 +8814,23 @@ For stock mergers (negative splits) use a negative value for the share distribut
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label847693</name>
<label>Description:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
@ -8856,6 +8875,21 @@ For stock mergers (negative splits) use a negative value for the share distribut
<class>Placeholder</class>
</widget>
</widget>
<widget>
<class>GtkEntry</class>
<name>description_entry</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text>Stock Split</text>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
</widget>
@ -8979,7 +9013,7 @@ enter the details of that payment here. Otherwise, just click `Next'.</label>
<name>vbox102</name>
<border_width>5</border_width>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<spacing>10</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
@ -9028,7 +9062,7 @@ enter the details of that payment here. Otherwise, just click `Next'.</label>
<widget>
<class>GtkLabel</class>
<name>label847689</name>
<label>Description:</label>
<label>Memo:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
@ -9072,12 +9106,12 @@ enter the details of that payment here. Otherwise, just click `Next'.</label>
<widget>
<class>GtkEntry</class>
<name>description_entry</name>
<name>memo_entry</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<text>Cash In Lieu</text>
<child>
<padding>0</padding>
<expand>False</expand>
@ -9113,6 +9147,7 @@ enter the details of that payment here. Otherwise, just click `Next'.</label>
<widget>
<class>GtkScrolledWindow</class>
<name>income_scroll</name>
<border_width>3</border_width>
<hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
@ -9139,6 +9174,7 @@ enter the details of that payment here. Otherwise, just click `Next'.</label>
<widget>
<class>GtkScrolledWindow</class>
<name>asset_scroll</name>
<border_width>3</border_width>
<hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>