From d1b672068b733d212c2630fa6cc4266821197237 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 10 Sep 2009 02:17:18 +0200 Subject: [PATCH] Add Undo and Redo menu items to the menubar and context menu --- midori/midori-browser.c | 44 +++++++++++++++++++++++++++++++++++++++++ midori/midori-view.c | 19 ++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index eb0cf7ee..ac58f11f 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2156,12 +2156,19 @@ _action_edit_activate (GtkAction* action, MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); + #if WEBKIT_CHECK_VERSION (1, 1, 14) + gboolean can_undo = FALSE, can_redo = FALSE; + #endif gboolean can_cut = FALSE, can_copy = FALSE, can_paste = FALSE; gboolean has_selection, can_select_all = FALSE; if (WEBKIT_IS_WEB_VIEW (widget)) { WebKitWebView* view = WEBKIT_WEB_VIEW (widget); + #if WEBKIT_CHECK_VERSION (1, 1, 14) + can_undo = webkit_web_view_can_undo (view); + can_redo = webkit_web_view_can_redo (view); + #endif can_cut = webkit_web_view_can_cut_clipboard (view); can_copy = webkit_web_view_can_copy_clipboard (view); can_paste = webkit_web_view_can_paste_clipboard (view); @@ -2187,6 +2194,10 @@ _action_edit_activate (GtkAction* action, can_select_all = TRUE; } + #if WEBKIT_CHECK_VERSION (1, 1, 14) + _action_set_sensitive (browser, "Undo", can_undo); + _action_set_sensitive (browser, "Redo", can_redo); + #endif _action_set_sensitive (browser, "Cut", can_cut); _action_set_sensitive (browser, "Copy", can_copy); _action_set_sensitive (browser, "Paste", can_paste); @@ -2194,6 +2205,26 @@ _action_edit_activate (GtkAction* action, _action_set_sensitive (browser, "SelectAll", can_select_all); } +#if WEBKIT_CHECK_VERSION (1, 1, 14) +static void +_action_undo_activate (GtkAction* action, + MidoriBrowser* browser) +{ + GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); + if (WEBKIT_IS_WEB_VIEW (widget)) + webkit_web_view_undo (WEBKIT_WEB_VIEW (widget)); +} + +static void +_action_redo_activate (GtkAction* action, + MidoriBrowser* browser) +{ + GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); + if (WEBKIT_IS_WEB_VIEW (widget)) + webkit_web_view_redo (WEBKIT_WEB_VIEW (widget)); +} +#endif + static void _action_cut_activate (GtkAction* action, MidoriBrowser* browser) @@ -4294,6 +4325,14 @@ static const GtkActionEntry entries[] = { N_("Quit the application"), G_CALLBACK (_action_quit_activate) }, { "Edit", NULL, N_("_Edit"), NULL, NULL, G_CALLBACK (_action_edit_activate) }, + #if WEBKIT_CHECK_VERSION (1, 1, 14) + { "Undo", GTK_STOCK_UNDO, + NULL, "z", + N_("Undo the last modification"), G_CALLBACK (_action_undo_activate) }, + { "Redo", GTK_STOCK_REDO, + NULL, "z", + N_("Redo the last modification"), G_CALLBACK (_action_redo_activate) }, + #endif { "Cut", GTK_STOCK_CUT, NULL, "x", N_("Cut the selected text"), G_CALLBACK (_action_cut_activate) }, @@ -4584,6 +4623,11 @@ static const gchar* ui_markup = "" "" "" + #if WEBKIT_CHECK_VERSION (1, 1, 14) + "" + "" + "" + #endif "" "" "" diff --git a/midori/midori-view.c b/midori/midori-view.c index 3b06aba0..4391152a 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -1204,7 +1204,26 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view, icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menuitem)); gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL); if (!strcmp (stock_id, GTK_STOCK_CUT)) + { + #if WEBKIT_CHECK_VERSION (1, 1, 14) + if (!strcmp (stock_id, GTK_STOCK_UNDO)) + return; + menuitem = gtk_separator_menu_item_new (); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem); + gtk_widget_show (menuitem); + menuitem = sokoke_action_create_popup_menu_item ( + gtk_action_group_get_action (actions, "Redo")); + gtk_widget_set_sensitive (menuitem, + webkit_web_view_can_redo (web_view)); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem); + menuitem = sokoke_action_create_popup_menu_item ( + gtk_action_group_get_action (actions, "Undo")); + gtk_widget_set_sensitive (menuitem, + webkit_web_view_can_undo (web_view)); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem); return; + } + #endif if (strcmp (stock_id, GTK_STOCK_FIND)) has_selection = FALSE; }