diff --git a/src/business/business-gnome/glade/businessprefs.glade b/src/business/business-gnome/glade/businessprefs.glade index 63c159ce89..0f416d34a6 100644 --- a/src/business/business-gnome/glade/businessprefs.glade +++ b/src/business/business-gnome/glade/businessprefs.glade @@ -9,7 +9,7 @@ True 6 - 8 + 9 4 12 @@ -33,8 +33,8 @@ 2 - 3 - 4 + 4 + 5 GTK_FILL @@ -50,8 +50,8 @@ True - 7 - 8 + 8 + 9 GTK_FILL 12 @@ -69,8 +69,8 @@ 3 4 - 6 - 7 + 7 + 8 @@ -86,8 +86,8 @@ 2 3 - 6 - 7 + 7 + 8 GTK_FILL @@ -104,8 +104,8 @@ 2 - 6 - 7 + 7 + 8 GTK_FILL 12 @@ -120,8 +120,8 @@ 2 - 5 - 6 + 6 + 7 GTK_FILL @@ -132,8 +132,8 @@ 0 - 4 - 5 + 5 + 6 GTK_FILL @@ -150,8 +150,8 @@ 2 - 4 - 5 + 5 + 6 GTK_FILL 12 @@ -169,8 +169,8 @@ 2 - 2 - 3 + 3 + 4 GTK_FILL 12 @@ -186,6 +186,37 @@ True True + + 2 + 2 + 3 + GTK_FILL + + 12 + + + + + True + 0 + 0.47999998927116394 + <b>General</b> + True + + + GTK_FILL + + + + + + Enable extra _buttons + True + True + False + If active, extra toolbar buttons for common business functions are shown as well. Otherwise they are not shown. + True + 2 1 @@ -244,17 +275,10 @@ - - True - 0 - 0.47999998927116394 - <b>General</b> - True - - - GTK_FILL - - + + + + diff --git a/src/business/business-gnome/gnc-plugin-business.c b/src/business/business-gnome/gnc-plugin-business.c index 8cc3081d1f..88dc1aac2d 100644 --- a/src/business/business-gnome/gnc-plugin-business.c +++ b/src/business/business-gnome/gnc-plugin-business.c @@ -46,11 +46,23 @@ #include "gnc-file.h" #include "guile-mappings.h" #include "gnc-session.h" +#include "gnome-utils/gnc-icons.h" /* for GNC_STOCK_INVOICE_NEW */ + +#include "core-utils/gnc-main.h" /* for GCONF_PATH */ +#include "core-utils/gnc-gconf-utils.h" +#include "gnome-utils/gnc-main-window.h" /* g_object functions */ static void gnc_plugin_business_class_init (GncPluginBusinessClass *klass); static void gnc_plugin_business_init (GncPluginBusiness *plugin); static void gnc_plugin_business_finalize (GObject *object); +static void gnc_plugin_business_gconf_changed (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data); +static void gnc_plugin_business_add_to_window (GncPlugin *plugin, + GncMainWindow *window, + GQuark type); /* Command callbacks */ static void gnc_plugin_business_cmd_customer_new_customer (GtkAction *action, @@ -282,6 +294,13 @@ static GtkActionEntry gnc_plugin_actions [] = N_("Initialize Test Data"), G_CALLBACK (gnc_plugin_business_cmd_test_init_data) }, + + /* Toolbar */ + { + "ToolbarNewInvoiceAction", GNC_STOCK_INVOICE_NEW, N_("New _Invoice..."), NULL, + N_("Open the New Invoice dialog"), + G_CALLBACK (gnc_plugin_business_cmd_customer_new_invoice) + }, }; static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions); @@ -358,12 +377,18 @@ gnc_plugin_business_class_init (GncPluginBusinessClass *klass) /* plugin info */ plugin_class->plugin_name = GNC_PLUGIN_BUSINESS_NAME; + /* function overrides */ + plugin_class->add_to_window = gnc_plugin_business_add_to_window; + /* widget addition/removal */ plugin_class->actions_name = PLUGIN_ACTIONS_NAME; plugin_class->actions = gnc_plugin_actions; plugin_class->n_actions = gnc_plugin_n_actions; plugin_class->ui_filename = PLUGIN_UI_FILENAME; + plugin_class->gconf_notifications = gnc_plugin_business_gconf_changed; + plugin_class->gconf_section = GCONF_SECTION_INVOICE; + g_type_class_add_private(klass, sizeof(GncPluginBusinessPrivate)); } @@ -843,3 +868,75 @@ gnc_plugin_business_cmd_test_init_data (GtkAction *action, // Launch the invoice editor gnc_ui_invoice_edit(invoice); } + +/* This is the list of actions which are switched invisible or visible + * depending on the preference "extra_toolbuttons". */ +static const char* extra_toolbar_actions[] = +{ + "ToolbarNewInvoiceAction", + NULL +}; + +/* The code below will set the visibility of some extra toolbar + * buttons based on a gconf key setting. */ +static void set_toolbuttons_visibility(GncMainWindow *mainwindow, + gboolean visible) +{ + GtkActionGroup *action_group; + const char **iter; + + /*g_warning("about to set button visibility %d", visible);*/ + + g_return_if_fail(mainwindow); + + /* Get the action group */ + action_group = + gnc_main_window_get_action_group(mainwindow, PLUGIN_ACTIONS_NAME); + g_assert(action_group); + + for (iter = extra_toolbar_actions; *iter; ++iter) + { + /* Set the action's visibility */ + GtkAction *action = gtk_action_group_get_action (action_group, *iter); + gtk_action_set_visible(action, visible); + } +} + +static void update_extra_toolbuttons(GncMainWindow *mainwindow) +{ + gboolean value = gnc_gconf_get_bool(GCONF_SECTION_INVOICE, + "enable_toolbuttons", NULL); + set_toolbuttons_visibility(mainwindow, value); +} + +/** This function is called whenever an entry in the business invoice + * section of gconf is changed. If the modified gconf entry concerns + * our toolbar buttons, we update their visibility status. */ +static void +gnc_plugin_business_gconf_changed (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data) +{ + GncMainWindow *mainwindow = user_data; + const char* full_gconf_path = + GCONF_PATH "/" GCONF_SECTION_INVOICE "/enable_toolbuttons"; + const char* entry_key = gconf_entry_get_key(entry); + + if (!entry_key) + return; + + if (safe_strcmp(entry_key, full_gconf_path) == 0) + { + update_extra_toolbuttons(mainwindow); + } +} + +/* Update the toolbar button visibility each time our plugin is added + * to a new GncMainWindow. */ +static void gnc_plugin_business_add_to_window (GncPlugin *plugin, + GncMainWindow *mainwindow, + GQuark type) +{ + update_extra_toolbuttons(mainwindow); +} diff --git a/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in b/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in index 48dfbf0831..472e38529e 100644 --- a/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in +++ b/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in @@ -47,6 +47,21 @@ + + /schemas/apps/gnucash/dialogs/business/invoice/enable_toolbuttons + /apps/gnucash/dialogs/business/invoice/enable_toolbuttons + gnucash + bool + FALSE + + Enable extra toolbar buttons for business + + If active, extra toolbar buttons for common business + functions are shown as well. Otherwise they are not shown. + + + + /schemas/apps/gnucash/dialogs/business/invoice/use_new_window /apps/gnucash/dialogs/business/invoice/use_new_window diff --git a/src/business/business-gnome/ui/gnc-plugin-business-ui.xml b/src/business/business-gnome/ui/gnc-plugin-business-ui.xml index eef266e44b..e96cb4855e 100644 --- a/src/business/business-gnome/ui/gnc-plugin-business-ui.xml +++ b/src/business/business-gnome/ui/gnc-plugin-business-ui.xml @@ -56,4 +56,11 @@ + + + + + + +