[Gnucash-changes] r13384 - gnucash/trunk - Provide the right edit
menu sensitivity for the register page.
David Hampton
hampton at cvs.gnucash.org
Fri Feb 24 18:17:10 EST 2006
Author: hampton
Date: 2006-02-24 18:17:10 -0500 (Fri, 24 Feb 2006)
New Revision: 13384
Trac: http://svn.gnucash.org/trac/changeset/13384
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/gnome-utils/gnc-main-window.c
gnucash/trunk/src/gnome-utils/gnc-plugin-page.h
gnucash/trunk/src/gnome/gnc-plugin-page-register.c
gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c
gnucash/trunk/src/register/register-gnome/gnucash-item-edit.h
gnucash/trunk/src/register/register-gnome/gnucash-sheet.c
gnucash/trunk/src/register/register-gnome/gnucash-sheet.h
Log:
Provide the right edit menu sensitivity for the register page.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/ChangeLog 2006-02-24 23:17:10 UTC (rev 13384)
@@ -1,5 +1,15 @@
2006-02-24 David Hampton <hampton at employees.org>
+ * src/register/register-gnome/gnucash-sheet.[ch]:
+ * src/register/register-gnome/gnucash-item-edit.[ch]:
+ * src/gnome/gnc-plugin-page-register.c: Override the generic edit
+ menu sensitivity code to provide the right sensitivity for the
+ entry widget buried in the register.
+
+ * src/gnome-utils/gnc-main-window.c:
+ * src/gnome-utils/gnc-plugin-page.h: Provide a hook for pages to
+ override the generic edit menu sensitivity code.
+
* src/gnome-utils/ui/gnc-main-window-ui.xml:
* src/gnome-utils/gnc-main-window.c: Remove unnecessary menu
item. The same functionality exists in the "Menus & Toolbars"
Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c 2006-02-24 23:17:10 UTC (rev 13384)
@@ -93,6 +93,7 @@
static void gnc_plugin_page_register_window_changed (GncPluginPage *plugin_page, GtkWidget *window);
static void gnc_plugin_page_register_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
static GncPluginPage *gnc_plugin_page_register_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
+static void gnc_plugin_page_register_update_edit_menu (GncPluginPage *page, gboolean hide);
static gchar *gnc_plugin_page_register_get_tab_name (GncPluginPage *plugin_page);
@@ -502,6 +503,7 @@
gnc_plugin_class->window_changed = gnc_plugin_page_register_window_changed;
gnc_plugin_class->save_page = gnc_plugin_page_register_save_page;
gnc_plugin_class->recreate_page = gnc_plugin_page_register_recreate_page;
+ gnc_plugin_class->update_edit_menu_actions = gnc_plugin_page_register_update_edit_menu;
g_type_class_add_private(klass, sizeof(GncPluginPageRegisterPrivate));
}
@@ -987,7 +989,39 @@
return page;
}
-
+
+/*
+ * Based on code from Epiphany (src/ephy-window.c)
+ */
+static void
+gnc_plugin_page_register_update_edit_menu (GncPluginPage *page, gboolean hide)
+{
+ GncPluginPageRegisterPrivate *priv;
+ GncPluginPageRegister *reg_page;
+ GtkAction *action;
+ gboolean can_copy = FALSE, can_cut = FALSE, can_paste = FALSE;
+ gboolean has_selection;
+
+ reg_page = GNC_PLUGIN_PAGE_REGISTER(page);
+ priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(reg_page);
+ has_selection = gnucash_register_has_selection (priv->gsr->reg);
+
+ can_copy = has_selection;
+ can_cut = has_selection;
+ can_paste = TRUE;
+
+ action = gnc_plugin_page_get_action (page, "EditCopyAction");
+ gtk_action_set_sensitive (action, can_copy);
+ gtk_action_set_visible (action, !hide || can_copy);
+ action = gnc_plugin_page_get_action (page, "EditCutAction");
+ gtk_action_set_sensitive (action, can_cut);
+ gtk_action_set_visible (action, !hide || can_cut);
+ action = gnc_plugin_page_get_action (page, "EditPasteAction");
+ gtk_action_set_sensitive (action, can_paste);
+ gtk_action_set_visible (action, !hide || can_paste);
+}
+
+
static gchar *
gnc_plugin_page_register_get_tab_name (GncPluginPage *plugin_page)
{
Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c 2006-02-24 23:17:10 UTC (rev 13384)
@@ -354,9 +354,6 @@
* have meaning. */
static const gchar *always_insensitive_actions[] = {
"FilePrintAction",
- "EditCutAction",
- "EditCopyAction",
- "EditPasteAction",
NULL
};
@@ -2171,10 +2168,19 @@
static void
gnc_main_window_update_edit_actions_sensitivity (GncMainWindow *window, gboolean hide)
{
+ GncMainWindowPrivate *priv;
+ GncPluginPage *page;
GtkWidget *widget = gtk_window_get_focus (GTK_WINDOW (window));
GtkAction *action;
gboolean can_copy = FALSE, can_cut = FALSE, can_paste = FALSE;
+ priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+ page = priv->current_page;
+ if (GNC_PLUGIN_PAGE_GET_CLASS(page)->update_edit_menu_actions) {
+ (GNC_PLUGIN_PAGE_GET_CLASS(page)->update_edit_menu_actions)(page, hide);
+ return;
+ }
+
if (GTK_IS_EDITABLE (widget))
{
gboolean has_selection;
Modified: gnucash/trunk/src/gnome-utils/gnc-plugin-page.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin-page.h 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin-page.h 2006-02-24 23:17:10 UTC (rev 13384)
@@ -165,6 +165,16 @@
* @param name The new name for this page. */
void (* page_name_changed) (GncPluginPage *plugin_page,
const gchar *name);
+
+ /** This function vector allows page specific actions to
+ * override the generic code for setting the sensitivity of
+ * items in the Edit menu.
+ *
+ * @param page The front page in a main window..
+ *
+ * @param hide Whether the widgets should be shown or
+ * hidden. */
+ void (* update_edit_menu_actions) (GncPluginPage *plugin_page, gboolean hide);
} GncPluginPageClass;
Modified: gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c 2006-02-24 23:17:10 UTC (rev 13384)
@@ -1542,6 +1542,18 @@
}
gboolean
+gnc_item_edit_get_has_selection (GncItemEdit *item_edit)
+{
+ GtkEditable *editable;
+
+ g_return_val_if_fail ((item_edit != NULL), FALSE);
+ g_return_val_if_fail (GNC_IS_ITEM_EDIT (item_edit), FALSE);
+
+ editable = GTK_EDITABLE (item_edit->editor);
+ return gtk_editable_get_selection_bounds(editable, NULL, NULL);
+}
+
+gboolean
gnc_item_edit_selection_clear (GncItemEdit *item_edit,
GdkEventSelection *event)
{
Modified: gnucash/trunk/src/register/register-gnome/gnucash-item-edit.h
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-item-edit.h 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/register/register-gnome/gnucash-item-edit.h 2006-02-24 23:17:10 UTC (rev 13384)
@@ -157,6 +157,7 @@
void gnc_item_edit_paste_primary (GncItemEdit *item_edit, guint32 time);
void gnc_item_edit_set_has_selection (GncItemEdit *item_edit, gboolean has_selection);
+gboolean gnc_item_edit_get_has_selection (GncItemEdit *item_edit);
gboolean gnc_item_edit_selection_clear (GncItemEdit *item_edit,
GdkEventSelection *event);
Modified: gnucash/trunk/src/register/register-gnome/gnucash-sheet.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-sheet.c 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/register/register-gnome/gnucash-sheet.c 2006-02-24 23:17:10 UTC (rev 13384)
@@ -1367,6 +1367,21 @@
return TRUE;
}
+gboolean
+gnucash_register_has_selection (GnucashRegister *reg)
+{
+ GnucashSheet *sheet;
+ GncItemEdit *item_edit;
+
+ g_return_val_if_fail((reg != NULL), FALSE);
+ g_return_val_if_fail(GNUCASH_IS_REGISTER(reg), FALSE);
+
+ sheet = GNUCASH_SHEET(reg->sheet);
+ item_edit = GNC_ITEM_EDIT(sheet->item_editor);
+
+ return gnc_item_edit_get_has_selection(item_edit);
+}
+
void
gnucash_register_cut_clipboard (GnucashRegister *reg)
{
Modified: gnucash/trunk/src/register/register-gnome/gnucash-sheet.h
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-sheet.h 2006-02-24 22:58:28 UTC (rev 13383)
+++ gnucash/trunk/src/register/register-gnome/gnucash-sheet.h 2006-02-24 23:17:10 UTC (rev 13384)
@@ -209,6 +209,7 @@
void gnucash_register_set_initial_rows(guint num_rows);
+gboolean gnucash_register_has_selection (GnucashRegister *reg);
void gnucash_register_cut_clipboard (GnucashRegister *reg);
void gnucash_register_copy_clipboard (GnucashRegister *reg);
void gnucash_register_paste_clipboard (GnucashRegister *reg);
More information about the gnucash-changes
mailing list