r20304 - gnucash/trunk/src/business/business-gnome - Add extra toolbar buttons as shortcuts for some business functions, "New Invoice" for now.

Christian Stimming cstim at code.gnucash.org
Wed Feb 16 15:13:37 EST 2011


Author: cstim
Date: 2011-02-16 15:13:37 -0500 (Wed, 16 Feb 2011)
New Revision: 20304
Trac: http://svn.gnucash.org/trac/changeset/20304

Modified:
   gnucash/trunk/src/business/business-gnome/glade/businessprefs.glade
   gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
   gnucash/trunk/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in
   gnucash/trunk/src/business/business-gnome/ui/gnc-plugin-business-ui.xml
Log:
Add extra toolbar buttons as shortcuts for some business functions, "New Invoice" for now.

The extra toolbar buttons are disabled until the user enables them
manually in Preferences -> Business -> Extra buttons.

Modified: gnucash/trunk/src/business/business-gnome/glade/businessprefs.glade
===================================================================
--- gnucash/trunk/src/business/business-gnome/glade/businessprefs.glade	2011-02-16 11:46:01 UTC (rev 20303)
+++ gnucash/trunk/src/business/business-gnome/glade/businessprefs.glade	2011-02-16 20:13:37 UTC (rev 20304)
@@ -9,7 +9,7 @@
       <widget class="GtkTable" id="business_prefs">
         <property name="visible">True</property>
         <property name="border_width">6</property>
-        <property name="n_rows">8</property>
+        <property name="n_rows">9</property>
         <property name="n_columns">4</property>
         <property name="column_spacing">12</property>
         <child>
@@ -33,8 +33,8 @@
           </widget>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">3</property>
-            <property name="bottom_attach">4</property>
+            <property name="top_attach">4</property>
+            <property name="bottom_attach">5</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
           </packing>
@@ -50,8 +50,8 @@
             <property name="draw_indicator">True</property>
           </widget>
           <packing>
-            <property name="top_attach">7</property>
-            <property name="bottom_attach">8</property>
+            <property name="top_attach">8</property>
+            <property name="bottom_attach">9</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
             <property name="x_padding">12</property>
@@ -69,8 +69,8 @@
           <packing>
             <property name="left_attach">3</property>
             <property name="right_attach">4</property>
-            <property name="top_attach">6</property>
-            <property name="bottom_attach">7</property>
+            <property name="top_attach">7</property>
+            <property name="bottom_attach">8</property>
             <property name="x_options"></property>
             <property name="y_options"></property>
           </packing>
@@ -86,8 +86,8 @@
           <packing>
             <property name="left_attach">2</property>
             <property name="right_attach">3</property>
-            <property name="top_attach">6</property>
-            <property name="bottom_attach">7</property>
+            <property name="top_attach">7</property>
+            <property name="bottom_attach">8</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
           </packing>
@@ -104,8 +104,8 @@
           </widget>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">6</property>
-            <property name="bottom_attach">7</property>
+            <property name="top_attach">7</property>
+            <property name="bottom_attach">8</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
             <property name="x_padding">12</property>
@@ -120,8 +120,8 @@
           </widget>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">5</property>
-            <property name="bottom_attach">6</property>
+            <property name="top_attach">6</property>
+            <property name="bottom_attach">7</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
           </packing>
@@ -132,8 +132,8 @@
             <property name="xalign">0</property>
           </widget>
           <packing>
-            <property name="top_attach">4</property>
-            <property name="bottom_attach">5</property>
+            <property name="top_attach">5</property>
+            <property name="bottom_attach">6</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
           </packing>
@@ -150,8 +150,8 @@
           </widget>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">4</property>
-            <property name="bottom_attach">5</property>
+            <property name="top_attach">5</property>
+            <property name="bottom_attach">6</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
             <property name="x_padding">12</property>
@@ -169,8 +169,8 @@
           </widget>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">2</property>
-            <property name="bottom_attach">3</property>
+            <property name="top_attach">3</property>
+            <property name="bottom_attach">4</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
             <property name="x_padding">12</property>
@@ -188,6 +188,37 @@
           </widget>
           <packing>
             <property name="right_attach">2</property>
+            <property name="top_attach">2</property>
+            <property name="bottom_attach">3</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+            <property name="x_padding">12</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="yalign">0.47999998927116394</property>
+            <property name="label" translatable="yes">&lt;b&gt;General&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </widget>
+          <packing>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkCheckButton" id="gconf/dialogs/business/invoice/enable_toolbuttons">
+            <property name="label" translatable="yes">Enable extra _buttons</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip" translatable="yes">If active, extra toolbar buttons for common business functions are shown as well.  Otherwise they are not shown.</property>
+            <property name="draw_indicator">True</property>
+          </widget>
+          <packing>
+            <property name="right_attach">2</property>
             <property name="top_attach">1</property>
             <property name="bottom_attach">2</property>
             <property name="x_options">GTK_FILL</property>
@@ -244,18 +275,11 @@
           <placeholder/>
         </child>
         <child>
-          <widget class="GtkLabel" id="label1">
-            <property name="visible">True</property>
-            <property name="xalign">0</property>
-            <property name="yalign">0.47999998927116394</property>
-            <property name="label" translatable="yes">&lt;b&gt;General&lt;/b&gt;</property>
-            <property name="use_markup">True</property>
-          </widget>
-          <packing>
-            <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
-          </packing>
+          <placeholder/>
         </child>
+        <child>
+          <placeholder/>
+        </child>
       </widget>
     </child>
   </widget>

Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c	2011-02-16 11:46:01 UTC (rev 20303)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c	2011-02-16 20:13:37 UTC (rev 20304)
@@ -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 @@
         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 @@
     /* 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 @@
     // 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);
+}

Modified: gnucash/trunk/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in
===================================================================
--- gnucash/trunk/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in	2011-02-16 11:46:01 UTC (rev 20303)
+++ gnucash/trunk/src/business/business-gnome/schemas/apps_gnucash_dialog_business_common.schemas.in	2011-02-16 20:13:37 UTC (rev 20304)
@@ -48,6 +48,21 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gnucash/dialogs/business/invoice/enable_toolbuttons</key>
+      <applyto>/apps/gnucash/dialogs/business/invoice/enable_toolbuttons</applyto>
+      <owner>gnucash</owner>
+      <type>bool</type>
+      <default>FALSE</default>
+      <locale name="C">
+        <short>Enable extra toolbar buttons for business</short>
+        <long>
+          If active, extra toolbar buttons for common business
+          functions are shown as well.  Otherwise they are not shown.
+        </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gnucash/dialogs/business/invoice/use_new_window</key>
       <applyto>/apps/gnucash/dialogs/business/invoice/use_new_window</applyto>
       <owner>gnucash</owner>

Modified: gnucash/trunk/src/business/business-gnome/ui/gnc-plugin-business-ui.xml
===================================================================
--- gnucash/trunk/src/business/business-gnome/ui/gnc-plugin-business-ui.xml	2011-02-16 11:46:01 UTC (rev 20303)
+++ gnucash/trunk/src/business/business-gnome/ui/gnc-plugin-business-ui.xml	2011-02-16 20:13:37 UTC (rev 20304)
@@ -56,4 +56,11 @@
     </menu>
 
   </menubar>
+
+  <toolbar name="DefaultToolbar">
+    <placeholder name="DefaultToolbarPlaceholder">
+      <toolitem name="ToolbarInvoiceNew" action="ToolbarNewInvoiceAction"/>
+    </placeholder>
+  </toolbar>
+
 </ui>



More information about the gnucash-changes mailing list