Commit 82be33bd authored by Carlos Alberto Lopez Perez's avatar Carlos Alberto Lopez Perez Committed by Michael Catanzaro

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
parent 649e66a6
......@@ -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;
}
......@@ -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
......
......@@ -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",
......
......@@ -1355,6 +1355,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)
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment