item = katze_item_new ();
katze_item_set_uri (item, uri);
- browser = (MidoriBrowser*)gtk_widget_get_toplevel (menuitem);
+ browser = midori_browser_get_for_widget (menuitem);
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
}
{
MidoriBrowser* browser;
- browser = (MidoriBrowser*)gtk_widget_get_toplevel (menuitem);
+ browser = midori_browser_get_for_widget (menuitem);
midori_browser_save_uri (browser, uri);
}
MidoriBrowser* browser;
GList* buttons;
- browser = MIDORI_BROWSER (gtk_widget_get_toplevel (button));
+ browser = midori_browser_get_for_widget (button);
switch (webkit_download_get_status (download))
{
midori_browser_panel_timeout (GtkWidget* hpaned)
{
gboolean position = gtk_paned_get_position (GTK_PANED (hpaned));
- MidoriBrowser* browser = MIDORI_BROWSER (gtk_widget_get_toplevel (hpaned));
+ MidoriBrowser* browser = midori_browser_get_for_widget (hpaned);
if (browser->settings)
g_object_set (browser->settings, "last-panel-position", position, NULL);
browser->panel_timeout = 0;
return browser->proxy_array;
}
+/**
+ * midori_browser_get_for_widget:
+ * @widget: a #GtkWidget
+ *
+ * Determines the browser appropriate for the specified widget.
+ *
+ * Return value: a #MidoriBrowser
+ *
+ * Since 0.1.7
+ **/
+MidoriBrowser*
+midori_browser_get_for_widget (GtkWidget* widget)
+{
+ gpointer browser;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ browser = gtk_widget_get_toplevel (GTK_WIDGET (widget));
+ if (!MIDORI_IS_BROWSER (browser))
+ {
+ if (!GTK_IS_WINDOW (browser))
+ return NULL;
+
+ browser = gtk_window_get_transient_for (GTK_WINDOW (browser));
+ if (!MIDORI_IS_BROWSER (browser))
+ return NULL;
+ }
+
+ return MIDORI_BROWSER (browser);
+}
+
/**
* midori_browser_quit:
* @browser: a #MidoriBrowser