diff options
-rw-r--r-- | ChangeLog | 39 | ||||
-rw-r--r-- | lib/ephy-dnd.c | 6 | ||||
-rw-r--r-- | lib/ephy-dnd.h | 10 | ||||
-rwxr-xr-x | lib/widgets/ephy-editable-toolbar.c | 77 | ||||
-rwxr-xr-x | lib/widgets/ephy-editable-toolbar.h | 25 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-sort.c | 54 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-sort.h | 6 | ||||
-rw-r--r-- | src/bookmarks/Makefile.am | 2 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 13 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.c | 95 | ||||
-rw-r--r-- | src/bookmarks/ephy-node-view.c | 27 | ||||
-rw-r--r-- | src/bookmarks/ephy-node-view.h | 5 | ||||
-rw-r--r-- | src/bookmarks/ephy-topic-action.c | 273 | ||||
-rw-r--r-- | src/bookmarks/ephy-topic-action.h | 54 | ||||
-rwxr-xr-x | src/history-dialog.c | 3 | ||||
-rwxr-xr-x | src/toolbar.c | 77 |
16 files changed, 610 insertions, 156 deletions
@@ -1,3 +1,42 @@ +2003-03-25 Marco Pesenti Gritti <marco@it.gnome.org> + + * lib/ephy-dnd.c: + * lib/ephy-dnd.h: + + Make ids private + + * lib/widgets/ephy-editable-toolbar.c: (impl_get_action_name), + (impl_get_action), (drag_data_received_cb), (setup_toolbar), + (setup_item), (ensure_action), (ephy_editable_toolbar_class_init), + (update_editor_sheet), (ephy_editable_toolbar_get_action_name), + (ephy_editable_toolbar_get_action): + * lib/widgets/ephy-editable-toolbar.h: + + Rework special actions api. + + * lib/widgets/ephy-tree-model-sort.c: (ephy_tree_model_sort_init), + (ephy_tree_model_sort_set_drag_property), + (each_url_get_data_binder), + (ephy_tree_model_sort_multi_drag_data_get): + * lib/widgets/ephy-tree-model-sort.h: + + Support nodes dnd. Need more work, see FIXME + + * src/bookmarks/Makefile.am: + * src/bookmarks/ephy-bookmarks-editor.c: + (ephy_bookmarks_editor_construct): + * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init), + (ephy_bookmarks_finalize), (ephy_bookmarks_find_keyword): + * src/bookmarks/ephy-node-view.c: + (ephy_node_view_enable_drag_source): + * src/bookmarks/ephy-node-view.h: + * src/history-dialog.c: (history_dialog_setup_view): + * src/toolbar.c: (toolbar_get_action_name), (toolbar_get_action), + (toolbar_class_init): + + Support for topics dnd. The menu is still not implemented + but the hard part is done. Cant finish it until the weekend :/ + 2003-03-25 Xan Lopez <xan@masilla.org> * src/bookmarks/ephy-bookmarks-import.c: (set_folder): diff --git a/lib/ephy-dnd.c b/lib/ephy-dnd.c index 99438495c..7dfd1f272 100644 --- a/lib/ephy-dnd.c +++ b/lib/ephy-dnd.c @@ -22,6 +22,12 @@ #include <gtk/gtktreeview.h> #include <string.h> +typedef enum { + EPHY_DND_URI_LIST, + EPHY_DND_TEXT, + EPHY_DND_URL +} EphyIconDndTargetType; + static GtkTargetEntry url_drag_types [] = { { EPHY_DND_URI_LIST_TYPE, 0, EPHY_DND_URI_LIST }, diff --git a/lib/ephy-dnd.h b/lib/ephy-dnd.h index e888977a8..c1756713f 100644 --- a/lib/ephy-dnd.h +++ b/lib/ephy-dnd.h @@ -25,19 +25,11 @@ G_BEGIN_DECLS -#define EPHY_DND_NODE_PROPERTY 3 - /* Drag & Drop target names. */ #define EPHY_DND_URI_LIST_TYPE "text/uri-list" #define EPHY_DND_TEXT_TYPE "text/plain" #define EPHY_DND_URL_TYPE "_NETSCAPE_URL" - -/* Standard Drag & Drop types. */ -typedef enum { - EPHY_DND_URI_LIST, - EPHY_DND_TEXT, - EPHY_DND_URL -} EphyIconDndTargetType; +#define EPHY_DND_TOPIC_TYPE "ephy_topic" typedef void (* EphyDragEachSelectedItemDataGet) (const char *url, int x, int y, int w, int h, diff --git a/lib/widgets/ephy-editable-toolbar.c b/lib/widgets/ephy-editable-toolbar.c index 7307140c8..2af974a87 100755 --- a/lib/widgets/ephy-editable-toolbar.c +++ b/lib/widgets/ephy-editable-toolbar.c @@ -29,18 +29,12 @@ #include <libgnome/gnome-i18n.h> #include <string.h> -/* This is copied from gtkscrollbarwindow.c */ -#define DEFAULT_SCROLLBAR_SPACING 3 - -#define SCROLLBAR_SPACING(w) \ - (GTK_SCROLLED_WINDOW_GET_CLASS (w)->scrollbar_spacing >= 0 ? \ - GTK_SCROLLED_WINDOW_GET_CLASS (w)->scrollbar_spacing : DEFAULT_SCROLLBAR_SPACING) - static GtkTargetEntry dest_drag_types [] = { { "EPHY_TOOLBAR_BUTTON", 0, 0 }, /* FIXME generic way to add types */ - { EPHY_DND_URL_TYPE, 0, EPHY_DND_URL } + { EPHY_DND_URL_TYPE, 0, 1 }, + { EPHY_DND_TOPIC_TYPE, 0, 2 } }; static GtkTargetEntry source_drag_types [] = @@ -180,23 +174,23 @@ find_action (EphyEditableToolbar *t, const char *name) return action; } +static char * +impl_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data) +{ + return NULL; +} + static EggAction * impl_get_action (EphyEditableToolbar *etoolbar, - const char *type, const char *name) { EggAction *action; g_return_val_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar), NULL); - if (type == NULL) - { - action = find_action (etoolbar, name); - } - else - { - action = NULL; - } + action = find_action (etoolbar, name); return action; } @@ -248,10 +242,12 @@ drag_data_received_cb (GtkWidget *widget, EphyToolbarsItem *sibling; const char *type = NULL; GdkAtom target; - EggAction *action; + EggAction *action = NULL; g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar)); + LOG ("Drag data received") + toolbar = (EphyToolbarsToolbar *)g_object_get_data (G_OBJECT (widget), "toolbar_data"); if (!toolbar) @@ -273,8 +269,28 @@ drag_data_received_cb (GtkWidget *widget, { type = EPHY_DND_URL_TYPE; } + else if (target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE)) + { + type = EPHY_DND_TOPIC_TYPE; + } + + if (type) + { + char *name; + + name = ephy_editable_toolbar_get_action_name + (etoolbar, type, selection_data->data); + if (name != NULL) + { + action = ephy_editable_toolbar_get_action (etoolbar, name); + g_free (name); + } + } + else + { + action = ephy_editable_toolbar_get_action (etoolbar, selection_data->data); + } - action = ephy_editable_toolbar_get_action (etoolbar, type, selection_data->data); if (action) { ephy_toolbars_group_add_item (etoolbar->priv->group, parent, sibling, @@ -540,7 +556,7 @@ setup_toolbar (EphyToolbarsToolbar *toolbar, EphyEditableToolbar *etoolbar) g_object_set_data (G_OBJECT (widget), "drag_dest_set", GINT_TO_POINTER (TRUE)); gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, - dest_drag_types, 2, + dest_drag_types, 3, GDK_ACTION_MOVE | GDK_ACTION_COPY); g_signal_connect (widget, "drag_data_received", G_CALLBACK (drag_data_received_cb), @@ -587,7 +603,7 @@ setup_item (EphyToolbarsItem *item, EphyEditableToolbar *etoolbar) g_object_set_data (G_OBJECT (toolitem), "drag_dest_set", GINT_TO_POINTER (TRUE)); gtk_drag_dest_set (toolitem, GTK_DEST_DEFAULT_ALL, - dest_drag_types, 2, + dest_drag_types, 3, GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect (toolitem, "drag_data_received", G_CALLBACK (drag_data_received_cb), @@ -676,7 +692,7 @@ ensure_action (EphyToolbarsItem *item, EphyEditableToolbar *t) g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (t)); g_return_if_fail (item != NULL); - ephy_editable_toolbar_get_action (t, NULL, item->action); + ephy_editable_toolbar_get_action (t, item->action); } static void @@ -774,6 +790,7 @@ ephy_editable_toolbar_class_init (EphyEditableToolbarClass *klass) object_class->get_property = ephy_editable_toolbar_get_property; klass->get_action = impl_get_action; + klass->get_action_name = impl_get_action_name; g_object_class_install_property (object_class, PROP_MENU_MERGE, @@ -1033,7 +1050,7 @@ update_editor_sheet (EphyEditableToolbar *etoolbar) gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (etoolbar->priv->scrolled_window), table); gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL, - dest_drag_types, 2, GDK_ACTION_MOVE); + dest_drag_types, 3, GDK_ACTION_MOVE); g_signal_connect (table, "drag_data_received", G_CALLBACK (editor_drag_data_received_cb), etoolbar); @@ -1057,7 +1074,7 @@ update_editor_sheet (EphyEditableToolbar *etoolbar) EggAction *action; action = ephy_editable_toolbar_get_action - (etoolbar, NULL, node->action); + (etoolbar, node->action); g_return_if_fail (action != NULL); event_box = gtk_event_box_new (); @@ -1202,11 +1219,19 @@ ephy_editable_toolbar_edit (EphyEditableToolbar *etoolbar, GtkWidget *window) show_editor (etoolbar); } +char * +ephy_editable_toolbar_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data) +{ + EphyEditableToolbarClass *klass = EPHY_EDITABLE_TOOLBAR_GET_CLASS (etoolbar); + return klass->get_action_name (etoolbar, drag_type, data); +} + EggAction * ephy_editable_toolbar_get_action (EphyEditableToolbar *etoolbar, - const char *type, const char *name) { EphyEditableToolbarClass *klass = EPHY_EDITABLE_TOOLBAR_GET_CLASS (etoolbar); - return klass->get_action (etoolbar, type, name); + return klass->get_action (etoolbar, name); } diff --git a/lib/widgets/ephy-editable-toolbar.h b/lib/widgets/ephy-editable-toolbar.h index 8c5f93932..68e6f39b5 100755 --- a/lib/widgets/ephy-editable-toolbar.h +++ b/lib/widgets/ephy-editable-toolbar.h @@ -48,21 +48,26 @@ struct EphyEditableToolbarClass { GObjectClass parent_class; - EggAction * (* get_action) (EphyEditableToolbar *etoolbar, - const char *type, - const char *name); + char * (* get_action_name) (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data); + EggAction * (* get_action) (EphyEditableToolbar *etoolbar, + const char *name); }; -GType ephy_editable_toolbar_get_type (void); +GType ephy_editable_toolbar_get_type (void); -EphyEditableToolbar *ephy_editable_toolbar_new (EggMenuMerge *merge); +EphyEditableToolbar *ephy_editable_toolbar_new (EggMenuMerge *merge); -void ephy_editable_toolbar_edit (EphyEditableToolbar *etoolbar, - GtkWidget *window); +void ephy_editable_toolbar_edit (EphyEditableToolbar *etoolbar, + GtkWidget *window); -EggAction *ephy_editable_toolbar_get_action (EphyEditableToolbar *etoolbar, - const char *type, - const char *name); +char *ephy_editable_toolbar_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data); + +EggAction *ephy_editable_toolbar_get_action (EphyEditableToolbar *etoolbar, + const char *name); G_END_DECLS diff --git a/lib/widgets/ephy-tree-model-sort.c b/lib/widgets/ephy-tree-model-sort.c index 3c2377cf0..41369afd9 100644 --- a/lib/widgets/ephy-tree-model-sort.c +++ b/lib/widgets/ephy-tree-model-sort.c @@ -26,6 +26,7 @@ #include "eggtreemultidnd.h" #include "ephy-dnd.h" #include "ephy-marshal.h" +#include "ephy-debug.h" static void ephy_tree_model_sort_class_init (EphyTreeModelSortClass *klass); static void ephy_tree_model_sort_init (EphyTreeModelSort *ma); @@ -43,6 +44,7 @@ static gboolean ephy_tree_model_sort_multi_drag_data_delete (EggTreeMultiDragSou struct EphyTreeModelSortPrivate { char *str_list; + guint drag_property_id; }; enum @@ -119,6 +121,8 @@ static void ephy_tree_model_sort_init (EphyTreeModelSort *ma) { ma->priv = g_new0 (EphyTreeModelSortPrivate, 1); + + ma->priv->drag_property_id = -1; } static void @@ -185,6 +189,13 @@ ephy_tree_model_sort_multi_row_draggable (EggTreeMultiDragSource *drag_source, G return TRUE; } +void +ephy_tree_model_sort_set_drag_property (EphyTreeModelSort *ms, + guint id) +{ + ms->priv->drag_property_id = id; +} + static gboolean ephy_tree_model_sort_multi_drag_data_delete (EggTreeMultiDragSource *drag_source, GList *path_list) @@ -216,8 +227,10 @@ each_url_get_data_binder (EphyDragEachSelectedItemDataGet iteratee, if (node == NULL) return; - value = ephy_node_get_property_string (node, - EPHY_DND_NODE_PROPERTY); + value = ephy_node_get_property_string + (node, EPHY_TREE_MODEL_SORT (model)->priv->drag_property_id); + + LOG ("Data get %s", value) iteratee (value, -1, -1, -1, -1, data); } @@ -228,13 +241,40 @@ ephy_tree_model_sort_multi_drag_data_get (EggTreeMultiDragSource *drag_source, GList *path_list, guint info, GtkSelectionData *selection_data) -{ gpointer icontext[2]; +{ + EphyTreeModelSort *ms = EPHY_TREE_MODEL_SORT (drag_source); - icontext[0] = path_list; - icontext[1] = drag_source; + /* FIXME use the target type here, not property_id */ - ephy_dnd_drag_data_get (NULL, NULL, selection_data, - info, 0, &icontext, each_url_get_data_binder); + if (ms->priv->drag_property_id != -1) + { + gpointer icontext[2]; + + icontext[0] = path_list; + icontext[1] = drag_source; + + ephy_dnd_drag_data_get (NULL, NULL, selection_data, + info, 0, &icontext, each_url_get_data_binder); + } + else + { + GtkTreeIter iter; + GtkTreePath *path = gtk_tree_row_reference_get_path (path_list->data); + EphyNode *node = NULL; + char *data; + + gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), &iter, path); + g_signal_emit (G_OBJECT (drag_source), + ephy_tree_model_sort_signals[NODE_FROM_ITER], + 0, &iter, &node); + + /* FIXME free */ + data = g_strdup_printf ("%ld", ephy_node_get_id (node)); + + gtk_selection_data_set (selection_data, + selection_data->target, + 8, data, strlen (data)); + } return TRUE; } diff --git a/lib/widgets/ephy-tree-model-sort.h b/lib/widgets/ephy-tree-model-sort.h index f8cb9fb68..2b8b38be9 100644 --- a/lib/widgets/ephy-tree-model-sort.h +++ b/lib/widgets/ephy-tree-model-sort.h @@ -49,10 +49,12 @@ typedef struct void (*node_from_iter) (EphyTreeModelSort *model, GtkTreeIter *iter, void **node); } EphyTreeModelSortClass; -GType ephy_tree_model_sort_get_type (void); +GType ephy_tree_model_sort_get_type (void); -GtkTreeModel *ephy_tree_model_sort_new (GtkTreeModel *child_model); +GtkTreeModel *ephy_tree_model_sort_new (GtkTreeModel *child_model); +void ephy_tree_model_sort_set_drag_property (EphyTreeModelSort *ms, + guint id); G_END_DECLS diff --git a/src/bookmarks/Makefile.am b/src/bookmarks/Makefile.am index b0410e184..563329335 100644 --- a/src/bookmarks/Makefile.am +++ b/src/bookmarks/Makefile.am @@ -34,6 +34,8 @@ libephybookmarks_la_SOURCES = \ ephy-new-bookmark.h \ ephy-node-view.c \ ephy-node-view.h \ + ephy-topic-action.c \ + ephy-topic-action.h \ ephy-topics-selector.c \ ephy-topics-selector.h \ ephy-tree-model-node.c \ diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index b4cc80a16..fdbba76c9 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -98,6 +98,12 @@ enum RESPONSE_GO }; +static GtkTargetEntry topic_drag_types [] = +{ + { EPHY_DND_TOPIC_TYPE, 0, 0 } +}; +static int n_topic_drag_types = G_N_ELEMENTS (topic_drag_types); + static GObjectClass *parent_class = NULL; static EggActionGroupEntry ephy_bookmark_popup_entries [] = { @@ -618,7 +624,10 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) /* Keywords View */ key_view = ephy_node_view_new (node, NULL); - ephy_node_view_enable_drag_source (key_view); + ephy_node_view_enable_drag_source (key_view, + topic_drag_types, + n_topic_drag_types, + -1); ephy_node_view_set_browse_mode (key_view); ephy_node_view_add_column (key_view, _("Topics"), EPHY_TREE_MODEL_NODE_COL_KEYWORD, TRUE, TRUE); @@ -646,7 +655,7 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) /* Bookmarks View */ bm_view = ephy_node_view_new (node, editor->priv->bookmarks_filter); ephy_node_view_set_hinted (bm_view, TRUE); - ephy_node_view_enable_drag_source (bm_view); + ephy_node_view_enable_drag_source (bm_view, NULL, 0, EPHY_NODE_BMK_PROP_LOCATION); ephy_node_view_add_icon_column (bm_view, EPHY_TREE_MODEL_NODE_COL_ICON); ephy_node_view_add_column (bm_view, _("Bookmarks"), EPHY_TREE_MODEL_NODE_COL_BOOKMARK, TRUE, TRUE); diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index a5d978de4..7441057d3 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -38,8 +38,6 @@ struct EphyBookmarksPrivate EphyNode *favorites; EphyNode *lower_fav; double lower_score; - GHashTable *keywords_hash; - GStaticRWLock *keywords_hash_lock; }; static void @@ -364,33 +362,6 @@ ephy_setup_history_notifiers (EphyBookmarks *eb) } static void -keywords_added_cb (EphyNode *node, - EphyNode *child, - EphyBookmarks *eb) -{ - g_static_rw_lock_writer_lock (eb->priv->keywords_hash_lock); - - g_hash_table_insert (eb->priv->keywords_hash, - (char *) ephy_node_get_property_string (child, EPHY_NODE_KEYWORD_PROP_NAME), - child); - - g_static_rw_lock_writer_unlock (eb->priv->keywords_hash_lock); -} - -static void -keywords_removed_cb (EphyNode *node, - EphyNode *child, - EphyBookmarks *eb) -{ - g_static_rw_lock_writer_lock (eb->priv->keywords_hash_lock); - - g_hash_table_remove (eb->priv->keywords_hash, - ephy_node_get_property_string (child, EPHY_NODE_KEYWORD_PROP_NAME)); - - g_static_rw_lock_writer_unlock (eb->priv->keywords_hash_lock); -} - -static void bookmarks_changed_cb (EphyNode *node, EphyNode *child, EphyBookmarks *eb) @@ -417,11 +388,6 @@ ephy_bookmarks_init (EphyBookmarks *eb) "bookmarks.xml", NULL); - eb->priv->keywords_hash = g_hash_table_new (g_str_hash, - g_str_equal); - eb->priv->keywords_hash_lock = g_new0 (GStaticRWLock, 1); - g_static_rw_lock_init (eb->priv->keywords_hash_lock); - /* Bookmarks */ eb->priv->bookmarks = ephy_node_new_with_id (BOOKMARKS_NODE_ID); ephy_node_ref (eb->priv->bookmarks); @@ -454,16 +420,6 @@ ephy_bookmarks_init (EphyBookmarks *eb) ephy_node_add_child (eb->priv->keywords, eb->priv->bookmarks); - g_signal_connect_object (G_OBJECT (eb->priv->keywords), - "child_added", - G_CALLBACK (keywords_added_cb), - G_OBJECT (eb), - 0); - g_signal_connect_object (G_OBJECT (eb->priv->keywords), - "child_removed", - G_CALLBACK (keywords_removed_cb), - G_OBJECT (eb), - 0); /* Favorites */ eb->priv->favorites = ephy_node_new_with_id (FAVORITES_NODE_ID); @@ -506,9 +462,6 @@ ephy_bookmarks_finalize (GObject *object) ephy_node_unref (eb->priv->keywords); ephy_node_unref (eb->priv->favorites); - g_hash_table_destroy (eb->priv->keywords_hash); - g_static_rw_lock_free (eb->priv->keywords_hash_lock); - g_free (eb->priv); LOG ("Bookmarks finalized") @@ -797,43 +750,35 @@ ephy_bookmarks_find_keyword (EphyBookmarks *eb, gboolean partial_match) { EphyNode *node; + GPtrArray *children; + int i; g_return_val_if_fail (name != NULL, NULL); - if (!partial_match) + + if (g_utf8_strlen (name, -1) == 0) { - g_static_rw_lock_reader_lock (eb->priv->keywords_hash_lock); - node = g_hash_table_lookup (eb->priv->keywords_hash, name); - g_static_rw_lock_reader_unlock (eb->priv->keywords_hash_lock); + LOG ("Empty name, no keyword matches.") + return NULL; } - else - { - GPtrArray *children; - int i; - - if (g_utf8_strlen (name, -1) == 0) - { - LOG ("Empty name, no keyword matches.") - return NULL; - } - children = ephy_node_get_children (eb->priv->keywords); - node = NULL; - for (i = 0; i < children->len; i++) - { - EphyNode *kid; - const char *key; + children = ephy_node_get_children (eb->priv->keywords); + node = NULL; + for (i = 0; i < children->len; i++) + { + EphyNode *kid; + const char *key; - kid = g_ptr_array_index (children, i); - key = ephy_node_get_property_string (kid, EPHY_NODE_KEYWORD_PROP_NAME); + kid = g_ptr_array_index (children, i); + key = ephy_node_get_property_string (kid, EPHY_NODE_KEYWORD_PROP_NAME); - if (g_str_has_prefix (key, name) > 0) - { - node = kid; - } - } - ephy_node_thaw (eb->priv->keywords); + if ((partial_match && g_str_has_prefix (key, name) > 0) || + (!partial_match && strcmp (key, name) == 0)) + { + node = kid; + } } + ephy_node_thaw (eb->priv->keywords); return node; } diff --git a/src/bookmarks/ephy-node-view.c b/src/bookmarks/ephy-node-view.c index 8d75d8a41..4270d58f2 100644 --- a/src/bookmarks/ephy-node-view.c +++ b/src/bookmarks/ephy-node-view.c @@ -718,12 +718,33 @@ ephy_node_view_select_node (EphyNodeView *view, } void -ephy_node_view_enable_drag_source (EphyNodeView *view) +ephy_node_view_enable_drag_source (EphyNodeView *view, + GtkTargetEntry *types, + int n_types, + guint prop_id) { + GtkWidget *treeview; + g_return_if_fail (view != NULL); - egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (view->priv->treeview)); - ephy_dnd_enable_model_drag_source (GTK_WIDGET (view->priv->treeview)); + treeview = view->priv->treeview; + + egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (treeview)); + + if (types == NULL) + { + ephy_dnd_enable_model_drag_source (GTK_WIDGET (treeview)); + } + else + { + gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview), + GDK_BUTTON1_MASK, + types, n_types, + GDK_ACTION_COPY); + } + + ephy_tree_model_sort_set_drag_property (EPHY_TREE_MODEL_SORT (view->priv->sortmodel), + prop_id); } void diff --git a/src/bookmarks/ephy-node-view.h b/src/bookmarks/ephy-node-view.h index 9055b914e..47b429cd7 100644 --- a/src/bookmarks/ephy-node-view.h +++ b/src/bookmarks/ephy-node-view.h @@ -79,7 +79,10 @@ void ephy_node_view_set_browse_mode (EphyNodeView *view); void ephy_node_view_select_node (EphyNodeView *view, EphyNode *node); -void ephy_node_view_enable_drag_source (EphyNodeView *view); +void ephy_node_view_enable_drag_source (EphyNodeView *view, + GtkTargetEntry *types, + int n_types, + guint prop_id); void ephy_node_view_set_hinted (EphyNodeView *view, gboolean hinted); diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c new file mode 100644 index 000000000..a560817e4 --- /dev/null +++ b/src/bookmarks/ephy-topic-action.c @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2003 Marco Pesenti Gritti + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "ephy-topic-action.h" +#include "ephy-bookmarks.h" +#include "ephy-shell.h" +#include "eggtoolitem.h" +#include "ephy-debug.h" + +static void ephy_topic_action_init (EphyTopicAction *action); +static void ephy_topic_action_class_init (EphyTopicActionClass *class); + +struct EphyTopicActionPrivate +{ + int bookmark_id; +}; + +enum +{ + PROP_0, + PROP_BOOKMARK_ID +}; + +enum +{ + GO_LOCATION, + LAST_SIGNAL +}; + +static GObjectClass *parent_class = NULL; + +static guint ephy_topic_action_signals[LAST_SIGNAL] = { 0 }; + +GType +ephy_topic_action_get_type (void) +{ + static GType type = 0; + + if (!type) + { + static const GTypeInfo type_info = + { + sizeof (EphyTopicActionClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) ephy_topic_action_class_init, + (GClassFinalizeFunc) NULL, + NULL, + sizeof (EphyTopicAction), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_topic_action_init, + }; + + type = g_type_register_static (EGG_TYPE_ACTION, + "EphyTopicAction", + &type_info, 0); + } + return type; +} + +static GtkWidget * +create_tool_item (EggAction *action) +{ + GtkWidget *item; + GtkWidget *button; + GtkWidget *hbox; + GtkWidget *label; + + item = (* EGG_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_button_new (); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_widget_show (button); + gtk_container_add (GTK_CONTAINER (hbox), button); + g_object_set_data (G_OBJECT (item), "button", button); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox); + gtk_container_add (GTK_CONTAINER (button), hbox); + + label = gtk_label_new (NULL); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (item), "label", label); + + return item; +} + +static void +ephy_topic_action_sync_label (EggAction *action, GParamSpec *pspec, GtkWidget *proxy) +{ + GtkLabel *label; + + 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); + + gtk_label_set_label (label, action->label); +} + +static void +button_press_cb (GtkWidget *button, + GdkEventButton *event, + EphyTopicAction *action) +{ +/* + if (event->button == 3) + { + GtkWidget *menu; + + menu = build_topics_menu (action); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 1, + gtk_get_current_event_time ()); + } +*/ +} + +static void +connect_proxy (EggAction *action, GtkWidget *proxy) +{ + GtkWidget *button; + + (* EGG_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); + + button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button")); + g_signal_connect (button, "button_press_event", + G_CALLBACK (button_press_cb), action); +} + +static void +ephy_topic_action_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyTopicAction *bmk; + + bmk = EPHY_TOPIC_ACTION (object); + + switch (prop_id) + { + case PROP_BOOKMARK_ID: + bmk->priv->bookmark_id = g_value_get_int (value); + break; + } +} + +static void +ephy_topic_action_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyTopicAction *bmk; + + bmk = EPHY_TOPIC_ACTION (object); + + switch (prop_id) + { + case PROP_BOOKMARK_ID: + g_value_set_boolean (value, bmk->priv->bookmark_id); + break; + } +} + +static void +ephy_topic_action_finalize (GObject *object) +{ + EphyTopicAction *eba; + + g_return_if_fail (EPHY_IS_TOPIC_ACTION (object)); + + eba = EPHY_TOPIC_ACTION (object); + + g_return_if_fail (eba->priv != NULL); + + g_free (eba->priv); + + LOG ("Bookmark action finalized") + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +ephy_topic_action_class_init (EphyTopicActionClass *class) +{ + EggActionClass *action_class; + GObjectClass *object_class = G_OBJECT_CLASS (class); + + parent_class = g_type_class_peek_parent (class); + action_class = EGG_ACTION_CLASS (class); + + action_class->toolbar_item_type = EGG_TYPE_TOOL_ITEM; + action_class->create_tool_item = create_tool_item; + action_class->connect_proxy = connect_proxy; + + object_class->finalize = ephy_topic_action_finalize; + object_class->set_property = ephy_topic_action_set_property; + object_class->get_property = ephy_topic_action_get_property; + + ephy_topic_action_signals[GO_LOCATION] = + g_signal_new ("go_location", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyTopicActionClass, go_location), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + + g_object_class_install_property (object_class, + PROP_BOOKMARK_ID, + g_param_spec_int ("bookmark_id", + "bookmark_id", + "bookmark_id", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); +} + +static void +ephy_topic_action_init (EphyTopicAction *action) +{ + action->priv = g_new0 (EphyTopicActionPrivate, 1); +} + +EggAction * +ephy_topic_action_new (const char *name, guint id) +{ + EphyNode *bmk; + const char *title; + EphyBookmarks *bookmarks; + + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + + bmk = ephy_node_get_from_id (id); + g_return_val_if_fail (bmk != NULL, NULL); + + title = ephy_node_get_property_string + (bmk, EPHY_NODE_KEYWORD_PROP_NAME); + + return EGG_ACTION (g_object_new (EPHY_TYPE_TOPIC_ACTION, + "name", name, + "label", title, + NULL)); +} + diff --git a/src/bookmarks/ephy-topic-action.h b/src/bookmarks/ephy-topic-action.h new file mode 100644 index 000000000..b85954873 --- /dev/null +++ b/src/bookmarks/ephy-topic-action.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2003 Marco Pesenti Gritti + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef EPHY_TOPIC_ACTION_H +#define EPHY_TOPIC_ACTION_H + +#include <gtk/gtk.h> +#include <egg-action.h> + +#define EPHY_TYPE_TOPIC_ACTION (ephy_topic_action_get_type ()) +#define EPHY_TOPIC_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_TOPIC_ACTION, EphyTopicAction)) +#define EPHY_TOPIC_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_TOPIC_ACTION, EphyTopicActionClass)) +#define EPHY_IS_TOPIC_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_TOPIC_ACTION)) +#define EPHY_IS_TOPIC_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EPHY_TYPE_TOPIC_ACTION)) +#define EPHY_TOPIC_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_TOPIC_ACTION, EphyTopicActionClass)) + +typedef struct _EphyTopicAction EphyTopicAction; +typedef struct _EphyTopicActionClass EphyTopicActionClass; +typedef struct EphyTopicActionPrivate EphyTopicActionPrivate; + +struct _EphyTopicAction +{ + EggAction parent; + EphyTopicActionPrivate *priv; +}; + +struct _EphyTopicActionClass +{ + EggActionClass parent_class; + + void (*go_location) (EphyTopicAction *action, char *location); +}; + +GType ephy_topic_action_get_type (void); + +EggAction *ephy_topic_action_new (const char *name, + guint id); + +#endif diff --git a/src/history-dialog.c b/src/history-dialog.c index 6756f14c3..a8c1221fa 100755 --- a/src/history-dialog.c +++ b/src/history-dialog.c @@ -278,6 +278,9 @@ history_dialog_setup_view (HistoryDialog *dialog) EPHY_HISTORY_MODEL_COL_VISIBLE); dialog->priv->sortmodel = EPHY_TREE_MODEL_SORT ( ephy_tree_model_sort_new (GTK_TREE_MODEL (dialog->priv->filtermodel))); + ephy_tree_model_sort_set_drag_property + (dialog->priv->sortmodel, EPHY_NODE_PAGE_PROP_TITLE); + g_signal_connect_object (G_OBJECT (dialog->priv->sortmodel), "node_from_iter", G_CALLBACK (node_from_sort_iter_cb), diff --git a/src/toolbar.c b/src/toolbar.c index f8ecf0316..76e992e7f 100755 --- a/src/toolbar.c +++ b/src/toolbar.c @@ -27,6 +27,7 @@ #include "ephy-spinner-action.h" #include "ephy-location-action.h" #include "ephy-favicon-action.h" +#include "ephy-topic-action.h" #include "ephy-go-action.h" #include "ephy-navigation-action.h" #include "ephy-bookmark-action.h" @@ -132,27 +133,30 @@ get_bookmark_action (Toolbar *t, EphyBookmarks *bookmarks, gulong id, const char return action; } -static EggAction * -toolbar_get_action (EphyEditableToolbar *etoolbar, - const char *type, - const char *name) +static char * +toolbar_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data) { Toolbar *t = TOOLBAR (etoolbar); - EggAction *action = NULL; EphyBookmarks *bookmarks; gulong id = 0; - char action_name[255]; + char *res = NULL; bookmarks = ephy_shell_get_bookmarks (ephy_shell); - if (type && (strcmp (type, EPHY_DND_URL_TYPE) == 0)) + if (drag_type && (strcmp (drag_type, EPHY_DND_TOPIC_TYPE) == 0)) + { + res = g_strdup_printf ("GoTopicId%s", data); + } + else if (drag_type && (strcmp (drag_type, EPHY_DND_URL_TYPE) == 0)) { GtkWidget *new_bookmark; const char *url; const char *title = NULL; GList *uris; - uris = ephy_dnd_uri_list_extract_uris (name); + uris = ephy_dnd_uri_list_extract_uris ((char *)data); g_return_val_if_fail (uris != NULL, NULL); url = (const char *)uris->data; if (uris->next) @@ -176,29 +180,59 @@ toolbar_get_action (EphyEditableToolbar *etoolbar, g_list_foreach (uris, (GFunc)g_free, NULL); g_list_free (uris); + + if (id != 0) + { + res = g_strdup_printf ("GoBookmarkId%ld", id); + } + else + { + res = NULL; + } + } + + return res; +} + +static EggAction * +toolbar_get_action (EphyEditableToolbar *etoolbar, + const char *name) +{ + Toolbar *t = TOOLBAR (etoolbar); + EggAction *action = NULL; + gulong id = 0; + EphyBookmarks *bookmarks; + + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + + action = EPHY_EDITABLE_TOOLBAR_CLASS + (parent_class)->get_action (etoolbar, name); + if (action) + { + return action; } else if (g_str_has_prefix (name, "GoBookmarkId")) { if (!ephy_str_to_int (name + strlen ("GoBookmarkId"), &id)) { - id = 0; + return NULL; } - } - if (id != 0) + action = get_bookmark_action (t, bookmarks, id, name); + } + else if (g_str_has_prefix (name, "GoTopicId")) { - snprintf (action_name, 255, "GoBookmarkId%ld", id); - action = EPHY_EDITABLE_TOOLBAR_CLASS - (parent_class)->get_action (etoolbar, NULL, action_name); - if (action == NULL) + if (!ephy_str_to_int (name + strlen ("GoTopicId"), &id)) { - action = get_bookmark_action (t, bookmarks, id, action_name); + return NULL; } - } - else - { - action = EPHY_EDITABLE_TOOLBAR_CLASS - (parent_class)->get_action (etoolbar, type, name); + + action = ephy_topic_action_new (name, id); + g_signal_connect (action, "go_location", + G_CALLBACK (go_location_cb), + t->priv->window); + egg_action_group_add_action (t->priv->action_group, action); + g_object_unref (action); } return action; @@ -218,6 +252,7 @@ toolbar_class_init (ToolbarClass *klass) object_class->get_property = toolbar_get_property; eet_class->get_action = toolbar_get_action; + eet_class->get_action_name = toolbar_get_action_name; g_object_class_install_property (object_class, PROP_EPHY_WINDOW, |