diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c index 9010465af5..90547adab0 100644 --- a/gnucash/gnome/gnc-plugin-page-register.c +++ b/gnucash/gnome/gnc-plugin-page-register.c @@ -1086,7 +1086,7 @@ gnc_plugin_page_register_ui_update (gpointer various, GncPluginPageRegisterPrivate* priv; SplitRegister* reg; GtkAction* action; - gboolean expanded, voided, read_only = FALSE; + gboolean expanded, voided, read_only = FALSE, read_only_reg = FALSE; Transaction* trans; GList* invoices; CursorClass cursor_class; @@ -1106,62 +1106,83 @@ gnc_plugin_page_register_ui_update (gpointer various, g_signal_handlers_unblock_by_func (action, gnc_plugin_page_register_cmd_expand_transaction, page); + /* If we are in a readonly book, or possibly a place holder + * account register make any modifying action inactive */ + if (qof_book_is_readonly (gnc_get_current_book()) || + gnc_split_reg_get_read_only (priv->gsr)) + read_only_reg = TRUE; + /* Set available actions based on read only */ trans = gnc_split_register_get_current_trans (reg); - if (trans) - read_only = xaccTransIsReadonlyByPostedDate (trans); - voided = xaccTransHasSplitsInState (trans, VREC); - - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "CutTransactionAction"); - gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); - - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "PasteTransactionAction"); - gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); - - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "DeleteTransactionAction"); - gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); - - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "DuplicateTransactionAction"); - gtk_action_set_sensitive (GTK_ACTION (action), TRUE); - - if (cursor_class == CURSOR_CLASS_SPLIT) + /* If the register is not read only, make any modifying action active + * to start with */ + if (!read_only_reg) { + 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, TRUE); + } + + if (trans) + read_only = xaccTransIsReadonlyByPostedDate (trans); + + voided = xaccTransHasSplitsInState (trans, VREC); + + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "CutTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); + + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "PasteTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); + + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "DeleteTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), "DuplicateTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), !read_only & TRUE); + + if (cursor_class == CURSOR_CLASS_SPLIT) + { + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "DuplicateTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); + } + + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "RemoveTransactionSplitsAction"); gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); + + /* Set 'Void' and 'Unvoid' */ + if (read_only) + voided = TRUE; + + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "VoidTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), !voided); + + if (read_only) + voided = FALSE; + + action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), + "UnvoidTransactionAction"); + gtk_action_set_sensitive (GTK_ACTION (action), voided); } - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "RemoveTransactionSplitsAction"); - gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided); - - /* Set 'Void' and 'Unvoid' */ - if (read_only) - voided = TRUE; - - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "VoidTransactionAction"); - gtk_action_set_sensitive (GTK_ACTION (action), !voided); - - if (read_only) - voided = FALSE; - - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), - "UnvoidTransactionAction"); - gtk_action_set_sensitive (GTK_ACTION (action), voided); - /* Set 'Open and Remove Linked Documents' */ - uri = xaccTransGetDocLink (trans); - action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), "LinkedTransactionOpenAction"); - gtk_action_set_sensitive (GTK_ACTION(action), (uri ? TRUE:FALSE)); - + if (trans) + { + uri = xaccTransGetDocLink (trans); + gtk_action_set_sensitive (GTK_ACTION(action), (uri ? TRUE:FALSE)); + } /* Set 'ExecAssociatedInvoice' We can determine an invoice from a txn if either - it is an invoice transaction @@ -1169,15 +1190,17 @@ gnc_plugin_page_register_ui_update (gpointer various, */ action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), "JumpLinkedInvoiceAction"); - - invoices = invoices_from_transaction (trans); - gtk_action_set_sensitive (GTK_ACTION (action), (invoices != NULL)); - g_list_free (invoices); + if (trans) + { + invoices = invoices_from_transaction (trans); + gtk_action_set_sensitive (GTK_ACTION (action), (invoices != NULL)); + g_list_free (invoices); + } gnc_plugin_business_split_reg_ui_update (GNC_PLUGIN_PAGE (page)); - /* If we are in a readonly book, make any modifying action inactive */ - if (qof_book_is_readonly (gnc_get_current_book())) + /* If we are read only, make any modifying action inactive */ + if (read_only_reg) { const char** iter; for (iter = readonly_inactive_actions; *iter; ++iter) @@ -1937,7 +1960,7 @@ finish_scrub (GncPluginPage* page) (GNC_PLUGIN_PAGE(page))), FALSE, _("'Check & Repair' is currently running, do you want to abort it?")); - + show_abort_verify = FALSE; if (ret) @@ -5020,10 +5043,10 @@ scrub_kp_handler (GtkWidget *widget, GdkEventKey *event, gpointer data) { gboolean abort_scrub = gnc_verify_dialog (GTK_WINDOW(widget), FALSE, _("'Check & Repair' is currently running, do you want to abort it?")); - + if (abort_scrub) gnc_set_abort_scrub (TRUE); - + return TRUE; } default: diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c index 717f144dc4..d27f347332 100644 --- a/gnucash/gnome/gnc-split-reg.c +++ b/gnucash/gnome/gnc-split-reg.c @@ -73,7 +73,7 @@ static GtkWidget* add_summary_label( GtkWidget *summarybar, gboolean pack_start, static void gsr_summarybar_set_arrow_draw (GNCSplitReg *gsr); -static void gnc_split_reg_determine_read_only( GNCSplitReg *gsr ); +static void gnc_split_reg_determine_read_only( GNCSplitReg *gsr, gboolean show_dialog ); static gboolean is_trans_readonly_and_warn (GtkWindow *parent, Transaction *trans); static GNCPlaceholderType gnc_split_reg_get_placeholder( GNCSplitReg *gsr ); @@ -378,7 +378,7 @@ gnc_split_reg_init2( GNCSplitReg *gsr ) { if ( !gsr ) return; - gnc_split_reg_determine_read_only( gsr ); + gnc_split_reg_determine_read_only( gsr, TRUE ); gsr_setup_status_widgets( gsr ); /* ordering is important here... setup_status before create_table */ @@ -2488,7 +2488,7 @@ gtk_callback_bug_workaround (gpointer argp) **/ static void -gnc_split_reg_determine_read_only( GNCSplitReg *gsr ) +gnc_split_reg_determine_read_only( GNCSplitReg *gsr, gboolean show_dialog ) { SplitRegister *reg; @@ -2542,7 +2542,8 @@ gnc_split_reg_determine_read_only( GNCSplitReg *gsr ) args = g_malloc(sizeof(dialog_args)); args->string = string; args->gsr = gsr; - g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */ + if (show_dialog) + g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */ } /* Make the contents immutable */ @@ -2631,7 +2632,16 @@ gnc_split_reg_get_summarybar( GNCSplitReg *gsr ) gboolean gnc_split_reg_get_read_only( GNCSplitReg *gsr ) { + SplitRegister *reg; + g_assert( gsr ); + + // reset read_only flag + gsr->read_only = FALSE; + gnc_split_reg_determine_read_only (gsr, FALSE); + + reg = gnc_ledger_display_get_split_register( gsr->ledger ); + gnc_split_register_set_read_only( reg, gsr->read_only ); return gsr->read_only; } diff --git a/gnucash/gnome/gnc-split-reg2.c b/gnucash/gnome/gnc-split-reg2.c index 9e774d3848..20191b109c 100644 --- a/gnucash/gnome/gnc-split-reg2.c +++ b/gnucash/gnome/gnc-split-reg2.c @@ -53,7 +53,7 @@ void gnc_split_reg2_raise (GNCSplitReg2 *gsr); static GtkWidget* add_summary_label (GtkWidget *summarybar, const char *label_str); -static void gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr); +static void gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr, gboolean show_dialog); static void gnc_split_reg2_determine_account_pr (GNCSplitReg2 *gsr); @@ -200,7 +200,7 @@ gnc_split_reg2_init2 (GNCSplitReg2 *gsr) { if (!gsr) return; - gnc_split_reg2_determine_read_only (gsr); + gnc_split_reg2_determine_read_only (gsr, TRUE); gnc_split_reg2_determine_account_pr (gsr); @@ -978,7 +978,7 @@ gtk_callback_bug_workaround (gpointer argp) **/ static void -gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr) //this works +gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr, gboolean show_dialog) { if (qof_book_is_readonly (gnc_get_current_book())) @@ -1018,7 +1018,8 @@ gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr) //this works gsr->read_only = TRUE; /* Put up a warning dialog */ args->gsr = gsr; - g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */ + if (show_dialog) + g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */ } } @@ -1125,6 +1126,10 @@ gboolean gnc_split_reg2_get_read_only (GNCSplitReg2 *gsr) { g_assert (gsr); + + // reset read_only flag + gsr->read_only = FALSE; + gnc_split_reg2_determine_read_only (gsr, FALSE); return gsr->read_only; }