[epiphany/mcatanzaro/#415: 116/116] Add support for paste as plaintext



commit 2b2368dca6a2b4ebdbf191f8f506466aee150ca8
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Mon May 18 15:17:48 2020 -0500

    Add support for paste as plaintext
    
    Requires new WebKitGTK APIs:
    
    https://bugs.webkit.org/show_bug.cgi?id=177638
    https://bugs.webkit.org/show_bug.cgi?id=212038
    
    Fixes #415

 meson.build           |  2 +-
 src/ephy-window.c     | 11 +++++++++++
 src/window-commands.c | 20 ++++++++++++++++++++
 src/window-commands.h |  3 +++
 4 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 05563d178..cb032e2a8 100644
--- a/meson.build
+++ b/meson.build
@@ -76,7 +76,7 @@ config_h = declare_dependency(
 glib_requirement = '>= 2.61.2'
 gtk_requirement = '>= 3.24.0'
 nettle_requirement = '>= 3.4'
-webkitgtk_requirement = '>= 2.27.4'
+webkitgtk_requirement = '>= 2.29.2'
 
 cairo_dep = dependency('cairo', version: '>= 1.2')
 gcr_dep = dependency('gcr-3', version: '>= 3.5.5')
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 9ef73392e..181b59653 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -93,6 +93,7 @@ const struct {
   { "win.copy", { "<Primary>C", NULL } },
   { "win.cut", { "<Primary>X", NULL } },
   { "win.paste", { "<Primary>V", NULL } },
+  { "win.paste-as-plain-text", { "<shift><Primary>V", NULL } },
   { "win.zoom-in", { "<Primary>plus", "<Primary>KP_Add", "<Primary>equal", "ZoomIn", NULL } },
   { "win.zoom-out", { "<Primary>minus", "<Primary>KP_Subtract", "ZoomOut", NULL } },
   { "win.zoom-normal", { "<Primary>0", "<Primary>KP_0", NULL } },
@@ -778,6 +779,7 @@ update_edit_actions_sensitivity (EphyWindow *window,
   update_edit_action_sensitivity (window, "cut", can_cut, hide);
   update_edit_action_sensitivity (window, "copy", can_copy, hide);
   update_edit_action_sensitivity (window, "paste", can_paste, hide);
+  update_edit_action_sensitivity (window, "paste-as-plain-text", can_paste, hide);
   update_edit_action_sensitivity (window, "undo", can_undo, hide);
   update_edit_action_sensitivity (window, "redo", can_redo, hide);
 }
@@ -797,6 +799,8 @@ enable_edit_actions_sensitivity (EphyWindow *window)
   g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
   action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "paste");
   g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+  action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "paste-as-plain-text");
+  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
   action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "undo");
   g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
   action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "redo");
@@ -835,6 +839,7 @@ static const GActionEntry window_entries [] = {
   { "cut", window_cmd_cut },
   { "copy", window_cmd_copy },
   { "paste", window_cmd_paste },
+  { "paste-as-plain-text", window_cmd_paste_as_plain_text },
   { "delete", window_cmd_delete },
   { "zoom-in", window_cmd_zoom_in },
   { "zoom-out", window_cmd_zoom_out },
@@ -952,6 +957,7 @@ const struct {
   { "cut", N_("Cu_t") },
   { "copy", N_("_Copy") },
   { "paste", N_("_Paste") },
+  { "paste-as-plain-text", N_("_Paste Text Only") },
   { "select-all", N_("Select _All") },
 
   { "send-to", N_("S_end Link by Email…") },
@@ -1489,6 +1495,7 @@ populate_context_menu (WebKitWebView       *web_view,
   WebKitContextMenuItem *toggle_controls_item = NULL;
   WebKitContextMenuItem *toggle_loop_item = NULL;
   WebKitContextMenuItem *fullscreen_item = NULL;
+  WebKitContextMenuItem *paste_as_plain_text_item = NULL;
   GActionGroup *window_action_group;
   GActionGroup *toolbar_action_group;
   GActionGroup *popup_action_group;
@@ -1524,6 +1531,7 @@ populate_context_menu (WebKitWebView       *web_view,
   }
 
   if (webkit_hit_test_result_context_is_editable (hit_test_result)) {
+    paste_as_plain_text_item = find_item_in_context_menu (context_menu, 
WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT);
     input_methods_item = find_item_in_context_menu (context_menu, WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
     insert_emoji_item = find_item_in_context_menu (context_menu, WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI);
     spelling_guess_items = find_spelling_guess_context_menu_items (context_menu);
@@ -1666,6 +1674,9 @@ populate_context_menu (WebKitWebView       *web_view,
                                 "copy", window);
     add_action_to_context_menu (context_menu, window_action_group,
                                 "paste", window);
+    if (paste_as_plain_text_item)
+      add_action_to_context_menu (context_menu, window_action_group,
+                                  "paste-as-plain-text", window);
     webkit_context_menu_append (context_menu,
                                 webkit_context_menu_item_new_separator ());
     add_action_to_context_menu (context_menu, window_action_group,
diff --git a/src/window-commands.c b/src/window-commands.c
index d706c969d..a9e7ab39f 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -2182,6 +2182,26 @@ window_cmd_paste (GSimpleAction *action,
   }
 }
 
+void
+window_cmd_paste_as_plain_text (GSimpleAction *action,
+                                GVariant      *parameter,
+                                gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  GtkWidget *widget = gtk_window_get_focus (GTK_WINDOW (window));
+
+  if (GTK_IS_EDITABLE (widget)) {
+    gtk_editable_paste_clipboard (GTK_EDITABLE (widget));
+  } else {
+    EphyEmbed *embed;
+
+    embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+    g_assert (embed != NULL);
+
+    webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), 
WEBKIT_EDITING_COMMAND_PASTE_AS_PLAIN_TEXT);
+  }
+}
+
 void
 window_cmd_delete (GSimpleAction *action,
                    GVariant      *parameter,
diff --git a/src/window-commands.h b/src/window-commands.h
index c7f58cd35..ca80dcf63 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -107,6 +107,9 @@ void window_cmd_copy                            (GSimpleAction *action,
 void window_cmd_paste                           (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);
+void window_cmd_paste_as_plain_text             (GSimpleAction *action,
+                                                 GVariant      *parameter,
+                                                 gpointer       user_data);
 void window_cmd_delete                          (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]