diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-04-21 04:57:13 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-04-21 04:57:13 +0800 |
commit | 55b65a38b1129a1e0874b22a565719750ce0ef14 (patch) | |
tree | 6404a092eabd214b5b9fc2f9ba8ce94a14dc0c49 /src | |
parent | 9f83e4c982e031826e3b0f020c3eafd8619fe1aa (diff) | |
download | gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.tar gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.tar.gz gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.tar.bz2 gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.tar.lz gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.tar.xz gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.tar.zst gsoc2013-epiphany-55b65a38b1129a1e0874b22a565719750ce0ef14.zip |
Allow to add topics, update when changing bookmarks.
2003-04-20 Marco Pesenti Gritti <marco@it.gnome.org>
* data/ui/epiphany-bookmark-editor-ui.xml.in:
* src/bookmarks/ephy-bookmarks-editor.c: (cmd_show_in_the_toolbar),
(cmd_copy), (ephy_bookmarks_editor_update_menu):
* src/bookmarks/ephy-bookmarks-toolbar.c: (bookmarks_changed_cb),
(ephy_bookmarks_toolbar_init), (ephy_bookmarks_toolbar_clean),
(go_location_cb), (add_toolitem), (ephy_bookmarks_toolbar_rebuild),
(ephy_bookmarks_toolbar_update):
Allow to add topics, update when changing bookmarks.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 73 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-toolbar.c | 106 |
2 files changed, 163 insertions, 16 deletions
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index 7ef98400e..51e2fef7f 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -41,6 +41,7 @@ #include "ephy-file-helpers.h" #include "egg-action-group.h" #include "egg-menu-merge.h" +#include "egg-toggle-action.h" #include "popup-commands.h" #include "ephy-state.h" #include "window-commands.h" @@ -87,6 +88,8 @@ static void cmd_open_bookmarks_in_tabs (EggAction *action, EphyBookmarksEditor *editor); static void cmd_open_bookmarks_in_browser (EggAction *action, EphyBookmarksEditor *editor); +static void cmd_show_in_the_toolbar (EggAction *action, + EphyBookmarksEditor *editor); static void cmd_delete (EggAction *action, EphyBookmarksEditor *editor); static void cmd_bookmark_properties (EggAction *action, @@ -146,6 +149,9 @@ static EggActionGroupEntry ephy_bookmark_popup_entries [] = { { "OpenInTab", N_("Open in New _Tab"), NULL, "<shift><control>O", NULL, G_CALLBACK (cmd_open_bookmarks_in_tabs), NULL }, + { "ShowInToolbar", N_("Show in the Toolbar"), NULL, NULL, + NULL, G_CALLBACK (cmd_show_in_the_toolbar), NULL, TOGGLE_ACTION }, + { "Cut", N_("Cu_t"), GTK_STOCK_CUT, "<control>X", NULL, G_CALLBACK (cmd_cut), NULL }, @@ -226,6 +232,44 @@ get_target_window (EphyBookmarksEditor *editor) } static void +cmd_show_in_the_toolbar (EggAction *action, + EphyBookmarksEditor *editor) +{ + EphyNode *node; + GList *selection; + GValue value = { 0, }; + gboolean state; + + if (ephy_node_view_is_target (EPHY_NODE_VIEW (editor->priv->bm_view))) + { + selection = ephy_node_view_get_selection + (EPHY_NODE_VIEW (editor->priv->bm_view)); + } + else if (ephy_node_view_is_target (EPHY_NODE_VIEW (editor->priv->key_view))) + { + selection = ephy_node_view_get_selection + (EPHY_NODE_VIEW (editor->priv->key_view)); + } + else + { + return; + } + + node = EPHY_NODE (selection->data); + + state = EGG_TOGGLE_ACTION (action)->active; + + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, state); + ephy_node_set_property (node, + EPHY_NODE_BMK_PROP_SHOW_IN_TOOLBAR, + &value); + g_value_unset (&value); + + g_list_free (selection); +} + +static void cmd_open_bookmarks_in_tabs (EggAction *action, EphyBookmarksEditor *editor) { @@ -337,14 +381,14 @@ cmd_copy (EggAction *action, else if (ephy_node_view_is_target (EPHY_NODE_VIEW (editor->priv->bm_view))) { GList *selection; - + selection = ephy_node_view_get_selection (EPHY_NODE_VIEW (editor->priv->bm_view)); if (g_list_length (selection) == 1) { const char *tmp; EphyNode *node = EPHY_NODE (selection->data); - tmp = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION); + tmp = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION); gtk_clipboard_set_text (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), tmp, -1); } @@ -510,6 +554,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) gboolean key_normal = FALSE; gboolean bmk_multiple_selection; gboolean cut, copy, paste, select_all; + gboolean can_show_in_toolbar, show_in_toolbar = FALSE; EggActionGroup *action_group; EggAction *action; GList *selected; @@ -533,7 +578,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (focus_widget), NULL, NULL); - clipboard_contains_text = gtk_clipboard_wait_is_text_available + clipboard_contains_text = gtk_clipboard_wait_is_text_available (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)); cut = has_selection; @@ -553,12 +598,27 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) if (key_focus && selected) { EphyNode *node = EPHY_NODE (selected->data); - EphyNodeViewPriority priority;; + EphyNodeViewPriority priority; priority = ephy_node_get_property_int (node, EPHY_NODE_KEYWORD_PROP_PRIORITY); if (priority == -1) priority = EPHY_NODE_VIEW_NORMAL_PRIORITY; key_normal = (priority == EPHY_NODE_VIEW_NORMAL_PRIORITY); + + show_in_toolbar = ephy_node_get_property_boolean + (node, EPHY_NODE_BMK_PROP_SHOW_IN_TOOLBAR); + + g_list_free (selected); + } + + selected = ephy_node_view_get_selection (EPHY_NODE_VIEW (editor->priv->bm_view)); + if (bmk_focus && selected) + { + EphyNode *node = EPHY_NODE (selected->data); + + show_in_toolbar = ephy_node_get_property_boolean + (node, EPHY_NODE_BMK_PROP_SHOW_IN_TOOLBAR); + g_list_free (selected); } @@ -589,6 +649,8 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) delete = (bmk_focus && bmk_selection) || (key_selection && key_focus && key_normal); properties = (bmk_focus && bmk_selection && !bmk_multiple_selection); + can_show_in_toolbar = (bmk_focus && bmk_selection && !bmk_multiple_selection) || + (key_selection && key_focus); action_group = editor->priv->action_group; action = egg_action_group_get_action (action_group, "OpenInWindow"); @@ -612,6 +674,9 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) g_object_set (action, "sensitive", paste, NULL); action = egg_action_group_get_action (action_group, "SelectAll"); g_object_set (action, "sensitive", select_all, NULL); + action = egg_action_group_get_action (action_group, "ShowInToolbar"); + g_object_set (action, "sensitive", can_show_in_toolbar, NULL); + egg_toggle_action_set_active (EGG_TOGGLE_ACTION (action), show_in_toolbar); } static void diff --git a/src/bookmarks/ephy-bookmarks-toolbar.c b/src/bookmarks/ephy-bookmarks-toolbar.c index ea716ca60..97e3025d9 100644 --- a/src/bookmarks/ephy-bookmarks-toolbar.c +++ b/src/bookmarks/ephy-bookmarks-toolbar.c @@ -22,6 +22,7 @@ #include "ephy-bookmarks-toolbar.h" #include "ephy-bookmark-action.h" +#include "ephy-topic-action.h" #include "ephy-gobject-misc.h" #include "egg-menu-merge.h" #include "ephy-shell.h" @@ -101,14 +102,34 @@ ephy_bookmarks_toolbar_class_init (EphyBookmarksToolbarClass *klass) } static void +bookmarks_changed_cb (EphyNode *node, + EphyNode *child, + EphyBookmarksToolbar *bt) +{ + /* FIXME this is updating way too often, be smarter */ + + ephy_bookmarks_toolbar_update (bt); +} + +static void ephy_bookmarks_toolbar_init (EphyBookmarksToolbar *wrhm) { EphyBookmarksToolbarPrivate *p = g_new0 (EphyBookmarksToolbarPrivate, 1); + EphyNode *bms, *topics; + wrhm->priv = p; wrhm->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell); wrhm->priv->ui_id = -1; wrhm->priv->action_group = NULL; + + bms = ephy_bookmarks_get_bookmarks (p->bookmarks); + topics = ephy_bookmarks_get_keywords (p->bookmarks); + + g_signal_connect (bms, "child_changed", + G_CALLBACK (bookmarks_changed_cb), wrhm); + g_signal_connect (topics, "child_changed", + G_CALLBACK (bookmarks_changed_cb), wrhm); } static void @@ -120,7 +141,6 @@ ephy_bookmarks_toolbar_clean (EphyBookmarksToolbar *wrhm) if (p->ui_id >= 0) { egg_menu_merge_remove_ui (merge, p->ui_id); - egg_menu_merge_ensure_update (merge); } if (p->action_group != NULL) @@ -182,6 +202,17 @@ ephy_bookmarks_toolbar_get_property (GObject *object, } } +static void +go_location_cb (EggAction *action, char *location, EphyWindow *window) +{ + EphyEmbed *embed; + + embed = ephy_window_get_active_embed (window); + g_return_if_fail (embed != NULL); + + ephy_embed_load_url (embed, location); +} + EphyBookmarksToolbar * ephy_bookmarks_toolbar_new (EphyWindow *window) { @@ -192,22 +223,39 @@ ephy_bookmarks_toolbar_new (EphyWindow *window) } static void +add_toolitem (const char *verb, + GString *xml) +{ + static int name_id = 0; + + name_id++; + + g_string_append (xml, "<toolitem name=\""); + g_string_append_printf (xml, "Name%d", name_id); + g_string_append (xml, "Menu"); + g_string_append (xml, "\" verb=\""); + g_string_append (xml, verb); + g_string_append (xml, "\"/>\n"); +} + +static void ephy_bookmarks_toolbar_rebuild (EphyBookmarksToolbar *wrhm) { EphyBookmarksToolbarPrivate *p = wrhm->priv; GString *xml; - gint i; EphyNode *bms; - GPtrArray *children; + EphyNode *topics; EggMenuMerge *merge = EGG_MENU_MERGE (p->window->ui_merge); GError *error = NULL; + GPtrArray *children; + gint i; LOG ("Rebuilding recent history menu") ephy_bookmarks_toolbar_clean (wrhm); bms = ephy_bookmarks_get_bookmarks (p->bookmarks); - children = ephy_node_get_children (bms); + topics = ephy_bookmarks_get_keywords (p->bookmarks); xml = g_string_new (NULL); g_string_append (xml, "<Root><dockitem name=\"BookmarksToolbar\">"); @@ -215,6 +263,7 @@ ephy_bookmarks_toolbar_rebuild (EphyBookmarksToolbar *wrhm) p->action_group = egg_action_group_new ("BookmarksToolbar"); egg_menu_merge_insert_action_group (merge, p->action_group, 0); + children = ephy_node_get_children (topics); for (i = 0; i < children->len; i++) { gulong id; @@ -232,20 +281,50 @@ ephy_bookmarks_toolbar_rebuild (EphyBookmarksToolbar *wrhm) id = ephy_node_get_id (child); verb = g_strdup_printf ("GoBookmark%ld", id); - action = ephy_bookmark_action_new (verb, id); + action = ephy_topic_action_new (verb, id); egg_action_group_add_action (p->action_group, action); g_object_unref (action); - g_string_append (xml, "<toolitem name=\""); - g_string_append (xml, verb); - g_string_append (xml, "Menu"); - g_string_append (xml, "\" verb=\""); - g_string_append (xml, verb); - g_string_append (xml, "\"/>\n"); + g_signal_connect (action, "go_location", + G_CALLBACK (go_location_cb), + p->window); + + add_toolitem (verb, xml); g_free (verb); } + ephy_node_thaw (topics); + children = ephy_node_get_children (bms); + for (i = 0; i < children->len; i++) + { + gulong id; + char *verb; + EphyNode *child; + EggAction *action; + gboolean in_toolbar; + + child = g_ptr_array_index (children, i); + + in_toolbar = ephy_node_get_property_boolean + (child, EPHY_NODE_BMK_PROP_SHOW_IN_TOOLBAR); + if (!in_toolbar) continue; + + id = ephy_node_get_id (child); + verb = g_strdup_printf ("GoBookmark%ld", id); + + action = ephy_bookmark_action_new (verb, id); + 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); + + add_toolitem (verb, xml); + + g_free (verb); + } ephy_node_thaw (bms); g_string_append (xml, "</dockitem></Root>"); @@ -254,10 +333,13 @@ ephy_bookmarks_toolbar_rebuild (EphyBookmarksToolbar *wrhm) p->ui_id = egg_menu_merge_add_ui_from_string (merge, xml->str, -1, &error); + egg_menu_merge_ensure_update (merge); + g_string_free (xml, TRUE); } -void ephy_bookmarks_toolbar_update (EphyBookmarksToolbar *wrhm) +void +ephy_bookmarks_toolbar_update (EphyBookmarksToolbar *wrhm) { ephy_bookmarks_toolbar_rebuild (wrhm); } |