Bug 794976 - Wrong context menu on register sheet

Block the entry one and signal for the gnucash one to show.
This commit is contained in:
Robert Fewell 2018-04-21 15:13:03 +01:00
parent 6a37d7f5dd
commit 4e2697b02f
7 changed files with 132 additions and 45 deletions

View File

@ -172,7 +172,6 @@ static void gnc_main_window_cmd_help_contents (GtkAction *action, GncMainWindow
static void gnc_main_window_cmd_help_about (GtkAction *action, GncMainWindow *window);
static void do_popup_menu(GncPluginPage *page, GdkEventButton *event);
static gboolean gnc_main_window_popup_menu_cb (GtkWidget *widget, GncPluginPage *page);
static GtkWidget *gnc_main_window_get_statusbar (GncWindow *window_in);
static void statusbar_notification_lastmodified(void);
@ -4797,7 +4796,7 @@ do_popup_menu(GncPluginPage *page, GdkEventButton *event)
* @return Always returns TRUE to indicate that the menu request was
* handled.
*/
static gboolean
gboolean
gnc_main_window_popup_menu_cb (GtkWidget *widget,
GncPluginPage *page)
{

View File

@ -322,6 +322,24 @@ gboolean gnc_main_window_button_press_cb (GtkWidget *whatever,
GdkEventButton *event,
GncPluginPage *page);
/** Callback function invoked when the user requests that Gnucash
* popup the contextual menu via the keyboard context-menu request
* key combination (Shift-F10 by default).
*
* @param page This is the GncPluginPage corresponding to the visible
* page.
*
* @param widget Whatever widget had focus when the user issued the
* keyboard context-menu request.
*
* @return Always returns TRUE to indicate that the menu request was
* handled.
*/
gboolean gnc_main_window_popup_menu_cb (GtkWidget *widget,
GncPluginPage *page);
/** Restore the persistent state of all windows.
*
* @param keyfile The GKeyFile containing persistent window state.

View File

@ -180,6 +180,7 @@ static void gnc_plugin_page_register_cmd_associate_location_transaction (GtkActi
static void gnc_plugin_page_register_cmd_execassociated_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
static void gnc_plugin_page_help_changed_cb( GNCSplitReg *gsr, GncPluginPageRegister *register_page );
static void gnc_plugin_page_popup_menu_cb( GNCSplitReg *gsr, GncPluginPageRegister *register_page );
static void gnc_plugin_page_register_refresh_cb (GHashTable *changes, gpointer user_data);
static void gnc_plugin_page_register_close_cb (gpointer user_data);
@ -1129,6 +1130,10 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
G_CALLBACK ( gnc_plugin_page_help_changed_cb ),
page );
g_signal_connect (G_OBJECT (gsr), "show-popup-menu",
G_CALLBACK ( gnc_plugin_page_popup_menu_cb ),
page );
reg = gnc_ledger_display_get_split_register(priv->ledger);
gnc_split_register_config(reg, reg->type, reg->style,
reg->use_double_line);
@ -4054,6 +4059,23 @@ gnc_plugin_page_help_changed_cb (GNCSplitReg *gsr, GncPluginPageRegister *regist
g_free(help);
}
static void
gnc_plugin_page_popup_menu_cb (GNCSplitReg *gsr, GncPluginPageRegister *register_page)
{
GncWindow *window;
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(register_page));
window = GNC_WINDOW(GNC_PLUGIN_PAGE(register_page)->window);
if (!window)
{
// This routine can be called before the page is added to a
// window.
return;
}
gnc_main_window_popup_menu_cb (GTK_WIDGET(window), GNC_PLUGIN_PAGE(register_page));
}
static void
gnc_plugin_page_register_refresh_cb (GHashTable *changes, gpointer user_data)
{

View File

@ -115,6 +115,7 @@ void gsr_default_execassociated_handler ( GNCSplitReg *w, gpointer ud );
static void gsr_emit_simple_signal ( GNCSplitReg *gsr, const char *sigName );
static void gsr_emit_help_changed ( GnucashRegister *reg, gpointer user_data );
static void gsr_emit_show_popup_menu ( GnucashRegister *reg, gpointer user_data );
static void gsr_emit_include_date_signal ( GNCSplitReg *gsr, time64 date );
void gnc_split_reg_cut_cb(GtkWidget *w, gpointer data);
@ -221,6 +222,7 @@ enum gnc_split_reg_signal_enum
UNVOID_TXN_SIGNAL,
REVERSE_TXN_SIGNAL,
HELP_CHANGED_SIGNAL,
SHOW_POPUP_MENU_SIGNAL,
INCLUDE_DATE_SIGNAL,
LAST_SIGNAL
};
@ -258,6 +260,7 @@ gnc_split_reg_class_init( GNCSplitRegClass *klass )
{ UNVOID_TXN_SIGNAL, "unvoid_txn", G_STRUCT_OFFSET( GNCSplitRegClass, unvoid_txn_cb ) },
{ REVERSE_TXN_SIGNAL, "reverse_txn", G_STRUCT_OFFSET( GNCSplitRegClass, reverse_txn_cb ) },
{ HELP_CHANGED_SIGNAL, "help-changed", G_STRUCT_OFFSET( GNCSplitRegClass, help_changed_cb ) },
{ SHOW_POPUP_MENU_SIGNAL, "show-popup-menu", G_STRUCT_OFFSET( GNCSplitRegClass, show_popup_menu_cb ) },
{ INCLUDE_DATE_SIGNAL, "include-date", G_STRUCT_OFFSET( GNCSplitRegClass, include_date_cb ) },
{ LAST_SIGNAL, NULL, 0 }
};
@ -309,6 +312,7 @@ gnc_split_reg_class_init( GNCSplitRegClass *klass )
klass->reverse_txn_cb = gsr_default_reverse_txn_handler;
klass->help_changed_cb = NULL;
klass->show_popup_menu_cb = NULL;
klass->include_date_cb = NULL;
}
@ -416,6 +420,8 @@ gsr_create_table( GNCSplitReg *gsr )
G_CALLBACK(gsr_redraw_all_cb), gsr);
g_signal_connect (gsr->reg, "redraw_help",
G_CALLBACK(gsr_emit_help_changed), gsr);
g_signal_connect (gsr->reg, "show_popup_menu",
G_CALLBACK(gsr_emit_show_popup_menu), gsr);
LEAVE(" ");
}
@ -2205,6 +2211,13 @@ gsr_emit_help_changed( GnucashRegister *reg, gpointer user_data )
gsr_emit_simple_signal( (GNCSplitReg*)user_data, "help-changed" );
}
static
void
gsr_emit_show_popup_menu( GnucashRegister *reg, gpointer user_data )
{
gsr_emit_simple_signal( (GNCSplitReg*)user_data, "show-popup-menu" );
}
static
void
gsr_emit_include_date_signal( GNCSplitReg *gsr, time64 date )

View File

@ -111,6 +111,7 @@ struct _GNCSplitRegClass
void (*unvoid_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*reverse_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*help_changed_cb) ( GNCSplitReg *w, gpointer user_data );
void (*show_popup_menu_cb) ( GNCSplitReg *w, gpointer user_data );
void (*include_date_cb) ( GNCSplitReg *w, time64 date, gpointer user_data );
};
/* Something somewhere sets these to silly values and causes problems */

View File

@ -801,6 +801,22 @@ gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side)
}
}
static gboolean
button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer *pointer)
{
GnucashSheet *sheet = GNUCASH_SHEET(pointer);
/* Ignore double-clicks and triple-clicks */
if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
{
// This is a right click event so over ride entry menu and
// display main register popup menu.
g_signal_emit_by_name (sheet->reg, "show_popup_menu");
return TRUE;
}
return FALSE;
}
GtkWidget *
gnc_item_edit_new (GnucashSheet *sheet)
{
@ -867,6 +883,11 @@ gnc_item_edit_new (GnucashSheet *sheet)
g_signal_connect (item_edit, "draw",
G_CALLBACK (draw_background_cb), item_edit);
// This call back intercepts the mouse button event so the main
// register popup menu can be displayed instead of the entry one.
g_signal_connect (item_edit->editor, "button-press-event",
G_CALLBACK (button_press_cb), sheet);
/* Create the popup button
It will only be displayed when the cell being edited provides
a popup item (like a calendar or account list) */

View File

@ -53,6 +53,7 @@ enum
ACTIVATE_CURSOR,
REDRAW_ALL,
REDRAW_HELP,
SHOW_POPUP_MENU,
LAST_SIGNAL
};
@ -82,6 +83,7 @@ struct _GnucashRegisterClass
void (*activate_cursor) (GnucashRegister *reg);
void (*redraw_all) (GnucashRegister *reg);
void (*redraw_help) (GnucashRegister *reg);
void (*show_popup_menu) (GnucashRegister *reg);
};
/** Implementation *****************************************************/
@ -351,9 +353,20 @@ gnucash_register_class_init (GnucashRegisterClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
register_signals[SHOW_POPUP_MENU] =
g_signal_new("show_popup_menu",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(GnucashRegisterClass,
show_popup_menu),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
klass->activate_cursor = NULL;
klass->redraw_all = NULL;
klass->redraw_help = NULL;
klass->show_popup_menu = NULL;
}