[gnome-notes/wip/igaldino/remove-format-paste] webkit-editor: enable text-only paste



commit f40d0ac1e6d78491b36a0faac3a37e3ccb79ef14
Author: Isaque Galdino <igaldino gmail com>
Date:   Tue Jun 16 14:56:52 2020 -0300

    webkit-editor: enable text-only paste
    
    It also disables webkit context menu.

 src/bjb-application.c                   |  2 ++
 src/bjb-window-base.c                   | 14 ++++++++++++++
 src/libbiji/editor/biji-webkit-editor.c | 14 +++++++++++++-
 3 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/src/bjb-application.c b/src/bjb-application.c
index b01409b..ec829d5 100644
--- a/src/bjb-application.c
+++ b/src/bjb-application.c
@@ -392,6 +392,7 @@ bijiben_startup (GApplication *application)
 
   const gchar *vaccels_close[] = {"<Primary>w", NULL};
   const gchar *vaccels_detach[] = {"<Primary>d", NULL};
+  const gchar *vaccels_paste[] = {"<Primary>v", NULL};
   const gchar *vaccels_redo[] = {"<Primary><Shift>z", NULL};
   const gchar *vaccels_undo[] = {"<Primary>z", NULL};
   const gchar *vaccels_trash[] = {"<Primary>Delete", NULL};
@@ -403,6 +404,7 @@ bijiben_startup (GApplication *application)
 
   gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.close", vaccels_close);
   gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.detach-window", vaccels_detach);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.paste", vaccels_paste);
   gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.redo", vaccels_redo);
   gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.undo", vaccels_undo);
   gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.trash", vaccels_trash);
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 63a8339..91cf26a 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -220,6 +220,19 @@ on_detach_window_cb (GSimpleAction *action,
   bijiben_new_window_for_note (g_application_get_default (), note);
 }
 
+static void
+on_paste_cb (GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
+{
+  BijiNoteObj *note = bjb_window_base_get_note (BJB_WINDOW_BASE (user_data));
+
+  if (!note)
+    return;
+
+  biji_webkit_editor_paste (BIJI_WEBKIT_EDITOR (biji_note_obj_get_editor (note)));
+}
+
 static void
 on_undo_cb (GSimpleAction *action,
             GVariant      *parameter,
@@ -353,6 +366,7 @@ bjb_window_base_configure_event (GtkWidget         *widget,
 
 static GActionEntry win_entries[] = {
   { "detach-window", on_detach_window_cb, NULL, NULL, NULL },
+  { "paste", on_paste_cb, NULL, NULL, NULL },
   { "undo", on_undo_cb, NULL, NULL, NULL },
   { "redo", on_redo_cb, NULL, NULL, NULL },
   { "view-notebooks", on_view_notebooks_cb, NULL, NULL, NULL },
diff --git a/src/libbiji/editor/biji-webkit-editor.c b/src/libbiji/editor/biji-webkit-editor.c
index 1e67741..f16b1fa 100644
--- a/src/libbiji/editor/biji-webkit-editor.c
+++ b/src/libbiji/editor/biji-webkit-editor.c
@@ -200,7 +200,7 @@ biji_webkit_editor_copy (BijiWebkitEditor *self)
 void
 biji_webkit_editor_paste (BijiWebkitEditor *self)
 {
-  webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (self), WEBKIT_EDITING_COMMAND_PASTE);
+  webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (self), "PasteAsPlainText");
 }
 
 void
@@ -390,6 +390,16 @@ on_load_change (WebKitWebView  *web_view,
   }
 }
 
+static gboolean
+on_context_menu (WebKitWebView       *web_view,
+                 WebKitContextMenu   *context_menu,
+                 GdkEvent            *event,
+                 WebKitHitTestResult *hit_test_result,
+                 gpointer             user_data)
+{
+  return TRUE;
+}
+
 static void
 biji_webkit_editor_handle_contents_update (BijiWebkitEditor *self,
                                            JSCValue         *js_value)
@@ -507,6 +517,8 @@ biji_webkit_editor_constructed (GObject *obj)
                     G_CALLBACK (on_navigation_request), NULL);
   g_signal_connect (view, "load-changed",
                     G_CALLBACK (on_load_change), NULL);
+  g_signal_connect (view, "context-menu",
+                    G_CALLBACK (on_context_menu), NULL);
 }
 
 static void


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