summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-06-22 08:47:53 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-06-25 12:28:58 +0200
commit00ed0403c66295790677fa5a67af8d625da35ab2 (patch)
tree4bca03fd2c666d8077163134ac9114d00ae82892 /src
parentca3d3d87e4bef29988b77fa978fe0771da087e72 (diff)
downloadepiphany-00ed0403c66295790677fa5a67af8d625da35ab2.tar.gz
Port editing commands to WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=678596
Diffstat (limited to 'src')
-rw-r--r--src/ephy-window.c81
-rw-r--r--src/window-commands.c12
2 files changed, 84 insertions, 9 deletions
diff --git a/src/ephy-window.c b/src/ephy-window.c
index c79890a21..8ebaa7e07 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1150,6 +1150,58 @@ update_edit_action_sensitivity (EphyWindow *window, const gchar *action_name, gb
gtk_action_set_visible (action, !hide || sensitive);
}
+#ifdef HAVE_WEBKIT2
+typedef struct
+{
+ EphyWindow *window;
+ const gchar *action_name;
+ gboolean hide;
+} CanEditCommandAsyncData;
+
+static CanEditCommandAsyncData *
+can_edit_command_async_data_new (EphyWindow *window, const gchar *action_name, gboolean hide)
+{
+ CanEditCommandAsyncData *data;
+
+ data = g_slice_new (CanEditCommandAsyncData);
+ data->window = g_object_ref (window);
+ data->action_name = action_name;
+ data->hide = hide;
+
+ return data;
+}
+
+static void
+can_edit_command_async_data_free (CanEditCommandAsyncData *data)
+{
+ if (G_UNLIKELY (!data))
+ return;
+
+ g_object_unref (data->window);
+ g_slice_free (CanEditCommandAsyncData, data);
+}
+
+static void
+can_edit_command_callback (GObject *object, GAsyncResult *result, CanEditCommandAsyncData *data)
+{
+ gboolean sensitive;
+ GError *error = NULL;
+
+ sensitive = webkit_web_view_can_execute_editing_command_finish (WEBKIT_WEB_VIEW (object), result, &error);
+ if (!error)
+ {
+ update_edit_action_sensitivity (data->window, data->action_name, sensitive, data->hide);
+
+ }
+ else
+ {
+ g_error_free (error);
+ }
+
+ can_edit_command_async_data_free (data);
+}
+#endif
+
static void
update_edit_actions_sensitivity (EphyWindow *window, gboolean hide)
{
@@ -1174,17 +1226,40 @@ update_edit_actions_sensitivity (EphyWindow *window, gboolean hide)
}
else
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
-#else
EphyEmbed *embed;
WebKitWebView *view;
+#ifdef HAVE_WEBKIT2
+ CanEditCommandAsyncData *data;
+#endif
embed = window->priv->active_embed;
g_return_if_fail (embed != NULL);
view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+#ifdef HAVE_WEBKIT2
+ data = can_edit_command_async_data_new (window, "EditCopy", hide);
+ webkit_web_view_can_execute_editing_command (view, WEBKIT_EDITING_COMMAND_COPY, NULL,
+ (GAsyncReadyCallback)can_edit_command_callback,
+ data);
+ data = can_edit_command_async_data_new (window, "EditCut", hide);
+ webkit_web_view_can_execute_editing_command (view, WEBKIT_EDITING_COMMAND_CUT, NULL,
+ (GAsyncReadyCallback)can_edit_command_callback,
+ data);
+ data = can_edit_command_async_data_new (window, "EditPaste", hide);
+ webkit_web_view_can_execute_editing_command (view, WEBKIT_EDITING_COMMAND_PASTE, NULL,
+ (GAsyncReadyCallback)can_edit_command_callback,
+ data);
+ data = can_edit_command_async_data_new (window, "EditUndo", hide);
+ webkit_web_view_can_execute_editing_command (view, "Undo", NULL,
+ (GAsyncReadyCallback)can_edit_command_callback,
+ data);
+ data = can_edit_command_async_data_new (window, "EditRedo", hide);
+ webkit_web_view_can_execute_editing_command (view, "Redo", NULL,
+ (GAsyncReadyCallback)can_edit_command_callback,
+ data);
+ return;
+#else
can_copy = webkit_web_view_can_copy_clipboard (view);
can_cut = webkit_web_view_can_cut_clipboard (view);
can_paste = webkit_web_view_can_paste_clipboard (view);
diff --git a/src/window-commands.c b/src/window-commands.c
index 5fc4dfd17..be0188a50 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -686,7 +686,7 @@ window_cmd_edit_undo (GtkAction *action,
if (embed)
{
#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)), "Undo");
#else
webkit_web_view_undo (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)));
#endif
@@ -715,7 +715,7 @@ window_cmd_edit_redo (GtkAction *action,
if (embed)
{
#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)), "Redo");
#else
webkit_web_view_redo (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)));
#endif
@@ -739,7 +739,7 @@ window_cmd_edit_cut (GtkAction *action,
g_return_if_fail (embed != NULL);
#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), WEBKIT_EDITING_COMMAND_CUT);
#else
webkit_web_view_cut_clipboard (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
#endif
@@ -763,7 +763,7 @@ window_cmd_edit_copy (GtkAction *action,
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
g_return_if_fail (embed != NULL);
#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), WEBKIT_EDITING_COMMAND_COPY);
#else
webkit_web_view_copy_clipboard (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
#endif
@@ -788,7 +788,7 @@ window_cmd_edit_paste (GtkAction *action,
g_return_if_fail (embed != NULL);
#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), WEBKIT_EDITING_COMMAND_PASTE);
#else
webkit_web_view_paste_clipboard (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
#endif
@@ -839,7 +839,7 @@ window_cmd_edit_select_all (GtkAction *action,
g_return_if_fail (embed != NULL);
#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), "SelectAll");
#else
webkit_web_view_select_all (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
#endif