[epiphany] Allow to toggle the Web Inspector with keyboard shortcuts.



commit 82be33bd7ee5be099111c7d0e63ea295fa4bb335
Author: Carlos Alberto Lopez Perez <clopez igalia com>
Date:   Mon May 30 19:57:36 2016 +0200

    Allow to toggle the Web Inspector with keyboard shortcuts.
    
      This maps the keyboard shortcuts CTRL+SHIFT+I and F12 (these are
      standard ones as are used also on Chromium, Firefox and Safari).
    
      It keeps track also of whether the Inspector window is loaded or
      not, so the keyboard shortcut closes the inspector window when it
      is already loaded on a given tab.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676870

 embed/ephy-embed.c    |   32 ++++++++++++++++++++++++++++++++
 embed/ephy-embed.h    |    1 +
 src/ephy-window.c     |    7 +++++++
 src/window-commands.c |   25 +++++++++++++++++++++++++
 src/window-commands.h |    2 ++
 5 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 1069abc..4e5ce46 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -84,6 +84,7 @@ struct _EphyEmbed {
 
   gulong status_handler_id;
   gulong progress_update_handler_id;
+  gboolean inspector_loaded;
 };
 
 G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX)
@@ -517,6 +518,16 @@ ephy_embed_attach_inspector_cb (WebKitWebInspector *inspector,
 
   gtk_paned_add2 (embed->paned, inspector_view);
   gtk_widget_show (inspector_view);
+  embed->inspector_loaded = TRUE;
+
+  return TRUE;
+}
+
+static gboolean
+ephy_embed_close_inspector_cb (WebKitWebInspector *inspector,
+                                EphyEmbed          *embed)
+{
+  embed->inspector_loaded = FALSE;
 
   return TRUE;
 }
@@ -779,6 +790,9 @@ ephy_embed_constructed (GObject *object)
   g_signal_connect (inspector, "attach",
                     G_CALLBACK (ephy_embed_attach_inspector_cb),
                     embed);
+  g_signal_connect (inspector, "closed",
+                    G_CALLBACK (ephy_embed_close_inspector_cb),
+                    embed);
 }
 
 static void
@@ -792,6 +806,7 @@ ephy_embed_init (EphyEmbed *embed)
   embed->seq_context_id = 1;
   embed->seq_message_id = 1;
   embed->tab_message_id = ephy_embed_statusbar_get_context_id (embed, 
EPHY_EMBED_STATUSBAR_TAB_MESSAGE_CONTEXT_DESCRIPTION);
+  embed->inspector_loaded = FALSE;
 }
 
 /**
@@ -925,3 +940,20 @@ ephy_embed_get_title (EphyEmbed *embed)
 
   return embed->title;
 }
+
+
+/**
+ * ephy_embed_inspector_is_loaded:
+ * @embed: a #EphyEmbed
+ *
+ * Checks if the Web Inspector is loaded in this #EphyEmbed.
+ *
+ * Returns: %TRUE or %FALSE
+ */
+gboolean
+ephy_embed_inspector_is_loaded (EphyEmbed *embed)
+{
+  g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE);
+
+  return embed->inspector_loaded;
+}
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index f552921..22f85bf 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -44,6 +44,7 @@ void             ephy_embed_set_delayed_load_request (EphyEmbed *embed,
                                                       WebKitURIRequest          *request,
                                                       WebKitWebViewSessionState *state);
 gboolean         ephy_embed_has_load_pending         (EphyEmbed *embed);
+gboolean         ephy_embed_inspector_is_loaded      (EphyEmbed *embed);
 const char      *ephy_embed_get_title                (EphyEmbed *embed);
 
 G_END_DECLS
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 220f0d9..1b2eb9a 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -153,6 +153,8 @@ static const GtkActionEntry ephy_menu_entries [] = {
     G_CALLBACK (window_cmd_view_encoding) },
   { "ViewPageSource", NULL, N_("_Page Source"), "<control>U", NULL,
     G_CALLBACK (window_cmd_view_page_source) },
+  { "ViewToggleInspector", NULL, N_("_Toggle Inspector"), "<shift><control>I", NULL,
+    G_CALLBACK (window_cmd_view_toggle_inspector) },
 
   /* Bookmarks actions. */
 
@@ -283,6 +285,10 @@ static const struct {
   { GDK_KEY_R, GDK_CONTROL_MASK, "ViewReload", FALSE },
   { GDK_KEY_R, GDK_CONTROL_MASK |
     GDK_SHIFT_MASK, "ViewReload", FALSE },
+  { GDK_KEY_F12, 0, "ViewToggleInspector", FALSE },
+  { GDK_KEY_I, GDK_CONTROL_MASK |
+    GDK_SHIFT_MASK, "ViewToggleInspector", FALSE },
+
   /* Tab navigation */
   { GDK_KEY_Page_Up, GDK_CONTROL_MASK, "TabsPrevious", FALSE },
   { GDK_KEY_Page_Down, GDK_CONTROL_MASK, "TabsNext", FALSE },
@@ -3064,6 +3070,7 @@ static const char *disabled_actions_for_app_mode[] = { "FileOpen",
                                                        "FileSaveAsApplication",
                                                        "ViewEncoding",
                                                        "ViewPageSource",
+                                                       "ViewToggleInspector",
                                                        "FileBookmarkPage",
                                                        "EditBookmarks",
                                                        "EditHistory",
diff --git a/src/window-commands.c b/src/window-commands.c
index be9744c..f06a7ca 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1356,6 +1356,31 @@ window_cmd_view_page_source (GtkAction  *action,
 }
 
 void
+window_cmd_view_toggle_inspector (GtkAction  *action,
+                                  EphyWindow *window)
+{
+
+  EphyEmbed *embed;
+  WebKitWebView *view;
+  WebKitWebInspector *inspector_window;
+
+  embed = ephy_embed_container_get_active_child
+            (EPHY_EMBED_CONTAINER (window));
+  g_return_if_fail (embed != NULL);
+
+  gtk_widget_grab_focus (GTK_WIDGET (embed));
+
+  view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+
+  inspector_window = webkit_web_view_get_inspector (view);
+
+  if (!ephy_embed_inspector_is_loaded (embed))
+    webkit_web_inspector_show (inspector_window);
+  else
+    webkit_web_inspector_close (inspector_window);
+}
+
+void
 window_cmd_help_contents (GtkAction *action,
                           GtkWidget *window)
 {
diff --git a/src/window-commands.h b/src/window-commands.h
index 1db5a47..922a84c 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -78,6 +78,8 @@ void window_cmd_view_zoom_normal          (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_view_page_source          (GtkAction  *action,
                                            EphyWindow *window);
+void window_cmd_view_toggle_inspector     (GtkAction  *action,
+                                           EphyWindow *window);
 void window_cmd_help_contents             (GtkAction  *action,
                                            GtkWidget  *window);
 void window_cmd_help_about                (GtkAction  *action,


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