Enhance the commodity selection dialog so that it can be limited to

currencies, non-currency commodities, or allow all commodities.  Fixes
#102023 and #115461.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8657 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2003-06-23 17:53:03 +00:00
parent 12cff36837
commit bed1d91aa9
10 changed files with 152 additions and 74 deletions

View File

@ -1,3 +1,20 @@
2003-06-23 David Hampton <hampton@employees.org>
* src/gnome-utils/dialog-account.c: Limit the commodity choices
based upon the current account type.
* src/gnome-utils/dialog-commodity.c: Add a new argument to the
dialog creation functions to specify what types of commodities
should be presented. Also tweak the title of the dialog based
upon this argument. Remove the "new" button when the dialog is
limited strictly to currencies.
* src/gnome-utils/gnc-commodity-edit.c:
* src/import-export/binary-import/druid-commodity.c:
* src/import-export/import-commodity-matcher.c:
* src/import-export/qif-import/druid-qif-import.c: Updated for new
commodity dialog argument.
2003-06-22 David Hampton <hampton@employees.org> 2003-06-22 David Hampton <hampton@employees.org>
* src/gnome-utils/dialog-commodity.[ch]: Clean up usage of the * src/gnome-utils/dialog-commodity.[ch]: Clean up usage of the

View File

@ -70,7 +70,7 @@
<widget> <widget>
<class>GtkButton</class> <class>GtkButton</class>
<name>button64</name> <name>new_button</name>
<can_default>True</can_default> <can_default>True</can_default>
<can_focus>True</can_focus> <can_focus>True</can_focus>
<signal> <signal>

View File

@ -30,6 +30,7 @@
#include "AccWindow.h" #include "AccWindow.h"
#include "Transaction.h" #include "Transaction.h"
#include "dialog-account.h" #include "dialog-account.h"
#include "dialog-commodity.h"
#include "dialog-utils.h" #include "dialog-utils.h"
#include "global-options.h" #include "global-options.h"
#include "gnc-account-tree.h" #include "gnc-account-tree.h"
@ -80,6 +81,7 @@ struct _AccountWindow
GtkWidget * notes_text; GtkWidget * notes_text;
GtkWidget * commodity_edit; GtkWidget * commodity_edit;
dialog_commodity_mode commodity_mode;
GtkWidget * account_scu; GtkWidget * account_scu;
GList * valid_types; GList * valid_types;
@ -145,6 +147,24 @@ aw_get_account (AccountWindow *aw)
return xaccAccountLookup (&aw->account, gnc_get_current_book ()); return xaccAccountLookup (&aw->account, gnc_get_current_book ());
} }
static void
gnc_account_commodity_from_type (AccountWindow * aw, gboolean update)
{
dialog_commodity_mode new_mode;
if ((aw->type == STOCK) || (aw->type == MUTUAL))
new_mode = DIAG_COMM_NON_CURRENCY;
else
new_mode = DIAG_COMM_CURRENCY;
if (update && (new_mode != aw->commodity_mode)) {
gnc_general_select_set_selected(GNC_GENERAL_SELECT (aw->commodity_edit),
NULL);
}
aw->commodity_mode = new_mode;
}
/* Copy the account values to the GUI widgets */ /* Copy the account values to the GUI widgets */
static void static void
gnc_account_to_ui(AccountWindow *aw) gnc_account_to_ui(AccountWindow *aw)
@ -169,6 +189,7 @@ gnc_account_to_ui(AccountWindow *aw)
commodity = xaccAccountGetCommodity (account); commodity = xaccAccountGetCommodity (account);
gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit), gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
commodity); commodity);
gnc_account_commodity_from_type (aw, FALSE);
nonstd_scu = xaccAccountGetNonStdSCU (account); nonstd_scu = xaccAccountGetNonStdSCU (account);
if (nonstd_scu) { if (nonstd_scu) {
@ -417,6 +438,7 @@ gnc_finish_ok (AccountWindow *aw,
commodity = xaccAccountGetCommodity (parent); commodity = xaccAccountGetCommodity (parent);
gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit), gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
commodity); commodity);
gnc_account_commodity_from_type (aw, FALSE);
gnc_account_tree_select_account (GNC_ACCOUNT_TREE(aw->parent_tree), gnc_account_tree_select_account (GNC_ACCOUNT_TREE(aw->parent_tree),
parent, TRUE); parent, TRUE);
@ -1090,6 +1112,7 @@ gnc_type_list_select_cb(GtkCList * type_list, gint row, gint column,
aw->type != STOCK && aw->type != STOCK &&
aw->type != MUTUAL); aw->type != MUTUAL);
gnc_account_commodity_from_type (aw, TRUE);
gtk_widget_set_sensitive(aw->opening_balance_page, sensitive); gtk_widget_set_sensitive(aw->opening_balance_page, sensitive);
if (!sensitive) if (!sensitive)
{ {
@ -1388,7 +1411,7 @@ gnc_account_window_create(AccountWindow *aw)
aw->commodity_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT, aw->commodity_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT,
gnc_commodity_edit_get_string, gnc_commodity_edit_get_string,
gnc_commodity_edit_new_select, gnc_commodity_edit_new_select,
NULL); &aw->commodity_mode);
gtk_box_pack_start(GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (aw->commodity_edit), "changed", gtk_signal_connect (GTK_OBJECT (aw->commodity_edit), "changed",
@ -1629,16 +1652,16 @@ gnc_ui_new_account_window_internal (Account *base_account,
gnc_resume_gui_refresh (); gnc_resume_gui_refresh ();
if(default_commodity!=NULL) if (default_commodity != NULL) {
{ commodity = default_commodity;
commodity = default_commodity; } else if ((aw->type != STOCK) && (aw->type != MUTUAL)) {
} commodity = gnc_default_currency ();
else } else {
{ commodity = NULL;
commodity = gnc_default_currency (); }
}
gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit), gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
commodity); commodity);
gnc_account_commodity_from_type (aw, FALSE);
gtk_widget_show_all (aw->dialog); gtk_widget_show_all (aw->dialog);

View File

@ -88,8 +88,8 @@ static gnc_commodity_help_callback help_callback = NULL;
/* The commodity selection window */ /* The commodity selection window */
static SelectCommodityWindow * static SelectCommodityWindow *
gnc_ui_select_commodity_create(const gnc_commodity * orig_sel); gnc_ui_select_commodity_create(const gnc_commodity * orig_sel,
dialog_commodity_mode mode);
void gnc_ui_select_commodity_new_cb(GtkButton * button, void gnc_ui_select_commodity_new_cb(GtkButton * button,
gpointer user_data); gpointer user_data);
void gnc_ui_select_commodity_changed_cb(GtkEditable * entry, void gnc_ui_select_commodity_changed_cb(GtkEditable * entry,
@ -121,6 +121,7 @@ gnc_ui_commodity_set_help_callback (gnc_commodity_help_callback cb)
gnc_commodity * gnc_commodity *
gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel, gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel,
GtkWidget * parent, GtkWidget * parent,
dialog_commodity_mode mode,
const char * user_message, const char * user_message,
const char * code, const char * code,
const char * fullname, const char * fullname,
@ -133,7 +134,7 @@ gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel,
gboolean done; gboolean done;
gint value; gint value;
win = gnc_ui_select_commodity_create(orig_sel); win = gnc_ui_select_commodity_create(orig_sel, mode);
win->default_exchange_code=code; win->default_exchange_code=code;
win->default_fullname=fullname; win->default_fullname=fullname;
win->default_mnemonic=mnemonic; win->default_mnemonic=mnemonic;
@ -191,10 +192,12 @@ gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel,
gnc_commodity * gnc_commodity *
gnc_ui_select_commodity_modal(gnc_commodity * orig_sel, gnc_ui_select_commodity_modal(gnc_commodity * orig_sel,
GtkWidget * parent) GtkWidget * parent,
dialog_commodity_mode mode)
{ {
return gnc_ui_select_commodity_modal_full(orig_sel, return gnc_ui_select_commodity_modal_full(orig_sel,
parent, parent,
mode,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -207,11 +210,13 @@ gnc_ui_select_commodity_modal(gnc_commodity * orig_sel,
********************************************************************/ ********************************************************************/
static SelectCommodityWindow * static SelectCommodityWindow *
gnc_ui_select_commodity_create(const gnc_commodity * orig_sel) gnc_ui_select_commodity_create(const gnc_commodity * orig_sel,
dialog_commodity_mode mode)
{ {
SelectCommodityWindow * retval = g_new0(SelectCommodityWindow, 1); SelectCommodityWindow * retval = g_new0(SelectCommodityWindow, 1);
GladeXML *xml; GladeXML *xml;
const char * namespace; const char * namespace, *title;
GtkWidget *button;
xml = gnc_glade_xml_new ("commodity.glade", "Commodity Selector Dialog"); xml = gnc_glade_xml_new ("commodity.glade", "Commodity Selector Dialog");
glade_xml_signal_autoconnect_full( xml, glade_xml_signal_autoconnect_full( xml,
@ -227,10 +232,26 @@ gnc_ui_select_commodity_create(const gnc_commodity * orig_sel)
gtk_label_set_text ((GtkLabel *)retval->select_user_prompt, ""); gtk_label_set_text ((GtkLabel *)retval->select_user_prompt, "");
switch (mode) {
case DIAG_COMM_ALL:
title = _("Select currency/security");
break;
case DIAG_COMM_NON_CURRENCY:
title = _("Select security");
break;
case DIAG_COMM_CURRENCY:
default:
title = _("Select currency");
button = glade_xml_get_widget (xml, "new_button");
gtk_widget_destroy(button);
break;
}
gtk_window_set_title (GTK_WINDOW(retval->dialog), title);
/* build the menus of namespaces and commodities */ /* build the menus of namespaces and commodities */
gnc_ui_update_namespace_picker(retval->namespace_combo, gnc_ui_update_namespace_picker(retval->namespace_combo,
gnc_commodity_get_namespace(orig_sel), gnc_commodity_get_namespace(orig_sel),
TRUE, FALSE); mode);
namespace = gnc_ui_namespace_picker_ns(retval->namespace_combo); namespace = gnc_ui_namespace_picker_ns(retval->namespace_combo);
gnc_ui_update_commodity_picker(retval->commodity_combo, namespace, gnc_ui_update_commodity_picker(retval->commodity_combo, namespace,
gnc_commodity_get_printname(orig_sel)); gnc_commodity_get_printname(orig_sel));
@ -270,7 +291,7 @@ gnc_ui_select_commodity_new_cb(GtkButton * button,
if(new_commodity) { if(new_commodity) {
gnc_ui_update_namespace_picker(w->namespace_combo, gnc_ui_update_namespace_picker(w->namespace_combo,
gnc_commodity_get_namespace(new_commodity), gnc_commodity_get_namespace(new_commodity),
TRUE, FALSE); DIAG_COMM_ALL);
gnc_ui_update_commodity_picker(w->commodity_combo, gnc_ui_update_commodity_picker(w->commodity_combo,
gnc_commodity_get_namespace(new_commodity), gnc_commodity_get_namespace(new_commodity),
gnc_commodity_get_printname(new_commodity)); gnc_commodity_get_printname(new_commodity));
@ -406,56 +427,50 @@ gnc_ui_update_commodity_picker(GtkWidget * combobox,
void void
gnc_ui_update_namespace_picker(GtkWidget * combobox, gnc_ui_update_namespace_picker(GtkWidget * combobox,
const char * init_string, const char * init_string,
gboolean include_iso, dialog_commodity_mode mode)
gboolean include_all)
{ {
GList * namespaces; GList * namespaces, *node;
const char * active; const char * active;
/* fetch a list of the namespaces */ /* fetch a list of the namespaces */
if (!include_all) switch (mode) {
namespaces = case DIAG_COMM_ALL:
gnc_commodity_table_get_namespaces (gnc_get_current_commodities()); namespaces =
else gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
{ break;
namespaces = NULL;
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_ISO); case DIAG_COMM_NON_CURRENCY:
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_NASDAQ); namespaces =
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_NYSE); gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_EUREX); node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_ISO, g_strcmp);
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_MUTUAL); if (node) {
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_ASX); namespaces = g_list_remove_link (namespaces, node);
namespaces = g_list_prepend (namespaces, GNC_COMMODITY_NS_AMEX); g_list_free_1 (node);
} else {
node->data = "CURRENCY";
}
if (gnc_commodity_namespace_is_iso (init_string))
init_string = NULL;
break;
case DIAG_COMM_CURRENCY:
default:
namespaces = g_list_prepend (NULL, "CURRENCY");
break;
} }
namespaces = g_list_sort(namespaces, g_strcmp); /* Legacy namespace should never be seen */
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_LEGACY, g_strcmp);
{ if (node) {
GList *node; namespaces = g_list_remove_link (namespaces, node);
g_list_free_1 (node);
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_ISO, g_strcmp);
if (node && !include_iso)
{
namespaces = g_list_remove_link (namespaces, node);
g_list_free_1 (node);
}
else
node->data = "CURRENCY";
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_LEGACY, g_strcmp);
if (node)
{
namespaces = g_list_remove_link (namespaces, node);
g_list_free_1 (node);
}
} }
/* stick them in the combobox */ /* stick them in the combobox */
namespaces = g_list_sort(namespaces, g_strcmp);
gtk_combo_set_popdown_strings (GTK_COMBO (combobox), namespaces); gtk_combo_set_popdown_strings (GTK_COMBO (combobox), namespaces);
if (!include_iso && gnc_commodity_namespace_is_iso (init_string))
init_string = NULL;
/* set the entry text */ /* set the entry text */
if (init_string) if (init_string)
active = init_string; active = init_string;
@ -615,7 +630,7 @@ gnc_ui_new_commodity_dialog(const char * selected_namespace,
gtk_entry_set_text (GTK_ENTRY (retval->mnemonic_entry), mnemonic ? mnemonic : ""); gtk_entry_set_text (GTK_ENTRY (retval->mnemonic_entry), mnemonic ? mnemonic : "");
gnc_ui_update_namespace_picker(retval->namespace_combo, gnc_ui_update_namespace_picker(retval->namespace_combo,
selected_namespace, selected_namespace,
include_iso, TRUE); include_iso ? DIAG_COMM_ALL : DIAG_COMM_NON_CURRENCY);
gtk_entry_set_text (GTK_ENTRY (retval->code_entry), cusip ? cusip : ""); gtk_entry_set_text (GTK_ENTRY (retval->code_entry), cusip ? cusip : "");
if (fraction > 0) if (fraction > 0)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (retval->fraction_spinbutton), gtk_spin_button_set_value (GTK_SPIN_BUTTON (retval->fraction_spinbutton),

View File

@ -36,6 +36,21 @@
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine.h" #include "gnc-engine.h"
/** The dialog commodity types are used to determine what commodity
* namespaces the currency dialog will present to a user. These
* values can be safely changed from one release to the next. Note
* that if values are added, the routines in dialog-commodity.c will
* need to be updated to match.
*/
typedef enum {
DIAG_COMM_CURRENCY, /**< Dialog box should only allow selection
of a currency. */
DIAG_COMM_NON_CURRENCY, /**< Dialog box should allow selection of
anything but a currency. */
DIAG_COMM_ALL, /**< Dialog box should allow selection of
anything. */
} dialog_commodity_mode;
typedef void (* gnc_commodity_help_callback)(void); typedef void (* gnc_commodity_help_callback)(void);
/** This function is used to set the action routine for the help /** This function is used to set the action routine for the help
@ -79,12 +94,16 @@ void gnc_ui_commodity_set_help_callback (gnc_commodity_help_callback cb);
* instruction providing this commodity's mnemonic, and this will be * instruction providing this commodity's mnemonic, and this will be
* the default mnemonic for any newly created commodities. * the default mnemonic for any newly created commodities.
* *
* @param mode Determines which namespaces the user may select a
* commodity from.
*
* @return The commodity selected. May or may not be a newly created * @return The commodity selected. May or may not be a newly created
* commodity. * commodity.
*/ */
gnc_commodity * gnc_commodity *
gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel, gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel,
GtkWidget * parent, GtkWidget * parent,
dialog_commodity_mode mode,
const char * user_message, const char * user_message,
const char * exchange_code, const char * exchange_code,
const char * fullname, const char * fullname,
@ -100,12 +119,18 @@ gnc_ui_select_commodity_modal_full(gnc_commodity * orig_sel,
* @param orig_sel A pointer to a commodity that should initially be * @param orig_sel A pointer to a commodity that should initially be
* selected in the dialog box. * selected in the dialog box.
* *
* @param parent The parent window for this new selection window.
*
* @param mode Determines which namespaces the user may select a
* commodity from.
*
* @return The commodity selected. May or may not be a newly created * @return The commodity selected. May or may not be a newly created
* commodity. * commodity.
*/ */
gnc_commodity * gnc_commodity *
gnc_ui_select_commodity_modal(gnc_commodity * orig_sel, gnc_ui_select_commodity_modal(gnc_commodity * orig_sel,
GtkWidget * parent); GtkWidget * parent,
dialog_commodity_mode mode);
/** @} */ /** @} */
@ -194,14 +219,8 @@ gnc_ui_edit_commodity_modal(gnc_commodity *commodity,
* @param sel The namespace that should be initially selected when * @param sel The namespace that should be initially selected when
* the combo box appears. * the combo box appears.
* *
* @param include_iso Set to TRUE if the combo box should inlude the * @param mode Determines which namespaces the user may select a
* ISO4217 namespace for currencies. FALSE if the currency namespace * commodity
* should not be included. This flag has precedence over the
* following flag.
*
* @param include_all Set to TRUE if the combo box should include all
* known namespaces, both application and user defined. FALSE if
* only the default application namespaces should be included.
* *
* @return The currently selected namespace. * @return The currently selected namespace.
* *
@ -209,8 +228,7 @@ gnc_ui_edit_commodity_modal(gnc_commodity *commodity,
*/ */
void gnc_ui_update_namespace_picker(GtkWidget * combobox, void gnc_ui_update_namespace_picker(GtkWidget * combobox,
const char * sel, const char * sel,
gboolean include_iso, dialog_commodity_mode mode);
gboolean include_all);
/** Given a combo box, return the currently selected namespaces. /** Given a combo box, return the currently selected namespaces.
* *

View File

@ -48,7 +48,11 @@ gpointer gnc_commodity_edit_new_select (gpointer arg, gpointer ptr,
GtkWidget *toplevel) GtkWidget *toplevel)
{ {
gnc_commodity * comm = (gnc_commodity *)ptr; gnc_commodity * comm = (gnc_commodity *)ptr;
return gnc_ui_select_commodity_modal(comm, toplevel); dialog_commodity_mode *mode_ptr = arg;
dialog_commodity_mode mode;
mode = mode_ptr ? *mode_ptr : DIAG_COMM_ALL;
return gnc_ui_select_commodity_modal(comm, toplevel, mode);
} }
/* /*

View File

@ -40,8 +40,8 @@ const char * gnc_commodity_edit_get_string (gpointer ptr);
/* Callback function to popup a new selection (modal) dialog. /* Callback function to popup a new selection (modal) dialog.
* *
* NOTE: The argument here is ignored, so you can safely set the * The generic argument is a pointer to a dialog_commodity_mode
* cb_arg to NULL when you create the general_select widget * enum. This tells the dialog how to limit the namespaces provided.
*/ */
gpointer gnc_commodity_edit_new_select (gpointer arg, gpointer ptr, gpointer gnc_commodity_edit_new_select (gpointer arg, gpointer ptr,
GtkWidget *toplevel); GtkWidget *toplevel);

View File

@ -283,7 +283,7 @@ make_commodity_druid_page(gnc_commodity * comm)
gnc_ui_update_namespace_picker(retval->new_type_combo, gnc_ui_update_namespace_picker(retval->new_type_combo,
gnc_commodity_get_namespace(comm), gnc_commodity_get_namespace(comm),
TRUE, TRUE); DIAG_COMM_ALL);
temp = gtk_hbox_new(FALSE, 0); temp = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(top_vbox), temp, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(top_vbox), temp, FALSE, FALSE, 5);

View File

@ -117,6 +117,7 @@ gnc_commodity * gnc_import_select_commodity(char * exchange_code,
{ {
retval=gnc_ui_select_commodity_modal_full(NULL, retval=gnc_ui_select_commodity_modal_full(NULL,
NULL, NULL,
DIAG_COMM_ALL,
_("Please select a commodity to match the following exchange specific code.\nPlease note that the exchange code of the commodity you select will be overwritten.\n"), _("Please select a commodity to match the following exchange specific code.\nPlease note that the exchange code of the commodity you select will be overwritten.\n"),
exchange_code, exchange_code,
default_fullname, default_fullname,

View File

@ -1583,7 +1583,7 @@ make_qif_druid_page(gnc_commodity * comm)
gnc_ui_update_namespace_picker(retval->new_type_combo, gnc_ui_update_namespace_picker(retval->new_type_combo,
gnc_commodity_get_namespace(comm), gnc_commodity_get_namespace(comm),
TRUE, TRUE); DIAG_COMM_ALL);
info_label = info_label =
gtk_label_new(_("Enter the full name of the commodity, " gtk_label_new(_("Enter the full name of the commodity, "