aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks/ephy-topic-action.c
diff options
context:
space:
mode:
authorPeter Harvey <pah06@uow.edu.au>2005-10-17 04:29:26 +0800
committerChristian Persch <chpe@src.gnome.org>2005-10-17 04:29:26 +0800
commitd21007362f8d0701d63e50fe6b219de067d95a87 (patch)
tree46326d5633d4f3c8504049476d0e72ae7ed0ca2c /src/bookmarks/ephy-topic-action.c
parent35b9deda1f37ac0cc81d926b5295983de6b55dcf (diff)
downloadgsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar
gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.gz
gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.bz2
gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.lz
gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.xz
gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.zst
gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.zip
H18 patch, by Peter Harvey <pah06@uow.edu.au>.
2005-10-16 Peter Harvey <pah06@uow.edu.au> H18 patch, by Peter Harvey <pah06@uow.edu.au>. * data/ui/epiphany-bookmark-editor-ui.xml: * data/ui/epiphany-ui.xml: * lib/egg/egg-editable-toolbar.c: (get_dock_position), (get_toolbar_position), (get_toolbar_nth), (find_action), (drag_data_delete_cb), (drag_begin_cb), (drag_end_cb), (drag_data_get_cb), (move_item_cb), (set_dock_visible), (remove_item_cb), (remove_toolbar_cb), (toggle_visibility_cb), (egg_editable_toolbar_add_visibility_items), (egg_editable_toolbar_add_popup_items), (popup_context_menu_cb), (button_press_event_cb), (configure_item_sensitivity), (configure_item_cursor), (connect_widget_signals), (action_sensitive_cb), (create_item_from_action), (create_item_from_position), (toolbar_drag_data_received_cb), (toolbar_drag_drop_cb), (toolbar_drag_motion_cb), (toolbar_drag_leave_cb), (configure_drag_dest), (create_dock), (toolbar_changed_cb), (unparent_fixed), (update_fixed), (toolbar_added_cb), (toolbar_removed_cb), (item_added_cb), (item_removed_cb), (egg_editable_toolbar_construct), (egg_editable_toolbar_set_ui_manager), (egg_editable_toolbar_set_property), (egg_editable_toolbar_get_property), (egg_editable_toolbar_init), (egg_editable_toolbar_finalize), (egg_editable_toolbar_get_edit_mode), (egg_editable_toolbar_set_edit_mode), (egg_editable_toolbar_set_fixed): * lib/egg/egg-editable-toolbar.h: * lib/egg/egg-toolbar-editor.c: (compare_items), (item_added_or_removed_cb), (toolbar_removed_cb), (egg_toolbar_editor_set_model), (egg_toolbar_editor_finalize), (drag_begin_cb), (drag_end_cb), (drag_data_get_cb), (editor_create_item), (editor_create_item_from_name), (append_table), (update_editor_sheet), (egg_toolbar_editor_init): * lib/egg/egg-toolbar-editor.h: * lib/egg/egg-toolbars-model.c: (egg_toolbars_model_to_xml), (egg_toolbars_model_save), (toolbar_node_new), (item_node_new), (item_node_free), (toolbar_node_free), (egg_toolbars_model_get_flags), (egg_toolbars_model_set_flags), (egg_toolbars_model_get_data), (egg_toolbars_model_get_name), (impl_add_item), (egg_toolbars_model_add_item), (egg_toolbars_model_add_toolbar), (parse_data_list), (parse_item_list), (parse_toolbars), (egg_toolbars_model_load), (egg_toolbars_model_class_init), (egg_toolbars_model_init), (egg_toolbars_model_finalize), (egg_toolbars_model_remove_toolbar), (egg_toolbars_model_remove_item), (egg_toolbars_model_move_item), (egg_toolbars_model_n_items), (egg_toolbars_model_item_nth), (egg_toolbars_model_n_toolbars), (egg_toolbars_model_toolbar_nth), (egg_toolbars_model_get_types), (egg_toolbars_model_set_types), (fill_avail_array), (egg_toolbars_model_get_avail), (egg_toolbars_model_get_n_avail), (egg_toolbars_model_set_n_avail): * lib/egg/egg-toolbars-model.h: * src/bookmarks/Makefile.am: * src/bookmarks/ephy-bookmark-action-group.c: (smart_added_cb), (smart_removed_cb), (node_changed_cb), (node_added_cb), (node_removed_cb), (ephy_bookmark_group_new): * src/bookmarks/ephy-bookmark-action-group.h: * src/bookmarks/ephy-bookmark-action.c: (create_tool_item), (ephy_bookmark_action_sync_icon), (show_context_menu), (popup_menu_cb), (button_press_cb), (button_release_cb), (connect_proxy), (ephy_bookmark_action_updated), (ephy_bookmark_action_get_bookmark), (ephy_bookmark_action_set_bookmark), (ephy_bookmark_action_set_property), (ephy_bookmark_action_get_property), (ephy_bookmark_action_finalize), (ephy_bookmark_action_class_init), (ephy_bookmark_action_init), (ephy_bookmark_action_name), (ephy_bookmark_action_new): * src/bookmarks/ephy-bookmark-action.h: * src/bookmarks/ephy-bookmark-factory-action.c: (ephy_bookmark_factory_action_get_type), (activate_item_cb), (build_menu_for_topic), (build_menu), (remove_placeholder_cb), (activate_placeholder_cb), (clicked_placeholder_cb), (realize_placeholder_cb), (create_tool_item), (connect_proxy), (ephy_bookmark_factory_action_class_init), (ephy_bookmark_factory_action_new): * src/bookmarks/ephy-bookmark-factory-action.h: * src/bookmarks/ephy-bookmark-properties.c: (ephy_bookmark_properties_set_property), (ephy_bookmark_properties_get_property), (bookmark_properties_response_cb), (update_entry), (location_entry_changed_cb), (build_ui): * src/bookmarks/ephy-bookmarks-editor.c: (add_entry_monitor), (cmd_add_topic), (delete_topic_dialog_construct), (cmd_bookmarks_import), (ephy_bookmarks_editor_finalize), (ephy_bookmarks_editor_node_activated_cb), (ephy_bookmarks_editor_update_menu), (view_focus_cb), (add_focus_monitor), (remove_focus_monitor), (bookmarks_filter), (search_entry_search_cb), (ephy_bookmarks_editor_construct), (ephy_bookmarks_editor_set_parent), (ephy_bookmarks_editor_set_property), (ephy_bookmarks_editor_get_property), (ephy_bookmarks_editor_init): * src/bookmarks/ephy-bookmarks-menu.c: (append_bookmarks), (append_menu), (ephy_bookmarks_menu_build): * src/bookmarks/ephy-bookmarks-menu.h: * src/bookmarks/ephy-bookmarks-ui.c: (find_action), (activate_bookmarks_menu), (activate_favorites_menu), (erase_bookmarks_menu), (erase_favorites_menu), (tree_changed_cb), (node_added_cb), (node_changed_cb), (node_removed_cb), (ephy_bookmarks_ui_attach_window), (ephy_bookmarks_ui_detach_window), (toolbar_node_removed_cb), (topic_has_data), (topic_get_data), (topic_get_name), (bookmark_has_data), (bookmark_get_data), (bookmark_get_name), (bookmark_new_name), (ephy_bookmarks_ui_attach_toolbar_model), (ephy_bookmarks_ui_detach_toolbar_model): * src/bookmarks/ephy-bookmarks-ui.h: * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_get_type), (ephy_bookmarks_init_defaults), (ephy_bookmarks_class_init), (ephy_bookmarks_save_delayed), (add_to_favorites), (update_bookmark_keywords), (ephy_bookmarks_init), (ephy_bookmarks_finalize), (ephy_bookmarks_add), (ephy_bookmarks_set_address), (ephy_bookmarks_set_icon), (ephy_bookmarks_add_keyword), (ephy_bookmarks_show_bookmark_properties), (ephy_bookmarks_get_from_id), (ephy_bookmarks_compare_topics), (ephy_bookmarks_compare_topic_pointers), (ephy_bookmarks_compare_bookmarks), (ephy_bookmarks_compare_bookmark_pointers): * src/bookmarks/ephy-bookmarks.h: * src/bookmarks/ephy-bookmarksbar-model.c: * src/bookmarks/ephy-bookmarksbar-model.h: * src/bookmarks/ephy-bookmarksbar.c: * src/bookmarks/ephy-bookmarksbar.h: * src/bookmarks/ephy-favorites-menu.c: * src/bookmarks/ephy-favorites-menu.h: * src/bookmarks/ephy-new-bookmark.c: (ephy_new_bookmark_add), (build_editing_table), (ephy_new_bookmark_construct), (ephy_new_bookmark_set_property), (ephy_new_bookmark_get_property): * src/bookmarks/ephy-nodes-cover.c: (ephy_nodes_count_covered), (ephy_nodes_remove_covered), (ephy_nodes_remove_not_covered), (ephy_nodes_get_covered), (ephy_nodes_covered), (ephy_nodes_get_covering): * src/bookmarks/ephy-nodes-cover.h: * src/bookmarks/ephy-open-tabs-action.c: (activate_cb), (node_added_cb), (node_removed_cb), (ephy_open_tabs_group_new), (ephy_open_tabs_action_name): * src/bookmarks/ephy-open-tabs-action.h: * src/bookmarks/ephy-related-action.c: (node_changed), (node_destroyed), (open_link), (iface_init), (ephy_related_action_get_type), (ephy_related_action_new): * src/bookmarks/ephy-related-action.h: * src/bookmarks/ephy-topic-action-group.c: (node_changed_cb), (node_added_cb), (node_removed_cb), (ephy_topic_group_new): * src/bookmarks/ephy-topic-action-group.h: * src/bookmarks/ephy-topic-action.c: (ephy_topic_action_get_type), (create_tool_item), (ephy_topic_action_sync_label), (get_popup), (erase_popup), (child_added_cb), (child_changed_cb), (child_removed_cb), (menu_destroy_cb), (menu_init_cb), (button_deactivate_cb), (button_toggled_cb), (button_release_cb), (button_press_cb), (connect_proxy), (ephy_topic_action_updated), (ephy_topic_action_get_topic), (ephy_topic_action_set_topic), (ephy_topic_action_set_property), (ephy_topic_action_get_property), (ephy_topic_action_class_init), (ephy_topic_action_init), (ephy_topic_action_name), (ephy_topic_action_new): * src/bookmarks/ephy-topic-action.h: * src/bookmarks/ephy-topic-factory-action.c: (ephy_topic_factory_action_get_type), (sort_topics), (activate_item_cb), (build_menu), (remove_placeholder_cb), (activate_placeholder_cb), (clicked_placeholder_cb), (realize_placeholder_cb), (create_tool_item), (connect_proxy), (ephy_topic_factory_action_class_init), (ephy_topic_factory_action_new): * src/bookmarks/ephy-topic-factory-action.h: * src/ephy-link-action.c: (ephy_link_action_group_get_type), (ephy_link_action_group_new): * src/ephy-link-action.h: * src/ephy-lockdown.c: (find_name), (find_action_group), (update_window): * src/ephy-notebook.c: (move_tab_to_another_notebook), (ephy_notebook_switch_page_cb), (ephy_notebook_init), (tab_label_style_set_cb), (build_tab_label), (ephy_notebook_add_tab): * src/ephy-shell.c: (ephy_shell_get_toolbars_model): * src/ephy-toolbar-editor.c: (ephy_toolbar_editor_constructor), (ephy_toolbar_editor_finalize), (ephy_toolbar_editor_set_property), (ephy_toolbar_editor_class_init): * src/ephy-toolbar.c: (ephy_toolbar_realize), (ephy_toolbar_unrealize), (ephy_toolbar_finalize): * src/ephy-toolbars-model.c: (update_flags), (ephy_toolbars_model_load): * src/ephy-window.c: (ephy_window_get_type), (get_chromes_visibility), (sync_chromes_visibility), (ephy_window_key_press_event), (tool_item_enter_cb), (tool_item_leave_cb), (tool_item_drag_begin_cb), (connect_tool_item), (disconnect_tool_item), (disconnect_proxy_cb), (connect_proxy_cb), (update_chromes_actions), (show_embed_popup), (tab_added_cb), (tab_removed_cb), (ephy_window_set_chrome), (ephy_window_dispose), (ephy_window_class_init), (ephy_window_init), (ephy_window_finalize), (ephy_window_remove_tab), (ephy_window_set_zoom), (sync_prefs_with_chrome), (ephy_window_view_toolbar_cb): * src/ephy-window.h: Revision history: h18, released 2005/09/23, for Epiphany 1.8.0 * Just an update for 1.8.0. h17, released 2005/08/30, for Epiphany 1.7.6 or CVS HEAD * Mostly just an update for 1.7.6. * Topic menus on the toolbar now open without releasing the mouse button. * Topic menus on the toolbar are now also hierarchical (see if you like it. h16, released 2005/08/25, for Epiphany 1.7.5 or CVS HEAD * Just an update for 1.7.5. Sorry, I've been busy. :) h15, released 2005/07/19, for Epiphany 1.7.2 or CVS HEAD * Code cleanup h14, released 2005/07/9, for Epiphany 1.7.1 or CVS HEAD * Improved helpful tip when adding a bookmark * Improved toolbar context menu * Toolbar visibility state is now saved * Separated bookmark/topic action groups into separate files * Topics in the overflow menu now behave as submenus * Now importing old bookmarksbar, and saving to new filename * Incremented toolbar file format version number to 1.1 * Fixed the 'sticky' statusbar help * Fixed a crashing bug (dnd then open a topic on the toolbar) h13, released 2005/05/12, for CVS HEAD * Added middle-mouse drag-drop for the editable toolbar. * Fixed some warnings at compile and run time. * Added brief help for the user when adding a new bookmark. * Cleaned up the editable toolbar code a little. h12, released 2005/05/10, for CVS HEAD * Added new editing facilities for the editable toolbar. h11, released 2005/04/29, for CVS HEAD * Fixed bug in statusbar information for toolbar items. * Added an all-new 'Related' toolbar widget which changes to show the most related topic whenever a bookmark is activated. h10, released 2005/04/15, for Epiphany 1.6.2 or CVS HEAD * Added statusbar information for all toolbar items. * Empty toolbars are now only deleted when exiting edit mode. * Fixed regression of middle-click for bookmarks on toolbar. * Fixed regression of ellipsized bookmark names in menus. h9, released 2005/04/12, for Epiphany 1.6.1 * Updated patch for 1.6.1. Long time no see. * Now using EphyLink objects everywhere. h7, released 2004/10/21, for Epiphany 1.4.4 * Updated patch for 1.4.4. * Fixed bugs causing crashes when bookmarks were added (thanks Reinout). * Added "Open in Tabs" back into bookmark menus where suitable. h6, released 2004/09/20, for Epiphany 1.4.0 * Updated patch for 1.4.0. * Removed the bookmarks bar. * Generate shared XML string for bookmarks menu. * Slightly improve performance of node-cover code. * Delay adding bookmarks menu until it is first used. * Fixed bug(?) in ephy-node. h4, released 2004/08/08, for Epiphany 1.3.4 * Updated patch due to changes to topics selector. * Removed 'Most Visited' from the min-cover calculations. * Fixed Epiphany 1.3.4 bug where topics in selector aren't sorted. * Updated patch due to other changes in Epiphany 1.3.4 source. h3, released 2004/07/12, for Epiphany 1.3.2 * Simple update for Epiphany 1.3.2 h3, released 2004/05/24, for Epiphany 1.2.5 * Moved duplicated functions into a seperate file. * Improved topic selector. * Bookmarks toolbar topic menus now have subdivisions. * Topic names in menu now change if modified in the bookmarks editor. h2, released 2004/05/23, for Epiphany 1.2.5 * Significantly cleaned up the code. * 'Most Visited' no longer appears as a submenu. * Subtopics are selected much more intelligently, giving a better approximation to a true minimum cover. * Topic selector now shows suggestions with arrows, not bold font. h1, released 2004/05/19, for Epiphany 1.2.5 * Initial release.
Diffstat (limited to 'src/bookmarks/ephy-topic-action.c')
-rw-r--r--src/bookmarks/ephy-topic-action.c996
1 files changed, 219 insertions, 777 deletions
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index 4885d2af6..3e0607509 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -22,28 +22,27 @@
#include "config.h"
#include "ephy-topic-action.h"
+#include "ephy-node.h"
#include "ephy-node-common.h"
+#include "ephy-nodes-cover.h"
#include "ephy-bookmarks.h"
-#include "ephy-bookmarksbar.h"
-#include "ephy-link.h"
-#include "ephy-favicon-cache.h"
-#include "ephy-shell.h"
-#include "ephy-dnd.h"
+#include "ephy-bookmarks-ui.h"
+#include "ephy-bookmarks-menu.h"
#include "ephy-gui.h"
#include "ephy-debug.h"
#include <glib/gi18n.h>
#include <gtk/gtkwidget.h>
-#include <gtk/gtkarrow.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkbutton.h>
-#include <gtk/gtktogglebutton.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkimage.h>
#include <gtk/gtkmenuitem.h>
#include <gtk/gtkimagemenuitem.h>
#include <gtk/gtkseparatormenuitem.h>
+#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkarrow.h>
#include <gtk/gtkmain.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <string.h>
@@ -54,26 +53,18 @@
#define EPHY_TOPIC_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOPIC_ACTION, EphyTopicActionPrivate))
-static GtkTargetEntry drag_targets[] =
-{
- { EPHY_DND_TOPIC_TYPE, 0, 0 }
-};
-static int n_drag_targets = G_N_ELEMENTS (drag_targets);
-
struct _EphyTopicActionPrivate
{
- EphyNode *topic_node;
-
- guint motion_handler;
- guint release_handler;
- gint drag_x;
- gint drag_y;
+ EphyNode *node;
+ GtkUIManager *manager;
+ guint merge_id;
};
enum
{
PROP_0,
- PROP_TOPIC
+ PROP_TOPIC,
+ PROP_MANAGER
};
static void ephy_topic_action_class_init (EphyTopicActionClass *class);
@@ -101,7 +92,7 @@ ephy_topic_action_get_type (void)
(GInstanceInitFunc) ephy_topic_action_init,
};
- type = g_type_register_static (EPHY_TYPE_LINK_ACTION,
+ type = g_type_register_static (GTK_TYPE_ACTION,
"EphyTopicAction",
&type_info, 0);
}
@@ -120,16 +111,11 @@ create_tool_item (GtkAction *action)
item = (* GTK_ACTION_CLASS (parent_class)->create_tool_item) (action);
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_widget_show (hbox);
- gtk_container_add (GTK_CONTAINER (item), hbox);
-
button = gtk_toggle_button_new ();
- gtk_widget_add_events (GTK_WIDGET (button), GDK_BUTTON1_MOTION_MASK);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
gtk_widget_show (button);
- gtk_container_add (GTK_CONTAINER (hbox), button);
+ gtk_container_add (GTK_CONTAINER (item), button);
g_object_set_data (G_OBJECT (item), "button", button);
arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
@@ -151,560 +137,122 @@ create_tool_item (GtkAction *action)
}
static void
-menu_deactivate_cb (GtkMenuShell *ms, GtkWidget *button)
-{
- g_object_set_data (G_OBJECT (button), "popup", NULL);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
- gtk_button_released (GTK_BUTTON (button));
-}
-
-static void
-menu_activate_cb (GtkWidget *item, GtkAction *action)
+ephy_topic_action_sync_label (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
{
- EphyBookmarks *bookmarks;
- EphyNode *node;
- const char *location;
- char *address;
-
- node = g_object_get_data (G_OBJECT (item), "node");
- location = ephy_node_get_property_string
- (node, EPHY_NODE_BMK_PROP_LOCATION);
- g_return_if_fail (location != NULL);
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ());
- address = ephy_bookmarks_resolve_address (bookmarks, location, NULL);
- g_return_if_fail (address != NULL);
-
- ephy_link_open (EPHY_LINK (action), address, NULL,
- ephy_gui_is_middle_click () ? EPHY_LINK_NEW_TAB : 0);
-
- g_free (address);
-}
+ GtkWidget *label = NULL;
+ GValue value = { 0, };
+ const char *label_text;
-static void
-ephy_topic_action_sync_label (GtkAction *gaction,
- GParamSpec *pspec,
- GtkWidget *proxy)
-{
- EphyTopicAction *action = EPHY_TOPIC_ACTION (gaction);
+ g_value_init (&value, G_TYPE_STRING);
+ g_object_get_property (G_OBJECT (action), "label", &value);
- g_return_if_fail (EPHY_IS_NODE (action->priv->topic_node));
+ label_text = g_value_get_string (&value);
- /* note that we cannot use ellipsizing label with defined width,
- * since that makes the label exactly that wide, even if the
- * text takes less space. So we have to shorten the string.
- */
if (GTK_IS_TOOL_ITEM (proxy))
{
- GtkWidget *label = NULL;
- char *title, *separator;
-
- label = g_object_get_data (G_OBJECT (proxy), "label");
- g_return_if_fail (label != NULL);
-
- g_object_get (G_OBJECT (action), "label", &title, NULL);
- g_return_if_fail (label != NULL);
-
- /* In case this is a multi-hierarchy topic, we only want to
- * display the leaf name. See bug #310963.
- */
- separator = g_strrstr (title, BOOKMARKS_HIERARCHY_SEP);
-
- gtk_label_set_label (GTK_LABEL (label),
- separator != NULL ? separator + strlen(BOOKMARKS_HIERARCHY_SEP) : title);
-
- g_free (title);
- }
-}
-
-static int
-sort_bookmarks (gconstpointer a, gconstpointer b)
-{
- EphyNode *node_a = (EphyNode *)a;
- EphyNode *node_b = (EphyNode *)b;
- const char *title1, *title2;
- int retval;
-
- title1 = ephy_node_get_property_string (node_a, EPHY_NODE_BMK_PROP_TITLE);
- title2 = ephy_node_get_property_string (node_b, EPHY_NODE_BMK_PROP_TITLE);
-
- if (title1 == NULL)
- {
- retval = -1;
+ label = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "label"));
}
- else if (title2 == NULL)
+ else if (GTK_IS_MENU_ITEM (proxy))
{
- retval = 1;
+ label = GTK_BIN (proxy)->child;
}
else
{
- char *str_a, *str_b;
-
- str_a = g_utf8_casefold (title1, -1);
- str_b = g_utf8_casefold (title2, -1);
- retval = g_utf8_collate (str_a, str_b);
- g_free (str_a);
- g_free (str_b);
- }
-
- return retval;
-}
-
-static gboolean
-can_open_in_tabs (EphyNode *node)
-{
- GPtrArray *children;
- int priority;
-
- priority = ephy_node_get_property_int (node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- children = ephy_node_get_children (node);
-
- return (priority != EPHY_NODE_ALL_PRIORITY) && (children->len > 1);
-}
-
-static void
-append_bookmarks_menu (EphyTopicAction *action, GtkWidget *menu, EphyNode *node, gboolean show_empty)
-{
- EphyFaviconCache *cache;
- GtkWidget *item;
- GtkLabel *label;
- GPtrArray *children;
-
- cache = EPHY_FAVICON_CACHE
- (ephy_embed_shell_get_favicon_cache (EPHY_EMBED_SHELL (ephy_shell)));
-
- children = ephy_node_get_children (node);
-
- if (children->len < 1 && show_empty)
- {
- /* This is the adjective, not the verb */
- item = gtk_menu_item_new_with_label (_("Empty"));
- gtk_widget_set_sensitive (item, FALSE);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
+ g_warning ("Unknown widget");
return;
}
- else
- {
- GList *node_list = NULL, *l;
- int i;
-
- for (i = 0; i < children->len; ++i)
- {
- node_list = g_list_prepend (node_list,
- g_ptr_array_index (children, i));
- }
-
- node_list = g_list_sort (node_list, (GCompareFunc)sort_bookmarks);
-
- for (l = node_list; l != NULL; l = l->next)
- {
- EphyNode *kid = (EphyNode*) l->data;
- const char *icon_location;
- const char *title;
-
- icon_location = ephy_node_get_property_string
- (kid, EPHY_NODE_BMK_PROP_ICON);
- title = ephy_node_get_property_string
- (kid, EPHY_NODE_BMK_PROP_TITLE);
- if (title == NULL) continue;
- item = gtk_image_menu_item_new_with_label (title);
- label = (GtkLabel *) ((GtkBin *) item)->child;
- gtk_label_set_max_width_chars (label, LABEL_WIDTH_CHARS);
- gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
- gtk_label_set_use_underline (label, FALSE);
+ g_return_if_fail (label != NULL);
- if (icon_location)
- {
- GdkPixbuf *icon;
- GtkWidget *image;
-
- icon = ephy_favicon_cache_get (cache, icon_location);
- if (icon != NULL)
- {
- image = gtk_image_new_from_pixbuf (icon);
- gtk_widget_show (image);
- gtk_image_menu_item_set_image
- (GTK_IMAGE_MENU_ITEM (item), image);
- g_object_unref (icon);
- }
- }
-
- g_object_set_data (G_OBJECT (item), "node", kid);
- g_signal_connect (item, "activate",
- G_CALLBACK (menu_activate_cb), action);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- }
-
- g_list_free (node_list);
+ if (label_text)
+ {
+ gtk_label_set_label (GTK_LABEL (label), label_text);
}
+
+ g_value_unset (&value);
}
-#define TOPIC_NODE_DATA_KEY "TopicNode"
-
-static void
-open_in_tabs_activate_cb (GtkWidget *item, EphyTopicAction *action)
+static GtkWidget *
+get_popup (EphyTopicAction *action)
{
- EphyBookmarks *bookmarks;
- EphyNode *node;
- GPtrArray *children;
- EphyTab *tab = NULL;
- GList *node_list = NULL, *l;
- int i;
-
- node = g_object_get_data (G_OBJECT (item), TOPIC_NODE_DATA_KEY);
- g_return_if_fail (node != NULL);
-
- children = ephy_node_get_children (node);
- for (i = 0; i < children->len; ++i)
- {
- node_list = g_list_prepend (node_list,
- g_ptr_array_index (children, i));
- }
-
- node_list = g_list_sort (node_list, (GCompareFunc) sort_bookmarks);
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ());
+ char path[40];
- for (l = node_list; l != NULL; l = l->next)
+ g_snprintf (path, sizeof (path), "/PopupTopic%ld",
+ (long int) ephy_node_get_id (action->priv->node));
+
+ if (action->priv->merge_id == 0)
{
- EphyNode *child = (EphyNode *) l->data;
- const char *location;
- char *address;
-
- location = ephy_node_get_property_string
- (child, EPHY_NODE_BMK_PROP_LOCATION);
- g_return_if_fail (location != NULL);
-
- address = ephy_bookmarks_resolve_address (bookmarks, location, NULL);
- g_return_if_fail (address != NULL);
-
- tab = ephy_link_open (EPHY_LINK (action), address, tab,
- tab ? EPHY_LINK_NEW_TAB : EPHY_LINK_NEW_WINDOW);
- g_free (address);
+ GString *popup_menu_string = g_string_new ("");
+ g_string_append_printf (popup_menu_string, "<ui><popup name=\"%s\">", path+1);
+ ephy_bookmarks_menu_build (popup_menu_string, action->priv->node);
+ g_string_append (popup_menu_string, "</popup></ui>");
+
+ action->priv->merge_id = gtk_ui_manager_add_ui_from_string
+ (action->priv->manager, popup_menu_string->str, popup_menu_string->len, 0);
+
+ g_string_free (popup_menu_string, TRUE);
}
-
- g_list_free (node_list);
+
+ return gtk_ui_manager_get_widget (action->priv->manager, path);
}
-static int
-get_item_position (GtkWidget *widget, gboolean *last)
+static void
+erase_popup (EphyTopicAction *action)
{
- GtkWidget *item, *toolbar;
- int index;
-
- item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
- g_return_val_if_fail (item != NULL, -1);
-
- toolbar = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR);
- g_return_val_if_fail (toolbar != NULL, -1);
-
- index = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
- GTK_TOOL_ITEM (item));
- if (last)
+ if (action->priv->merge_id != 0)
{
- int n_items;
-
- n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
- *last = (index == n_items - 1);
+ gtk_ui_manager_remove_ui (action->priv->manager, action->priv->merge_id);
+ action->priv->merge_id = 0;
}
-
- return index;
}
static void
-remove_from_model (GtkWidget *widget)
+child_added_cb (EphyNode *node, EphyNode *child, GObject *object)
{
- EphyBookmarks *bookmarks;
- EggToolbarsModel *model;
- int pos;
-
- pos = get_item_position (widget, NULL);
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- model = EGG_TOOLBARS_MODEL (ephy_bookmarks_get_toolbars_model (bookmarks));
-
- egg_toolbars_model_remove_item (model, 0, pos);
+ EphyTopicAction *action = EPHY_TOPIC_ACTION (object);
+ erase_popup (action);
}
static void
-move_in_model (GtkWidget *widget, int direction)
+child_changed_cb (EphyNode *node, EphyNode *child, guint property, GObject *object)
{
- EphyBookmarks *bookmarks;
- EggToolbarsModel *model;
- int pos, new_pos;
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- model = EGG_TOOLBARS_MODEL (ephy_bookmarks_get_toolbars_model (bookmarks));
-
- pos = get_item_position (widget, NULL);
- new_pos = MAX (0, pos + direction);
-
- egg_toolbars_model_move_item (model, 0, pos, 0, new_pos);
+ EphyTopicAction *action = EPHY_TOPIC_ACTION (object);
+ erase_popup (action);
}
static void
-remove_activate_cb (GtkWidget *menu, GtkWidget *proxy)
+child_removed_cb (EphyNode *node, EphyNode *child, guint index, GObject *object)
{
- remove_from_model (proxy);
+ EphyTopicAction *action = EPHY_TOPIC_ACTION (object);
+ erase_popup (action);
}
static void
-move_left_activate_cb (GtkWidget *menu, GtkWidget *proxy)
+menu_destroy_cb (GtkWidget *menuitem,
+ gpointer user_data)
{
- move_in_model (proxy, -1);
+ /* Save the submenu from similar destruction,
+ * because it doesn't rightly belong to this menuitem. */
+ gtk_menu_item_remove_submenu (GTK_MENU_ITEM (menuitem));
}
static void
-move_right_activate_cb (GtkWidget *menu, GtkWidget *proxy)
-{
- move_in_model (proxy, +1);
-}
-
-static GtkWidget *
-add_open_in_tabs_menu (EphyTopicAction *action,
- GtkWidget *menu,
- EphyNode *node)
-{
- GtkWidget *item;
- const char *label;
-
- label = ngettext ("Open in New _Tab",
- "Open in New _Tabs",
- ephy_node_get_n_children (node));
-
- item = gtk_menu_item_new_with_mnemonic (label);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- g_object_set_data (G_OBJECT (item), TOPIC_NODE_DATA_KEY, node);
-
- g_signal_connect (item, "activate",
- G_CALLBACK (open_in_tabs_activate_cb), action);
-
- return item;
-}
-
-static GtkWidget *
-build_bookmarks_menu (EphyTopicAction *action, EphyNode *node)
-{
- GtkWidget *menu;
-
- menu = gtk_menu_new ();
-
- append_bookmarks_menu (action, menu, node, TRUE);
-
- if (can_open_in_tabs (node))
- {
- GtkWidget *item;
-
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- add_open_in_tabs_menu (action, menu, node);
- }
-
- return menu;
-}
-
-static int
-sort_topics (gconstpointer a, gconstpointer b)
-{
- EphyNode *node_a = (EphyNode *)a;
- EphyNode *node_b = (EphyNode *)b;
- const char *title1, *title2;
- int retval;
-
- title1 = ephy_node_get_property_string (node_a, EPHY_NODE_KEYWORD_PROP_NAME);
- title2 = ephy_node_get_property_string (node_b, EPHY_NODE_KEYWORD_PROP_NAME);
-
- if (title1 == NULL)
- {
- retval = -1;
- }
- else if (title2 == NULL)
- {
- retval = 1;
- }
- else
- {
- char *str_a, *str_b;
-
- str_a = g_utf8_casefold (title1, -1);
- str_b = g_utf8_casefold (title2, -1);
- retval = g_utf8_collate (str_a, str_b);
- g_free (str_a);
- g_free (str_b);
- }
-
- return retval;
-}
-
-static GtkWidget *
-build_topics_menu (EphyTopicAction *action)
-{
- GtkWidget *menu, *item;
- GPtrArray *children;
- int i;
- EphyBookmarks *bookmarks;
- EphyNode *all, *uncategorized, *node;
- EphyNodePriority priority;
- GList *node_list = NULL, *l = NULL;
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- all = ephy_bookmarks_get_bookmarks (bookmarks);
- node = ephy_bookmarks_get_keywords (bookmarks);
-
- menu = gtk_menu_new ();
-
- children = ephy_node_get_children (node);
-
- for (i = 0; i < children->len; ++i)
- {
- EphyNode *kid;
-
- kid = g_ptr_array_index (children, i);
- priority = ephy_node_get_property_int
- (kid, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- if (priority == EPHY_NODE_NORMAL_PRIORITY)
- {
- node_list = g_list_prepend (node_list, kid);
- }
- }
-
- node_list = g_list_sort (node_list, (GCompareFunc)sort_topics);
-
- for (l = g_list_first (node_list); l != NULL; l = g_list_next (l))
- {
- EphyNode *kid;
- const char *title;
- GtkWidget *bmk_menu;
- GtkLabel *label;
-
- kid = (EphyNode*)l->data;
- if (kid == all) continue;
-
- title = ephy_node_get_property_string
- (kid, EPHY_NODE_KEYWORD_PROP_NAME);
-
- item = gtk_image_menu_item_new_with_label (title);
- label = (GtkLabel *) ((GtkBin *) item)->child;
- gtk_label_set_max_width_chars (label, MENUITEM_WIDTH_CHARS);
- gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
-
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- bmk_menu = build_bookmarks_menu (action, kid);
- gtk_widget_show (bmk_menu);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), bmk_menu);
- }
- g_list_free (node_list);
-
- uncategorized = ephy_bookmarks_get_not_categorized (bookmarks);
- append_bookmarks_menu (action, menu, uncategorized, FALSE);
-
- return menu;
-}
-
-static GtkWidget *
-build_menu (EphyTopicAction *action)
+menu_init_cb (GtkWidget *menuitem,
+ EphyTopicAction *action)
{
- if (ephy_node_get_id (action->priv->topic_node) == BOOKMARKS_NODE_ID)
- {
- return build_topics_menu (action);
- }
- else
+ if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menuitem)) == NULL)
{
- return build_bookmarks_menu (action, action->priv->topic_node);
+ GtkWidget *popup = get_popup (action);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), popup);
+ g_signal_connect (menuitem, "destroy", G_CALLBACK (menu_destroy_cb), NULL);
}
}
static void
-drag_data_get_cb (GtkWidget *widget, GdkDragContext *context,
- GtkSelectionData *selection_data, guint info,
- guint32 time, EphyTopicAction *action)
-{
- EphyBookmarks *bookmarks;
- char *uri;
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- g_return_if_fail (bookmarks != NULL);
-
- uri = ephy_bookmarks_get_topic_uri (bookmarks, action->priv->topic_node);
- g_return_if_fail (uri != NULL);
-
- gtk_selection_data_set (selection_data, selection_data->target, 8,
- (unsigned char *) uri, strlen (uri));
-
- g_free (uri);
-}
-
-static void
-drag_data_delete_cb (GtkWidget *widget, GdkDragContext *context,
- EphyTopicAction *action)
-{
- remove_from_model (widget);
-}
-
-static void
-stop_drag_check (EphyTopicAction *action, GtkWidget *widget)
-{
- if (action->priv->motion_handler)
- {
- g_signal_handler_disconnect (widget, action->priv->motion_handler);
- action->priv->motion_handler = 0;
-
- g_signal_handler_disconnect (widget, action->priv->release_handler);
- action->priv->release_handler = 0;
- }
-}
-
-static gboolean
-check_horizontal_threshold (GtkWidget *widget, gint start_x, gint start_y,
- gint current_x, gint current_y)
-{
- gint drag_threshold;
-
- g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-dnd-drag-threshold", &drag_threshold,
- NULL);
-
- return (ABS (current_x - start_x) > drag_threshold &&
- ABS (current_y - start_y) < drag_threshold);
-}
-
-static gboolean
-drag_motion_cb (GtkWidget *widget, GdkEventMotion *event, EphyTopicAction *action)
+button_deactivate_cb (GtkMenuShell *ms, GtkWidget *button)
{
- GtkWidget *button, *event_widget;
-
- event_widget = gtk_get_event_widget ((GdkEvent*) event);
- button = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "button"));
-
- if (!gtk_widget_is_ancestor (event_widget, widget) &&
- check_horizontal_threshold (widget, action->priv->drag_x,
- action->priv->drag_y, event->x, event->y))
- {
- GtkTargetList *target_list;
-
- target_list = gtk_target_list_new (drag_targets, n_drag_targets);
-
- stop_drag_check (action, widget);
- gtk_menu_popdown (GTK_MENU (widget));
- gtk_drag_begin (button, target_list, GDK_ACTION_MOVE |
- GDK_ACTION_COPY, 1, (GdkEvent*)event);
-
- gtk_target_list_unref (target_list);
- }
-
- return TRUE;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+ gtk_button_released (GTK_BUTTON (button));
}
static void
@@ -713,196 +261,43 @@ button_toggled_cb (GtkWidget *button,
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
- GtkWidget *menu;
- GdkEvent *event;
- guint32 event_time = 0;
- guint event_button = 0;
-
- menu = build_menu (action);
- g_signal_connect_object (menu, "deactivate",
- G_CALLBACK (menu_deactivate_cb), button, 0);
-
- event = gtk_get_current_event ();
- if (event != NULL)
- {
- if (event->type == GDK_BUTTON_PRESS)
- {
- event_button = ((GdkEventButton *) event)->button;
- event_time = ((GdkEventButton *) event)->time;
- }
-
- gdk_event_free (event);
- }
-
- if (event_button == 0)
- {
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- ephy_gui_menu_position_under_widget,
- button, 0 , gtk_get_current_event_time ());
- gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
- }
- else
- {
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- ephy_gui_menu_position_under_widget,
- button, event_button, event_time);
- }
-
- g_object_set_data (G_OBJECT (button), "popup", menu);
- }
-}
-
-static GtkWidget *
-create_menu_item (GtkAction *action)
-{
- GtkWidget *menu, *menu_item;
- GValue value = { 0, };
- const char *title;
-
- g_value_init (&value, G_TYPE_STRING);
- g_object_get_property (G_OBJECT (action), "label", &value);
-
- title = g_value_get_string (&value);
-
- menu_item = gtk_menu_item_new_with_label (title);
-
- g_value_unset (&value);
-
- menu = build_menu (EPHY_TOPIC_ACTION (action));
- gtk_widget_show (menu);
-
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu);
-
- return menu_item;
-}
-
-static void
-show_context_menu (EphyTopicAction *action,
- GtkWidget *proxy,
- GdkEventButton *event,
- GtkMenuPositionFunc func)
-{
- GtkWidget *menu, *item, *image;
- gboolean last;
-
- menu = gtk_menu_new ();
-
- item = add_open_in_tabs_menu (action, menu, action->priv->topic_node);
- gtk_widget_set_sensitive (item, can_open_in_tabs (action->priv->topic_node));
-
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- item = gtk_image_menu_item_new_with_mnemonic (_("_Remove from Toolbar"));
- gtk_widget_show (item);
- image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
- gtk_widget_show (image);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- g_signal_connect (item, "activate",
- G_CALLBACK (remove_activate_cb), proxy);
-
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- item = gtk_menu_item_new_with_mnemonic (_("Move _Left"));
- gtk_widget_set_sensitive (item, get_item_position (proxy, NULL) > 0);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- g_signal_connect (item, "activate",
- G_CALLBACK (move_left_activate_cb), proxy);
-
- item = gtk_menu_item_new_with_mnemonic (_("Move Ri_ght"));
- get_item_position (proxy, &last);
- gtk_widget_set_sensitive (item, !last);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- g_signal_connect (item, "activate",
- G_CALLBACK (move_right_activate_cb), proxy);
-
- if (event != NULL)
- {
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL, func, proxy,
- event->button, event->time);
- }
- else
- {
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL, func, proxy, 0,
- gtk_get_current_event_time ());
- gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
+ GtkWidget *popup = get_popup (action);
+ g_signal_connect_object (popup, "deactivate",
+ G_CALLBACK (button_deactivate_cb), button, 0);
+ gtk_menu_popup (GTK_MENU (popup), NULL, NULL,
+ ephy_gui_menu_position_under_widget,
+ button, 1, gtk_get_current_event_time ());
}
}
static gboolean
-popup_menu_cb (GtkWidget *widget, EphyTopicAction *action)
-{
- if (gtk_widget_get_ancestor (widget, EPHY_TYPE_BOOKMARKSBAR))
- {
- show_context_menu (action, widget, NULL,
- ephy_gui_menu_position_under_widget);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-button_release_cb (GtkWidget *widget,
+button_release_cb (GtkWidget *button,
GdkEventButton *event,
EphyTopicAction *action)
{
if (event->button == 1)
{
- stop_drag_check (action, widget);
-
- if (GTK_IS_TOGGLE_BUTTON (widget))
- {
- gtk_toggle_button_set_active
- (GTK_TOGGLE_BUTTON (widget), FALSE);
- }
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (button), FALSE);
}
return FALSE;
}
static gboolean
-button_press_cb (GtkWidget *widget,
+button_press_cb (GtkWidget *button,
GdkEventButton *event,
EphyTopicAction *action)
{
- if (event->button == 1 &&
- gtk_widget_get_ancestor (widget, EPHY_TYPE_BOOKMARKSBAR))
+ if (event->button == 1)
{
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
- GtkWidget *menu;
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
- menu = g_object_get_data (G_OBJECT (widget), "popup");
- g_return_val_if_fail (menu != NULL, FALSE);
-
- g_object_set_data (G_OBJECT (menu), "button", widget);
-
- action->priv->drag_x = event->x;
- action->priv->drag_y = event->y;
- action->priv->motion_handler = g_signal_connect
- (menu, "motion_notify_event",
- G_CALLBACK (drag_motion_cb), action);
- action->priv->release_handler = g_signal_connect
- (menu, "button_release_event",
- G_CALLBACK (button_release_cb), action);
-
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ button_toggled_cb (button, action);
return TRUE;
}
}
- else if (event->button == 3 &&
- gtk_widget_get_ancestor (widget, EPHY_TYPE_BOOKMARKSBAR))
- {
- show_context_menu (action, widget, event, NULL);
- return TRUE;
- }
return FALSE;
}
@@ -910,113 +305,140 @@ button_press_cb (GtkWidget *widget,
static void
connect_proxy (GtkAction *action, GtkWidget *proxy)
{
- GtkWidget *button;
-
- LOG ("connect_proxy action %p, proxy %p", action, proxy);
-
(* GTK_ACTION_CLASS (parent_class)->connect_proxy) (action, proxy);
+
+ ephy_topic_action_sync_label (action, NULL, proxy);
+ g_signal_connect_object (action, "notify::label",
+ G_CALLBACK (ephy_topic_action_sync_label), proxy, 0);
if (GTK_IS_TOOL_ITEM (proxy))
{
- ephy_topic_action_sync_label (action, NULL, proxy);
- g_signal_connect_object (action, "notify::label",
- G_CALLBACK (ephy_topic_action_sync_label), proxy, 0);
-
- button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button"));
+ GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button"));
g_signal_connect (button, "toggled",
G_CALLBACK (button_toggled_cb), action);
- g_signal_connect (button, "popup_menu",
- G_CALLBACK (popup_menu_cb), action);
g_signal_connect (button, "button-press-event",
G_CALLBACK (button_press_cb), action);
g_signal_connect (button, "button-release-event",
G_CALLBACK (button_release_cb), action);
- g_signal_connect (button, "drag_data_get",
- G_CALLBACK (drag_data_get_cb), action);
- g_signal_connect (button, "drag_data_delete",
- G_CALLBACK (drag_data_delete_cb), action);
}
else if (GTK_IS_MENU_ITEM (proxy))
{
- GtkLabel *label;
-
- label = (GtkLabel *) ((GtkBin *) proxy)->child;
-
- gtk_label_set_use_underline (label, FALSE);
- gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (label, LABEL_WIDTH_CHARS);
+ g_signal_connect (proxy, "map", G_CALLBACK (menu_init_cb), action);
}
}
-static void
-topic_changed_cb (EphyNode *node,
- guint property_id,
- EphyTopicAction *action)
+void
+ephy_topic_action_updated (EphyTopicAction *action)
{
- if (property_id == EPHY_NODE_KEYWORD_PROP_NAME)
+ GValue value = { 0, };
+ const char *title;
+ int priority;
+
+ g_return_if_fail (action->priv->node != NULL);
+
+ priority = ephy_node_get_property_int
+ (action->priv->node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
+
+ if (priority == EPHY_NODE_ALL_PRIORITY)
{
- GValue value = { 0, };
- const char *title;
- int priority;
-
- priority = ephy_node_get_property_int
- (node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
-
- if (priority == EPHY_NODE_ALL_PRIORITY)
- {
- title = _("Bookmarks");
- }
- else
- {
- title = ephy_node_get_property_string
- (node, EPHY_NODE_KEYWORD_PROP_NAME);
- }
-
- g_value_init(&value, G_TYPE_STRING);
- g_value_set_static_string (&value, title);
- g_object_set_property (G_OBJECT (action), "label", &value);
- g_value_unset (&value);
+ title = _("Bookmarks");
+ }
+ else
+ {
+ title = ephy_node_get_property_string
+ (action->priv->node, EPHY_NODE_KEYWORD_PROP_NAME);
}
+
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_static_string (&value, title);
+ g_object_set_property (G_OBJECT (action), "label", &value);
+ g_object_set_property (G_OBJECT (action), "tooltip", &value);
+ g_value_unset (&value);
}
-static void
+EphyNode *
+ephy_topic_action_get_topic (EphyTopicAction *action)
+{
+ return action->priv->node;
+}
+
+void
ephy_topic_action_set_topic (EphyTopicAction *action,
EphyNode *node)
{
- action->priv->topic_node = node;
+ g_return_if_fail (node != NULL);
+
+ if (action->priv->node == node) return;
+
+ if (action->priv->node != NULL)
+ {
+ ephy_node_signal_disconnect_object
+ (action->priv->node, EPHY_NODE_CHILD_ADDED,
+ (EphyNodeCallback)child_added_cb, G_OBJECT (action));
+ ephy_node_signal_disconnect_object
+ (action->priv->node, EPHY_NODE_CHILD_CHANGED,
+ (EphyNodeCallback)child_changed_cb, G_OBJECT (action));
+ ephy_node_signal_disconnect_object
+ (action->priv->node, EPHY_NODE_CHILD_REMOVED,
+ (EphyNodeCallback)child_removed_cb, G_OBJECT (action));
+ }
- topic_changed_cb (node, EPHY_NODE_KEYWORD_PROP_NAME, action);
- ephy_node_signal_connect_object (node, EPHY_NODE_CHANGED,
- (EphyNodeCallback) topic_changed_cb,
- G_OBJECT (action));
+ ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_ADDED,
+ (EphyNodeCallback)child_added_cb,
+ G_OBJECT (action));
+ ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_CHANGED,
+ (EphyNodeCallback)child_changed_cb,
+ G_OBJECT (action));
+ ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_REMOVED,
+ (EphyNodeCallback)child_removed_cb,
+ G_OBJECT (action));
+
+ action->priv->node = node;
+
+ erase_popup (action);
+
+ g_object_freeze_notify (G_OBJECT (action));
+ g_object_notify (G_OBJECT (action), "topic");
+ ephy_topic_action_updated (action);
+ g_object_thaw_notify (G_OBJECT (action));
}
static void
ephy_topic_action_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- EphyTopicAction *topic;
-
- topic = EPHY_TOPIC_ACTION (object);
+ EphyTopicAction *action = EPHY_TOPIC_ACTION (object);
switch (prop_id)
{
case PROP_TOPIC:
- ephy_topic_action_set_topic (topic, g_value_get_pointer (value));
+ ephy_topic_action_set_topic (action, g_value_get_pointer (value));
+ break;
+ case PROP_MANAGER:
+ action->priv->manager = g_value_get_object (value);
break;
}
}
static void
ephy_topic_action_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- /* no readable properties */
- g_return_if_reached ();
+ EphyTopicAction *action = EPHY_TOPIC_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_TOPIC:
+ g_value_set_pointer (value, action->priv->node);
+ break;
+ case PROP_MANAGER:
+ g_value_set_object (value, action->priv->manager);
+ break;
+ }
}
static void
@@ -1029,21 +451,28 @@ ephy_topic_action_class_init (EphyTopicActionClass *class)
action_class->toolbar_item_type = GTK_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->set_property = ephy_topic_action_set_property;
object_class->get_property = ephy_topic_action_get_property;
- g_object_class_install_property
- (object_class,
- PROP_TOPIC,
- g_param_spec_pointer ("topic",
- "Topic",
- "Topic",
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
-
+ g_object_class_install_property (object_class,
+ PROP_TOPIC,
+ g_param_spec_pointer ("topic",
+ "Topic",
+ "Topic",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class,
+ PROP_MANAGER,
+ g_param_spec_object ("manager",
+ "Manager",
+ "UI Manager",
+ GTK_TYPE_UI_MANAGER,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+
g_type_class_add_private (object_class, sizeof(EphyTopicActionPrivate));
}
@@ -1051,14 +480,27 @@ static void
ephy_topic_action_init (EphyTopicAction *action)
{
action->priv = EPHY_TOPIC_ACTION_GET_PRIVATE (action);
+
+ action->priv->merge_id = 0;
+ action->priv->node = NULL;
+ action->priv->manager = NULL;
+}
+
+char *
+ephy_topic_action_name (EphyNode *node)
+{
+ return g_strdup_printf("Tpc%u", ephy_node_get_id (node));
}
GtkAction *
-ephy_topic_action_new (const char *name,
- EphyNode *node)
+ephy_topic_action_new (EphyNode *node, GtkUIManager *manager, char *name)
{
- return g_object_new (EPHY_TYPE_TOPIC_ACTION,
- "name", name,
- "topic", node,
- NULL);
+ if(!name) name = ephy_topic_action_name (node);
+ g_return_val_if_fail (name, NULL);
+
+ return GTK_ACTION (g_object_new (EPHY_TYPE_TOPIC_ACTION,
+ "name", name,
+ "topic", node,
+ "manager", manager,
+ NULL));
}