Popup bookmarkbar when focussing location if bookmarkbar is hidden

This commit is contained in:
Christian Dywan 2009-07-17 17:36:03 +02:00
parent 34c26da9f0
commit 0c9058f566

View file

@ -50,6 +50,7 @@ struct _MidoriBrowser
GtkWidget* menu_tools;
GtkWidget* throbber;
GtkWidget* navigationbar;
GtkWidget* bookmark_popup;
GtkWidget* bookmarkbar;
GtkToolItem* homepage;
@ -3011,12 +3012,90 @@ _action_location_active_changed (GtkAction* action,
}
}
static void
midori_browser_bookmark_homepage_clicked_cb (GtkToolItem* button,
MidoriBrowser* browser)
{
gchar* homepage;
g_object_get (browser->settings, "homepage", &homepage, NULL);
midori_browser_set_current_uri (browser, homepage);
g_free (homepage);
gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
}
static void
midori_browser_position_popup (GtkWidget* popup,
GtkWidget* widget)
{
gint wx, wy;
GtkRequisition menu_req;
GtkRequisition widget_req;
if (GTK_WIDGET_NO_WINDOW (widget))
{
gdk_window_get_position (widget->window, &wx, &wy);
wx += widget->allocation.x;
wy += widget->allocation.y;
}
else
gdk_window_get_origin (widget->window, &wx, &wy);
gtk_widget_size_request (popup, &menu_req);
gtk_widget_size_request (widget, &widget_req);
gtk_widget_show_all (popup);
gtk_window_move (GTK_WINDOW (popup),
wx, wy + widget_req.height);
gtk_window_resize (GTK_WINDOW (popup),
widget->allocation.width, 1);
}
static void
browser_bookmarks_add_item_cb (KatzeArray* array,
KatzeItem* item,
GtkWidget* toolbar);
static void
_action_location_focus_in (GtkAction* action,
MidoriBrowser* browser)
{
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
if (!GTK_WIDGET_VISIBLE (browser->bookmarkbar))
{
GSList* proxies = gtk_action_get_proxies (action);
GtkWidget* proxy = g_slist_nth_data (proxies, 0);
if (G_UNLIKELY (!browser->bookmark_popup))
{
GtkWidget* popup = gtk_window_new (GTK_WINDOW_POPUP);
GtkWidget* box = gtk_toolbar_new ();
GtkToolItem* homepage = gtk_tool_button_new_from_stock (STOCK_HOMEPAGE);
guint i;
KatzeItem* item;
/* FIXME: Resize popup to avoid overflowing items */
/* FIXME: Take care of added and removed items */
gtk_tool_item_set_is_important (homepage, TRUE);
gtk_widget_show (GTK_WIDGET (homepage));
g_signal_connect (homepage, "clicked",
G_CALLBACK (midori_browser_bookmark_homepage_clicked_cb), browser);
gtk_container_add (GTK_CONTAINER (popup), box);
gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (browser));
gtk_toolbar_set_icon_size (GTK_TOOLBAR (box), GTK_ICON_SIZE_MENU);
gtk_toolbar_insert (GTK_TOOLBAR (box), homepage, -1);
i = 0;
if (browser->bookmarks)
while ((item = katze_array_get_nth_item (browser->bookmarks, i++)))
browser_bookmarks_add_item_cb (browser->bookmarks, item, box);
browser->bookmark_popup = popup;
g_signal_connect (popup, "destroy",
G_CALLBACK (gtk_widget_destroyed), &browser->bookmark_popup);
}
if (!GTK_IS_TOOL_ITEM (proxy))
proxy = g_slist_nth_data (proxies, 1);
midori_browser_position_popup (browser->bookmark_popup, proxy);
}
}
static void
@ -3025,6 +3104,9 @@ _action_location_focus_out (GtkAction* action,
{
GtkWidget* view = midori_browser_get_current_tab (browser);
if (browser->bookmark_popup)
gtk_widget_hide (browser->bookmark_popup);
if (!browser->show_navigationbar)
gtk_widget_hide (browser->navigationbar);
@ -4567,16 +4649,6 @@ midori_browser_accel_switch_tab_activate_cb (GtkAccelGroup* accel_group,
}
}
static void
midori_browser_bookmark_homepage_clicked_cb (GtkToolItem* button,
MidoriBrowser* browser)
{
gchar* homepage;
g_object_get (browser->settings, "homepage", &homepage, NULL);
midori_browser_set_current_uri (browser, homepage);
g_free (homepage);
}
static void
midori_browser_init (MidoriBrowser* browser)
{
@ -4604,6 +4676,7 @@ midori_browser_init (MidoriBrowser* browser)
browser->net = katze_net_new ();
browser->bookmark_popup = NULL;
browser->settings = midori_web_settings_new ();
browser->proxy_array = katze_array_new (KATZE_TYPE_ARRAY);
browser->bookmarks = NULL;
@ -5391,10 +5464,11 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings,
}
static void
browser_bookmarks_add_item_cb (KatzeArray* array,
KatzeItem* item,
MidoriBrowser* browser)
browser_bookmarks_add_item_cb (KatzeArray* array,
KatzeItem* item,
GtkWidget* toolbar)
{
MidoriBrowser* browser = midori_browser_get_for_widget (toolbar);
GtkToolItem* toolitem;
toolitem = katze_array_action_create_tool_item_for (
@ -5424,7 +5498,7 @@ browser_bookmarks_add_item_cb (KatzeArray* array,
g_object_set_data (G_OBJECT (toolitem), "KatzeItem", item);
}
gtk_widget_show (GTK_WIDGET (toolitem));
gtk_toolbar_insert (GTK_TOOLBAR (browser->bookmarkbar), toolitem, -1);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
}
static void
@ -5472,9 +5546,9 @@ midori_browser_set_bookmarks (MidoriBrowser* browser,
i = 0;
while ((item = katze_array_get_nth_item (browser->bookmarks, i++)))
browser_bookmarks_add_item_cb (browser->bookmarks, item, browser);
browser_bookmarks_add_item_cb (browser->bookmarks, item, browser->bookmarkbar);
g_signal_connect (browser->bookmarks, "add-item",
G_CALLBACK (browser_bookmarks_add_item_cb), browser);
G_CALLBACK (browser_bookmarks_add_item_cb), browser->bookmarkbar);
g_signal_connect (browser->bookmarks, "remove-item",
G_CALLBACK (browser_bookmarks_remove_item_cb), browser);