2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "ui-bookmark.h"
27 #include "history-list.h"
28 #include "ui-fileops.h"
31 #include "ui-utildlg.h"
32 #include "ui-tabcomp.h"
33 #include "uri-utils.h"
38 *-----------------------------------------------------------------------------
40 *-----------------------------------------------------------------------------
43 #define BOOKMARK_DATA_KEY "bookmarkdata"
44 #define MARKER_PATH "[path]"
45 #define MARKER_ICON "[icon]"
47 typedef struct _BookMarkData BookMarkData;
48 typedef struct _BookButtonData BookButtonData;
49 typedef struct _BookPropData BookPropData;
57 void (*select_func)(const gchar *path, gpointer data);
62 gboolean only_directories;
64 BookButtonData *active_button;
67 struct _BookButtonData
82 GtkWidget *name_entry;
83 GtkWidget *path_entry;
84 GtkWidget *icon_entry;
95 static GtkTargetEntry bookmark_drop_types[] = {
96 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
97 { const_cast<gchar *>("x-url/http"), 0, TARGET_X_URL },
98 { const_cast<gchar *>("_NETSCAPE_URL"), 0, TARGET_X_URL }
100 #define bookmark_drop_types_n 3
102 static GtkTargetEntry bookmark_drag_types[] = {
103 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
104 { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
106 #define bookmark_drag_types_n 2
109 static GList *bookmark_widget_list = NULL;
110 static GList *bookmark_default_list = NULL;
113 static void bookmark_populate_all(const gchar *key);
116 static BookButtonData *bookmark_from_string(const gchar *text)
119 const gchar *path_ptr;
120 const gchar *icon_ptr;
122 b = g_new0(BookButtonData, 1);
126 b->name = g_strdup(_("New Bookmark"));
127 b->path = g_strdup(homedir());
132 b->key = g_strdup(text);
134 path_ptr = strstr(text, MARKER_PATH);
135 icon_ptr = strstr(text, MARKER_ICON);
137 if (path_ptr && icon_ptr && icon_ptr < path_ptr)
139 log_printf("warning, bookmark icon must be after path\n");
148 b->name = g_strndup(text, l);
149 path_ptr += strlen(MARKER_PATH);
152 l = icon_ptr - path_ptr;
153 b->path = g_strndup(path_ptr, l);
157 b->path = g_strdup(path_ptr);
162 b->name = g_strdup(text);
163 b->path = g_strdup("");
168 icon_ptr += strlen(MARKER_ICON);
169 b->icon = g_strdup(icon_ptr);
175 static void bookmark_free(BookButtonData *b)
187 static gchar *bookmark_string(const gchar *name, const gchar *path, const gchar *icon)
189 if (!name) name = _("New Bookmark");
193 return g_strdup_printf("%s" MARKER_PATH "%s" MARKER_ICON "%s", name, path, icon);
196 return g_strdup_printf("%s" MARKER_PATH "%s", name, path);
199 static void bookmark_select_cb(GtkWidget *button, gpointer data)
201 BookMarkData *bm = static_cast<BookMarkData *>(data);
204 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
207 if (bm->select_func) bm->select_func(b->path, bm->select_data);
210 static void bookmark_edit_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
212 BookPropData *p = static_cast<BookPropData *>(data);
214 bookmark_free(p->bb);
218 static void bookmark_edit_cancel_cb(GenericDialog *UNUSED(gd), gpointer UNUSED(data))
222 static void bookmark_edit_ok_cb(GenericDialog *UNUSED(gd), gpointer data)
224 BookPropData *p = static_cast<BookPropData *>(data);
230 name = gtk_entry_get_text(GTK_ENTRY(p->name_entry));
231 path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(p->path_entry)));
232 icon = gtk_entry_get_text(GTK_ENTRY(p->icon_entry));
234 new_string = bookmark_string(name, path, icon);
238 history_list_item_change(p->bb->parent, p->bb->key, new_string);
242 history_list_add_to_key(p->bb->parent, new_string, 0);
245 if (path && strlen(path) > 0) tab_completion_append_to_history(p->path_entry, path);
246 if (icon && strlen(icon) > 0) tab_completion_append_to_history(p->icon_entry, icon);
251 bookmark_populate_all(p->bb->parent);
254 /* simply pass NULL for text to turn this into a 'new bookmark' dialog */
256 static void bookmark_edit(const gchar *key, const gchar *text, GtkWidget *parent)
264 if (!key) key = "bookmarks";
266 p = g_new0(BookPropData, 1);
268 p->bb = bookmark_from_string(text);
269 p->bb->parent = g_strdup(key);
271 gd = generic_dialog_new(_("Edit Bookmark"), "bookmark_edit",
273 bookmark_edit_cancel_cb, p);
274 g_signal_connect(G_OBJECT(gd->dialog), "destroy",
275 G_CALLBACK(bookmark_edit_destroy_cb), p);
277 generic_dialog_add_message(gd, NULL, _("Edit Bookmark"), NULL, FALSE);
279 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
280 bookmark_edit_ok_cb, TRUE);
282 table = pref_table_new(gd->vbox, 3, 2, FALSE, TRUE);
283 pref_table_label(table, 0, 0, _("Name:"), 1.0);
285 p->name_entry = gtk_entry_new();
286 gtk_widget_set_size_request(p->name_entry, 300, -1);
287 if (p->bb->name) gtk_entry_set_text(GTK_ENTRY(p->name_entry), p->bb->name);
288 gtk_table_attach_defaults(GTK_TABLE(table), p->name_entry, 1, 2, 0, 1);
289 generic_dialog_attach_default(gd, p->name_entry);
290 gtk_widget_show(p->name_entry);
292 pref_table_label(table, 0, 1, _("Path:"), 1.0);
294 label = tab_completion_new_with_history(&p->path_entry, p->bb->path,
295 "bookmark_path", -1, NULL, NULL);
296 tab_completion_add_select_button(p->path_entry, NULL, TRUE);
297 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2);
298 generic_dialog_attach_default(gd, p->path_entry);
299 gtk_widget_show(label);
301 pref_table_label(table, 0, 2, _("Icon:"), 1.0);
304 if (!icon) icon = "";
305 label = tab_completion_new_with_history(&p->icon_entry, icon,
306 "bookmark_icons", -1, NULL, NULL);
307 tab_completion_add_select_button(p->icon_entry, _("Select icon"), FALSE);
308 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 2, 3);
309 generic_dialog_attach_default(gd, p->icon_entry);
310 gtk_widget_show(label);
312 gtk_widget_show(gd->dialog);
315 static void bookmark_move(BookMarkData *bm, GtkWidget *button, gint direction)
320 const gchar *key_holder;
322 if (!bm->editable) return;
324 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
327 list = gtk_container_get_children(GTK_CONTAINER(bm->box));
328 p = g_list_index(list, button);
331 if (p < 0 || p + direction < 0) return;
333 key_holder = bm->key;
334 bm->key = "_TEMPHOLDER";
335 history_list_item_move(key_holder, b->key, -direction);
336 bookmark_populate_all(key_holder);
337 bm->key = key_holder;
339 gtk_box_reorder_child(GTK_BOX(bm->box), button, p + direction);
342 static void bookmark_menu_prop_cb(GtkWidget *widget, gpointer data)
344 BookMarkData *bm = static_cast<BookMarkData *>(data);
346 if (!bm->active_button) return;
348 bookmark_edit(bm->key, bm->active_button->key, widget);
351 static void bookmark_menu_move(BookMarkData *bm, gint direction)
353 if (!bm->active_button) return;
355 bookmark_move(bm, bm->active_button->button, direction);
358 static void bookmark_menu_up_cb(GtkWidget *UNUSED(widget), gpointer data)
360 bookmark_menu_move(static_cast<BookMarkData *>(data), -1);
363 static void bookmark_menu_down_cb(GtkWidget *UNUSED(widget), gpointer data)
365 bookmark_menu_move(static_cast<BookMarkData *>(data), 1);
368 static void bookmark_menu_remove_cb(GtkWidget *UNUSED(widget), gpointer data)
370 BookMarkData *bm = static_cast<BookMarkData *>(data);
372 if (!bm->active_button) return;
374 history_list_item_remove(bm->key, bm->active_button->key);
375 bookmark_populate_all(bm->key);
378 static void bookmark_menu_popup(BookMarkData *bm, GtkWidget *button,
379 gint UNUSED(button_n), guint32 UNUSED(time), gboolean local)
384 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
387 bm->active_button = b;
389 menu = popup_menu_short_lived();
390 menu_item_add_stock_sensitive(menu, _("_Properties..."), GTK_STOCK_PROPERTIES, bm->editable,
391 G_CALLBACK(bookmark_menu_prop_cb), bm);
392 menu_item_add_stock_sensitive(menu, _("Move _up"), GTK_STOCK_GO_UP, bm->editable,
393 G_CALLBACK(bookmark_menu_up_cb), bm);
394 menu_item_add_stock_sensitive(menu, _("Move _down"), GTK_STOCK_GO_DOWN, bm->editable,
395 G_CALLBACK(bookmark_menu_down_cb), bm);
396 menu_item_add_stock_sensitive(menu, _("_Remove"), GTK_STOCK_REMOVE, bm->editable,
397 G_CALLBACK(bookmark_menu_remove_cb), bm);
401 gtk_menu_popup_at_widget(GTK_MENU(menu), button, GDK_GRAVITY_NORTH_EAST, GDK_GRAVITY_CENTER, NULL);
405 gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
409 static gboolean bookmark_press_cb(GtkWidget *button, GdkEventButton *event, gpointer data)
411 BookMarkData *bm = static_cast<BookMarkData *>(data);
413 if (event->button != MOUSE_BUTTON_RIGHT) return FALSE;
415 bookmark_menu_popup(bm, button, event->button, event->time, FALSE);
420 static gboolean bookmark_keypress_cb(GtkWidget *button, GdkEventKey *event, gpointer data)
422 BookMarkData *bm = static_cast<BookMarkData *>(data);
424 switch (event->keyval)
427 if (!(event->state & GDK_CONTROL_MASK)) return FALSE;
430 bookmark_menu_popup(bm, button, 0, event->time, TRUE);
434 if (event->state & GDK_SHIFT_MASK)
436 bookmark_move(bm, button, -1);
441 if (event->state & GDK_SHIFT_MASK)
443 bookmark_move(bm, button, 1);
452 static void bookmark_drag_set_data(GtkWidget *button,
453 GdkDragContext *context, GtkSelectionData *selection_data,
454 guint UNUSED(info), guint UNUSED(time), gpointer data)
456 BookMarkData *bm = static_cast<BookMarkData *>(data);
461 if (gdk_drag_context_get_dest_window(context) == gtk_widget_get_window(bm->widget)) return;
463 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
466 list = g_list_append(list, b->path);
468 gchar **uris = uris_from_pathlist(list);
469 gboolean ret = gtk_selection_data_set_uris(selection_data, uris);
472 char *str = g_strjoinv("\r\n", uris);
473 ret = gtk_selection_data_set_text(selection_data, str, -1);
481 static void bookmark_drag_begin(GtkWidget *button, GdkDragContext *context, gpointer UNUSED(data))
484 GdkModifierType mask;
486 GtkAllocation allocation;
490 gtk_widget_get_allocation(button, &allocation);
492 pixbuf = gdk_pixbuf_get_from_window(gtk_widget_get_window(button),
493 allocation.x, allocation.y,
494 allocation.width, allocation.height);
495 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(button)));
496 device = gdk_seat_get_pointer(seat);
497 gdk_window_get_device_position(gtk_widget_get_window(button), device, &x, &y, &mask);
499 gtk_drag_set_icon_pixbuf(context, pixbuf,
500 x - allocation.x, y - allocation.y);
501 g_object_unref(pixbuf);
504 static gboolean bookmark_path_tooltip_cb(GtkWidget *button, gpointer UNUSED(data))
508 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
509 gtk_widget_set_tooltip_text(GTK_WIDGET(button), b->path);
514 static void bookmark_populate(BookMarkData *bm)
520 box = GTK_BOX(bm->box);
521 children = gtk_container_get_children(GTK_CONTAINER(box));
525 GtkWidget *widget = GTK_WIDGET(work->data);
527 gtk_widget_destroy(widget);
530 if (!bm->no_defaults && !history_list_get_by_key(bm->key))
535 if (!bookmark_default_list)
537 buf = bookmark_string(_("Home"), homedir(), NULL);
538 history_list_add_to_key(bm->key, buf, 0);
541 if (!g_strcmp0(bm->key, "shortcuts") == 0)
543 buf = bookmark_string(".", g_strdup(history_list_find_last_path_by_key("path_list")), NULL);
544 history_list_add_to_key(bm->key, buf, 0);
548 path = g_build_filename(homedir(), "Desktop", NULL);
551 buf = bookmark_string(_("Desktop"), path, NULL);
552 history_list_add_to_key(bm->key, buf, 0);
558 work = bookmark_default_list;
559 while (work && work->next)
563 name = static_cast<gchar *>(work->data);
565 path = static_cast<gchar *>(work->data);
568 if (strcmp(name, ".") == 0)
570 if (!g_strcmp0(bm->key, "shortcuts") == 0)
572 buf = bookmark_string(name, g_strdup(history_list_find_last_path_by_key("path_list")), NULL);
581 buf = bookmark_string(name, path, NULL);
583 history_list_add_to_key(bm->key, buf, 0);
588 work = history_list_get_by_key(bm->key);
589 work = g_list_last(work);
594 b = bookmark_from_string(static_cast<const gchar *>(work->data));
597 if (strcmp(b->name, ".") == 0)
601 b->path = g_strdup(history_list_find_last_path_by_key("path_list"));
602 buf = bookmark_string(".", b->path, b->icon);
603 history_list_item_change("bookmarks", b->key, buf);
604 b->key = g_strdup(buf);
609 b->button = gtk_button_new();
610 gtk_button_set_relief(GTK_BUTTON(b->button), GTK_RELIEF_NONE);
611 gtk_box_pack_start(GTK_BOX(bm->box), b->button, FALSE, FALSE, 0);
612 gtk_widget_show(b->button);
614 g_object_set_data_full(G_OBJECT(b->button), "bookbuttondata",
615 b, (GDestroyNotify)bookmark_free);
617 box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
618 gtk_container_add(GTK_CONTAINER(b->button), box);
619 gtk_widget_show(box);
623 GdkPixbuf *pixbuf = NULL;
626 iconl = path_from_utf8(b->icon);
627 pixbuf = gdk_pixbuf_new_from_file(iconl, NULL);
631 pixbuf = gdk_pixbuf_new_from_file(iconl, NULL);
638 gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &w, &h);
640 pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), b->icon, w, GTK_ICON_LOOKUP_NO_SVG, NULL);
650 gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &w, &h);
652 scaled = gdk_pixbuf_scale_simple(pixbuf, w, h,
653 GDK_INTERP_BILINEAR);
654 b->image = gtk_image_new_from_pixbuf(scaled);
655 g_object_unref(scaled);
656 g_object_unref(pixbuf);
660 b->image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY,
661 GTK_ICON_SIZE_BUTTON);
666 b->image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_BUTTON);
668 gtk_box_pack_start(GTK_BOX(box), b->image, FALSE, FALSE, 0);
669 gtk_widget_show(b->image);
671 b->label = gtk_label_new(b->name);
672 gtk_box_pack_start(GTK_BOX(box), b->label, FALSE, FALSE, 0);
673 gtk_widget_show(b->label);
675 g_signal_connect(G_OBJECT(b->button), "clicked",
676 G_CALLBACK(bookmark_select_cb), bm);
677 g_signal_connect(G_OBJECT(b->button), "button_press_event",
678 G_CALLBACK(bookmark_press_cb), bm);
679 g_signal_connect(G_OBJECT(b->button), "key_press_event",
680 G_CALLBACK(bookmark_keypress_cb), bm);
682 gtk_drag_source_set(b->button, GDK_BUTTON1_MASK,
683 bookmark_drag_types, bookmark_drag_types_n,
684 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
685 g_signal_connect(G_OBJECT(b->button), "drag_data_get",
686 G_CALLBACK(bookmark_drag_set_data), bm);
687 g_signal_connect(G_OBJECT(b->button), "drag_begin",
688 G_CALLBACK(bookmark_drag_begin), bm);
690 gtk_widget_set_has_tooltip(GTK_WIDGET(b->button), TRUE);
691 g_signal_connect(G_OBJECT(b->button), "query_tooltip", G_CALLBACK(bookmark_path_tooltip_cb), bm);
698 static void bookmark_populate_all(const gchar *key)
704 work = bookmark_widget_list;
709 bm = static_cast<BookMarkData *>(work->data);
712 if (strcmp(bm->key, key) == 0)
714 bookmark_populate(bm);
719 static void bookmark_dnd_get_data(GtkWidget *UNUSED(widget),
720 GdkDragContext *UNUSED(context), gint UNUSED(x), gint UNUSED(y),
721 GtkSelectionData *selection_data, guint UNUSED(info),
722 guint UNUSED(time), gpointer data)
724 BookMarkData *bm = static_cast<BookMarkData *>(data);
726 GList *errors = NULL;
731 if (!bm->editable) return;
733 uris = gtk_selection_data_get_uris(selection_data);
736 list = uri_pathlist_from_uris(uris, &errors);
739 warning_dialog_dnd_uri_error(errors);
740 string_list_free(errors);
747 gchar *path = static_cast<gchar *>(work->data);
752 if (bm->only_directories && !isdir(path)) continue;
754 real_path = realpath(path, NULL);
756 if (strstr(real_path, get_collections_dir()) && isfile(path))
758 buf = bookmark_string(filename_from_path(path), path, "gq-collection");
760 else if (isfile(path))
762 buf = bookmark_string(filename_from_path(path), path, GTK_STOCK_FILE);
766 buf = bookmark_string(filename_from_path(path), path, NULL);
768 history_list_add_to_key(bm->key, buf, 0);
773 string_list_free(list);
775 bookmark_populate_all(bm->key);
779 static void bookmark_list_destroy(GtkWidget *UNUSED(widget), gpointer data)
781 BookMarkData *bm = static_cast<BookMarkData *>(data);
783 bookmark_widget_list = g_list_remove(bookmark_widget_list, bm);
785 g_free((gpointer)bm->key);
789 GtkWidget *bookmark_list_new(const gchar *key,
790 void (*select_func)(const gchar *path, gpointer data), gpointer select_data)
795 if (!key) key = "bookmarks";
797 bm = g_new0(BookMarkData, 1);
798 bm->key = g_strdup(key);
800 bm->select_func = select_func;
801 bm->select_data = select_data;
803 bm->no_defaults = FALSE;
805 bm->only_directories = FALSE;
807 scrolled = gtk_scrolled_window_new(NULL, NULL);
812 layout = gtk_widget_create_pango_layout(GTK_WIDGET(scrolled), "reasonable width");
813 pango_layout_get_pixel_size(layout, &width, &height);
814 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scrolled), width);
815 g_object_unref(layout);
817 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
819 bm->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
820 gtk_container_add(GTK_CONTAINER(scrolled), bm->box);
821 gtk_widget_show(bm->box);
823 bookmark_populate(bm);
825 g_signal_connect(G_OBJECT(bm->box), "destroy",
826 G_CALLBACK(bookmark_list_destroy), bm);
827 g_object_set_data(G_OBJECT(bm->box), BOOKMARK_DATA_KEY, bm);
828 g_object_set_data(G_OBJECT(scrolled), BOOKMARK_DATA_KEY, bm);
829 bm->widget = scrolled;
831 gtk_drag_dest_set(scrolled,
832 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP),
833 bookmark_drop_types, bookmark_drop_types_n,
834 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
835 g_signal_connect(G_OBJECT(scrolled), "drag_data_received",
836 G_CALLBACK(bookmark_dnd_get_data), bm);
838 bookmark_widget_list = g_list_append(bookmark_widget_list, bm);
843 void bookmark_list_set_key(GtkWidget *list, const gchar *key)
847 if (!list || !key) return;
849 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
852 if (bm->key && strcmp(bm->key, key) == 0) return;
854 g_free((gpointer)bm->key);
855 bm->key = g_strdup(key);
857 bookmark_populate(bm);
860 void bookmark_list_set_no_defaults(GtkWidget *list, gboolean no_defaults)
864 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
867 bm->no_defaults = no_defaults;
870 void bookmark_list_set_editable(GtkWidget *list, gboolean editable)
874 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
877 bm->editable = editable;
880 void bookmark_list_set_only_directories(GtkWidget *list, gboolean only_directories)
884 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
887 bm->only_directories = only_directories;
890 void bookmark_list_add(GtkWidget *list, const gchar *name, const gchar *path)
896 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
899 buf = bookmark_string(name, path, NULL);
900 real_path = realpath(path, NULL);
902 if (strstr(real_path, get_collections_dir()) && isfile(path))
904 buf = bookmark_string(name, path, "gq-collection");
910 buf = bookmark_string(name, path, "gtk-file");
914 buf = bookmark_string(name, path, NULL);
918 history_list_add_to_key(bm->key, buf, 0);
922 bookmark_populate_all(bm->key);
925 void bookmark_add_default(const gchar *name, const gchar *path)
927 if (!name || !path) return;
928 bookmark_default_list = g_list_append(bookmark_default_list, g_strdup(name));
929 bookmark_default_list = g_list_append(bookmark_default_list, g_strdup(path));
933 *-----------------------------------------------------------------------------
934 * combo with history key
935 *-----------------------------------------------------------------------------
938 typedef struct _HistoryComboData HistoryComboData;
939 struct _HistoryComboData
947 static void history_combo_destroy(GtkWidget *UNUSED(widget), gpointer data)
949 HistoryComboData *hc = static_cast<HistoryComboData *>(data);
951 g_free(hc->history_key);
955 /* if text is NULL, entry is set to the most recent item */
956 GtkWidget *history_combo_new(GtkWidget **entry, const gchar *text,
957 const gchar *history_key, gint max_levels)
959 HistoryComboData *hc;
963 hc = g_new0(HistoryComboData, 1);
964 hc->history_key = g_strdup(history_key);
965 hc->history_levels = max_levels;
967 hc->combo = gtk_combo_box_text_new_with_entry();
969 hc->entry = gtk_bin_get_child(GTK_BIN(hc->combo));
971 g_object_set_data(G_OBJECT(hc->combo), "history_combo_data", hc);
972 g_object_set_data(G_OBJECT(hc->entry), "history_combo_data", hc);
973 g_signal_connect(G_OBJECT(hc->combo), "destroy",
974 G_CALLBACK(history_combo_destroy), hc);
976 work = history_list_get_by_key(hc->history_key);
979 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hc->combo), (gchar *)work->data);
986 gtk_entry_set_text(GTK_ENTRY(hc->entry), text);
990 gtk_combo_box_set_active(GTK_COMBO_BOX(hc->combo), 0);
993 if (entry) *entry = hc->entry;
997 /* if text is NULL, current entry text is used
998 * widget can be the combo or entry widget
1000 void history_combo_append_history(GtkWidget *widget, const gchar *text)
1002 HistoryComboData *hc;
1005 hc = static_cast<HistoryComboData *>(g_object_get_data(G_OBJECT(widget), "history_combo_data"));
1008 log_printf("widget is not a history combo\n");
1014 new_text = g_strdup(text);
1018 new_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(hc->entry)));
1021 if (new_text && strlen(new_text) > 0)
1023 GtkTreeModel *store;
1026 history_list_add_to_key(hc->history_key, new_text, hc->history_levels);
1028 gtk_combo_box_set_active(GTK_COMBO_BOX(hc->combo), -1);
1030 store = gtk_combo_box_get_model(GTK_COMBO_BOX(hc->combo));
1031 gtk_list_store_clear(GTK_LIST_STORE(store));
1033 work = history_list_get_by_key(hc->history_key);
1036 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hc->combo), (gchar *)work->data);
1043 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */