From a1dbbfe2307b6305bb9fe61f00ba7672eeda7aab Mon Sep 17 00:00:00 2001 From: David Hampton Date: Fri, 24 Feb 2006 23:17:10 +0000 Subject: [PATCH] Provide the right edit menu sensitivity for the register page. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13384 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 10 ++++++ src/gnome-utils/gnc-main-window.c | 12 +++++-- src/gnome-utils/gnc-plugin-page.h | 10 ++++++ src/gnome/gnc-plugin-page-register.c | 36 ++++++++++++++++++- .../register-gnome/gnucash-item-edit.c | 12 +++++++ .../register-gnome/gnucash-item-edit.h | 1 + src/register/register-gnome/gnucash-sheet.c | 15 ++++++++ src/register/register-gnome/gnucash-sheet.h | 1 + 8 files changed, 93 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 025e60edb8..3dd1dac37b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2006-02-24 David Hampton + * 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" diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c index 5f77720066..18fe35ccfa 100644 --- a/src/gnome-utils/gnc-main-window.c +++ b/src/gnome-utils/gnc-main-window.c @@ -354,9 +354,6 @@ static const gchar *gnc_menu_important_actions[] = { * have meaning. */ static const gchar *always_insensitive_actions[] = { "FilePrintAction", - "EditCutAction", - "EditCopyAction", - "EditPasteAction", NULL }; @@ -2171,10 +2168,19 @@ gnc_main_window_update_toolbar (GncMainWindow *window) 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; diff --git a/src/gnome-utils/gnc-plugin-page.h b/src/gnome-utils/gnc-plugin-page.h index 864a789e04..8bfefc0c3a 100644 --- a/src/gnome-utils/gnc-plugin-page.h +++ b/src/gnome-utils/gnc-plugin-page.h @@ -165,6 +165,16 @@ typedef struct { * @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; diff --git a/src/gnome/gnc-plugin-page-register.c b/src/gnome/gnc-plugin-page-register.c index 5d5ae8a432..e57df757a4 100644 --- a/src/gnome/gnc-plugin-page-register.c +++ b/src/gnome/gnc-plugin-page-register.c @@ -93,6 +93,7 @@ static void gnc_plugin_page_register_destroy_widget (GncPluginPage *plugin_page) 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_page_register_class_init (GncPluginPageRegisterClass *klass) 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 @@ gnc_plugin_page_register_recreate_page (GtkWidget *window, 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) { diff --git a/src/register/register-gnome/gnucash-item-edit.c b/src/register/register-gnome/gnucash-item-edit.c index c53bf46fb0..198c5128ed 100644 --- a/src/register/register-gnome/gnucash-item-edit.c +++ b/src/register/register-gnome/gnucash-item-edit.c @@ -1541,6 +1541,18 @@ gnc_item_edit_set_has_selection (GncItemEdit *item_edit, gboolean has_selection) item_edit->has_selection = has_selection; } +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) diff --git a/src/register/register-gnome/gnucash-item-edit.h b/src/register/register-gnome/gnucash-item-edit.h index fb887d9cf7..4e6d4b29f2 100644 --- a/src/register/register-gnome/gnucash-item-edit.h +++ b/src/register/register-gnome/gnucash-item-edit.h @@ -157,6 +157,7 @@ void gnc_item_edit_paste_clipboard (GncItemEdit *item_edit, guint32 time); 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); diff --git a/src/register/register-gnome/gnucash-sheet.c b/src/register/register-gnome/gnucash-sheet.c index d999b177e9..54c204b01b 100644 --- a/src/register/register-gnome/gnucash-sheet.c +++ b/src/register/register-gnome/gnucash-sheet.c @@ -1367,6 +1367,21 @@ gnucash_button_press_event (GtkWidget *widget, GdkEventButton *event) 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) { diff --git a/src/register/register-gnome/gnucash-sheet.h b/src/register/register-gnome/gnucash-sheet.h index a50f3c1b23..a2686d9a24 100644 --- a/src/register/register-gnome/gnucash-sheet.h +++ b/src/register/register-gnome/gnucash-sheet.h @@ -209,6 +209,7 @@ void gnucash_register_attach_popup(GnucashRegister *reg, GtkWidget *popup, 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);