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.
22 #include "ui-bookmark.h"
31 #include "history-list.h"
33 #include "main-defines.h"
35 #include "pixbuf-util.h"
37 #include "ui-fileops.h"
40 #include "ui-tabcomp.h"
41 #include "ui-utildlg.h"
42 #include "uri-utils.h"
45 *-----------------------------------------------------------------------------
47 *-----------------------------------------------------------------------------
50 #define BOOKMARK_DATA_KEY "bookmarkdata"
51 #define MARKER_PATH "[path]"
52 #define MARKER_ICON "[icon]"
54 struct BookButtonData;
62 void (*select_func)(const gchar *path, gpointer data);
67 gboolean only_directories;
69 BookButtonData *active_button;
87 GtkWidget *name_entry;
88 GtkWidget *path_entry;
89 GtkWidget *icon_entry;
100 static GtkTargetEntry bookmark_drop_types[] = {
101 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
102 { const_cast<gchar *>("x-url/http"), 0, TARGET_X_URL },
103 { const_cast<gchar *>("_NETSCAPE_URL"), 0, TARGET_X_URL }
106 bookmark_drop_types_n = 3
109 static GtkTargetEntry bookmark_drag_types[] = {
110 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
111 { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
114 bookmark_drag_types_n = 2
118 static GList *bookmark_widget_list = nullptr;
119 static GList *bookmark_default_list = nullptr;
122 static void bookmark_populate_all(const gchar *key);
125 static BookButtonData *bookmark_from_string(const gchar *text)
128 const gchar *path_ptr;
129 const gchar *icon_ptr;
131 b = g_new0(BookButtonData, 1);
135 b->name = g_strdup(_("New Bookmark"));
136 b->path = g_strdup(homedir());
141 b->key = g_strdup(text);
143 path_ptr = strstr(text, MARKER_PATH);
144 icon_ptr = strstr(text, MARKER_ICON);
146 if (path_ptr && icon_ptr && icon_ptr < path_ptr)
148 log_printf("warning, bookmark icon must be after path\n");
157 b->name = g_strndup(text, l);
158 path_ptr += strlen(MARKER_PATH);
161 l = icon_ptr - path_ptr;
162 b->path = g_strndup(path_ptr, l);
166 b->path = g_strdup(path_ptr);
171 b->name = g_strdup(text);
172 b->path = g_strdup("");
177 icon_ptr += strlen(MARKER_ICON);
178 b->icon = g_strdup(icon_ptr);
184 static void bookmark_free(BookButtonData *b)
196 static gchar *bookmark_string(const gchar *name, const gchar *path, const gchar *icon)
198 if (!name) name = _("New Bookmark");
202 return g_strdup_printf("%s" MARKER_PATH "%s" MARKER_ICON "%s", name, path, icon);
205 return g_strdup_printf("%s" MARKER_PATH "%s", name, path);
208 static void bookmark_select_cb(GtkWidget *button, gpointer data)
210 auto bm = static_cast<BookMarkData *>(data);
213 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
216 if (bm->select_func) bm->select_func(b->path, bm->select_data);
219 static void bookmark_edit_destroy_cb(GtkWidget *, gpointer data)
221 auto p = static_cast<BookPropData *>(data);
223 bookmark_free(p->bb);
227 static void bookmark_edit_cancel_cb(GenericDialog *, gpointer)
231 static void bookmark_edit_ok_cb(GenericDialog *, gpointer data)
233 auto p = static_cast<BookPropData *>(data);
239 name = gq_gtk_entry_get_text(GTK_ENTRY(p->name_entry));
240 path = remove_trailing_slash(gq_gtk_entry_get_text(GTK_ENTRY(p->path_entry)));
241 icon = gq_gtk_entry_get_text(GTK_ENTRY(p->icon_entry));
243 new_string = bookmark_string(name, path, icon);
247 history_list_item_change(p->bb->parent, p->bb->key, new_string);
251 history_list_add_to_key(p->bb->parent, new_string, 0);
254 if (path && strlen(path) > 0) tab_completion_append_to_history(p->path_entry, path);
255 if (icon && strlen(icon) > 0) tab_completion_append_to_history(p->icon_entry, icon);
260 bookmark_populate_all(p->bb->parent);
263 /* simply pass NULL for text to turn this into a 'new bookmark' dialog */
265 static void bookmark_edit(const gchar *key, const gchar *text, GtkWidget *parent)
273 if (!key) key = "bookmarks";
275 p = g_new0(BookPropData, 1);
277 p->bb = bookmark_from_string(text);
278 p->bb->parent = g_strdup(key);
280 gd = generic_dialog_new(_("Edit Bookmark"), "bookmark_edit",
282 bookmark_edit_cancel_cb, p);
283 g_signal_connect(G_OBJECT(gd->dialog), "destroy",
284 G_CALLBACK(bookmark_edit_destroy_cb), p);
286 generic_dialog_add_message(gd, nullptr, _("Edit Bookmark"), nullptr, FALSE);
288 generic_dialog_add_button(gd, GQ_ICON_OK, "OK",
289 bookmark_edit_ok_cb, TRUE);
291 table = pref_table_new(gd->vbox, 3, 2, FALSE, TRUE);
292 pref_table_label(table, 0, 0, _("Name:"), GTK_ALIGN_END);
294 p->name_entry = gtk_entry_new();
295 gtk_widget_set_size_request(p->name_entry, 300, -1);
296 if (p->bb->name) gq_gtk_entry_set_text(GTK_ENTRY(p->name_entry), p->bb->name);
297 gq_gtk_grid_attach_default(GTK_GRID(table), p->name_entry, 1, 2, 0, 1);
298 generic_dialog_attach_default(gd, p->name_entry);
299 gtk_widget_show(p->name_entry);
301 pref_table_label(table, 0, 1, _("Path:"), GTK_ALIGN_END);
303 label = tab_completion_new_with_history(&p->path_entry, p->bb->path,
304 "bookmark_path", -1, nullptr, nullptr);
305 tab_completion_add_select_button(p->path_entry, nullptr, TRUE);
306 gq_gtk_grid_attach_default(GTK_GRID(table), label, 1, 2, 1, 2);
307 generic_dialog_attach_default(gd, p->path_entry);
308 gtk_widget_show(label);
310 pref_table_label(table, 0, 2, _("Icon:"), GTK_ALIGN_END);
313 if (!icon) icon = "";
314 label = tab_completion_new_with_history(&p->icon_entry, icon,
315 "bookmark_icons", -1, nullptr, nullptr);
316 tab_completion_add_select_button(p->icon_entry, _("Select icon"), FALSE);
317 gq_gtk_grid_attach_default(GTK_GRID(table), label, 1, 2, 2, 3);
318 generic_dialog_attach_default(gd, p->icon_entry);
319 gtk_widget_show(label);
321 gtk_widget_show(gd->dialog);
324 static void bookmark_move(BookMarkData *bm, GtkWidget *button, gint direction)
329 const gchar *key_holder;
331 if (!bm->editable) return;
333 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
336 list = gtk_container_get_children(GTK_CONTAINER(bm->box));
337 p = g_list_index(list, button);
340 if (p < 0 || p + direction < 0) return;
342 key_holder = bm->key;
343 bm->key = "_TEMPHOLDER";
344 history_list_item_move(key_holder, b->key, -direction);
345 bookmark_populate_all(key_holder);
346 bm->key = key_holder;
348 gtk_box_reorder_child(GTK_BOX(bm->box), button, p + direction);
351 static void bookmark_menu_prop_cb(GtkWidget *widget, gpointer data)
353 auto bm = static_cast<BookMarkData *>(data);
355 if (!bm->active_button) return;
357 bookmark_edit(bm->key, bm->active_button->key, widget);
360 static void bookmark_menu_move(BookMarkData *bm, gint direction)
362 if (!bm->active_button) return;
364 bookmark_move(bm, bm->active_button->button, direction);
367 static void bookmark_menu_up_cb(GtkWidget *, gpointer data)
369 bookmark_menu_move(static_cast<BookMarkData *>(data), -1);
372 static void bookmark_menu_down_cb(GtkWidget *, gpointer data)
374 bookmark_menu_move(static_cast<BookMarkData *>(data), 1);
377 static void bookmark_menu_remove_cb(GtkWidget *, gpointer data)
379 auto bm = static_cast<BookMarkData *>(data);
381 if (!bm->active_button) return;
383 history_list_item_remove(bm->key, bm->active_button->key);
384 bookmark_populate_all(bm->key);
387 static void bookmark_menu_popup(BookMarkData *bm, GtkWidget *button, gint, guint32, gboolean local)
392 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
395 bm->active_button = b;
397 menu = popup_menu_short_lived();
398 menu_item_add_icon_sensitive(menu, _("_Properties..."), PIXBUF_INLINE_ICON_PROPERTIES, bm->editable,
399 G_CALLBACK(bookmark_menu_prop_cb), bm);
400 menu_item_add_icon_sensitive(menu, _("Move _up"), GQ_ICON_GO_UP, bm->editable,
401 G_CALLBACK(bookmark_menu_up_cb), bm);
402 menu_item_add_icon_sensitive(menu, _("Move _down"), GQ_ICON_GO_DOWN, bm->editable,
403 G_CALLBACK(bookmark_menu_down_cb), bm);
404 menu_item_add_icon_sensitive(menu, _("_Remove"), GQ_ICON_REMOVE, bm->editable,
405 G_CALLBACK(bookmark_menu_remove_cb), bm);
409 gtk_menu_popup_at_widget(GTK_MENU(menu), button, GDK_GRAVITY_NORTH_EAST, GDK_GRAVITY_CENTER, nullptr);
413 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
417 static gboolean bookmark_press_cb(GtkWidget *button, GdkEventButton *event, gpointer data)
419 auto bm = static_cast<BookMarkData *>(data);
421 if (event->button != MOUSE_BUTTON_RIGHT) return FALSE;
423 bookmark_menu_popup(bm, button, event->button, event->time, FALSE);
428 static gboolean bookmark_keypress_cb(GtkWidget *button, GdkEventKey *event, gpointer data)
430 auto bm = static_cast<BookMarkData *>(data);
432 switch (event->keyval)
435 if (!(event->state & GDK_CONTROL_MASK)) return FALSE;
438 bookmark_menu_popup(bm, button, 0, event->time, TRUE);
442 if (event->state & GDK_SHIFT_MASK)
444 bookmark_move(bm, button, -1);
449 if (event->state & GDK_SHIFT_MASK)
451 bookmark_move(bm, button, 1);
460 static void bookmark_drag_set_data(GtkWidget *button,
461 GdkDragContext *context, GtkSelectionData *selection_data,
462 guint, guint, gpointer data)
464 auto bm = static_cast<BookMarkData *>(data);
466 GList *list = nullptr;
469 if (gdk_drag_context_get_dest_window(context) == gtk_widget_get_window(bm->widget)) return;
471 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
474 list = g_list_append(list, b->path);
476 gchar **uris = uris_from_pathlist(list);
477 gboolean ret = gtk_selection_data_set_uris(selection_data, uris);
480 char *str = g_strjoinv("\r\n", uris);
481 ret = gtk_selection_data_set_text(selection_data, str, -1);
489 static void bookmark_drag_begin(GtkWidget *button, GdkDragContext *context, gpointer)
492 GdkModifierType mask;
495 GtkAllocation allocation;
499 gtk_widget_get_allocation(button, &allocation);
501 pixbuf = gdk_pixbuf_get_from_window(gtk_widget_get_window(button),
502 allocation.x, allocation.y,
503 allocation.width, allocation.height);
504 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(button)));
505 device = gdk_seat_get_pointer(seat);
506 gdk_window_get_device_position(gtk_widget_get_window(button), device, &x, &y, &mask);
508 gtk_drag_set_icon_pixbuf(context, pixbuf,
509 x - allocation.x, y - allocation.y);
510 g_object_unref(pixbuf);
513 static gboolean bookmark_path_tooltip_cb(GtkWidget *button, gpointer)
517 b = static_cast<BookButtonData *>(g_object_get_data(G_OBJECT(button), "bookbuttondata"));
518 gtk_widget_set_tooltip_text(GTK_WIDGET(button), b->path);
523 static void bookmark_populate(BookMarkData *bm)
529 box = GTK_BOX(bm->box);
530 children = gtk_container_get_children(GTK_CONTAINER(box));
534 GtkWidget *widget = GTK_WIDGET(work->data);
536 gq_gtk_widget_destroy(widget);
539 if (!bm->no_defaults && !history_list_get_by_key(bm->key))
544 if (!bookmark_default_list)
546 buf = bookmark_string(_("Home"), homedir(), nullptr);
547 history_list_add_to_key(bm->key, buf, 0);
550 if (g_strcmp0(bm->key, "shortcuts") != 0)
552 buf = bookmark_string(".", g_strdup(history_list_find_last_path_by_key("path_list")), nullptr);
553 history_list_add_to_key(bm->key, buf, 0);
557 path = g_build_filename(homedir(), "Desktop", NULL);
560 buf = bookmark_string(_("Desktop"), path, nullptr);
561 history_list_add_to_key(bm->key, buf, 0);
567 work = bookmark_default_list;
568 while (work && work->next)
572 name = static_cast<gchar *>(work->data);
574 path = static_cast<gchar *>(work->data);
577 if (strcmp(name, ".") == 0)
579 if (g_strcmp0(bm->key, "shortcuts") != 0)
581 buf = bookmark_string(name, g_strdup(history_list_find_last_path_by_key("path_list")), nullptr);
590 buf = bookmark_string(name, path, nullptr);
592 history_list_add_to_key(bm->key, buf, 0);
597 work = history_list_get_by_key(bm->key);
598 work = g_list_last(work);
603 b = bookmark_from_string(static_cast<const gchar *>(work->data));
606 if (strcmp(b->name, ".") == 0)
610 b->path = g_strdup(history_list_find_last_path_by_key("path_list"));
611 buf = bookmark_string(".", b->path, b->icon);
612 history_list_item_change("bookmarks", b->key, buf);
613 b->key = g_strdup(buf);
618 b->button = gtk_button_new();
619 gtk_button_set_relief(GTK_BUTTON(b->button), GTK_RELIEF_NONE);
620 gq_gtk_box_pack_start(GTK_BOX(bm->box), b->button, FALSE, FALSE, 0);
621 gtk_widget_show(b->button);
623 g_object_set_data_full(G_OBJECT(b->button), "bookbuttondata",
624 b, reinterpret_cast<GDestroyNotify>(bookmark_free));
626 box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
627 gq_gtk_container_add(GTK_WIDGET(b->button), box);
628 gtk_widget_show(box);
632 GdkPixbuf *pixbuf = nullptr;
635 iconl = path_from_utf8(b->icon);
636 pixbuf = gdk_pixbuf_new_from_file(iconl, nullptr);
640 pixbuf = gdk_pixbuf_new_from_file(iconl, nullptr);
648 gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &w, &h);
650 pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), b->icon, w, GTK_ICON_LOOKUP_NO_SVG, nullptr);
661 gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &w, &h);
663 scaled = gdk_pixbuf_scale_simple(pixbuf, w, h,
664 GDK_INTERP_BILINEAR);
665 b->image = gtk_image_new_from_pixbuf(scaled);
666 g_object_unref(scaled);
667 g_object_unref(pixbuf);
671 b->image = gtk_image_new_from_icon_name(GQ_ICON_DIRECTORY, GTK_ICON_SIZE_BUTTON);
676 b->image = gtk_image_new_from_icon_name(GQ_ICON_DIRECTORY, GTK_ICON_SIZE_BUTTON);
678 gq_gtk_box_pack_start(GTK_BOX(box), b->image, FALSE, FALSE, 0);
679 gtk_widget_show(b->image);
681 b->label = gtk_label_new(b->name);
682 gq_gtk_box_pack_start(GTK_BOX(box), b->label, FALSE, FALSE, 0);
683 gtk_widget_show(b->label);
685 g_signal_connect(G_OBJECT(b->button), "clicked",
686 G_CALLBACK(bookmark_select_cb), bm);
687 g_signal_connect(G_OBJECT(b->button), "button_press_event",
688 G_CALLBACK(bookmark_press_cb), bm);
689 g_signal_connect(G_OBJECT(b->button), "key_press_event",
690 G_CALLBACK(bookmark_keypress_cb), bm);
692 gtk_drag_source_set(b->button, GDK_BUTTON1_MASK,
693 bookmark_drag_types, bookmark_drag_types_n,
694 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
695 g_signal_connect(G_OBJECT(b->button), "drag_data_get",
696 G_CALLBACK(bookmark_drag_set_data), bm);
697 g_signal_connect(G_OBJECT(b->button), "drag_begin",
698 G_CALLBACK(bookmark_drag_begin), bm);
700 gtk_widget_set_has_tooltip(GTK_WIDGET(b->button), TRUE);
701 g_signal_connect(G_OBJECT(b->button), "query_tooltip", G_CALLBACK(bookmark_path_tooltip_cb), bm);
708 static void bookmark_populate_all(const gchar *key)
714 work = bookmark_widget_list;
719 bm = static_cast<BookMarkData *>(work->data);
722 if (strcmp(bm->key, key) == 0)
724 bookmark_populate(bm);
729 static void bookmark_dnd_get_data(GtkWidget *, GdkDragContext *,
731 GtkSelectionData *selection_data, guint,
732 guint, gpointer data)
734 auto bm = static_cast<BookMarkData *>(data);
735 GList *list = nullptr;
736 GList *errors = nullptr;
741 if (!bm->editable) return;
743 uris = gtk_selection_data_get_uris(selection_data);
746 list = uri_pathlist_from_uris(uris, &errors);
749 warning_dialog_dnd_uri_error(errors);
750 g_list_free_full(errors, g_free);
757 auto path = static_cast<gchar *>(work->data);
762 if (bm->only_directories && !isdir(path)) continue;
764 real_path = realpath(path, nullptr);
766 if (strstr(real_path, get_collections_dir()) && isfile(path))
768 buf = bookmark_string(filename_from_path(path), path, "gq-icon-collection");
770 else if (isfile(path))
772 buf = bookmark_string(filename_from_path(path), path, GQ_ICON_FILE);
776 buf = bookmark_string(filename_from_path(path), path, nullptr);
778 history_list_add_to_key(bm->key, buf, 0);
783 g_list_free_full(list, g_free);
785 bookmark_populate_all(bm->key);
789 static void bookmark_list_destroy(GtkWidget *, gpointer data)
791 auto bm = static_cast<BookMarkData *>(data);
793 bookmark_widget_list = g_list_remove(bookmark_widget_list, bm);
795 g_free(const_cast<gchar *>(bm->key));
799 GtkWidget *bookmark_list_new(const gchar *key,
800 void (*select_func)(const gchar *path, gpointer data), gpointer select_data)
805 if (!key) key = "bookmarks";
807 bm = g_new0(BookMarkData, 1);
808 bm->key = g_strdup(key);
810 bm->select_func = select_func;
811 bm->select_data = select_data;
813 bm->no_defaults = FALSE;
815 bm->only_directories = FALSE;
817 scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
823 layout = gtk_widget_create_pango_layout(GTK_WIDGET(scrolled), "reasonable width");
824 pango_layout_get_pixel_size(layout, &width, &height);
825 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scrolled), width);
826 g_object_unref(layout);
828 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
830 bm->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
831 gq_gtk_container_add(GTK_WIDGET(scrolled), bm->box);
832 gtk_widget_show(bm->box);
834 bookmark_populate(bm);
836 g_signal_connect(G_OBJECT(bm->box), "destroy",
837 G_CALLBACK(bookmark_list_destroy), bm);
838 g_object_set_data(G_OBJECT(bm->box), BOOKMARK_DATA_KEY, bm);
839 g_object_set_data(G_OBJECT(scrolled), BOOKMARK_DATA_KEY, bm);
840 bm->widget = scrolled;
842 gtk_drag_dest_set(scrolled,
843 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP),
844 bookmark_drop_types, bookmark_drop_types_n,
845 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
846 g_signal_connect(G_OBJECT(scrolled), "drag_data_received",
847 G_CALLBACK(bookmark_dnd_get_data), bm);
849 bookmark_widget_list = g_list_append(bookmark_widget_list, bm);
854 void bookmark_list_set_key(GtkWidget *list, const gchar *key)
858 if (!list || !key) return;
860 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
863 if (bm->key && strcmp(bm->key, key) == 0) return;
865 g_free(const_cast<gchar *>(bm->key));
866 bm->key = g_strdup(key);
868 bookmark_populate(bm);
871 void bookmark_list_set_no_defaults(GtkWidget *list, gboolean no_defaults)
875 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
878 bm->no_defaults = no_defaults;
881 void bookmark_list_set_editable(GtkWidget *list, gboolean editable)
885 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
888 bm->editable = editable;
891 void bookmark_list_set_only_directories(GtkWidget *list, gboolean only_directories)
895 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
898 bm->only_directories = only_directories;
901 void bookmark_list_add(GtkWidget *list, const gchar *name, const gchar *path)
906 bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
909 std::unique_ptr<gchar, decltype(&g_free)> buf(bookmark_string(name, path, nullptr), g_free);
910 real_path = realpath(path, nullptr);
912 if (strstr(real_path, get_collections_dir()) && isfile(path))
914 buf.reset(bookmark_string(name, path, "gq-icon-collection"));
920 buf.reset(bookmark_string(name, path, GQ_ICON_FILE));
924 buf.reset(bookmark_string(name, path, nullptr));
928 history_list_add_to_key(bm->key, buf.get(), 0);
931 bookmark_populate_all(bm->key);
934 void bookmark_add_default(const gchar *name, const gchar *path)
936 if (!name || !path) return;
937 bookmark_default_list = g_list_append(bookmark_default_list, g_strdup(name));
938 bookmark_default_list = g_list_append(bookmark_default_list, g_strdup(path));
942 *-----------------------------------------------------------------------------
943 * combo with history key
944 *-----------------------------------------------------------------------------
947 struct HistoryComboData
955 static void history_combo_destroy(GtkWidget *, gpointer data)
957 auto hc = static_cast<HistoryComboData *>(data);
959 g_free(hc->history_key);
963 /* if text is NULL, entry is set to the most recent item */
964 GtkWidget *history_combo_new(GtkWidget **entry, const gchar *text,
965 const gchar *history_key, gint max_levels)
967 HistoryComboData *hc;
971 hc = g_new0(HistoryComboData, 1);
972 hc->history_key = g_strdup(history_key);
973 hc->history_levels = max_levels;
975 hc->combo = gtk_combo_box_text_new_with_entry();
977 hc->entry = gtk_bin_get_child(GTK_BIN(hc->combo));
979 g_object_set_data(G_OBJECT(hc->combo), "history_combo_data", hc);
980 g_object_set_data(G_OBJECT(hc->entry), "history_combo_data", hc);
981 g_signal_connect(G_OBJECT(hc->combo), "destroy",
982 G_CALLBACK(history_combo_destroy), hc);
984 work = history_list_get_by_key(hc->history_key);
987 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hc->combo), static_cast<gchar *>(work->data));
994 gq_gtk_entry_set_text(GTK_ENTRY(hc->entry), text);
998 gtk_combo_box_set_active(GTK_COMBO_BOX(hc->combo), 0);
1001 if (entry) *entry = hc->entry;
1005 /* if text is NULL, current entry text is used
1006 * widget can be the combo or entry widget
1008 void history_combo_append_history(GtkWidget *widget, const gchar *text)
1010 HistoryComboData *hc;
1013 hc = static_cast<HistoryComboData *>(g_object_get_data(G_OBJECT(widget), "history_combo_data"));
1016 log_printf("widget is not a history combo\n");
1022 new_text = g_strdup(text);
1026 new_text = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(hc->entry)));
1029 if (new_text && strlen(new_text) > 0)
1031 GtkTreeModel *store;
1034 history_list_add_to_key(hc->history_key, new_text, hc->history_levels);
1036 gtk_combo_box_set_active(GTK_COMBO_BOX(hc->combo), -1);
1038 store = gtk_combo_box_get_model(GTK_COMBO_BOX(hc->combo));
1039 gtk_list_store_clear(GTK_LIST_STORE(store));
1041 work = history_list_get_by_key(hc->history_key);
1044 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hc->combo), static_cast<gchar *>(work->data));
1051 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */