r21638 - gnucash/trunk/src - Read-only mode: Buttons in account tree window and owner tree window switch to insensitive.

Christian Stimming cstim at code.gnucash.org
Mon Nov 28 16:44:46 EST 2011


Author: cstim
Date: 2011-11-28 16:44:46 -0500 (Mon, 28 Nov 2011)
New Revision: 21638
Trac: http://svn.gnucash.org/trac/changeset/21638

Modified:
   gnucash/trunk/src/business/business-gnome/gnc-plugin-page-owner-tree.c
   gnucash/trunk/src/gnome-utils/gnc-plugin.c
   gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c
Log:
Read-only mode: Buttons in account tree window and owner tree window switch to insensitive.

Along the way, gnc_plugin_update_actions() shows a more detailed error
message if any of the action names do not result in an actual GtkAction,
e.g. because of a typo.

Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-page-owner-tree.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-page-owner-tree.c	2011-11-28 21:44:34 UTC (rev 21637)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-page-owner-tree.c	2011-11-28 21:44:46 UTC (rev 21638)
@@ -100,6 +100,7 @@
 static void gnc_plugin_page_owner_tree_class_init (GncPluginPageOwnerTreeClass *klass);
 static void gnc_plugin_page_owner_tree_init (GncPluginPageOwnerTree *plugin_page);
 static void gnc_plugin_page_owner_tree_finalize (GObject *object);
+static void gnc_plugin_page_owner_tree_selected (GObject *object, gpointer user_data);
 
 static GtkWidget *gnc_plugin_page_owner_tree_create_widget (GncPluginPage *plugin_page);
 static void gnc_plugin_page_owner_tree_destroy_widget (GncPluginPage *plugin_page);
@@ -227,20 +228,39 @@
 
 
 /** Actions that require an owner to be selected before they are
- *  enabled. */
-static const gchar *actions_requiring_owner[] =
+ *  enabled. These ones are only sensitive in a read-write book. */
+static const gchar *actions_requiring_owner_rw[] =
 {
     "OTEditVendorAction",
     "OTEditCustomerAction",
     "OTEditEmployeeAction",
+/* FIXME disabled due to crash    "EditDeleteOwnerAction", */
+    NULL
+};
+
+/** Actions that require an owner to be selected before they are
+ *  enabled. These are sensitive always. */
+static const gchar *actions_requiring_owner_always[] =
+{
     "OTVendorReportAction",
     "OTCustomerReportAction",
     "OTEmployeeReportAction",
-/* FIXME disabled due to crash    "EditDeleteOwnerAction", */
     NULL
 };
 
+/* This is the list of actions which are switched inactive in a read-only book. */
+static const gchar* readonly_inactive_actions[] =
+{
+    "OTNewVendorAction",
+    "OTNewCustomerAction",
+    "OTNewEmployeeAction",
+    "OTNewBillAction",
+    "OTNewInvoiceAction",
+    "OTNewVoucherAction",
+    NULL
+};
 
+
 /** Short labels for use on the toolbar buttons. */
 static action_toolbar_labels toolbar_labels[] =
 {
@@ -448,6 +468,8 @@
                  "page-uri",       "default:",
                  "ui-description", "gnc-plugin-page-owner-tree-ui.xml",
                  NULL);
+    g_signal_connect (G_OBJECT (plugin_page), "selected",
+                      G_CALLBACK (gnc_plugin_page_owner_tree_selected), plugin_page);
 
     /* change me when the system supports multiple books */
     gnc_plugin_page_add_book(parent, gnc_get_current_book());
@@ -487,6 +509,33 @@
     LEAVE(" ");
 }
 
+static void update_inactive_actions(GncPluginPage *plugin_page)
+{
+    GtkActionGroup *action_group;
+    gboolean is_sensitive = !qof_book_is_readonly(gnc_get_current_book());
+
+    // We are readonly - so we have to switch particular actions to inactive.
+    g_return_if_fail(plugin_page);
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE(plugin_page));
+
+    /* Get the action group */
+    action_group = gnc_plugin_page_get_action_group(plugin_page);
+    g_return_if_fail(GTK_IS_ACTION_GROUP (action_group));
+
+    /* Set the action's sensitivity */
+    gnc_plugin_update_actions (action_group, readonly_inactive_actions,
+                               "sensitive", is_sensitive);
+}
+
+static void
+gnc_plugin_page_owner_tree_selected (GObject *object, gpointer user_data)
+{
+    GncPluginPage *page = GNC_PLUGIN_PAGE (object);
+    g_return_if_fail (GNC_IS_PLUGIN_PAGE (page));
+    update_inactive_actions(page);
+}
+
+
 GncOwner *
 gnc_plugin_page_owner_tree_get_current_owner (GncPluginPageOwnerTree *page)
 {
@@ -805,6 +854,7 @@
     GtkTreeView *view;
     GncOwner *owner = NULL;
     gboolean sensitive;
+    gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
 
     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(page));
 
@@ -821,8 +871,10 @@
     }
 
     action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(page));
-    gnc_plugin_update_actions (action_group, actions_requiring_owner,
+    gnc_plugin_update_actions (action_group, actions_requiring_owner_always,
                                "sensitive", sensitive);
+    gnc_plugin_update_actions (action_group, actions_requiring_owner_rw,
+                               "sensitive", sensitive && is_readwrite);
     g_signal_emit (page, plugin_page_signals[OWNER_SELECTED], 0, owner);
 }
 

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c	2011-11-28 21:44:34 UTC (rev 21637)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c	2011-11-28 21:44:46 UTC (rev 21638)
@@ -105,6 +105,7 @@
 static void gnc_plugin_page_account_tree_class_init (GncPluginPageAccountTreeClass *klass);
 static void gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_page);
 static void gnc_plugin_page_account_tree_finalize (GObject *object);
+static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data);
 
 static GtkWidget *gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page);
 static void gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page);
@@ -247,20 +248,44 @@
 
 
 /** Actions that require an account to be selected before they are
- *  enabled. */
-static const gchar *actions_requiring_account[] =
+ *  enabled, and the book is in read-write mode. */
+static const gchar *actions_requiring_account_rw[] =
 {
+    "EditEditAccountAction",
+    "EditDeleteAccountAction",
+    "ActionsReconcileAction",
+    "ActionsAutoClearAction",
+    NULL
+};
+
+/** Actions that require an account to be selected before they are
+ *  enabled. Those actions can be selected even if the book is in readonly mode. */
+static const gchar *actions_requiring_account_always[] =
+{
     "FileOpenAccountAction",
     "FileOpenSubaccountsAction",
+    "ActionsLotsAction",
+    NULL
+};
+
+/* This is the list of actions which are switched inactive in a read-only book. */
+static const gchar* readonly_inactive_actions[] =
+{
+    "FileNewAccountAction",
+    "FileAddAccountHierarchyDruidAction",
     "EditEditAccountAction",
     "EditDeleteAccountAction",
+    "EditRenumberSubaccountsAction",
+    "ActionsTransferAction",
     "ActionsReconcileAction",
     "ActionsAutoClearAction",
-    "ActionsLotsAction",
+    "ActionsStockSplitAction",
+    "ScrubAction",
+    "ScrubSubAction",
+    "ScrubAllAction",
     NULL
 };
 
-
 /** Short labels for use on the toolbar buttons. */
 static action_toolbar_labels toolbar_labels[] =
 {
@@ -361,6 +386,8 @@
                  "page-uri",       "default:",
                  "ui-description", "gnc-plugin-page-account-tree-ui.xml",
                  NULL);
+    g_signal_connect (G_OBJECT (plugin_page), "selected",
+                      G_CALLBACK (gnc_plugin_page_account_tree_selected), plugin_page);
 
     /* change me when the system supports multiple books */
     gnc_plugin_page_add_book(parent, gnc_get_current_book());
@@ -578,6 +605,35 @@
     LEAVE("widget destroyed");
 }
 
+static void update_inactive_actions(GncPluginPage *plugin_page)
+{
+    GtkActionGroup *action_group;
+    gboolean is_sensitive = !qof_book_is_readonly(gnc_get_current_book());
+
+    // We are readonly - so we have to switch particular actions to inactive.
+    g_return_if_fail(plugin_page);
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE(plugin_page));
+
+    /* Get the action group */
+    action_group = gnc_plugin_page_get_action_group(plugin_page);
+    g_return_if_fail(GTK_IS_ACTION_GROUP (action_group));
+
+    /* Set the action's sensitivity */
+    gnc_plugin_update_actions (action_group, readonly_inactive_actions,
+                               "sensitive", is_sensitive);
+}
+
+/**
+ * Called when this page is selected.
+ *
+ * Update the toolbar button sensitivity. */
+static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data)
+{
+    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE (object);
+    g_return_if_fail (GNC_IS_PLUGIN_PAGE (plugin_page));
+    update_inactive_actions(plugin_page);
+}
+
 /** Save enough information about this account tree page that it can
  *  be recreated next time the user starts gnucash.
  *
@@ -749,6 +805,7 @@
     Account *account = NULL;
     gboolean sensitive;
     gboolean subaccounts;
+    gboolean is_readwrite = qof_book_is_readonly(gnc_get_current_book());
 
     g_return_if_fail(GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page));
 
@@ -769,15 +826,19 @@
     }
 
     action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(page));
-    gnc_plugin_update_actions (action_group, actions_requiring_account,
+    gnc_plugin_update_actions (action_group, actions_requiring_account_rw,
+                               "sensitive", is_readwrite && sensitive);
+    gnc_plugin_update_actions (action_group, actions_requiring_account_always,
                                "sensitive", sensitive);
     g_signal_emit (page, plugin_page_signals[ACCOUNT_SELECTED], 0, account);
 
     action = gtk_action_group_get_action (action_group, "EditRenumberSubaccountsAction");
     g_object_set (G_OBJECT(action), "sensitive",
-                  sensitive && subaccounts, NULL);
+                  is_readwrite && sensitive && subaccounts, NULL);
 
-    gnc_plugin_update_actions (action_group, actions_requiring_account,
+    gnc_plugin_update_actions (action_group, actions_requiring_account_rw,
+                               "sensitive", is_readwrite && sensitive);
+    gnc_plugin_update_actions (action_group, actions_requiring_account_always,
                                "sensitive", sensitive);
 }
 

Modified: gnucash/trunk/src/gnome-utils/gnc-plugin.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin.c	2011-11-28 21:44:34 UTC (rev 21637)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin.c	2011-11-28 21:44:46 UTC (rev 21638)
@@ -353,7 +353,16 @@
     for (i = 0; action_names[i]; i++)
     {
         action = gtk_action_group_get_action (action_group, action_names[i]);
-        g_object_set_property (G_OBJECT(action), property_name, &gvalue);
+        if (action)
+        {
+            g_object_set_property (G_OBJECT(action), property_name, &gvalue);
+        }
+        else
+        {
+            g_warning("No such action with name '%s' in action group %s (size %d)",
+                      action_names[i], gtk_action_group_get_name(action_group),
+                      g_list_length(gtk_action_group_list_actions(action_group)));
+        }
     }
 }
 



More information about the gnucash-changes mailing list