diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-07-27 21:10:56 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-07-27 21:10:56 +0800 |
commit | d1f38adb951f506e11864f0784f325a940a3d232 (patch) | |
tree | d58f9243e7c3926ac2840edb05797fbbe75e1de6 /lib | |
parent | e9f8e15bf4f624f566eb0ea66e47be67098d5dc2 (diff) | |
download | gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.gz gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.bz2 gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.lz gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.xz gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.zst gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.zip |
2003-07-27 Marco Pesenti Gritti <marco@it.gnome.org>
* data/ui/epiphany-toolbar.xml.in:
* lib/egg/egg-editable-toolbar.c: (drag_data_received_cb):
* lib/egg/egg-editable-toolbar.h:
* lib/egg/egg-toolbar-editor.c: (parse_item_list):
* lib/egg/egg-toolbars-model.c: (egg_toolbars_model_to_xml),
(safe_save_xml), (egg_toolbars_model_save), (toolbars_item_new),
(free_item_node), (egg_toolbars_model_add_separator),
(egg_toolbars_model_add_item), (parse_item_list),
(impl_get_item_id), (impl_get_item_name), (impl_get_item_type),
(egg_toolbars_model_class_init), (egg_toolbars_model_item_nth),
(egg_toolbars_model_toolbar_nth), (egg_toolbars_model_get_item_id),
(egg_toolbars_model_get_item_name),
(egg_toolbars_model_get_item_type):
* lib/egg/egg-toolbars-model.h:
* lib/egg/eggtoolbar.c: (egg_toolbar_finalize):
* lib/ephy-dnd.c: (add_one_topic), (ephy_dnd_drag_data_get):
* lib/ephy-dnd.h:
* lib/widgets/ephy-node-view.c: (drag_data_received_cb),
(ephy_node_view_select_node_by_key), (ephy_node_view_construct),
(ephy_node_view_add_data_column),
(ephy_node_view_enable_drag_source):
* lib/widgets/ephy-node-view.h:
* lib/widgets/ephy-tree-model-sort.c:
(ephy_tree_model_sort_class_init), (ephy_tree_model_sort_init),
(ephy_tree_model_sort_multi_row_draggable),
(ephy_tree_model_sort_set_column_id),
(each_property_get_data_binder),
(ephy_tree_model_sort_multi_drag_data_get):
* lib/widgets/ephy-tree-model-sort.h:
* src/bookmarks/ephy-bookmark-properties.c:
(toolbar_checkbox_changed_cb), (build_ui):
* src/bookmarks/ephy-bookmarks-editor.c:
(cmd_show_in_bookmarks_bar), (ephy_bookmarks_editor_update_menu),
(node_dropped_cb), (provide_keyword_uri),
(ephy_bookmarks_editor_construct):
* src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init_defaults),
(ephy_bookmarks_remove_keyword), (ephy_bookmarks_get_topic_uri),
(ephy_bookmarks_find_keyword):
* src/bookmarks/ephy-bookmarks.h:
* src/ephy-history-window.c: (ephy_history_window_construct):
* src/ephy-toolbars-model.c: (ephy_toolbars_model_get_action_name),
(ephy_toolbars_model_get_node), (bookmark_destroy_cb),
(impl_get_item_name), (impl_get_item_id), (impl_get_item_type),
(connect_item), (ephy_toolbars_model_set_bookmarks),
(ephy_toolbars_model_class_init), (save_changes), (item_added),
(item_removed), (toolbar_added), (toolbar_removed),
(ephy_toolbars_model_init), (ephy_toolbars_model_finalize),
(ephy_toolbars_model_remove_bookmark),
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/egg/egg-editable-toolbar.c | 10 | ||||
-rwxr-xr-x | lib/egg/egg-editable-toolbar.h | 2 | ||||
-rwxr-xr-x | lib/egg/egg-toolbar-editor.c | 8 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.c | 210 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.h | 35 | ||||
-rw-r--r-- | lib/egg/eggtoolbar.c | 1 | ||||
-rw-r--r-- | lib/ephy-dnd.c | 45 | ||||
-rw-r--r-- | lib/ephy-dnd.h | 3 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.c | 66 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.h | 8 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-sort.c | 148 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-sort.h | 4 |
12 files changed, 282 insertions, 258 deletions
diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index 81a7c1a58..2fc401cde 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -180,11 +180,17 @@ drag_data_received_cb (GtkWidget *widget, else { GdkAtom target; + char *type; + char *id; target = gtk_drag_dest_find_target (widget, context, NULL); + type = egg_toolbars_model_get_item_type (etoolbar->priv->model, target); + id = egg_toolbars_model_get_item_id (etoolbar->priv->model, type, + selection_data->data); egg_toolbars_model_add_item (etoolbar->priv->model, - toolbar_pos, pos, target, - selection_data->data); + toolbar_pos, pos, id, type); + g_free (type); + g_free (id); } } diff --git a/lib/egg/egg-editable-toolbar.h b/lib/egg/egg-editable-toolbar.h index 28b9976a2..6460d724a 100755 --- a/lib/egg/egg-editable-toolbar.h +++ b/lib/egg/egg-editable-toolbar.h @@ -39,8 +39,6 @@ typedef struct EggEditableToolbarClass EggEditableToolbarClass; typedef struct EggEditableToolbar EggEditableToolbar; typedef struct EggEditableToolbarPrivate EggEditableToolbarPrivate; -#define EGG_TOOLBAR_ITEM_TYPE "application/x-toolbar-item" - struct EggEditableToolbar { GtkVBox parent_object; diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c index a373b520c..2813d992b 100755 --- a/lib/egg/egg-toolbar-editor.c +++ b/lib/egg/egg-toolbar-editor.c @@ -494,11 +494,11 @@ parse_item_list (EggToolbarEditor *t, { if (xmlStrEqual (child->name, "toolitem")) { - xmlChar *verb; + xmlChar *name; - verb = xmlGetProp (child, "verb"); - egg_toolbar_editor_add_action (t, verb); - xmlFree (verb); + name = xmlGetProp (child, "name"); + egg_toolbar_editor_add_action (t, name); + xmlFree (name); } child = child->next; } diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c index 8d8829dcf..e030bd29d 100755 --- a/lib/egg/egg-toolbars-model.c +++ b/lib/egg/egg-toolbars-model.c @@ -21,6 +21,7 @@ #include <string.h> #include <libxml/tree.h> +#include <gdk/gdkproperty.h> static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass); static void egg_toolbars_model_init (EggToolbarsModel *t); @@ -44,7 +45,8 @@ typedef struct typedef struct { - char *action_name; + char *id; + char *type; gboolean separator; } EggToolbarsItem; @@ -118,8 +120,12 @@ egg_toolbars_model_to_xml (EggToolbarsModel *t) } else { + char *name; + node = xmlNewChild (tnode, NULL, "toolitem", NULL); - xmlSetProp (node, "verb", item->action_name); + name = egg_toolbars_model_get_item_name (t, item->type, item->id); + xmlSetProp (node, "type", item->type); + xmlSetProp (node, "name", name); } } } @@ -127,16 +133,76 @@ egg_toolbars_model_to_xml (EggToolbarsModel *t) return doc; } +gboolean +safe_save_xml (const char *xml_file, xmlDocPtr doc) +{ + char *tmp_file; + char *old_file; + gboolean old_exist; + gboolean retval = TRUE; + + tmp_file = g_strconcat (xml_file, ".tmp", NULL); + old_file = g_strconcat (xml_file, ".old", NULL); + + if (!xmlSaveFormatFile (tmp_file, doc, 1)) + { + g_warning ("Failed to write XML data to %s", tmp_file); + goto failed; + } + + old_exist = g_file_test (xml_file, G_FILE_TEST_EXISTS); + + if (old_exist) + { + if (rename (xml_file, old_file) < 0) + { + g_warning ("Failed to rename %s to %s", xml_file, old_file); + retval = FALSE; + goto failed; + } + } + + if (rename (tmp_file, xml_file) < 0) + { + g_warning ("Failed to rename %s to %s", tmp_file, xml_file); + + if (rename (old_file, xml_file) < 0) + { + g_warning ("Failed to restore %s from %s", xml_file, tmp_file); + } + retval = FALSE; + goto failed; + } + + if (old_exist) + { + if (unlink (old_file) < 0) + { + g_warning ("Failed to delete old file %s", old_file); + } + } + + failed: + g_free (old_file); + g_free (tmp_file); + + return retval; +} + void egg_toolbars_model_save (EggToolbarsModel *t, - const char *xml_file) + const char *xml_file, + const char *version) { xmlDocPtr doc; + xmlNodePtr root; g_return_if_fail (IS_EGG_TOOLBARS_MODEL (t)); doc = egg_toolbars_model_to_xml (t); - xmlSaveFormatFile (xml_file, doc, 1); + root = xmlDocGetRootElement (doc); + xmlSetProp (root, "version", version); + safe_save_xml (xml_file, doc); xmlFreeDoc (doc); } @@ -153,15 +219,18 @@ toolbars_toolbar_new (const char *name) } static EggToolbarsItem * -toolbars_item_new (const char *action, +toolbars_item_new (const char *id, + const char *type, gboolean separator) { EggToolbarsItem *item; - g_return_val_if_fail (action != NULL, NULL); + g_return_val_if_fail (id != NULL, NULL); + g_return_val_if_fail (type != NULL, NULL); item = g_new0 (EggToolbarsItem, 1); - item->action_name = g_strdup (action); + item->id = g_strdup (id); + item->type = g_strdup (type); item->separator = separator; return item; @@ -181,7 +250,8 @@ free_item_node (EggToolbarsItem *item) { g_return_if_fail (item != NULL); - g_free (item->action_name); + g_free (item->id); + g_free (item->type); g_free (item); } @@ -227,46 +297,39 @@ egg_toolbars_model_add_separator (EggToolbarsModel *t, GNode *parent_node; GNode *node; EggToolbarsItem *item; + int real_position; g_return_if_fail (IS_EGG_TOOLBARS_MODEL (t)); parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position); - item = toolbars_item_new ("separator", TRUE); + item = toolbars_item_new ("separator", "separator", TRUE); node = g_node_new (item); g_node_insert (parent_node, position, node); + real_position = g_node_child_position (parent_node, node); + g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0, - toolbar_position, position); + toolbar_position, real_position); } -const char * +void egg_toolbars_model_add_item (EggToolbarsModel *t, int toolbar_position, int position, - GdkAtom type, - const char *name) -{ - EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); - return klass->add_item (t, toolbar_position, position, type, name); -} - -const char * -impl_add_item (EggToolbarsModel *t, - int toolbar_position, - int position, - GdkAtom type, - const char *name) + const char *id, + const char *type) { GNode *parent_node; GNode *node; EggToolbarsItem *item; int real_position; - g_return_val_if_fail (IS_EGG_TOOLBARS_MODEL (t), NULL); - g_return_val_if_fail (name != NULL, NULL); + g_return_if_fail (IS_EGG_TOOLBARS_MODEL (t)); + g_return_if_fail (id != NULL); + g_return_if_fail (type != NULL); parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position); - item = toolbars_item_new (name, FALSE); + item = toolbars_item_new (id, type, FALSE); node = g_node_new (item); g_node_insert (parent_node, position, node); @@ -274,8 +337,6 @@ impl_add_item (EggToolbarsModel *t, g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0, toolbar_position, real_position); - - return item->action_name; } static void @@ -287,11 +348,24 @@ parse_item_list (EggToolbarsModel *t, { if (xmlStrEqual (child->name, "toolitem")) { - xmlChar *verb; + xmlChar *name, *type; + char *id; - verb = xmlGetProp (child, "verb"); - egg_toolbars_model_add_item (t, position, -1, NULL, verb); - xmlFree (verb); + name = xmlGetProp (child, "name"); + type = xmlGetProp (child, "type"); + if (type == NULL) + { + type = g_strdup (EGG_TOOLBAR_ITEM_TYPE); + } + + id = egg_toolbars_model_get_item_id (t, type, name); + if (id != NULL) + { + egg_toolbars_model_add_item (t, position, -1, id, type); + } + xmlFree (name); + g_free (type); + g_free (id); } else if (xmlStrEqual (child->name, "separator")) { @@ -363,6 +437,44 @@ egg_toolbars_model_load (EggToolbarsModel *t, xmlFreeDoc (doc); } +char * +impl_get_item_id (EggToolbarsModel *t, + const char *type, + const char *name) +{ + if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) + { + return g_strdup (name); + } + + return NULL; +} + +char * +impl_get_item_name (EggToolbarsModel *t, + const char *type, + const char *id) +{ + if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) + { + return g_strdup (id); + } + + return NULL; +} + +char * +impl_get_item_type (EggToolbarsModel *t, + GdkAtom type) +{ + if (gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE) == type) + { + return g_strdup (EGG_TOOLBAR_ITEM_TYPE); + } + + return NULL; +} + static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass) { @@ -372,7 +484,9 @@ egg_toolbars_model_class_init (EggToolbarsModelClass *klass) object_class->finalize = egg_toolbars_model_finalize; - klass->add_item = impl_add_item; + klass->get_item_id = impl_get_item_id; + klass->get_item_name = impl_get_item_name; + klass->get_item_type = impl_get_item_type; egg_toolbars_model_signals[ITEM_ADDED] = g_signal_new ("item_added", @@ -525,7 +639,7 @@ egg_toolbars_model_item_nth (EggToolbarsModel *t, *is_separator = idata->separator; - return idata->action_name; + return idata->id; } int @@ -548,3 +662,29 @@ egg_toolbars_model_toolbar_nth (EggToolbarsModel *t, return tdata->name; } + +char * +egg_toolbars_model_get_item_id (EggToolbarsModel *t, + const char *type, + const char *name) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); + return klass->get_item_id (t, type, name); +} + +char * +egg_toolbars_model_get_item_name (EggToolbarsModel *t, + const char *type, + const char *id) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); + return klass->get_item_name (t, type, id); +} + +char * +egg_toolbars_model_get_item_type (EggToolbarsModel *t, + GdkAtom type) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); + return klass->get_item_type (t, type); +} diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h index 5d79787b9..5de72fbcb 100755 --- a/lib/egg/egg-toolbars-model.h +++ b/lib/egg/egg-toolbars-model.h @@ -21,7 +21,7 @@ #include <glib.h> #include <glib-object.h> -#include "gdk/gdktypes.h" +#include <gdk/gdktypes.h> G_BEGIN_DECLS @@ -37,6 +37,8 @@ typedef struct EggToolbarsModelClass EggToolbarsModelClass; typedef struct EggToolbarsModel EggToolbarsModel; typedef struct EggToolbarsModelPrivate EggToolbarsModelPrivate; +#define EGG_TOOLBAR_ITEM_TYPE "application/x-toolbar-item" + typedef enum { EGG_TB_MODEL_NOT_REMOVABLE = 1, @@ -68,12 +70,14 @@ struct EggToolbarsModelClass int position); /* Virtual Table */ - const char * (* add_item) (EggToolbarsModel *t, - int toolbar_position, - int position, - GdkAtom type, - const char *item_name); - + char * (* get_item_type) (EggToolbarsModel *t, + GdkAtom dnd_type); + char * (* get_item_id) (EggToolbarsModel *t, + const char *type, + const char *name); + char * (* get_item_name) (EggToolbarsModel *t, + const char *type, + const char *id); }; GType egg_toolbars_model_get_type (void); @@ -81,7 +85,8 @@ EggToolbarsModel *egg_toolbars_model_new (void); void egg_toolbars_model_load (EggToolbarsModel *t, const char *xml_file); void egg_toolbars_model_save (EggToolbarsModel *t, - const char *xml_file); + const char *xml_file, + const char *version); int egg_toolbars_model_add_toolbar (EggToolbarsModel *t, int position, const char *name); @@ -93,11 +98,19 @@ void egg_toolbars_model_set_flags (EggToolbarsModel *t, void egg_toolbars_model_add_separator (EggToolbarsModel *t, int toolbar_position, int position); -const char *egg_toolbars_model_add_item (EggToolbarsModel *t, +char *egg_toolbars_model_get_item_type (EggToolbarsModel *t, + GdkAtom dnd_type); +char *egg_toolbars_model_get_item_id (EggToolbarsModel *t, + const char *type, + const char *name); +char *egg_toolbars_model_get_item_name (EggToolbarsModel *t, + const char *type, + const char *id); +void egg_toolbars_model_add_item (EggToolbarsModel *t, int toolbar_position, int position, - GdkAtom type, - const char *item_name); + const char *id, + const char *type); void egg_toolbars_model_remove_toolbar (EggToolbarsModel *t, int position); void egg_toolbars_model_remove_item (EggToolbarsModel *t, diff --git a/lib/egg/eggtoolbar.c b/lib/egg/eggtoolbar.c index bae64f324..547f0e33c 100644 --- a/lib/egg/eggtoolbar.c +++ b/lib/egg/eggtoolbar.c @@ -494,7 +494,6 @@ static void egg_toolbar_finalize (GObject *object) { EggToolbar *toolbar = EGG_TOOLBAR (object); - GList *list; if (toolbar->tooltips) g_object_unref (GTK_OBJECT (toolbar->tooltips)); diff --git a/lib/ephy-dnd.c b/lib/ephy-dnd.c index 4bf9cd2cd..a9e4b0c33 100644 --- a/lib/ephy-dnd.c +++ b/lib/ephy-dnd.c @@ -53,14 +53,14 @@ add_one_uri (const char *uri, int x, int y, int w, int h, gpointer data) } static void -add_one_node (const char *uri, int x, int y, int w, int h, gpointer data) +add_one_topic (const char *uri, int x, int y, int w, int h, gpointer data) { GString *result; result = (GString *) data; g_string_append (result, uri); - g_string_append (result, ";"); + g_string_append (result, "\r\n"); } gboolean @@ -87,12 +87,11 @@ ephy_dnd_drag_data_get (GtkWidget *widget, result = g_string_new (NULL); (* each_selected_item_iterator) (add_one_netscape_url, container_context, result); } - else if (target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) || - target == gdk_atom_intern (EPHY_DND_BOOKMARK_TYPE, FALSE)) + else if (target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE)) { result = g_string_new (NULL); - (* each_selected_item_iterator) (add_one_node, container_context, result); - g_string_erase (result, result->len - 1, -1); + (* each_selected_item_iterator) (add_one_topic, container_context, result); + g_string_erase (result, result->len - 2, -1); } else { @@ -107,37 +106,3 @@ ephy_dnd_drag_data_get (GtkWidget *widget, return TRUE; } - -GList * -ephy_dnd_node_list_extract_nodes (const char *node_list) -{ - GList *result = NULL; - char **nodes; - int i; - - nodes = g_strsplit (node_list, ";", -1); - - for (i = 0; nodes[i] != NULL && nodes[i+1] != NULL; i = i + 2) - { - gulong id; - EphyNodeDb *db; - - db = ephy_node_db_get_by_name (nodes[i]); - g_return_val_if_fail (db != NULL, NULL); - - if (ephy_string_to_int (nodes[i + 1], &id)) - { - EphyNode *node; - - node = ephy_node_db_get_node_from_id (db, id); - g_return_val_if_fail (node != NULL, NULL); - result = g_list_prepend (result, node); - } - } - - result = g_list_reverse (result); - - g_strfreev (nodes); - - return result; -} diff --git a/lib/ephy-dnd.h b/lib/ephy-dnd.h index e708654f5..8f6a16a51 100644 --- a/lib/ephy-dnd.h +++ b/lib/ephy-dnd.h @@ -30,7 +30,6 @@ G_BEGIN_DECLS #define EPHY_DND_TEXT_TYPE "text/plain" #define EPHY_DND_URL_TYPE "_NETSCAPE_URL" #define EPHY_DND_TOPIC_TYPE "ephy_topic_node" -#define EPHY_DND_BOOKMARK_TYPE "ephy_bookmark_node" typedef void (* EphyDragEachSelectedItemDataGet) (const char *url, int x, int y, int w, int h, @@ -47,8 +46,6 @@ gboolean ephy_dnd_drag_data_get (GtkWidget *widget, gpointer container_context, EphyDragEachSelectedItemIterator each_selected_item_iterator); -GList *ephy_dnd_node_list_extract_nodes (const char *node_list); - G_END_DECLS #endif diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c index 86eb48f49..0a83d0744 100644 --- a/lib/widgets/ephy-node-view.c +++ b/lib/widgets/ephy-node-view.c @@ -24,6 +24,7 @@ #include <gtk/gtkcellrendererpixbuf.h> #include <gtk/gtkwindow.h> #include <gdk/gdkkeysyms.h> +#include <libgnomevfs/gnome-vfs-uri.h> #include "eggtreemodelfilter.h" #include "ephy-node-view.h" @@ -306,18 +307,15 @@ drag_data_received_cb (GtkWidget *widget, x, y, &path, &pos)) { EphyNode *node; - GList *src_nodes; + GList *uris; node = get_node_from_path (view, path); - src_nodes = ephy_dnd_node_list_extract_nodes - (selection_data->data); - + uris = gnome_vfs_uri_list_parse (selection_data->data); g_signal_emit (G_OBJECT (view), ephy_node_view_signals[NODE_DROPPED], 0, - node, src_nodes); - - g_list_free (src_nodes); + node, uris); + gnome_vfs_uri_list_free (uris); gtk_tree_path_free (path); } @@ -426,7 +424,7 @@ ephy_node_view_select_node_by_key (EphyNodeView *view, GdkEventKey *event) gboolean found = FALSE; gchar outbuf[6]; gint length; - + length = g_unichar_to_utf8 (gdk_keyval_to_unicode (event->keyval), outbuf); event_string = g_utf8_casefold (outbuf, length); @@ -456,7 +454,7 @@ ephy_node_view_select_node_by_key (EphyNodeView *view, GdkEventKey *event) { iter = last_iter; } - + path = gtk_tree_model_get_path (view->priv->sortmodel, &iter); gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE); gtk_tree_path_free (path); @@ -573,22 +571,6 @@ ephy_node_view_get_property (GObject *object, } static void -node_from_sort_iter_cb (EphyTreeModelSort *model, - GtkTreeIter *iter, - void **node, - EphyNodeView *view) -{ - GtkTreeIter filter_iter, node_iter; - - gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model), - &filter_iter, iter); - egg_tree_model_filter_convert_iter_to_child_iter (EGG_TREE_MODEL_FILTER (view->priv->filtermodel), - &node_iter, &filter_iter); - *node = ephy_tree_model_node_node_from_iter - (EPHY_TREE_MODEL_NODE (view->priv->nodemodel), &node_iter); -} - -static void ephy_node_view_construct (EphyNodeView *view) { GtkTreeSelection *selection; @@ -600,11 +582,6 @@ ephy_node_view_construct (EphyNodeView *view) egg_tree_model_filter_set_visible_column (EGG_TREE_MODEL_FILTER (view->priv->filtermodel), EPHY_TREE_MODEL_NODE_COL_VISIBLE); view->priv->sortmodel = ephy_tree_model_sort_new (view->priv->filtermodel); - g_signal_connect_object (G_OBJECT (view->priv->sortmodel), - "node_from_iter", - G_CALLBACK (node_from_sort_iter_cb), - view, - 0); gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (view->priv->sortmodel)); g_signal_connect_object (G_OBJECT (view), "button_press_event", @@ -779,6 +756,29 @@ provide_text_weight (EphyNode *node, GValue *value, EphyNodeView *view) } } +int +ephy_node_view_add_data_column (EphyNodeView *view, + GType value_type, + int prop_id, + EphyTreeModelNodeValueFunc func, + gpointer data) +{ + int column; + + if (func) + { + column = ephy_tree_model_node_add_func_column + (view->priv->nodemodel, value_type, func, data); + } + else + { + column = ephy_tree_model_node_add_prop_column + (view->priv->nodemodel, value_type, prop_id); + } + + return column; +} + GtkTreeViewColumn * ephy_node_view_add_column (EphyNodeView *view, const char *title, @@ -1040,7 +1040,7 @@ void ephy_node_view_enable_drag_source (EphyNodeView *view, GtkTargetEntry *types, int n_types, - guint prop_id) + int column) { GtkWidget *treeview; @@ -1055,8 +1055,8 @@ ephy_node_view_enable_drag_source (EphyNodeView *view, types, n_types, GDK_ACTION_COPY); - ephy_tree_model_sort_set_drag_property (EPHY_TREE_MODEL_SORT (view->priv->sortmodel), - prop_id); + ephy_tree_model_sort_set_column_id (EPHY_TREE_MODEL_SORT (view->priv->sortmodel), + column); } void diff --git a/lib/widgets/ephy-node-view.h b/lib/widgets/ephy-node-view.h index 1ccc6cda4..55fab714a 100644 --- a/lib/widgets/ephy-node-view.h +++ b/lib/widgets/ephy-node-view.h @@ -85,6 +85,12 @@ GtkTreeViewColumn *ephy_node_view_add_column (EphyNodeView *view, EphyNodeViewFlags flags, EphyTreeModelNodeValueFunc icon_func); +int ephy_node_view_add_data_column (EphyNodeView *view, + GType value_type, + int prop_id, + EphyTreeModelNodeValueFunc func, + gpointer data); + void ephy_node_view_remove (EphyNodeView *view); gboolean ephy_node_view_has_selection (EphyNodeView *view, @@ -98,7 +104,7 @@ void ephy_node_view_select_node (EphyNodeView *view, void ephy_node_view_enable_drag_source (EphyNodeView *view, GtkTargetEntry *types, int n_types, - guint prop_id); + int column_id); void ephy_node_view_enable_drag_dest (EphyNodeView *view, GtkTargetEntry *types, diff --git a/lib/widgets/ephy-tree-model-sort.c b/lib/widgets/ephy-tree-model-sort.c index d3b425325..14096989b 100644 --- a/lib/widgets/ephy-tree-model-sort.c +++ b/lib/widgets/ephy-tree-model-sort.c @@ -44,19 +44,11 @@ static gboolean ephy_tree_model_sort_multi_drag_data_delete (EggTreeMultiDragSou struct EphyTreeModelSortPrivate { char *str_list; - guint drag_property_id; -}; - -enum -{ - NODE_FROM_ITER, - LAST_SIGNAL + int drag_column_id; }; static GObjectClass *parent_class = NULL; -static guint ephy_tree_model_sort_signals[LAST_SIGNAL] = { 0 }; - GType ephy_tree_model_sort_get_type (void) { @@ -103,18 +95,6 @@ ephy_tree_model_sort_class_init (EphyTreeModelSortClass *klass) parent_class = g_type_class_peek_parent (klass); object_class->finalize = ephy_tree_model_sort_finalize; - - ephy_tree_model_sort_signals[NODE_FROM_ITER] = - g_signal_new ("node_from_iter", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EphyTreeModelSortClass, node_from_iter), - NULL, NULL, - ephy_marshal_VOID__POINTER_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_POINTER, - G_TYPE_POINTER); } static void @@ -122,7 +102,7 @@ ephy_tree_model_sort_init (EphyTreeModelSort *ma) { ma->priv = g_new0 (EphyTreeModelSortPrivate, 1); - ma->priv->drag_property_id = -1; + ma->priv->drag_column_id = -1; } static void @@ -166,36 +146,14 @@ ephy_tree_model_sort_multi_drag_source_init (EggTreeMultiDragSourceIface *iface) static gboolean ephy_tree_model_sort_multi_row_draggable (EggTreeMultiDragSource *drag_source, GList *path_list) { - GList *l; - - for (l = path_list; l != NULL; l = g_list_next (l)) - { - GtkTreeIter iter; - GtkTreePath *path; - EphyNode *node = NULL; - - path = gtk_tree_row_reference_get_path (l->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); - - gtk_tree_path_free (path); - - if (node == NULL) - { - return FALSE; - } - } - - return TRUE; + return (EPHY_TREE_MODEL_SORT (drag_source)->priv->drag_column_id > 0); } void -ephy_tree_model_sort_set_drag_property (EphyTreeModelSort *ms, - guint id) +ephy_tree_model_sort_set_column_id (EphyTreeModelSort *ms, + int id) { - ms->priv->drag_property_id = id; + ms->priv->drag_column_id = id; } static gboolean @@ -206,75 +164,36 @@ ephy_tree_model_sort_multi_drag_data_delete (EggTreeMultiDragSource *drag_source } static void -each_url_get_data_binder (EphyDragEachSelectedItemDataGet iteratee, - gpointer iterator_context, gpointer data) +each_property_get_data_binder (EphyDragEachSelectedItemDataGet iteratee, + gpointer iterator_context, gpointer data) { gpointer *context = (gpointer *) iterator_context; GList *path_list = (GList *) (context[0]); GList *i; - GtkTreeModel *model = GTK_TREE_MODEL (context[1]); + EphyTreeModelSort *model = EPHY_TREE_MODEL_SORT (context[1]); + GValue value = {0, }; for (i = path_list; i != NULL; i = i->next) { GtkTreeIter iter; GtkTreePath *path = NULL; - EphyNode *node = NULL; - const char *value; + const char *svalue; path = gtk_tree_row_reference_get_path (i->data); - gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path); - g_signal_emit (G_OBJECT (model), - ephy_tree_model_sort_signals[NODE_FROM_ITER], - 0, &iter, &node); + gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter, + model->priv->drag_column_id, + &value); + svalue = g_value_get_string (&value); - gtk_tree_path_free (path); - - if (node == NULL) - return; - - 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); - } -} + g_return_if_fail (svalue != NULL); -static void -each_node_get_data_binder (EphyDragEachSelectedItemDataGet iteratee, - gpointer iterator_context, gpointer data) -{ - gpointer *context = (gpointer *) iterator_context; - GList *path_list = (GList *) (context[0]); - GList *i; - GtkTreeModel *model = GTK_TREE_MODEL (context[1]); + LOG ("Data get %s", svalue) - for (i = path_list; i != NULL; i = i->next) - { - GtkTreeIter iter; - GtkTreePath *path = NULL; - EphyNode *node = NULL; - EphyNodeDb *db; - char *value; + iteratee (svalue, -1, -1, -1, -1, data); - path = gtk_tree_row_reference_get_path (i->data); - gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path); - g_signal_emit (G_OBJECT (model), - ephy_tree_model_sort_signals[NODE_FROM_ITER], - 0, &iter, &node); gtk_tree_path_free (path); - - if (node == NULL) - return; - - db = ephy_node_get_db (node); - value = g_strdup_printf ("%s;%ld", - ephy_node_db_get_name (db), - ephy_node_get_id (node)); - iteratee (value, -1, -1, -1, -1, data); - g_free (value); + g_value_unset (&value); } } @@ -283,32 +202,13 @@ ephy_tree_model_sort_multi_drag_data_get (EggTreeMultiDragSource *drag_source, GList *path_list, GtkSelectionData *selection_data) { - GdkAtom target; - - target = selection_data->target; - - if (target == gdk_atom_intern (EPHY_DND_BOOKMARK_TYPE, FALSE) || - target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE)) - { - gpointer icontext[2]; - - icontext[0] = path_list; - icontext[1] = drag_source; + gpointer icontext[2]; - ephy_dnd_drag_data_get (NULL, NULL, selection_data, - 0, &icontext, each_node_get_data_binder); + icontext[0] = path_list; + icontext[1] = drag_source; - } - else - { - gpointer icontext[2]; - - icontext[0] = path_list; - icontext[1] = drag_source; - - ephy_dnd_drag_data_get (NULL, NULL, selection_data, - 0, &icontext, each_url_get_data_binder); - } + ephy_dnd_drag_data_get (NULL, NULL, selection_data, + 0, &icontext, each_property_get_data_binder); return TRUE; } diff --git a/lib/widgets/ephy-tree-model-sort.h b/lib/widgets/ephy-tree-model-sort.h index 2b8b38be9..abe21ddbb 100644 --- a/lib/widgets/ephy-tree-model-sort.h +++ b/lib/widgets/ephy-tree-model-sort.h @@ -53,8 +53,8 @@ GType ephy_tree_model_sort_get_type (void); GtkTreeModel *ephy_tree_model_sort_new (GtkTreeModel *child_model); -void ephy_tree_model_sort_set_drag_property (EphyTreeModelSort *ms, - guint id); +void ephy_tree_model_sort_set_column_id (EphyTreeModelSort *ms, + int id); G_END_DECLS |