Skip to content

Bug 799363 - When selecting "load" two layer ... #2094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions gnucash/html/gnc-html-history.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <gtk/gtk.h>
#include <string.h>
#include <stdbool.h>

#include "gnc-html-history.h"

Expand All @@ -33,6 +34,9 @@ struct _gnc_html_history
GList * current_node;
GList * last_node;

/* To know in gnc_html_history_append that the history should not be added if it was pressed */
bool pressedBACK, pressedFWD;

/* call this whenever a node is destroyed */
gnc_html_history_destroy_cb destroy_cb;
gpointer destroy_cb_data;
Expand All @@ -49,6 +53,8 @@ gnc_html_history_new(void)
hist->nodes = NULL;
hist->current_node = NULL;
hist->last_node = NULL;
hist->pressedBACK = FALSE;
hist->pressedFWD = FALSE;
return hist;
}

Expand Down Expand Up @@ -126,6 +132,20 @@ gnc_html_history_append(gnc_html_history * hist,
GList * n;
gnc_html_history_node * hn;

// If Back button has been pressed don't append history.
if (hist && hist->pressedBACK) {
hist->pressedBACK = FALSE;
hist->last_node = hist->current_node;
return;
}

// If Forward button has been pressed don't append history.
if (hist && hist->pressedFWD) {
hist->pressedFWD = FALSE;
hist->last_node = hist->current_node;
return;
}

if (hist->current_node)
{
hn = hist->current_node->data;
Expand Down Expand Up @@ -210,6 +230,7 @@ gnc_html_history_forward(gnc_html_history * hist)
if (hist->current_node->next)
{
hist->current_node = hist->current_node->next;
hist->pressedFWD = TRUE;
}

return hist->current_node->data;
Expand All @@ -232,6 +253,7 @@ gnc_html_history_back(gnc_html_history * hist)
if (hist->current_node->prev)
{
hist->current_node = hist->current_node->prev;
hist->pressedBACK = TRUE;
}

return hist->current_node->data;
Expand Down
59 changes: 59 additions & 0 deletions gnucash/html/gnc-html-webkit2.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ static void impl_webkit_print (GncHtml* self,const gchar* jobname);
static void impl_webkit_cancel( GncHtml* self );
static void impl_webkit_set_parent( GncHtml* self, GtkWindow* parent );
static void impl_webkit_default_zoom_changed(gpointer prefs, gchar *pref, gpointer user_data);
static gboolean webkit_context_menu_cb(WebKitWebView *web_view,
WebKitContextMenu *context_menu,
GdkEvent *event,
WebKitHitTestResult *hit_test_result,
gpointer user_data);

static GtkWidget*
gnc_html_webkit_webview_new (void)
Expand Down Expand Up @@ -206,6 +211,10 @@ gnc_html_webkit_init( GncHtmlWebkit* self )
g_signal_connect (priv->web_view, "resource-load-started",
G_CALLBACK (webkit_resource_load_started_cb),
self);
g_signal_connect(priv->web_view, "context-menu",
G_CALLBACK(webkit_context_menu_cb),
self);

gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REPORT,
GNC_PREF_RPT_DFLT_ZOOM,
impl_webkit_default_zoom_changed,
Expand Down Expand Up @@ -727,6 +736,56 @@ webkit_resource_load_started_cb (WebKitWebView *web_view,
data);
}

/*
*
* We need to delete the Back and Forward items from the right-click menu because
* otherwise the Back and Forward buttons won't work properly.
Comment on lines +741 to +742
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes the context menu different from those of most browsers. Better to replace the menu items with new ones that use the same actions as the toolbar buttons.

*
*/
static gboolean
webkit_context_menu_cb(WebKitWebView *web_view,
WebKitContextMenu *context_menu,
GdkEvent *event,
WebKitHitTestResult *hit_test_result,
gpointer data)
{
// We can only delete one item at a time.
GList *menu_items = webkit_context_menu_get_items(context_menu);
for (GList *l = menu_items; l != NULL; l = g_list_next(l)) {
WebKitContextMenuItem *item = WEBKIT_CONTEXT_MENU_ITEM(l->data);
WebKitContextMenuAction action = webkit_context_menu_item_get_stock_action(item);
if (action == WEBKIT_CONTEXT_MENU_ACTION_GO_BACK)
{
webkit_context_menu_remove(context_menu, item);
// Because GList has changed we cannot remove another item.
break;
} else if (action == WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD) {
webkit_context_menu_remove(context_menu, item);
// Because GList has changed we cannot remove another item.
break;
}
}

// We need to get items again.
menu_items = webkit_context_menu_get_items(context_menu);
for (GList *l = menu_items; l != NULL; l = g_list_next(l)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid single-letter names except for integer indexes. node is a typical name for list members.
Always put curly braces on their own line. GnuCash's style specifies that they should be flush with the introducing line.

WebKitContextMenuItem *item = WEBKIT_CONTEXT_MENU_ITEM(l->data);
WebKitContextMenuAction action = webkit_context_menu_item_get_stock_action(item);
if (action == WEBKIT_CONTEXT_MENU_ACTION_GO_BACK)
{
webkit_context_menu_remove(context_menu, item);
// Because GList has changed we cannot remove another item.
break;
} else if (action == WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD) {
webkit_context_menu_remove(context_menu, item);
// Because GList has changed we cannot remove another item.
break;
}
}
Comment on lines +769 to +784
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't duplicate code. You could extract this to a separate function that takes the WebKitContextMenuAction as an argument and call it twice.

But you don't need to do either. You can keep on working with the list, you just need to advance the node before you delete it:

for (GList* node = menu_items; node;)
{
    WebKitContextMenuItem *item = WEBKIT_CONTEXT_MENU_ITEM (node->data);
    WebKitContextMenuAction action = webkit_context_menu_item_get_stock_action (item);
    node = g_list_next (node);
    if (action == WEBKIT_CONTEXT_MENU_ACTION_GO_BACK ||
        action == WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD)
        webkit_context_menu_remove(context_menu, item);
}


return FALSE;
}

/********************************************************************
* gnc_html_open_scm
* insert some scheme-generated HTML
Expand Down