[epiphany] Add Middle click on open-new-tab to paste the url



commit 088c1afc65835b4cc53d3f3040cf38e569aa4401
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Fri Jan 11 13:03:31 2019 +0100

    Add Middle click on open-new-tab to paste the url
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/203

 src/ephy-action-bar-start.c | 28 +++++++++++++++++++++++++++-
 src/ephy-window.c           |  1 +
 src/window-commands.c       | 39 +++++++++++++++++++++++++++++++++++++++
 src/window-commands.h       |  3 +++
 4 files changed, 70 insertions(+), 1 deletion(-)
---
diff --git a/src/ephy-action-bar-start.c b/src/ephy-action-bar-start.c
index 4576cc045..231e5cfb6 100644
--- a/src/ephy-action-bar-start.c
+++ b/src/ephy-action-bar-start.c
@@ -392,7 +392,30 @@ homepage_button_release_event_cb (GtkButton *button,
   switch (((GdkEventButton *)event)->button) {
     case GDK_BUTTON_MIDDLE:
       action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "homepage-new-tab");
-       g_action_activate (action, NULL);
+      g_action_activate (action, NULL);
+      break;
+    default:
+      break;
+  }
+
+  return G_SOURCE_REMOVE;
+}
+
+static gboolean
+new_tab_button_release_event_cb (GtkButton *button,
+                                 GdkEvent  *event,
+                                 gpointer   user_data)
+{
+  EphyActionBarStart *action_bar_start = EPHY_ACTION_BAR_START (user_data);
+  GActionGroup *action_group;
+  GAction *action;
+
+  action_group = gtk_widget_get_action_group (gtk_widget_get_ancestor (GTK_WIDGET (action_bar_start), 
EPHY_TYPE_WINDOW), "toolbar");
+
+  switch (((GdkEventButton *)event)->button) {
+    case GDK_BUTTON_MIDDLE:
+      action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "new-tab-from-clipboard");
+      g_action_activate (action, NULL);
       break;
     default:
       break;
@@ -488,6 +511,9 @@ ephy_action_bar_start_constructed (GObject *object)
   /* New Tab Button */
   if (ephy_embed_shell_get_mode (embed_shell) == EPHY_EMBED_SHELL_MODE_APPLICATION)
     gtk_widget_set_visible (action_bar_start->new_tab_button, FALSE);
+
+  g_signal_connect (action_bar_start->new_tab_button, "button-release-event",
+                    G_CALLBACK (new_tab_button_release_event_cb), action_bar_start);
 }
 
 static void
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 7c0774b37..aabd740b4 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -857,6 +857,7 @@ static const GActionEntry toolbar_entries [] = {
   { "navigation-forward", window_cmd_navigation },
   { "navigation-forward-new-tab", window_cmd_navigation_new_tab },
   { "homepage-new-tab", window_cmd_homepage_new_tab },
+  { "new-tab-from-clipboard", window_cmd_new_tab_from_clipboard },
 
   { "stop", window_cmd_stop },
   { "reload", window_cmd_reload },
diff --git a/src/window-commands.c b/src/window-commands.c
index 56fe6f86e..41b57c64b 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -2636,3 +2636,42 @@ window_cmd_homepage_new_tab (GSimpleAction *action,
 
   gtk_widget_grab_focus (GTK_WIDGET (embed));
 }
+
+static void
+clipboard_text_received_cb (GtkClipboard *clipboard,
+                            const gchar  *text,
+                            EphyWindow   *window)
+{
+  EphyEmbed *embed;
+  EphyWebView *web_view;
+
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+  g_assert (embed != NULL);
+
+  embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                              EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))),
+                              NULL,
+                              0);
+
+  web_view = ephy_embed_get_web_view (embed);
+  ephy_web_view_load_url (web_view, text);
+
+  ephy_embed_container_set_active_child (EPHY_EMBED_CONTAINER (window), embed);
+  gtk_widget_grab_focus (GTK_WIDGET (embed));
+
+  g_object_unref (window);
+}
+
+void
+window_cmd_new_tab_from_clipboard (GSimpleAction *action,
+                                   GVariant      *parameter,
+                                   gpointer       user_data)
+{
+  EphyWindow *ephy_window = EPHY_WINDOW (user_data);
+  GtkClipboard *clipboard;
+
+  clipboard = gtk_clipboard_get_default (gdk_display_get_default ());
+  gtk_clipboard_request_text (clipboard,
+                              (GtkClipboardTextReceivedFunc)clipboard_text_received_cb,
+                              g_object_ref (ephy_window));
+}
diff --git a/src/window-commands.h b/src/window-commands.h
index c06aa39b7..0e8ad4a54 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -215,5 +215,8 @@ void window_cmd_open_application_manager        (GSimpleAction *action,
 void window_cmd_homepage_new_tab                (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);
+void window_cmd_new_tab_from_clipboard          (GSimpleAction *action,
+                                                 GVariant      *parameter,
+                                                 gpointer       user_data);
 
 G_END_DECLS


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