r21815 - gnucash/trunk/src - Read-only mode: More menu items grayed out: Close Book; Online Banking Setup.
Christian Stimming
cstim at code.gnucash.org
Sun Jan 1 15:36:30 EST 2012
Author: cstim
Date: 2012-01-01 15:36:29 -0500 (Sun, 01 Jan 2012)
New Revision: 21815
Trac: http://svn.gnucash.org/trac/changeset/21815
Modified:
gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c
gnucash/trunk/src/import-export/aqbanking/gnc-plugin-aqbanking.c
Log:
Read-only mode: More menu items grayed out: Close Book; Online Banking Setup.
Modified: gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c 2012-01-01 19:49:28 UTC (rev 21814)
+++ gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c 2012-01-01 20:36:29 UTC (rev 21815)
@@ -65,6 +65,7 @@
static void gnc_plugin_basic_commands_finalize (GObject *object);
static void gnc_plugin_basic_commands_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
+static void gnc_plugin_basic_commands_main_window_page_changed(GncMainWindow *window, GncPluginPage *page, gpointer user_data);
/* Command callbacks */
static void gnc_main_window_cmd_file_new (GtkAction *action, GncMainWindowActionData *data);
@@ -218,6 +219,12 @@
NULL,
};
+static const gchar *readonly_inactive_actions[] =
+{
+ "FileSaveAction",
+ "ToolsBookCloseAction",
+ NULL
+};
/** The instance private data structure for an basic commands
* plugin. */
@@ -297,8 +304,48 @@
GncMainWindow *window,
GQuark type)
{
+ g_signal_connect(window, "page_changed",
+ G_CALLBACK(gnc_plugin_basic_commands_main_window_page_changed),
+ plugin);
}
+/** Update the actions sensitivity
+*/
+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);
+}
+
+static void
+gnc_plugin_basic_commands_main_window_page_changed(GncMainWindow *window,
+ GncPluginPage *page,
+ gpointer user_data)
+{
+ /* Make sure not to call this with a NULL GncPluginPage */
+ if (page)
+ {
+ // Update the action sensitivity due to read-only
+ update_inactive_actions(page);
+ }
+}
+
/** Initialize the class for a new basic commands plugin. This will
* set up any function pointers that override functions in the parent
* class, and also configure the private data storage for this
Modified: gnucash/trunk/src/import-export/aqbanking/gnc-plugin-aqbanking.c
===================================================================
--- gnucash/trunk/src/import-export/aqbanking/gnc-plugin-aqbanking.c 2012-01-01 19:49:28 UTC (rev 21814)
+++ gnucash/trunk/src/import-export/aqbanking/gnc-plugin-aqbanking.c 2012-01-01 20:36:29 UTC (rev 21815)
@@ -48,6 +48,7 @@
#include "gnc-plugin-page-account-tree.h"
#include "gnc-plugin-page-register.h"
#include "gnc-main-window.h"
+#include "gnc-ui-util.h" // for gnc_get_current_book
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = G_LOG_DOMAIN;
@@ -174,6 +175,13 @@
NULL
};
+static const gchar *readonly_inactive_actions[] =
+{
+ "OnlineActionsAction",
+ "ABSetupAction",
+ NULL
+};
+
static GncMainWindow *gnc_main_window = NULL;
/************************************************************
@@ -286,6 +294,31 @@
LEAVE(" ");
}
+/** Update the actions sensitivity
+*/
+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);
+}
+
+
/**
* Whenever the current page has changed, update the aqbanking menus based upon
* the page that is currently selected.
@@ -299,7 +332,11 @@
/* Make sure not to call this with a NULL GncPluginPage */
if (page)
{
+ // Update the menu items according to the selected account
gnc_plugin_ab_account_selected(page, account, user_data);
+
+ // Also update the action sensitivity due to read-only
+ update_inactive_actions(page);
}
}
More information about the gnucash-changes
mailing list