r21636 - gnucash/trunk/src - Read-only mode: Business toolbar actions switch to insensitive.

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


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

Modified:
   gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
   gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
   gnucash/trunk/src/gnome-utils/gnc-autosave.c
Log:
Read-only mode: Business toolbar actions switch to insensitive.

Also, disable book auto-save if the book is read-only.

Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c	2011-11-28 19:18:33 UTC (rev 21635)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c	2011-11-28 21:44:21 UTC (rev 21636)
@@ -142,6 +142,7 @@
 
 static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,
         GncMainWindowActionData *data);
+static void update_inactive_actions(GncPluginPage *page);
 
 #define PLUGIN_ACTIONS_NAME "gnc-plugin-business-actions"
 #define PLUGIN_UI_FILENAME  "gnc-plugin-business-ui.xml"
@@ -969,6 +970,7 @@
 {
 //    g_message("gnc_plugin_business_main_window_page_changed, page=%p", page);
     gnc_plugin_business_update_menus(page);
+    update_inactive_actions(page);
 }
 
 static void
@@ -1044,6 +1046,48 @@
     gnc_ui_invoice_edit(invoice);
 }
 
+/* This is the list of actions which are switched inactive in a read-only book. */
+static const gchar* readonly_inactive_actions[] =
+{
+    "CustomerNewCustomerOpenAction",
+    "CustomerNewInvoiceOpenAction",
+    "CustomerNewInvoiceOpenAction",
+    "CustomerNewJobOpenAction",
+    "CustomerProcessPaymentAction",
+    "VendorNewVendorOpenAction",
+    "VendorNewBillOpenAction",
+    "VendorNewJobOpenAction",
+    "VendorProcessPaymentAction",
+    "EmployeeNewEmployeeOpenAction",
+    "EmployeeNewExpenseVoucherOpenAction",
+    "EmployeeProcessPaymentAction",
+    "ToolbarNewInvoiceAction",
+    "RegisterAssignPayment",
+    NULL
+};
+
+static void update_inactive_actions(GncPluginPage *plugin_page)
+{
+    GncMainWindow  *window;
+    GtkActionGroup *action_group;
+
+    // We are readonly - so we have to switch particular actions to inactive.
+    gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
+
+    // We continue only if the current page is a plugin page
+    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
+        return;
+
+    window = GNC_MAIN_WINDOW(plugin_page->window);
+    g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
+    action_group = gnc_main_window_get_action_group(window, PLUGIN_ACTIONS_NAME);
+    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_readwrite);
+}
+
 /* This is the list of actions which are switched invisible or visible
  * depending on the preference "extra_toolbuttons". */
 static const char* extra_toolbar_actions[] =

Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c	2011-11-28 19:18:33 UTC (rev 21635)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c	2011-11-28 21:44:21 UTC (rev 21636)
@@ -217,6 +217,16 @@
 };
 static guint n_radio_entries = G_N_ELEMENTS (radio_entries);
 
+static const gchar *invoice_book_readwrite_actions[] =
+{
+    // Only insert actions here which are not yet in posted_actions and unposted_actions!
+    "FileNewAccountAction",
+    "EditDuplicateInvoiceAction",
+    "BusinessNewInvoiceAction",
+    "ToolsProcessPaymentAction",
+    NULL
+};
+
 static const gchar *posted_actions[] =
 {
     NULL
@@ -420,10 +430,11 @@
 gnc_plugin_page_invoice_update_menus (GncPluginPage *page, gboolean is_posted, gboolean can_unpost)
 {
     GtkActionGroup *action_group;
+    gboolean is_readonly = qof_book_is_readonly(gnc_get_current_book());
 
     g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(page));
 
-    if (qof_book_is_readonly(gnc_get_current_book()))
+    if (is_readonly)
     {
         // Are we readonly? Then don't allow any actions.
         is_posted = TRUE;
@@ -437,6 +448,8 @@
                                "sensitive", !is_posted);
     gnc_plugin_update_actions (action_group, can_unpost_actions,
                                "sensitive", can_unpost);
+    gnc_plugin_update_actions (action_group, invoice_book_readwrite_actions,
+                               "sensitive", !is_readonly);
 }
 
 

Modified: gnucash/trunk/src/gnome-utils/gnc-autosave.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-autosave.c	2011-11-28 19:18:33 UTC (rev 21635)
+++ gnucash/trunk/src/gnome-utils/gnc-autosave.c	2011-11-28 21:44:21 UTC (rev 21636)
@@ -178,7 +178,8 @@
     /* Is there already a save in progress? If yes, return FALSE so that
        the timeout is automatically destroyed and the function will not
        be called again. */
-    if (gnc_file_save_in_progress() || !gnc_current_session_exist())
+    if (gnc_file_save_in_progress() || !gnc_current_session_exist()
+            || qof_book_is_readonly(book))
         return FALSE;
 
     /* Store the current toplevel window for later use. */
@@ -287,6 +288,12 @@
             (dirty ? "TRUE" : "FALSE"));
     if (dirty)
     {
+        if (qof_book_is_readonly(book))
+        {
+            //g_debug("Book is read-only, ignoring dirty flag");
+            return;
+        }
+
         /* Book state changed from non-dirty to dirty. */
         if (!qof_book_shutting_down(book))
         {



More information about the gnucash-changes mailing list