Revision: 1776 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1776&view=re... Author: colombanw Date: 2010-12-19 13:23:32 +0000 (Sun, 19 Dec 2010)
Log Message: ----------- WebHelper: make possible to place the browser widget in it's own window
This may be useful for dual-head setups, or simply for better flexibility.
Modified Paths: -------------- trunk/geany-plugins/webhelper/src/gwh-browser.h trunk/geany-plugins/webhelper/src/gwh-plugin.c trunk/geany-plugins/webhelper/src/gwh-settings.c
Modified: trunk/geany-plugins/webhelper/src/gwh-browser.h =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-browser.h 2010-12-19 13:23:10 UTC (rev 1775) +++ trunk/geany-plugins/webhelper/src/gwh-browser.h 2010-12-19 13:23:32 UTC (rev 1776) @@ -36,7 +36,8 @@
typedef enum { GWH_BROWSER_POSITION_MESSAGE_WINDOW, - GWH_BROWSER_POSITION_SIDEBAR + GWH_BROWSER_POSITION_SIDEBAR, + GWH_BROWSER_POSITION_SEPARATE_WINDOW } GwhBrowserPosition;
Modified: trunk/geany-plugins/webhelper/src/gwh-plugin.c =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-plugin.c 2010-12-19 13:23:10 UTC (rev 1775) +++ trunk/geany-plugins/webhelper/src/gwh-plugin.c 2010-12-19 13:23:32 UTC (rev 1776) @@ -29,6 +29,7 @@ #include <geany.h> #include <document.h>
+#include "gwh-utils.h" #include "gwh-browser.h" #include "gwh-settings.h"
@@ -55,50 +56,130 @@ )
+enum { + CONTAINER_NOTEBOOK, + CONTAINER_WINDOW +}; + + static GtkWidget *G_browser = NULL; -static gint G_page_num = 0; -static GtkWidget *G_notebook = NULL; +static struct { + guint type; + GtkWidget *widget; + + /* only valid if type == CONTAINER_NOTEBOOK */ + gint page_num; +} G_container; static GwhSettings *G_settings = NULL;
static void +on_separate_window_destroy (GtkWidget *widget, + gpointer data) +{ + gwh_browser_set_inspector_transient_for (GWH_BROWSER (G_browser), NULL); + gtk_container_remove (GTK_CONTAINER (G_container.widget), G_browser); +} + +static gboolean +on_idle_widget_show (gpointer data) +{ + gchar *geometry; + + gtk_widget_show (data); + g_object_get (G_settings, "browser-separate-window-geometry", &geometry, NULL); + gwh_set_window_geometry (GTK_WINDOW (data), geometry, NULL, NULL); + g_free (geometry); + /* present back the Geany's window because it is very unlikely the user + * expects the focus on our newly created window at this point, since we + * either just loaded the plugin or activated a element from Geany's UI */ + gtk_window_present (GTK_WINDOW (geany_data->main_widgets->window)); + + return FALSE; +} + +static GtkWidget * +create_separate_window (void) +{ + GtkWidget *window; + + window = g_object_new (GTK_TYPE_WINDOW, + "type", GTK_WINDOW_TOPLEVEL, + "skip-taskbar-hint", TRUE, + "title", _("Web view"), + "deletable", FALSE, + NULL); + g_signal_connect (window, "destroy", + G_CALLBACK (on_separate_window_destroy), NULL); + gtk_container_add (GTK_CONTAINER (window), G_browser); + gtk_window_set_transient_for (GTK_WINDOW (window), + GTK_WINDOW (geany_data->main_widgets->window)); + gwh_browser_set_inspector_transient_for (GWH_BROWSER (G_browser), + GTK_WINDOW (window)); + + return window; +} + +static void attach_browser (void) { GwhBrowserPosition position;
g_object_get (G_settings, "browser-position", &position, NULL); - if (position == GWH_BROWSER_POSITION_SIDEBAR) { - G_notebook = geany_data->main_widgets->sidebar_notebook; + if (position == GWH_BROWSER_POSITION_SEPARATE_WINDOW) { + G_container.type = CONTAINER_WINDOW; + G_container.widget = create_separate_window (); + /* seems that if a window is shown before it's transient parent, bad stuff + * happend. so, show our window a little later. */ + g_idle_add (on_idle_widget_show, G_container.widget); } else { - G_notebook = geany_data->main_widgets->message_window_notebook; + G_container.type = CONTAINER_NOTEBOOK; + if (position == GWH_BROWSER_POSITION_SIDEBAR) { + G_container.widget = geany_data->main_widgets->sidebar_notebook; + } else { + G_container.widget = geany_data->main_widgets->message_window_notebook; + } + G_container.page_num = gtk_notebook_append_page (GTK_NOTEBOOK (G_container.widget), + G_browser, + gtk_label_new (_("Web preview"))); + gwh_browser_set_inspector_transient_for (GWH_BROWSER (G_browser), + GTK_WINDOW (geany_data->main_widgets->window)); } - G_page_num = gtk_notebook_append_page (GTK_NOTEBOOK (G_notebook), G_browser, - gtk_label_new (_("Web preview"))); }
static void detach_browser (void) { - /* remove the page we added. we handle the case where the page were - * reordered */ - if (gtk_notebook_get_nth_page (GTK_NOTEBOOK (G_notebook), - G_page_num) != G_browser) { - gint i; - gint n; + if (G_container.type == CONTAINER_WINDOW) { + gchar *geometry;
- G_page_num = -1; - n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (G_notebook)); - for (i = 0; i < n; i++) { - if (gtk_notebook_get_nth_page (GTK_NOTEBOOK (G_notebook), - i) == G_browser) { - G_page_num = i; - break; + geometry = gwh_get_window_geometry (GTK_WINDOW (G_container.widget), 0, 0); + g_object_set (G_settings, "browser-separate-window-geometry", geometry, NULL); + g_free (geometry); + gtk_widget_destroy (G_container.widget); + } else { + GtkNotebook *notebook = GTK_NOTEBOOK (G_container.widget); + gint page_num = G_container.page_num; + + /* remove the page we added. we handle the case where the page were + * reordered */ + if (gtk_notebook_get_nth_page (notebook, page_num) != G_browser) { + gint i; + gint n; + + page_num = -1; + n = gtk_notebook_get_n_pages (notebook); + for (i = 0; i < n; i++) { + if (gtk_notebook_get_nth_page (notebook, i) == G_browser) { + page_num = i; + break; + } } } + if (page_num >= 0) { + gtk_notebook_remove_page (notebook, page_num); + } } - if (G_page_num >= 0) { - gtk_notebook_remove_page (GTK_NOTEBOOK (G_notebook), G_page_num); - } }
static void @@ -210,8 +291,6 @@ load_config ();
G_browser = gwh_browser_new (); - gwh_browser_set_inspector_transient_for (GWH_BROWSER (G_browser), - GTK_WINDOW (data->main_widgets->window)); g_signal_connect (G_browser, "populate-popup", G_CALLBACK (on_browser_populate_popup), NULL);
Modified: trunk/geany-plugins/webhelper/src/gwh-settings.c =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-settings.c 2010-12-19 13:23:10 UTC (rev 1775) +++ trunk/geany-plugins/webhelper/src/gwh-settings.c 2010-12-19 13:23:32 UTC (rev 1776) @@ -45,6 +45,7 @@ gchar *browser_last_uri; GtkOrientation browser_orientation; GwhBrowserPosition browser_position; + gchar *browser_separate_window_geometry; gchar *inspector_window_geometry; };
@@ -55,6 +56,7 @@ PROP_BROWSER_LAST_URI, PROP_BROWSER_ORIENTATION, PROP_BROWSER_POSITION, + PROP_BROWSER_SEPARATE_WINDOW_GEOMETRY, PROP_INSPECTOR_WINDOW_GEOMETRY };
@@ -83,6 +85,9 @@ case PROP_BROWSER_POSITION: g_value_set_enum (value, self->priv->browser_position); break; + case PROP_BROWSER_SEPARATE_WINDOW_GEOMETRY: + g_value_set_string (value, self->priv->browser_separate_window_geometry); + break; case PROP_INSPECTOR_WINDOW_GEOMETRY: g_value_set_string (value, self->priv->inspector_window_geometry); break; @@ -113,6 +118,10 @@ case PROP_BROWSER_POSITION: self->priv->browser_position = g_value_get_enum (value); break; + case PROP_BROWSER_SEPARATE_WINDOW_GEOMETRY: + setptr (self->priv->browser_separate_window_geometry, + g_value_dup_string (value)); + break; case PROP_INSPECTOR_WINDOW_GEOMETRY: setptr (self->priv->inspector_window_geometry, g_value_dup_string (value)); break; @@ -193,6 +202,12 @@ GWH_TYPE_BROWSER_POSITION, GWH_BROWSER_POSITION_MESSAGE_WINDOW, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_BROWSER_SEPARATE_WINDOW_GEOMETRY, + g_param_spec_string ("browser-separate-window-geometry", + "Browser separate window geometry", + "Last geometry of the separated browser's window", + "400x300", + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_INSPECTOR_WINDOW_GEOMETRY, g_param_spec_string ("inspector-window-geometry", "Inspector window geometry", @@ -212,6 +227,7 @@ self->priv->browser_last_uri = g_strdup ("about:blank"); self->priv->browser_orientation = GTK_ORIENTATION_VERTICAL; self->priv->browser_position = GWH_BROWSER_POSITION_MESSAGE_WINDOW; + self->priv->browser_separate_window_geometry = g_strdup ("400x300"); self->priv->inspector_window_geometry = g_strdup ("400x300"); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.