Add Undo and Redo menu items to the menubar and context menu
This commit is contained in:
parent
39e47ac3b7
commit
d1b672068b
2 changed files with 63 additions and 0 deletions
|
@ -2156,12 +2156,19 @@ _action_edit_activate (GtkAction* action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (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 can_cut = FALSE, can_copy = FALSE, can_paste = FALSE;
|
||||||
gboolean has_selection, can_select_all = FALSE;
|
gboolean has_selection, can_select_all = FALSE;
|
||||||
|
|
||||||
if (WEBKIT_IS_WEB_VIEW (widget))
|
if (WEBKIT_IS_WEB_VIEW (widget))
|
||||||
{
|
{
|
||||||
WebKitWebView* view = WEBKIT_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_cut = webkit_web_view_can_cut_clipboard (view);
|
||||||
can_copy = webkit_web_view_can_copy_clipboard (view);
|
can_copy = webkit_web_view_can_copy_clipboard (view);
|
||||||
can_paste = webkit_web_view_can_paste_clipboard (view);
|
can_paste = webkit_web_view_can_paste_clipboard (view);
|
||||||
|
@ -2187,6 +2194,10 @@ _action_edit_activate (GtkAction* action,
|
||||||
can_select_all = TRUE;
|
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, "Cut", can_cut);
|
||||||
_action_set_sensitive (browser, "Copy", can_copy);
|
_action_set_sensitive (browser, "Copy", can_copy);
|
||||||
_action_set_sensitive (browser, "Paste", can_paste);
|
_action_set_sensitive (browser, "Paste", can_paste);
|
||||||
|
@ -2194,6 +2205,26 @@ _action_edit_activate (GtkAction* action,
|
||||||
_action_set_sensitive (browser, "SelectAll", can_select_all);
|
_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
|
static void
|
||||||
_action_cut_activate (GtkAction* action,
|
_action_cut_activate (GtkAction* action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
|
@ -4294,6 +4325,14 @@ static const GtkActionEntry entries[] = {
|
||||||
N_("Quit the application"), G_CALLBACK (_action_quit_activate) },
|
N_("Quit the application"), G_CALLBACK (_action_quit_activate) },
|
||||||
|
|
||||||
{ "Edit", NULL, N_("_Edit"), NULL, NULL, G_CALLBACK (_action_edit_activate) },
|
{ "Edit", NULL, N_("_Edit"), NULL, NULL, G_CALLBACK (_action_edit_activate) },
|
||||||
|
#if WEBKIT_CHECK_VERSION (1, 1, 14)
|
||||||
|
{ "Undo", GTK_STOCK_UNDO,
|
||||||
|
NULL, "<Ctrl>z",
|
||||||
|
N_("Undo the last modification"), G_CALLBACK (_action_undo_activate) },
|
||||||
|
{ "Redo", GTK_STOCK_REDO,
|
||||||
|
NULL, "<Ctrl><Shift>z",
|
||||||
|
N_("Redo the last modification"), G_CALLBACK (_action_redo_activate) },
|
||||||
|
#endif
|
||||||
{ "Cut", GTK_STOCK_CUT,
|
{ "Cut", GTK_STOCK_CUT,
|
||||||
NULL, "<Ctrl>x",
|
NULL, "<Ctrl>x",
|
||||||
N_("Cut the selected text"), G_CALLBACK (_action_cut_activate) },
|
N_("Cut the selected text"), G_CALLBACK (_action_cut_activate) },
|
||||||
|
@ -4584,6 +4623,11 @@ static const gchar* ui_markup =
|
||||||
"<menuitem action='Quit'/>"
|
"<menuitem action='Quit'/>"
|
||||||
"</menu>"
|
"</menu>"
|
||||||
"<menu action='Edit'>"
|
"<menu action='Edit'>"
|
||||||
|
#if WEBKIT_CHECK_VERSION (1, 1, 14)
|
||||||
|
"<menuitem action='Undo'/>"
|
||||||
|
"<menuitem action='Redo'/>"
|
||||||
|
"<separator/>"
|
||||||
|
#endif
|
||||||
"<menuitem action='Cut'/>"
|
"<menuitem action='Cut'/>"
|
||||||
"<menuitem action='Copy'/>"
|
"<menuitem action='Copy'/>"
|
||||||
"<menuitem action='Paste'/>"
|
"<menuitem action='Paste'/>"
|
||||||
|
|
|
@ -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));
|
icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menuitem));
|
||||||
gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL);
|
gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL);
|
||||||
if (!strcmp (stock_id, GTK_STOCK_CUT))
|
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;
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (strcmp (stock_id, GTK_STOCK_FIND))
|
if (strcmp (stock_id, GTK_STOCK_FIND))
|
||||||
has_selection = FALSE;
|
has_selection = FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue