diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-06-04 17:26:25 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-06-04 17:26:25 +0800 |
commit | 15358f9939f56b8ba5bc9df4499a72d65535ce41 (patch) | |
tree | 4b7d37f6deeea333796ee95c7237c3ae9ae61db3 /src | |
parent | ee88ca67057b3635d4bb18b361ca6fd5ac8661e6 (diff) | |
download | gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.tar gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.tar.gz gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.tar.bz2 gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.tar.lz gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.tar.xz gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.tar.zst gsoc2013-epiphany-15358f9939f56b8ba5bc9df4499a72d65535ce41.zip |
Add a bookmarks menu. (still not the tree)
2003-06-04 Marco Pesenti Gritti <marco@it.gnome.org>
* data/ui/epiphany-ui.xml.in:
Add a bookmarks menu. (still not the tree)
* src/bookmarks/ephy-bookmark-action.c: (create_menu_item),
(ephy_bookmark_action_sync_icon),
(ephy_bookmark_action_sync_label), (activate_cb), (connect_proxy),
(ephy_bookmark_action_class_init):
Implement create_menu_item.
* src/ephy-favorites-menu.c: (ephy_favorites_menu_get_type),
(go_location_cb), (ephy_favorites_menu_rebuild),
(ephy_favorites_menu_set_property),
(ephy_favorites_menu_get_property),
(ephy_favorites_menu_class_init), (ephy_favorites_menu_init),
(ephy_favorites_menu_finalize), (ephy_favorites_menu_new):
Use bookmark action.
* src/ephy-window.c:
Change verbs for bookmarks menu.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.c | 88 | ||||
-rw-r--r-- | src/ephy-favorites-menu.c | 287 | ||||
-rw-r--r-- | src/ephy-window.c | 15 |
3 files changed, 210 insertions, 180 deletions
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 8c2862534..046d24798 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -25,9 +25,12 @@ #include "ephy-bookmark-action.h" #include "ephy-bookmarks.h" #include "ephy-shell.h" +#include "ephy-string.h" #include "eggtoolitem.h" #include "ephy-debug.h" +#define MAX_LABEL_LENGTH 30 + static void ephy_bookmark_action_init (EphyBookmarkAction *action); static void ephy_bookmark_action_class_init (EphyBookmarkActionClass *class); @@ -86,6 +89,16 @@ ephy_bookmark_action_get_type (void) } static GtkWidget * +create_menu_item (EggAction *action) +{ + GtkWidget *item; + + item = gtk_image_menu_item_new (); + + return item; +} + +static GtkWidget * create_tool_item (EggAction *action) { GtkWidget *item; @@ -138,13 +151,9 @@ static void ephy_bookmark_action_sync_icon (EggAction *action, GParamSpec *pspec, GtkWidget *proxy) { char *icon_location; - GtkImage *icon; EphyFaviconCache *cache; GdkPixbuf *pixbuf = NULL; - icon = GTK_IMAGE (g_object_get_data (G_OBJECT (proxy), "icon")); - g_return_if_fail (icon != NULL); - icon_location = EPHY_BOOKMARK_ACTION (action)->priv->icon; cache = ephy_embed_shell_get_favicon_cache @@ -155,35 +164,70 @@ ephy_bookmark_action_sync_icon (EggAction *action, GParamSpec *pspec, GtkWidget pixbuf = ephy_favicon_cache_get (cache, icon_location); } - if (pixbuf) + if (pixbuf == NULL) return; + + if (EGG_IS_TOOL_ITEM (proxy)) { + GtkImage *icon; + + icon = GTK_IMAGE (g_object_get_data (G_OBJECT (proxy), "icon")); + g_return_if_fail (icon != NULL); + gtk_image_set_from_pixbuf (icon, pixbuf); - g_object_unref (pixbuf); } + else if (GTK_IS_MENU_ITEM (proxy)) + { + GtkWidget *image; + + image = gtk_image_new_from_pixbuf (pixbuf); + gtk_widget_show (image); + + gtk_image_menu_item_set_image + (GTK_IMAGE_MENU_ITEM (proxy), image); + } + + g_object_unref (pixbuf); } static void ephy_bookmark_action_sync_label (EggAction *action, GParamSpec *pspec, GtkWidget *proxy) { - GtkLabel *label; - gchar *toolbar_label; + GtkWidget *label; + char *label_text; + char *title; LOG ("Set bookmark action proxy label to %s", action->label) - label = GTK_LABEL (g_object_get_data (G_OBJECT (proxy), "label")); - g_return_if_fail (label != NULL); + title = ephy_string_shorten (action->label, MAX_LABEL_LENGTH); if (EPHY_BOOKMARK_ACTION (action)->priv->smart_url) - { - toolbar_label = g_strdup_printf (_("%s:"), action->label); + { + label_text = g_strdup_printf (_("%s:"), title); + } + else + { + label_text = g_strdup (title); + } + + if (EGG_IS_TOOL_ITEM (proxy)) + { + label = g_object_get_data (G_OBJECT (proxy), "label"); + g_return_if_fail (label != NULL); + } + else if (GTK_IS_MENU_ITEM (proxy)) + { + label = GTK_BIN (proxy)->child; } else { - toolbar_label = g_strdup (action->label); + g_warning ("Unkown widget"); + return; } - gtk_label_set_label (label, toolbar_label); - g_free (toolbar_label); + gtk_label_set_label (GTK_LABEL (label), label_text); + + g_free (label_text); + g_free (title); } static void @@ -211,7 +255,7 @@ entry_activated_cb (GtkWidget *entry, EggAction *action) } static void -button_clicked_cb (GtkWidget *button, EggAction *action) +activate_cb (GtkWidget *widget, EggAction *action) { g_signal_emit (action, ephy_bookmark_action_signals[GO_LOCATION], @@ -233,8 +277,15 @@ connect_proxy (EggAction *action, GtkWidget *proxy) g_signal_connect_object (action, "notify::icon", G_CALLBACK (ephy_bookmark_action_sync_icon), proxy, 0); - button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button")); - g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), action); + if (EGG_IS_TOOL_ITEM (proxy)) + { + button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button")); + g_signal_connect (button, "clicked", G_CALLBACK (activate_cb), action); + } + else if (GTK_IS_MENU_ITEM (proxy)) + { + g_signal_connect (proxy, "activate", G_CALLBACK (activate_cb), action); + } if (EPHY_BOOKMARK_ACTION (action)->priv->smart_url) { @@ -327,6 +378,7 @@ ephy_bookmark_action_class_init (EphyBookmarkActionClass *class) action_class->toolbar_item_type = EGG_TYPE_TOOL_ITEM; action_class->create_tool_item = create_tool_item; + action_class->create_menu_item = create_menu_item; action_class->connect_proxy = connect_proxy; object_class->finalize = ephy_bookmark_action_finalize; diff --git a/src/ephy-favorites-menu.c b/src/ephy-favorites-menu.c index ef31b3c52..f5da952d3 100644 --- a/src/ephy-favorites-menu.c +++ b/src/ephy-favorites-menu.c @@ -21,19 +21,11 @@ #endif #include "ephy-favorites-menu.h" -#include "ephy-gobject-misc.h" -#include "ephy-string.h" #include "egg-menu-merge.h" -#include "ephy-marshal.h" +#include "ephy-bookmark-action.h" #include "ephy-shell.h" #include "ephy-debug.h" -#include <string.h> -#include <stdlib.h> -#include <libxml/entities.h> - -#define MAX_LABEL_LENGTH 30 - /** * Private data */ @@ -45,27 +37,12 @@ struct _EphyFavoritesMenuPrivate guint ui_id; }; -typedef struct -{ - EphyWindow *window; - const char *url; -} FavoriteData; - /** * Private functions, only availble from this file */ static void ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass); static void ephy_favorites_menu_init (EphyFavoritesMenu *wrhm); -static void ephy_favorites_menu_finalize_impl (GObject *o); -static void ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm); -static void ephy_favorites_menu_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ephy_favorites_menu_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); +static void ephy_favorites_menu_finalize (GObject *o); enum { @@ -73,45 +50,33 @@ enum PROP_EPHY_WINDOW }; -static gpointer g_object_class; - -/** - * EphyFavoritesMenu object - */ -MAKE_GET_TYPE (ephy_favorites_menu, - "EphyFavoritesMenu", EphyFavoritesMenu, - ephy_favorites_menu_class_init, ephy_favorites_menu_init, - G_TYPE_OBJECT); - -static void -ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - G_OBJECT_CLASS (klass)->finalize = ephy_favorites_menu_finalize_impl; - g_object_class = g_type_class_peek_parent (klass); - - object_class->set_property = ephy_favorites_menu_set_property; - object_class->get_property = ephy_favorites_menu_get_property; - - g_object_class_install_property (object_class, - PROP_EPHY_WINDOW, - g_param_spec_object ("EphyWindow", - "EphyWindow", - "Parent window", - EPHY_WINDOW_TYPE, - G_PARAM_READWRITE)); -} +static gpointer parent_class; -static void -ephy_favorites_menu_init (EphyFavoritesMenu *wrhm) +GType +ephy_favorites_menu_get_type (void) { - EphyFavoritesMenuPrivate *p = g_new0 (EphyFavoritesMenuPrivate, 1); - wrhm->priv = p; + static GType ephy_favorites_menu_type = 0; - wrhm->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell); - wrhm->priv->ui_id = -1; - wrhm->priv->action_group = NULL; + if (ephy_favorites_menu_type == 0) + { + static const GTypeInfo our_info = + { + sizeof (EphyFavoritesMenuClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) ephy_favorites_menu_class_init, + NULL, + NULL, /* class_data */ + sizeof (EphyFavoritesMenu), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_favorites_menu_init + }; + + ephy_favorites_menu_type = g_type_register_static (G_TYPE_OBJECT, + "EphyFavoritesMenu", + &our_info, 0); + } + return ephy_favorites_menu_type; } static void @@ -134,71 +99,14 @@ ephy_favorites_menu_clean (EphyFavoritesMenu *wrhm) } static void -ephy_favorites_menu_finalize_impl (GObject *o) -{ - EphyFavoritesMenu *wrhm = EPHY_FAVORITES_MENU (o); - EphyFavoritesMenuPrivate *p = wrhm->priv; - - if (p->action_group != NULL) - { - egg_menu_merge_remove_action_group - (EGG_MENU_MERGE (p->window->ui_merge), - p->action_group); - g_object_unref (p->action_group); - } - - g_free (p); - - G_OBJECT_CLASS (g_object_class)->finalize (o); -} - -static void -ephy_favorites_menu_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object); - - switch (prop_id) - { - case PROP_EPHY_WINDOW: - m->priv->window = g_value_get_object (value); - ephy_favorites_menu_rebuild (m); - break; - } -} - -static void -ephy_favorites_menu_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +go_location_cb (EggAction *action, char *location, EphyWindow *window) { - EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object); + EphyEmbed *embed; - switch (prop_id) - { - case PROP_EPHY_WINDOW: - g_value_set_object (value, m->priv->window); - break; - } -} + embed = ephy_window_get_active_embed (window); + g_return_if_fail (embed != NULL); -EphyFavoritesMenu * -ephy_favorites_menu_new (EphyWindow *window) -{ - EphyFavoritesMenu *ret = g_object_new (EPHY_TYPE_FAVORITES_MENU, - "EphyWindow", window, - NULL); - return ret; -} - -static void -ephy_favorites_menu_verb_cb (EggMenuMerge *merge, - FavoriteData *data) -{ - ephy_window_load_url (data->window, data->url); + ephy_embed_load_url (embed, location); } static void @@ -229,38 +137,17 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) for (i = 0; i < children->len; i++) { char *verb = g_strdup_printf ("GoFav%d", i); - char *title_s; - const char *title; - const char *url; - xmlChar *label_x; - EphyNode *child; - FavoriteData *data; + EphyNode *node; EggAction *action; - child = g_ptr_array_index (children, i); - title = ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_TITLE); - url = ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_LOCATION); - title_s = ephy_string_shorten (title, MAX_LABEL_LENGTH); - label_x = xmlEncodeSpecialChars (NULL, title_s); - - data = g_new0 (FavoriteData, 1); - data->window = wrhm->priv->window; - data->url = url; - - action = g_object_new (EGG_TYPE_ACTION, - "name", verb, - "label", label_x, - "tooltip", "Hello", - "stock_id", NULL, - NULL); - g_signal_connect_closure - (action, "activate", - g_cclosure_new (G_CALLBACK (ephy_favorites_menu_verb_cb), - data, - (GClosureNotify)g_free), - FALSE); + node = g_ptr_array_index (children, i); + + action = ephy_bookmark_action_new (verb, + ephy_node_get_id (node)); egg_action_group_add_action (p->action_group, action); g_object_unref (action); + g_signal_connect (action, "go_location", + G_CALLBACK (go_location_cb), p->window); g_string_append (xml, "<menuitem name=\""); g_string_append (xml, verb); @@ -268,12 +155,7 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) g_string_append (xml, "\" verb=\""); g_string_append (xml, verb); g_string_append (xml, "\"/>\n"); - - xmlFree (label_x); - g_free (title_s); - g_free (verb); } - ephy_node_thaw (fav); g_string_append (xml, "</placeholder></submenu></menu></Root>"); @@ -289,6 +171,99 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) g_string_free (xml, TRUE); } +static void +ephy_favorites_menu_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object); + + switch (prop_id) + { + case PROP_EPHY_WINDOW: + m->priv->window = g_value_get_object (value); + ephy_favorites_menu_rebuild (m); + break; + } +} + +static void +ephy_favorites_menu_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object); + + switch (prop_id) + { + case PROP_EPHY_WINDOW: + g_value_set_object (value, m->priv->window); + break; + } +} + + +static void +ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = ephy_favorites_menu_finalize; + object_class->set_property = ephy_favorites_menu_set_property; + object_class->get_property = ephy_favorites_menu_get_property; + + g_object_class_install_property (object_class, + PROP_EPHY_WINDOW, + g_param_spec_object ("EphyWindow", + "EphyWindow", + "Parent window", + EPHY_WINDOW_TYPE, + G_PARAM_READWRITE)); +} + +static void +ephy_favorites_menu_init (EphyFavoritesMenu *wrhm) +{ + EphyFavoritesMenuPrivate *p = g_new0 (EphyFavoritesMenuPrivate, 1); + wrhm->priv = p; + + wrhm->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell); + wrhm->priv->ui_id = -1; + wrhm->priv->action_group = NULL; +} + +static void +ephy_favorites_menu_finalize (GObject *o) +{ + EphyFavoritesMenu *wrhm = EPHY_FAVORITES_MENU (o); + EphyFavoritesMenuPrivate *p = wrhm->priv; + + if (p->action_group != NULL) + { + egg_menu_merge_remove_action_group + (EGG_MENU_MERGE (p->window->ui_merge), + p->action_group); + g_object_unref (p->action_group); + } + + g_free (p); + + G_OBJECT_CLASS (parent_class)->finalize (o); +} + +EphyFavoritesMenu * +ephy_favorites_menu_new (EphyWindow *window) +{ + EphyFavoritesMenu *ret = g_object_new (EPHY_TYPE_FAVORITES_MENU, + "EphyWindow", window, + NULL); + return ret; +} + void ephy_favorites_menu_update (EphyFavoritesMenu *wrhm) { ephy_favorites_menu_rebuild (wrhm); diff --git a/src/ephy-window.c b/src/ephy-window.c index 20f45a8d5..b4f47c9d5 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -61,6 +61,7 @@ static EggActionGroupEntry ephy_menu_entries [] = { { "File", N_("_File"), NULL, NULL, NULL, NULL, NULL }, { "Edit", N_("_Edit"), NULL, NULL, NULL, NULL, NULL }, { "View", N_("_View"), NULL, NULL, NULL, NULL, NULL }, + { "Bookmarks", N_("_Bookmarks"), NULL, NULL, NULL, NULL, NULL }, { "Go", N_("_Go"), NULL, NULL, NULL, NULL, NULL }, { "Tabs", N_("_Tabs"), NULL, NULL, NULL, NULL, NULL }, { "Help", N_("_Help"), NULL, NULL, NULL, NULL, NULL }, @@ -84,9 +85,6 @@ static EggActionGroupEntry ephy_menu_entries [] = { { "FileSendTo", N_("S_end To..."), EPHY_STOCK_SEND_LINK, NULL, N_("Send a link of the current page"), G_CALLBACK (window_cmd_file_send_to), NULL }, - { "FileBookmarkPage", N_("Boo_kmark Page..."), EPHY_STOCK_BOOKMARK_PAGE, "<control>D", - N_("Add a bookmark for the current page"), - G_CALLBACK (window_cmd_file_bookmark_page), NULL }, { "FileCloseWindow", N_("_Close"), GTK_STOCK_CLOSE, "<control>W", N_("Close this window"), G_CALLBACK (window_cmd_file_close_window), NULL }, @@ -156,6 +154,14 @@ static EggActionGroupEntry ephy_menu_entries [] = { N_("View the source code of the page"), G_CALLBACK (window_cmd_view_page_source), NULL }, + /* Bookmarks menu */ + { "FileBookmarkPage", N_("_Add Bookmark"), EPHY_STOCK_BOOKMARK_PAGE, "<control>D", + N_("Add a bookmark for the current page"), + G_CALLBACK (window_cmd_file_bookmark_page), NULL }, + { "GoBookmarks", N_("_Edit Bookmarks"), EPHY_STOCK_BOOKMARKS, "<control>B", + N_("Go to a bookmark"), + G_CALLBACK (window_cmd_go_bookmarks), NULL }, + /* Go menu */ { "GoBack", N_("_Back"), GTK_STOCK_GO_BACK, "<alt>Left", N_("Go to the previous visited page"), @@ -175,9 +181,6 @@ static EggActionGroupEntry ephy_menu_entries [] = { { "GoHistory", N_("H_istory"), EPHY_STOCK_HISTORY, "<control>H", N_("Go to an already visited page"), G_CALLBACK (window_cmd_go_history), NULL }, - { "GoBookmarks", N_("Boo_kmarks"), EPHY_STOCK_BOOKMARKS, "<control>B", - N_("Go to a bookmark"), - G_CALLBACK (window_cmd_go_bookmarks), NULL }, /* Tabs menu */ { "TabsPrevious", N_("_Previous Tab"), NULL, "<control>Page_Up", |