r21569 - gnucash/trunk/src - Take into account the read-only flag of the book to update the buttons in the register accordingly.

Christian Stimming cstim at code.gnucash.org
Mon Nov 14 16:28:32 EST 2011


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

Modified:
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
   gnucash/trunk/src/gnome/gnc-split-reg.c
Log:
Take into account the read-only flag of the book to update the buttons in the register accordingly.

Also, the register itself must be read-only.

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2011-11-14 19:43:20 UTC (rev 21568)
+++ gnucash/trunk/src/engine/Transaction.c	2011-11-14 21:28:32 UTC (rev 21569)
@@ -1121,8 +1121,11 @@
 
     if (qof_book_shutting_down(qof_instance_get_book(trans))) return;
 
-    xaccOpenLog ();
-    xaccTransWriteLog (trans, 'B');
+    if (!qof_book_is_readonly(qof_instance_get_book(trans)))
+    {
+        xaccOpenLog ();
+        xaccTransWriteLog (trans, 'B');
+    }
 
     /* Make a clone of the transaction; we will use this
      * in case we need to roll-back the edit. */
@@ -1179,7 +1182,7 @@
     	destroy_gains (trans);
 
     /* Make a log in the journal before destruction.  */
-    if (!shutting_down)
+    if (!shutting_down && !qof_book_is_readonly(qof_instance_get_book(trans)))
         xaccTransWriteLog (trans, 'D');
 
     qof_event_gen (&trans->inst, QOF_EVENT_DESTROY, NULL);
@@ -1288,7 +1291,8 @@
     }
     g_list_free(slist);
 
-    xaccTransWriteLog (trans, 'C');
+    if (!qof_book_is_readonly(qof_instance_get_book(trans)))
+        xaccTransWriteLog (trans, 'C');
 
     /* Get rid of the copy we made. We won't be rolling back,
      * so we don't need it any more.  */
@@ -1512,7 +1516,8 @@
         }
     }
 
-    xaccTransWriteLog (trans, 'R');
+    if (!qof_book_is_readonly(qof_instance_get_book(trans)))
+        xaccTransWriteLog (trans, 'R');
 
     xaccFreeTransaction (trans->orig);
 

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2011-11-14 19:43:20 UTC (rev 21568)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2011-11-14 21:28:32 UTC (rev 21569)
@@ -745,6 +745,31 @@
     return NULL;
 }
 
+/* This is the list of actions which are switched inactive in a read-only book. */
+static const char* readonly_inactive_actions[] =
+{
+    "EditCutAction",
+    "EditPasteAction",
+    "CutTransactionAction",
+    "PasteTransactionAction",
+    "DuplicateTransactionAction",
+    "DeleteTransactionAction",
+    "RemoveTransactionSplitsAction",
+    "RecordTransactionAction",
+    "CancelTransactionAction",
+    "UnvoidTransactionAction",
+    "VoidTransactionAction",
+    "ReverseTransactionAction",
+    "ShiftTransactionForwardAction",
+    "ActionsTransferAction",
+    "ActionsReconcileAction",
+    "ActionsStockSplitAction",
+    "ScheduleTransactionAction",
+    "ScrubAllAction",
+    "ScrubCurrentAction",
+    NULL
+};
+
 static void
 gnc_plugin_page_register_ui_update (gpointer various, GncPluginPageRegister *page)
 {
@@ -777,6 +802,19 @@
     action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page),
                                          "UnvoidTransactionAction");
     gtk_action_set_sensitive (GTK_ACTION(action), voided);
+
+    /* If we are in a readonly book, make any modifying action inactive */
+    if (qof_book_is_readonly(gnc_get_current_book()))
+    {
+        const char **iter;
+        for (iter = readonly_inactive_actions; *iter; ++iter)
+        {
+            /* Set the action's sensitivity */
+            GtkAction *action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), *iter);
+            gtk_action_set_sensitive(action, FALSE);
+        }
+
+    }
 }
 
 static void

Modified: gnucash/trunk/src/gnome/gnc-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.c	2011-11-14 19:43:20 UTC (rev 21568)
+++ gnucash/trunk/src/gnome/gnc-split-reg.c	2011-11-14 21:28:32 UTC (rev 21569)
@@ -1975,6 +1975,13 @@
     dialog_args *args = g_malloc(sizeof(dialog_args));
     SplitRegister *reg;
 
+    if (qof_book_is_readonly(gnc_get_current_book()))
+    {
+        /* Is the book read-only? Then for sure also make this register
+        read-only. */
+        gsr->read_only = TRUE;
+    }
+
     if ( !gsr->read_only )
     {
 



More information about the gnucash-changes mailing list