[epiphany/webkit2: 7/17] Port editing commands to WebKit2
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/webkit2: 7/17] Port editing commands to WebKit2
- Date: Thu, 21 Jun 2012 11:14:56 +0000 (UTC)
commit 4a10cf7cfcd53469db38e3523f6596748429740f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed May 30 16:49:44 2012 +0200
Port editing commands to WebKit2
src/ephy-window.c | 114 +++++++++++++++++++++++++++++++++++++++---------
src/window-commands.c | 12 +++---
2 files changed, 98 insertions(+), 28 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 6af1699..12c1a21 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1141,11 +1141,71 @@ update_popup_actions_visibility (EphyWindow *window,
}
static void
+update_edit_action_sensitivity (EphyWindow *window, const gchar *action_name, gboolean sensitive, gboolean hide)
+{
+ GtkAction *action;
+
+ action = gtk_action_group_get_action (window->priv->action_group, action_name);
+ gtk_action_set_sensitive (action, sensitive);
+ 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)
{
GtkWidget *widget = gtk_window_get_focus (GTK_WINDOW (window));
- GtkActionGroup *action_group;
- GtkAction *action;
gboolean can_copy, can_cut, can_undo, can_redo, can_paste;
if (GTK_IS_EDITABLE (widget))
@@ -1166,9 +1226,6 @@ update_edit_actions_sensitivity (EphyWindow *window, gboolean hide)
}
else
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Editor */
-#else
EphyEmbed *embed;
WebKitWebView *view;
@@ -1177,6 +1234,31 @@ update_edit_actions_sensitivity (EphyWindow *window, gboolean hide)
view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+#ifdef HAVE_WEBKIT2
+ CanEditCommandAsyncData *data;
+
+ 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);
@@ -1185,23 +1267,11 @@ update_edit_actions_sensitivity (EphyWindow *window, gboolean hide)
#endif
}
- action_group = window->priv->action_group;
-
- action = gtk_action_group_get_action (action_group, "EditCopy");
- gtk_action_set_sensitive (action, can_copy);
- gtk_action_set_visible (action, !hide || can_copy);
- action = gtk_action_group_get_action (action_group, "EditCut");
- gtk_action_set_sensitive (action, can_cut);
- gtk_action_set_visible (action, !hide || can_cut);
- action = gtk_action_group_get_action (action_group, "EditPaste");
- gtk_action_set_sensitive (action, can_paste);
- gtk_action_set_visible (action, !hide || can_paste);
- action = gtk_action_group_get_action (action_group, "EditUndo");
- gtk_action_set_sensitive (action, can_undo);
- gtk_action_set_visible (action, !hide || can_undo);
- action = gtk_action_group_get_action (action_group, "EditRedo");
- gtk_action_set_sensitive (action, can_redo);
- gtk_action_set_visible (action, !hide || can_redo);
+ update_edit_action_sensitivity (window, "EditCopy", can_copy, hide);
+ update_edit_action_sensitivity (window, "EditCut", can_cut, hide);
+ update_edit_action_sensitivity (window, "EditPaste", can_paste, hide);
+ update_edit_action_sensitivity (window, "EditUndo", can_undo, hide);
+ update_edit_action_sensitivity (window, "EditRedo", can_redo, hide);
}
static void
diff --git a/src/window-commands.c b/src/window-commands.c
index 5fc4dfd..be0188a 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]