[PATCH] Show the WebKit inspector in the main window

From: Gregor Best <gbe_AT_ring0.de>
Date: Sat, 26 Jan 2013 20:46:59 +0100

Signed-off-by: Gregor Best <gbe_AT_ring0.de>
---
 surf.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/surf.c b/surf.c
index 682c1e2..7156c1d 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -42,14 +42,14 @@ union Arg {
 };
 
 typedef struct Client {
-	GtkWidget *win, *scroll, *vbox, *indicator;
+	GtkWidget *win, *scroll, *vbox, *indicator, *pane;
 	WebKitWebView *view;
 	WebKitWebInspector *inspector;
 	char *title, *linkhover;
 	const char *uri, *needle;
 	gint progress;
 	struct Client *next;
-	gboolean zoomed, fullscreen, isinspector, sslfailed;
+	gboolean zoomed, fullscreen, isinspecting, sslfailed;
 } Client;
 
 typedef struct {
_AT_@ -506,28 +506,35 @@ initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
 
 static void
 inspector(Client *c, const Arg *arg) {
-	if(c->isinspector)
-		return;
-	webkit_web_inspector_show(c->inspector);
+	if(c->isinspecting)
+		webkit_web_inspector_close(c->inspector);
+	else
+		webkit_web_inspector_show(c->inspector);
 }
 
 static WebKitWebView *
 inspector_new(WebKitWebInspector *i, WebKitWebView *v, Client *c) {
-	Client *n = newclient();
-	n->isinspector = true;
-
-	return n->view;
+	return WEBKIT_WEB_VIEW(webkit_web_view_new());
 }
 
 static gboolean
 inspector_show(WebKitWebInspector *i, Client *c) {
-	gtk_widget_show(GTK_WIDGET(webkit_web_inspector_get_web_view(i)));
+	if (c->isinspecting)
+		return false;
+	WebKitWebView *w = webkit_web_inspector_get_web_view(i);
+	gtk_paned_pack2(GTK_PANED(c->pane), GTK_WIDGET(w), TRUE, TRUE);
+	gtk_widget_show(GTK_WIDGET(w));
+	c->isinspecting = true;
 	return true;
 }
 
 static gboolean
 inspector_close(WebKitWebInspector *i, Client *c) {
-	gtk_widget_hide(GTK_WIDGET(webkit_web_inspector_get_web_view(i)));
+	if (!c->isinspecting)
+		return false;
+	GtkWidget *w = GTK_WIDGET(webkit_web_inspector_get_web_view(i));
+	gtk_widget_hide(w);
+	c->isinspecting = false;
 	return true;
 }
 
_AT_@ -671,8 +678,12 @@ newclient(void) {
 			"key-press-event",
 			G_CALLBACK(keypress), c);
 
+	/* Pane */
+	c->pane = gtk_vpaned_new();
+
 	/* VBox */
 	c->vbox = gtk_vbox_new(FALSE, 0);
+	gtk_paned_pack1(GTK_PANED(c->pane), c->vbox, TRUE, TRUE);
 
 	/* Scrolled Window */
 	c->scroll = gtk_scrolled_window_new(NULL, NULL);
_AT_@ -726,7 +737,7 @@ newclient(void) {
 
 	/* Arranging */
 	gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
-	gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
+	gtk_container_add(GTK_CONTAINER(c->win), c->pane);
 	gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
 	gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
 
_AT_@ -736,6 +747,7 @@ newclient(void) {
 	gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE,
 			TRUE, 0, GTK_PACK_START);
 	gtk_widget_grab_focus(GTK_WIDGET(c->view));
+	gtk_widget_show(c->pane);
 	gtk_widget_show(c->vbox);
 	gtk_widget_show(c->scroll);
 	gtk_widget_show(GTK_WIDGET(c->view));
_AT_@ -776,7 +788,7 @@ newclient(void) {
 				G_CALLBACK(inspector_close), c);
 		g_signal_connect(G_OBJECT(c->inspector), "finished",
 				G_CALLBACK(inspector_finished), c);
-		c->isinspector = false;
+		c->isinspecting = false;
 	}
 
 	g_free(uri);
-- 
1.8.0.1
--3U8TY7m7wOx7RL1F--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sat Jan 26 2013 - 21:00:05 CET