r3916: Selecting an entry from the bookmarks menu can open a new window
[rox-filer/dt.git] / ROX-Filer / src / bookmarks.c
blobe29e834d7e2887e066d19a50c7744b66ee096f2a
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* bookmarks.c - handles the bookmarks menu */
24 #include "config.h"
26 #include <stdlib.h>
27 #include <gtk/gtk.h>
28 #include <string.h>
30 #include "global.h"
32 #include "bookmarks.h"
33 #include "choices.h"
34 #include "filer.h"
35 #include "xml.h"
36 #include "support.h"
37 #include "gui_support.h"
38 #include "main.h"
39 #include "mount.h"
40 #include "action.h"
41 #include "options.h"
42 #include "bind.h"
44 static GList *history = NULL; /* Most recent first */
45 static GList *history_tail = NULL; /* Oldest item */
46 static GHashTable *history_hash = NULL; /* Path -> GList link */
47 static gint history_free = 30; /* Space left in history */
49 static XMLwrapper *bookmarks = NULL;
50 static GtkWidget *bookmarks_window = NULL;
52 /* Static prototypes */
53 static void update_bookmarks(void);
54 static xmlNode *bookmark_find(const gchar *mark);
55 static void bookmarks_save(void);
56 static void bookmarks_add(GtkMenuItem *menuitem, gpointer user_data);
57 static void bookmarks_activate(GtkMenuShell *item, FilerWindow *filer_window);
58 static GtkWidget *bookmarks_build_menu(FilerWindow *filer_window);
59 static void position_menu(GtkMenu *menu, gint *x, gint *y,
60 gboolean *push_in, gpointer data);
61 static void cell_edited(GtkCellRendererText *cell,
62 const gchar *path_string,
63 const gchar *new_text,
64 gpointer data);
65 static void reorder_up(GtkButton *button, GtkTreeView *view);
66 static void reorder_down(GtkButton *button, GtkTreeView *view);
67 static void edit_response(GtkWidget *window, gint response,
68 GtkTreeModel *model);
69 static void edit_delete(GtkButton *button, GtkTreeView *view);
70 static gboolean dir_dropped(GtkWidget *window, GdkDragContext *context,
71 int x, int y,
72 GtkSelectionData *selection_data, guint info,
73 guint time, GtkTreeView *view);
74 static void bookmarks_add_dir(const guchar *dir);
75 static void commit_edits(GtkTreeModel *model);
78 /****************************************************************
79 * EXTERNAL INTERFACE *
80 ****************************************************************/
82 /* Shows the bookmarks menu */
83 void bookmarks_show_menu(FilerWindow *filer_window)
85 GdkEvent *event;
86 GtkMenu *menu;
87 int button = 0;
89 event = gtk_get_current_event();
90 if (event->type == GDK_BUTTON_RELEASE ||
91 event->type == GDK_BUTTON_PRESS)
92 button = ((GdkEventButton *) event)->button;
94 menu = GTK_MENU(bookmarks_build_menu(filer_window));
95 gtk_menu_popup(menu, NULL, NULL, position_menu, filer_window,
96 button, gtk_get_current_event_time());
99 /* Show the Edit Bookmarks dialog */
100 void bookmarks_edit(void)
102 GtkListStore *model;
103 GtkWidget *list, *hbox, *button, *swin;
104 GtkTreeSelection *selection;
105 GtkCellRenderer *cell;
106 xmlNode *node;
107 GtkTreeIter iter;
109 if (bookmarks_window)
111 gtk_window_present(GTK_WINDOW(bookmarks_window));
112 return;
115 update_bookmarks();
117 bookmarks_window = gtk_dialog_new();
118 number_of_windows++;
120 gtk_dialog_add_button(GTK_DIALOG(bookmarks_window),
121 GTK_STOCK_CLOSE, GTK_RESPONSE_OK);
123 g_signal_connect(bookmarks_window, "destroy",
124 G_CALLBACK(gtk_widget_destroyed), &bookmarks_window);
125 g_signal_connect(bookmarks_window, "destroy",
126 G_CALLBACK(one_less_window), NULL);
128 swin = gtk_scrolled_window_new(NULL, NULL);
129 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin),
130 GTK_SHADOW_IN);
131 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
132 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
133 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(bookmarks_window)->vbox),
134 swin, TRUE, TRUE, 0);
136 model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
138 list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
140 cell = gtk_cell_renderer_text_new();
141 g_signal_connect(G_OBJECT(cell), "edited",
142 G_CALLBACK(cell_edited), model);
143 g_object_set(G_OBJECT(cell), "editable", TRUE, NULL);
144 g_object_set_data(G_OBJECT(cell), "column", GINT_TO_POINTER(0));
145 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(list), -1,
146 _("Path"), cell, "text", 0, NULL);
148 cell = gtk_cell_renderer_text_new();
149 g_signal_connect(G_OBJECT(cell), "edited",
150 G_CALLBACK(cell_edited), model);
151 g_object_set(G_OBJECT(cell), "editable", TRUE, NULL);
152 g_object_set_data(G_OBJECT(cell), "column", GINT_TO_POINTER(1));
153 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(list), -1,
154 _("Title"), cell, "text", 1, NULL);
156 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(list), TRUE);
157 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), TRUE);
159 node = xmlDocGetRootElement(bookmarks->doc);
160 for (node = node->xmlChildrenNode; node; node = node->next)
162 GtkTreeIter iter;
163 gchar *mark, *title;
165 if (node->type != XML_ELEMENT_NODE)
166 continue;
167 if (strcmp(node->name, "bookmark") != 0)
168 continue;
170 mark = xmlNodeListGetString(bookmarks->doc,
171 node->xmlChildrenNode, 1);
172 if (!mark)
173 continue;
175 title=xmlGetProp(node, "title");
176 if(!title)
177 title=mark;
179 gtk_list_store_append(model, &iter);
180 gtk_list_store_set(model, &iter, 0, mark, 1, title, -1);
181 if(title!=mark)
182 xmlFree(title);
184 xmlFree(mark);
187 gtk_widget_set_size_request(list, 300, 300);
188 gtk_container_add(GTK_CONTAINER(swin), list);
190 hbox = gtk_hbutton_box_new();
191 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(bookmarks_window)->vbox),
192 hbox, FALSE, TRUE, 0);
193 gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
195 button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
196 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 0);
197 g_signal_connect(button, "clicked", G_CALLBACK(edit_delete), list);
199 button = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
200 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 0);
201 g_signal_connect(button, "clicked", G_CALLBACK(reorder_up), list);
202 button = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
203 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 0);
204 g_signal_connect(button, "clicked", G_CALLBACK(reorder_down), list);
206 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
207 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
209 /* Select the first item, otherwise the first click starts edit
210 * mode, which is very confusing!
212 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter))
213 gtk_tree_selection_select_iter(selection, &iter);
215 g_signal_connect(bookmarks_window, "response",
216 G_CALLBACK(edit_response), model);
218 /* Allow directories to be dropped in */
220 GtkTargetEntry targets[] = { {"text/uri-list", 0, 0} };
221 gtk_drag_dest_set(bookmarks_window, GTK_DEST_DEFAULT_ALL,
222 targets, G_N_ELEMENTS(targets),
223 GDK_ACTION_COPY |GDK_ACTION_PRIVATE);
224 g_signal_connect(bookmarks_window, "drag-data-received",
225 G_CALLBACK(dir_dropped), list);
228 g_signal_connect_swapped(model, "row-changed",
229 G_CALLBACK(commit_edits), model);
230 g_signal_connect_swapped(model, "row-inserted",
231 G_CALLBACK(commit_edits), model);
232 g_signal_connect_swapped(model, "row-deleted",
233 G_CALLBACK(commit_edits), model);
234 g_signal_connect_swapped(model, "rows-reordered",
235 G_CALLBACK(commit_edits), model);
237 gtk_widget_show_all(bookmarks_window);
240 static void history_remove(const char *path)
242 GList *old;
244 old = g_hash_table_lookup(history_hash, path);
245 if (old)
247 g_hash_table_remove(history_hash, path);
249 if (history_tail == old)
250 history_tail = old->prev;
251 g_free(old->data);
252 history = g_list_delete_link(history, old);
254 history_free++;
258 /* Add this path to the global history of visited directories. If it
259 * already exists there, make it the most recent. If its parent exists
260 * already, remove the parent.
262 void bookmarks_add_history(const gchar *path)
264 char *new;
266 new = g_strdup(path);
267 ensure_utf8(&new);
269 if (!history_hash)
270 history_hash = g_hash_table_new(g_str_hash, g_str_equal);
272 history_remove(new);
275 char *parent;
276 parent = g_dirname(path);
277 history_remove(parent);
278 g_free(parent);
281 history = g_list_prepend(history, new);
282 if (!history_tail)
283 history_tail = history;
284 g_hash_table_insert(history_hash, new, history);
286 history_free--;
287 if (history_free == -1)
289 g_return_if_fail(history_tail != NULL);
290 history_remove((char *) history_tail->data);
294 void bookmarks_add_uri(const EscapedPath *uri)
296 char *path;
297 struct stat info;
299 path = get_local_path(uri);
301 if (!path)
303 delayed_error(_("Can't bookmark non-local resource '%s'\n"),
304 uri);
305 return;
308 if (mc_stat(path, &info) == 0 && S_ISDIR(info.st_mode))
309 bookmarks_add_dir(path);
310 else
311 delayed_error(_("'%s' isn't a directory"), path);
312 g_free(path);
315 /****************************************************************
316 * INTERNAL FUNCTIONS *
317 ****************************************************************/
319 /* Initialise the bookmarks document to be empty. Does not save. */
320 static void bookmarks_new(void)
322 if (bookmarks)
323 g_object_unref(G_OBJECT(bookmarks));
324 bookmarks = xml_new(NULL);
325 bookmarks->doc = xmlNewDoc("1.0");
326 xmlDocSetRootElement(bookmarks->doc,
327 xmlNewDocNode(bookmarks->doc, NULL, "bookmarks", NULL));
330 static void position_menu(GtkMenu *menu, gint *x, gint *y,
331 gboolean *push_in, gpointer data)
333 FilerWindow *filer_window = (FilerWindow *) data;
335 gdk_window_get_origin(GTK_WIDGET(filer_window->view)->window, x, y);
338 /* Makes sure that 'bookmarks' is up-to-date, reloading from file if it has
339 * changed. If no bookmarks were loaded and there is no file then initialise
340 * bookmarks to an empty document.
342 static void update_bookmarks()
344 gchar *path;
346 /* Update the bookmarks, if possible */
347 path = choices_find_xdg_path_load("Bookmarks.xml", PROJECT, SITE);
348 if (path)
350 XMLwrapper *wrapper;
351 wrapper = xml_cache_load(path);
352 if (wrapper)
354 if (bookmarks)
355 g_object_unref(bookmarks);
356 bookmarks = wrapper;
359 g_free(path);
362 if (!bookmarks)
363 bookmarks_new();
366 /* Return the node for the 'mark' bookmark */
367 static xmlNode *bookmark_find(const gchar *mark)
369 xmlNode *node;
371 update_bookmarks();
373 node = xmlDocGetRootElement(bookmarks->doc);
375 for (node = node->xmlChildrenNode; node; node = node->next)
377 gchar *path;
378 gboolean same;
380 if (node->type != XML_ELEMENT_NODE)
381 continue;
382 if (strcmp(node->name, "bookmark") != 0)
383 continue;
385 path = xmlNodeListGetString(bookmarks->doc,
386 node->xmlChildrenNode, 1);
387 if (!path)
388 continue;
390 same = strcmp(mark, path) == 0;
391 xmlFree(path);
393 if (same)
394 return node;
397 return NULL;
400 /* Save the bookmarks to a file */
401 static void bookmarks_save()
403 guchar *save_path;
405 save_path = choices_find_xdg_path_save("Bookmarks.xml", PROJECT, SITE,
406 TRUE);
407 if (save_path)
409 save_xml_file(bookmarks->doc, save_path);
410 g_free(save_path);
414 /* Add a bookmark if it doesn't already exist, and save the
415 * bookmarks.
417 static void bookmarks_add(GtkMenuItem *menuitem, gpointer user_data)
419 FilerWindow *filer_window = (FilerWindow *) user_data;
421 bookmarks_add_dir(filer_window->sym_path);
424 static void bookmarks_add_dir(const guchar *dir)
426 xmlNode *bookmark;
428 if (bookmark_find(dir))
429 return;
431 bookmark = xmlNewTextChild(xmlDocGetRootElement(bookmarks->doc),
432 NULL, "bookmark", dir);
433 xmlSetProp(bookmark, "title", dir);
435 bookmarks_save();
437 if (bookmarks_window)
438 gtk_widget_destroy(bookmarks_window);
441 /* Called when a bookmark has been chosen */
442 static void bookmarks_activate(GtkMenuShell *item, FilerWindow *filer_window)
444 const gchar *mark;
445 GtkLabel *label;
446 GdkEvent *event;
447 gboolean new_win=FALSE;
449 mark=g_object_get_data(G_OBJECT(item), "bookmark-path");
450 if(!mark) {
451 label = GTK_LABEL(GTK_BIN(item)->child);
452 mark = gtk_label_get_text(label);
455 event=gtk_get_current_event();
456 if(event)
458 if(event->type==GDK_BUTTON_PRESS ||
459 event->type==GDK_BUTTON_RELEASE)
461 GdkEventButton *button=(GdkEventButton *) event;
463 new_win=o_new_button_1.int_value?
464 button->button==1: button->button!=1;
466 gdk_event_free(event);
469 if (strcmp(mark, filer_window->sym_path) != 0)
471 if(new_win)
472 filer_opendir(mark, filer_window, NULL);
473 else
474 filer_change_to(filer_window, mark, NULL);
476 if (g_hash_table_lookup(fstab_mounts, filer_window->real_path) &&
477 !mount_is_mounted(filer_window->real_path, NULL, NULL))
479 GList *paths;
481 paths = g_list_prepend(NULL, filer_window->real_path);
482 action_mount(paths, FALSE, -1);
483 g_list_free(paths);
487 static void edit_delete(GtkButton *button, GtkTreeView *view)
489 GtkTreeModel *model;
490 GtkListStore *list;
491 GtkTreeSelection *selection;
492 GtkTreeIter iter;
493 gboolean more, any = FALSE;
495 model = gtk_tree_view_get_model(view);
496 list = GTK_LIST_STORE(model);
498 selection = gtk_tree_view_get_selection(view);
500 more = gtk_tree_model_get_iter_first(model, &iter);
502 while (more)
504 GtkTreeIter old = iter;
506 more = gtk_tree_model_iter_next(model, &iter);
508 if (gtk_tree_selection_iter_is_selected(selection, &old))
510 any = TRUE;
511 gtk_list_store_remove(list, &old);
515 if (!any)
517 report_error(_("You should first select some rows to delete"));
518 return;
522 static void reorder(GtkTreeView *view, int dir)
524 GtkTreeModel *model;
525 GtkListStore *list;
526 GtkTreePath *cursor = NULL;
527 GtkTreeIter iter, old, new;
528 GValue mark = {0};
529 GValue title = {0};
530 gboolean ok;
532 g_return_if_fail(view != NULL);
533 g_return_if_fail(dir == 1 || dir == -1);
535 model = gtk_tree_view_get_model(view);
536 list = GTK_LIST_STORE(model);
538 gtk_tree_view_get_cursor(view, &cursor, NULL);
539 if (!cursor)
541 report_error(_("Put the cursor on an entry in the "
542 "list to move it"));
543 return;
546 gtk_tree_model_get_iter(model, &old, cursor);
547 if (dir > 0)
549 gtk_tree_path_next(cursor);
550 ok = gtk_tree_model_get_iter(model, &iter, cursor);
552 else
554 ok = gtk_tree_path_prev(cursor);
555 if (ok)
556 gtk_tree_model_get_iter(model, &iter, cursor);
558 if (!ok)
560 gtk_tree_path_free(cursor);
561 report_error(_("This item is already at the end"));
562 return;
565 gtk_tree_model_get_value(model, &old, 0, &mark);
566 gtk_tree_model_get_value(model, &old, 1, &title);
567 if (dir > 0)
568 gtk_list_store_insert_after(list, &new, &iter);
569 else
570 gtk_list_store_insert_before(list, &new, &iter);
571 gtk_list_store_set(list, &new, 0, g_value_get_string(&mark), -1);
572 gtk_list_store_set(list, &new, 1, g_value_get_string(&title), -1);
573 gtk_list_store_remove(list, &old);
575 g_value_unset(&mark);
576 g_value_unset(&title);
578 gtk_tree_view_set_cursor(view, cursor, 0, FALSE);
579 gtk_tree_path_free(cursor);
582 static void reorder_up(GtkButton *button, GtkTreeView *view)
584 reorder(view, -1);
587 static void reorder_down(GtkButton *button, GtkTreeView *view)
589 reorder(view, 1);
592 static gboolean dir_dropped(GtkWidget *window, GdkDragContext *context,
593 int x, int y,
594 GtkSelectionData *selection_data, guint info,
595 guint time, GtkTreeView *view)
597 GtkListStore *model;
598 GList *uris, *next;
600 if (!selection_data->data)
602 /* Timeout? */
603 gtk_drag_finish(context, FALSE, FALSE, time); /* Failure */
604 return TRUE;
607 model = GTK_LIST_STORE(gtk_tree_view_get_model(view));
609 uris = uri_list_to_glist(selection_data->data);
611 for (next = uris; next; next = next->next)
613 guchar *path;
615 path = get_local_path((EscapedPath *) next->data);
617 if (path)
619 GtkTreeIter iter;
620 struct stat info;
622 if (mc_stat(path, &info) == 0 && S_ISDIR(info.st_mode))
624 gtk_list_store_append(model, &iter);
625 gtk_list_store_set(model, &iter, 0, path,
626 1, path, -1);
628 else
629 delayed_error(_("'%s' isn't a directory"),
630 path);
632 g_free(path);
634 else
635 delayed_error(_("Can't bookmark non-local directories "
636 "like '%s'"), (gchar *) next->data);
639 destroy_glist(&uris);
641 return TRUE;
644 static void commit_edits(GtkTreeModel *model)
646 GtkTreeIter iter;
648 bookmarks_new();
650 if (gtk_tree_model_get_iter_first(model, &iter))
652 GValue mark = {0}, title={0};
653 xmlNode *root = xmlDocGetRootElement(bookmarks->doc);
657 xmlNode *bookmark;
659 gtk_tree_model_get_value(model, &iter, 0, &mark);
660 bookmark = xmlNewTextChild(root, NULL, "bookmark",
661 g_value_get_string(&mark));
662 g_value_unset(&mark);
663 gtk_tree_model_get_value(model, &iter, 1, &title);
664 xmlSetProp(bookmark, "title",
665 g_value_get_string(&title));
666 g_value_unset(&title);
667 } while (gtk_tree_model_iter_next(model, &iter));
670 bookmarks_save();
673 static void edit_response(GtkWidget *window, gint response, GtkTreeModel *model)
675 commit_edits(model);
677 gtk_widget_destroy(window);
680 static void cell_edited(GtkCellRendererText *cell,
681 const gchar *path_string,
682 const gchar *new_text,
683 gpointer data)
685 GtkTreeModel *model = (GtkTreeModel *) data;
686 GtkTreePath *path;
687 GtkTreeIter iter;
688 gint col;
690 path = gtk_tree_path_new_from_string(path_string);
691 gtk_tree_model_get_iter(model, &iter, path);
692 gtk_tree_path_free(path);
693 col=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cell), "column"));
695 gtk_list_store_set(GTK_LIST_STORE(model), &iter, col, new_text, -1);
698 static void activate_edit(GtkMenuShell *item, gpointer data)
700 bookmarks_edit();
703 static gint cmp_dirname(gconstpointer a, gconstpointer b)
705 return g_utf8_collate(*(gchar **) a, *(gchar **) b);
708 static void free_path_for_item(GtkWidget *widget, gpointer udata)
710 gchar *path=(gchar *) udata;
711 g_free(path);
714 static GtkWidget *build_history_menu(FilerWindow *filer_window)
716 GtkWidget *menu;
717 GPtrArray *items;
718 GList *next;
719 int i;
721 menu = gtk_menu_new();
723 if (!history)
724 return menu;
726 g_return_val_if_fail(history_hash != NULL, menu);
727 g_return_val_if_fail(history_tail != NULL, menu);
729 items = g_ptr_array_new();
731 for (next = history; next; next = next->next)
732 g_ptr_array_add(items, next->data);
734 g_ptr_array_sort(items, cmp_dirname);
736 for (i = 0; i < items->len; i++)
738 GtkWidget *item;
739 const char *path = (char *) items->pdata[i];
740 gchar *copy;
742 item = gtk_menu_item_new_with_label(path);
744 copy=g_strdup(path);
745 g_object_set_data(G_OBJECT(item), "bookmark-path", copy);
746 g_signal_connect(item, "destroy",
747 G_CALLBACK(free_path_for_item), copy);
749 if (strcmp(path, filer_window->sym_path) == 0)
750 gtk_widget_set_sensitive(item, FALSE);
751 else
752 g_signal_connect(item, "activate",
753 G_CALLBACK(bookmarks_activate),
754 filer_window);
756 gtk_widget_show(item);
757 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
760 g_ptr_array_free(items, TRUE);
762 return menu;
765 /* Builds the bookmarks' menu. Done whenever the bookmarks icon has been
766 * clicked.
768 static GtkWidget *bookmarks_build_menu(FilerWindow *filer_window)
770 GtkWidget *menu;
771 GtkWidget *item;
772 xmlNode *node;
773 gboolean need_separator = TRUE;
775 menu = gtk_menu_new();
777 item = gtk_menu_item_new_with_label(_("Add New Bookmark"));
778 g_signal_connect(item, "activate",
779 G_CALLBACK(bookmarks_add), filer_window);
780 gtk_widget_show(item);
781 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
782 gtk_menu_shell_select_item(GTK_MENU_SHELL(menu), item);
784 item = gtk_menu_item_new_with_label(_("Edit Bookmarks"));
785 g_signal_connect(item, "activate", G_CALLBACK(activate_edit), NULL);
786 gtk_widget_show(item);
787 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
789 item = gtk_menu_item_new_with_label(_("Recently Visited"));
790 gtk_widget_show(item);
791 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
792 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),
793 build_history_menu(filer_window));
795 /* Now add all the bookmarks to the menu */
797 update_bookmarks();
799 node = xmlDocGetRootElement(bookmarks->doc);
801 for (node = node->xmlChildrenNode; node; node = node->next)
803 gchar *mark, *title, *path;
805 if (node->type != XML_ELEMENT_NODE)
806 continue;
807 if (strcmp(node->name, "bookmark") != 0)
808 continue;
810 mark = xmlNodeListGetString(bookmarks->doc,
811 node->xmlChildrenNode, 1);
812 if (!mark)
813 continue;
814 path=g_strdup(mark);
816 title=xmlGetProp(node, "title");
817 if(!title)
818 title=mark;
820 item = gtk_menu_item_new_with_label(title);
822 g_object_set_data(G_OBJECT(item), "bookmark-path", path);
823 g_signal_connect(item, "destroy",
824 G_CALLBACK(free_path_for_item), path);
826 if(title!=mark)
827 xmlFree(title);
828 xmlFree(mark);
830 g_signal_connect(item, "activate",
831 G_CALLBACK(bookmarks_activate),
832 filer_window);
834 gtk_widget_show(item);
836 if (need_separator)
838 GtkWidget *sep;
839 sep = gtk_separator_menu_item_new();
840 gtk_widget_show(sep);
841 gtk_menu_shell_append(GTK_MENU_SHELL(menu), sep);
842 need_separator = FALSE;
845 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
849 return menu;