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.
33 #include <gdk/gdkkeysyms.h> /* for key values */
38 #include "history_list.h"
40 #include "ui_bookmark.h"
41 #include "ui_fileops.h"
44 #include "ui_utildlg.h"
45 #include "ui_tabcomp.h"
46 #include "uri_utils.h"
51 *-----------------------------------------------------------------------------
53 *-----------------------------------------------------------------------------
56 #define BOOKMARK_DATA_KEY "bookmarkdata"
57 #define MARKER_PATH "[path]"
58 #define MARKER_ICON "[icon]"
60 typedef struct _BookMarkData BookMarkData;
61 typedef struct _BookButtonData BookButtonData;
62 typedef struct _BookPropData BookPropData;
70 void (*select_func)(const gchar *path, gpointer data);
75 gboolean only_directories;
77 BookButtonData *active_button;
80 struct _BookButtonData
95 GtkWidget *name_entry;
96 GtkWidget *path_entry;
97 GtkWidget *icon_entry;
108 static GtkTargetEntry bookmark_drop_types[] = {
109 { "text/uri-list", 0, TARGET_URI_LIST },
110 { "x-url/http", 0, TARGET_X_URL },
111 { "_NETSCAPE_URL", 0, TARGET_X_URL }
113 #define bookmark_drop_types_n 3
115 static GtkTargetEntry bookmark_drag_types[] = {
116 { "text/uri-list", 0, TARGET_URI_LIST },
117 { "text/plain", 0, TARGET_TEXT_PLAIN }
119 #define bookmark_drag_types_n 2
122 static GList *bookmark_widget_list = NULL;
123 static GList *bookmark_default_list = NULL;
126 static void bookmark_populate_all(const gchar *key);
129 static BookButtonData *bookmark_from_string(const gchar *text)
132 const gchar *path_ptr;
133 const gchar *icon_ptr;
135 b = g_new0(BookButtonData, 1);
139 b->name = g_strdup(_("New Bookmark"));
140 b->path = g_strdup(homedir());
145 b->key = g_strdup(text);
147 path_ptr = strstr(text, MARKER_PATH);
148 icon_ptr = strstr(text, MARKER_ICON);
150 if (path_ptr && icon_ptr && icon_ptr < path_ptr)
152 log_printf("warning, bookmark icon must be after path\n");
161 b->name = g_strndup(text, l);
162 path_ptr += strlen(MARKER_PATH);
165 l = icon_ptr - path_ptr;
166 b->path = g_strndup(path_ptr, l);
170 b->path = g_strdup(path_ptr);
175 b->name = g_strdup(text);
176 b->path = g_strdup("");
181 icon_ptr += strlen(MARKER_ICON);
182 b->icon = g_strdup(icon_ptr);
188 static void bookmark_free(BookButtonData *b)
200 static gchar *bookmark_string(const gchar *name, const gchar *path, const gchar *icon)
202 if (!name) name = _("New Bookmark");
203 if (icon && strncmp(icon, G_DIR_SEPARATOR_S, 1) != 0) icon = NULL;
207 return g_strdup_printf("%s"MARKER_PATH"%s"MARKER_ICON"%s", name, path, icon);
210 return g_strdup_printf("%s"MARKER_PATH"%s", name, path);
213 static void bookmark_select_cb(GtkWidget *button, gpointer data)
215 BookMarkData *bm = data;
218 b = g_object_get_data(G_OBJECT(button), "bookbuttondata");
221 if (bm->select_func) bm->select_func(b->path, bm->select_data);
224 static void bookmark_edit_destroy_cb(GtkWidget *widget, gpointer data)
226 BookPropData *p = data;
228 bookmark_free(p->bb);
232 static void bookmark_edit_cancel_cb(GenericDialog *gd, gpointer data)
236 static void bookmark_edit_ok_cb(GenericDialog *gd, gpointer data)
238 BookPropData *p = data;
244 name = gtk_entry_get_text(GTK_ENTRY(p->name_entry));
245 path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(p->path_entry)));
246 icon = gtk_entry_get_text(GTK_ENTRY(p->icon_entry));
248 new = bookmark_string(name, path, icon);
252 history_list_item_change(p->bb->parent, p->bb->key, new);
256 history_list_add_to_key(p->bb->parent, new, 0);
259 if (path && strlen(path) > 0) tab_completion_append_to_history(p->path_entry, path);
260 if (icon && strlen(icon) > 0) tab_completion_append_to_history(p->icon_entry, icon);
265 bookmark_populate_all(p->bb->parent);
268 /* simply pass NULL for text to turn this into a 'new bookmark' dialog */
270 static void bookmark_edit(const gchar *key, const gchar *text, GtkWidget *parent)
278 if (!key) key = "bookmarks";
280 p = g_new0(BookPropData, 1);
282 p->bb = bookmark_from_string(text);
283 p->bb->parent = g_strdup(key);
285 gd = generic_dialog_new(_("Edit Bookmark"), "bookmark_edit",
287 bookmark_edit_cancel_cb, p);
288 g_signal_connect(G_OBJECT(gd->dialog), "destroy",
289 G_CALLBACK(bookmark_edit_destroy_cb), p);
291 generic_dialog_add_message(gd, NULL, _("Edit Bookmark"), NULL, FALSE);
293 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
294 bookmark_edit_ok_cb, TRUE);
296 table = pref_table_new(gd->vbox, 3, 2, FALSE, TRUE);
297 pref_table_label(table, 0, 0, _("Name:"), 1.0);
299 p->name_entry = gtk_entry_new();
300 gtk_widget_set_size_request(p->name_entry, 300, -1);
301 if (p->bb->name) gtk_entry_set_text(GTK_ENTRY(p->name_entry), p->bb->name);
302 gtk_table_attach_defaults(GTK_TABLE(table), p->name_entry, 1, 2, 0, 1);
303 generic_dialog_attach_default(gd, p->name_entry);
304 gtk_widget_show(p->name_entry);
306 pref_table_label(table, 0, 1, _("Path:"), 1.0);
308 label = tab_completion_new_with_history(&p->path_entry, p->bb->path,
309 "bookmark_path", -1, NULL, NULL);
310 tab_completion_add_select_button(p->path_entry, NULL, TRUE);
311 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2);
312 generic_dialog_attach_default(gd, p->path_entry);
313 gtk_widget_show(label);
315 pref_table_label(table, 0, 2, _("Icon:"), 1.0);
318 if (!icon) icon = "";
319 label = tab_completion_new_with_history(&p->icon_entry, icon,
320 "bookmark_icons", -1, NULL, NULL);
321 tab_completion_add_select_button(p->icon_entry, _("Select icon"), FALSE);
322 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 2, 3);
323 generic_dialog_attach_default(gd, p->icon_entry);
324 gtk_widget_show(label);
326 gtk_widget_show(gd->dialog);
329 static void bookmark_move(BookMarkData *bm, GtkWidget *button, gint direction)
336 if (!bm->editable) return;
338 b = g_object_get_data(G_OBJECT(button), "bookbuttondata");
341 list = gtk_container_get_children(GTK_CONTAINER(bm->box));
342 p = g_list_index(list, button);
345 if (p < 0 || p + direction < 0) return;
347 key_holder = bm->key;
348 bm->key = "_TEMPHOLDER";
349 history_list_item_move(key_holder, b->key, -direction);
350 bookmark_populate_all(key_holder);
351 bm->key = key_holder;
353 gtk_box_reorder_child(GTK_BOX(bm->box), button, p + direction);
356 static void bookmark_menu_prop_cb(GtkWidget *widget, gpointer data)
358 BookMarkData *bm = data;
360 if (!bm->active_button) return;
362 bookmark_edit(bm->key, bm->active_button->key, widget);
365 static void bookmark_menu_move(BookMarkData *bm, gint direction)
367 if (!bm->active_button) return;
369 bookmark_move(bm, bm->active_button->button, direction);
372 static void bookmark_menu_up_cb(GtkWidget *widget, gpointer data)
374 bookmark_menu_move(data, -1);
377 static void bookmark_menu_down_cb(GtkWidget *widget, gpointer data)
379 bookmark_menu_move(data, 1);
382 static void bookmark_menu_remove_cb(GtkWidget *widget, gpointer data)
384 BookMarkData *bm = data;
386 if (!bm->active_button) return;
388 history_list_item_remove(bm->key, bm->active_button->key);
389 bookmark_populate_all(bm->key);
392 static void bookmark_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gint *pushed_in, gpointer data)
394 GtkWidget *button = data;
395 GtkAllocation allocation;
397 gtk_widget_set_allocation(button, &allocation);
398 gdk_window_get_origin(gtk_widget_get_window(button), x, y);
399 *y += allocation.y + allocation.height;
402 static void bookmark_menu_popup(BookMarkData *bm, GtkWidget *button,
403 gint button_n, guint32 time, gboolean local)
408 b = g_object_get_data(G_OBJECT(button), "bookbuttondata");
411 bm->active_button = b;
413 menu = popup_menu_short_lived();
414 menu_item_add_stock_sensitive(menu, _("_Properties..."), GTK_STOCK_PROPERTIES, bm->editable,
415 G_CALLBACK(bookmark_menu_prop_cb), bm);
416 menu_item_add_stock_sensitive(menu, _("Move _up"), GTK_STOCK_GO_UP, bm->editable,
417 G_CALLBACK(bookmark_menu_up_cb), bm);
418 menu_item_add_stock_sensitive(menu, _("Move _down"), GTK_STOCK_GO_DOWN, bm->editable,
419 G_CALLBACK(bookmark_menu_down_cb), bm);
420 menu_item_add_stock_sensitive(menu, _("_Remove"), GTK_STOCK_REMOVE, bm->editable,
421 G_CALLBACK(bookmark_menu_remove_cb), bm);
425 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
426 bookmark_menu_position_cb, button, button_n, time);
430 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button_n, time);
434 static gboolean bookmark_press_cb(GtkWidget *button, GdkEventButton *event, gpointer data)
436 BookMarkData *bm = data;
438 if (event->button != MOUSE_BUTTON_RIGHT) return FALSE;
440 bookmark_menu_popup(bm, button, event->button, event->time, FALSE);
445 static gboolean bookmark_keypress_cb(GtkWidget *button, GdkEventKey *event, gpointer data)
447 BookMarkData *bm = data;
449 switch (event->keyval)
452 if (!(event->state & GDK_CONTROL_MASK)) return FALSE;
455 bookmark_menu_popup(bm, button, 0, event->time, TRUE);
459 if (event->state & GDK_SHIFT_MASK)
461 bookmark_move(bm, button, -1);
466 if (event->state & GDK_SHIFT_MASK)
468 bookmark_move(bm, button, 1);
477 static void bookmark_drag_set_data(GtkWidget *button,
478 GdkDragContext *context, GtkSelectionData *selection_data,
479 guint info, guint time, gpointer data)
481 BookMarkData *bm = data;
485 #if GTK_CHECK_VERSION(3,0,0)
487 if (gdk_drag_context_get_dest_window(context) == gtk_widget_get_window(bm->widget)) return;
489 if (context->dest_window == bm->widget->window) return;
492 b = g_object_get_data(G_OBJECT(button), "bookbuttondata");
495 list = g_list_append(list, b->path);
497 gchar **uris = uris_from_pathlist(list);
498 gboolean ret = gtk_selection_data_set_uris(selection_data, uris);
501 char *str = g_strjoinv("\r\n", uris);
502 ret = gtk_selection_data_set_text(selection_data, str, -1);
510 static void bookmark_drag_begin(GtkWidget *button, GdkDragContext *context, gpointer data)
513 GdkModifierType mask;
515 GtkAllocation allocation;
516 #if GTK_CHECK_VERSION(3,0,0)
517 GdkDeviceManager *device_manager;
521 gtk_widget_get_allocation(button, &allocation);
523 #if GTK_CHECK_VERSION(3,0,0)
524 pixbuf = gdk_pixbuf_get_from_window(gtk_widget_get_window(button),
525 allocation.x, allocation.y,
526 allocation.width, allocation.height);
527 device_manager = gdk_display_get_device_manager(gdk_window_get_display(gtk_widget_get_window(button)));
528 device = gdk_device_manager_get_client_pointer(device_manager);
529 gdk_window_get_device_position(gtk_widget_get_window(button), device, &x, &y, &mask);
531 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
532 allocation.width, allocation.height);
533 gdk_pixbuf_get_from_drawable(pixbuf, gtk_widget_get_window(button), NULL,
534 allocation.x, allocation.y,
535 0, 0, allocation.width, allocation.height);
536 gdk_window_get_pointer(gtk_widget_get_window(button), &x, &y, &mask);
539 gtk_drag_set_icon_pixbuf(context, pixbuf,
540 x - allocation.x, y - allocation.y);
541 g_object_unref(pixbuf);
544 static gboolean bookmark_path_tooltip_cb(GtkWidget *button, gpointer data)
546 BookMarkData *bm = data;
549 b = g_object_get_data(G_OBJECT(button), "bookbuttondata");
550 gtk_widget_set_tooltip_text(GTK_WIDGET(button), b->path);
555 static void bookmark_populate(BookMarkData *bm)
561 box = GTK_BOX(bm->box);
562 children = gtk_container_get_children(GTK_CONTAINER(box));
566 GtkWidget *widget = GTK_WIDGET(work->data);
568 gtk_widget_destroy(widget);
571 if (!bm->no_defaults && !history_list_get_by_key(bm->key))
576 if (!bookmark_default_list)
578 buf = bookmark_string(_("Home"), homedir(), NULL);
579 history_list_add_to_key(bm->key, buf, 0);
582 buf = bookmark_string(".", g_strdup(history_list_find_last_path_by_key("path_list")), NULL);
583 history_list_add_to_key(bm->key, buf, 0);
586 path = g_build_filename(homedir(), "Desktop", NULL);
589 buf = bookmark_string(_("Desktop"), path, NULL);
590 history_list_add_to_key(bm->key, buf, 0);
596 work = bookmark_default_list;
597 while (work && work->next)
606 if (strcmp(name, ".") == 0)
608 buf = bookmark_string(name, g_strdup(history_list_find_last_path_by_key("path_list")), NULL);
612 buf = bookmark_string(name, path, NULL);
614 history_list_add_to_key(bm->key, buf, 0);
619 work = history_list_get_by_key(bm->key);
620 work = g_list_last(work);
625 b = bookmark_from_string(work->data);
628 if (strcmp(b->name, ".") == 0)
632 b->path = g_strdup(history_list_find_last_path_by_key("path_list"));
633 buf = bookmark_string(".", b->path, b->icon);
634 history_list_item_change("bookmarks", b->key, buf);
635 b->key = g_strdup(buf);
640 b->button = gtk_button_new();
641 gtk_button_set_relief(GTK_BUTTON(b->button), GTK_RELIEF_NONE);
642 gtk_box_pack_start(GTK_BOX(bm->box), b->button, FALSE, FALSE, 0);
643 gtk_widget_show(b->button);
645 g_object_set_data_full(G_OBJECT(b->button), "bookbuttondata",
646 b, (GDestroyNotify)bookmark_free);
648 box = gtk_hbox_new(FALSE, PREF_PAD_BUTTON_GAP);
649 gtk_container_add(GTK_CONTAINER(b->button), box);
650 gtk_widget_show(box);
657 iconl = path_from_utf8(b->icon);
658 pixbuf = gdk_pixbuf_new_from_file(iconl, NULL);
666 gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &w, &h);
668 scaled = gdk_pixbuf_scale_simple(pixbuf, w, h,
669 GDK_INTERP_BILINEAR);
670 b->image = gtk_image_new_from_pixbuf(scaled);
671 g_object_unref(scaled);
672 g_object_unref(pixbuf);
676 b->image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE,
677 GTK_ICON_SIZE_BUTTON);
682 b->image = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_BUTTON);
684 gtk_box_pack_start(GTK_BOX(box), b->image, FALSE, FALSE, 0);
685 gtk_widget_show(b->image);
687 b->label = gtk_label_new(b->name);
688 gtk_box_pack_start(GTK_BOX(box), b->label, FALSE, FALSE, 0);
689 gtk_widget_show(b->label);
691 g_signal_connect(G_OBJECT(b->button), "clicked",
692 G_CALLBACK(bookmark_select_cb), bm);
693 g_signal_connect(G_OBJECT(b->button), "button_press_event",
694 G_CALLBACK(bookmark_press_cb), bm);
695 g_signal_connect(G_OBJECT(b->button), "key_press_event",
696 G_CALLBACK(bookmark_keypress_cb), bm);
698 gtk_drag_source_set(b->button, GDK_BUTTON1_MASK,
699 bookmark_drag_types, bookmark_drag_types_n,
700 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
701 g_signal_connect(G_OBJECT(b->button), "drag_data_get",
702 G_CALLBACK(bookmark_drag_set_data), bm);
703 g_signal_connect(G_OBJECT(b->button), "drag_begin",
704 G_CALLBACK(bookmark_drag_begin), bm);
706 gtk_widget_set_has_tooltip(GTK_WIDGET(b->button), TRUE);
707 g_signal_connect(G_OBJECT(b->button), "query_tooltip", G_CALLBACK(bookmark_path_tooltip_cb), bm);
714 static void bookmark_populate_all(const gchar *key)
720 work = bookmark_widget_list;
728 if (strcmp(bm->key, key) == 0)
730 bookmark_populate(bm);
735 static void bookmark_dnd_get_data(GtkWidget *widget,
736 GdkDragContext *context, gint x, gint y,
737 GtkSelectionData *selection_data, guint info,
738 guint time, gpointer data)
740 BookMarkData *bm = data;
742 GList *errors = NULL;
746 if (!bm->editable) return;
748 uris = gtk_selection_data_get_uris(selection_data);
751 list = uri_pathlist_from_uris(uris, &errors);
754 warning_dialog_dnd_uri_error(errors);
755 string_list_free(errors);
762 gchar *path = work->data;
767 if (bm->only_directories && !isdir(path)) continue;
768 buf = bookmark_string(filename_from_path(path), path, NULL);
769 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 *widget, gpointer data)
781 BookMarkData *bm = data;
783 bookmark_widget_list = g_list_remove(bookmark_widget_list, bm);
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);
809 #if GTK_CHECK_VERSION(3,0,0)
813 layout = gtk_widget_create_pango_layout(GTK_WIDGET(scrolled), "reasonable width");
814 pango_layout_get_pixel_size(layout, &width, &height);
815 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scrolled), width);
816 g_object_unref(layout);
818 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
820 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
823 bm->box = gtk_vbox_new(FALSE, 0);
824 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), bm->box);
825 gtk_widget_show(bm->box);
827 bookmark_populate(bm);
829 g_signal_connect(G_OBJECT(bm->box), "destroy",
830 G_CALLBACK(bookmark_list_destroy), bm);
831 g_object_set_data(G_OBJECT(bm->box), BOOKMARK_DATA_KEY, bm);
832 g_object_set_data(G_OBJECT(scrolled), BOOKMARK_DATA_KEY, bm);
833 bm->widget = scrolled;
835 gtk_drag_dest_set(scrolled,
836 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
837 bookmark_drop_types, bookmark_drop_types_n,
838 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
839 g_signal_connect(G_OBJECT(scrolled), "drag_data_received",
840 G_CALLBACK(bookmark_dnd_get_data), bm);
842 bookmark_widget_list = g_list_append(bookmark_widget_list, bm);
847 void bookmark_list_set_key(GtkWidget *list, const gchar *key)
851 if (!list || !key) return;
853 bm = g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY);
856 if (bm->key && strcmp(bm->key, key) == 0) return;
859 bm->key = g_strdup(key);
861 bookmark_populate(bm);
864 void bookmark_list_set_no_defaults(GtkWidget *list, gboolean no_defaults)
868 bm = g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY);
871 bm->no_defaults = no_defaults;
874 void bookmark_list_set_editable(GtkWidget *list, gboolean editable)
878 bm = g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY);
881 bm->editable = editable;
884 void bookmark_list_set_only_directories(GtkWidget *list, gboolean only_directories)
888 bm = g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY);
891 bm->only_directories = only_directories;
894 void bookmark_list_add(GtkWidget *list, const gchar *name, const gchar *path)
899 bm = g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY);
902 buf = bookmark_string(name, path, NULL);
903 history_list_add_to_key(bm->key, buf, 0);
906 bookmark_populate_all(bm->key);
909 void bookmark_add_default(const gchar *name, const gchar *path)
911 if (!name || !path) return;
912 bookmark_default_list = g_list_append(bookmark_default_list, g_strdup(name));
913 bookmark_default_list = g_list_append(bookmark_default_list, g_strdup(path));
917 *-----------------------------------------------------------------------------
918 * combo with history key
919 *-----------------------------------------------------------------------------
922 typedef struct _HistoryComboData HistoryComboData;
923 struct _HistoryComboData
931 static void history_combo_destroy(GtkWidget *widget, gpointer data)
933 HistoryComboData *hc = data;
935 g_free(hc->history_key);
939 /* if text is NULL, entry is set to the most recent item */
940 GtkWidget *history_combo_new(GtkWidget **entry, const gchar *text,
941 const gchar *history_key, gint max_levels)
943 HistoryComboData *hc;
947 hc = g_new0(HistoryComboData, 1);
948 hc->history_key = g_strdup(history_key);
949 hc->history_levels = max_levels;
951 hc->combo = gtk_combo_box_text_new_with_entry();
953 hc->entry = gtk_bin_get_child(GTK_BIN(hc->combo));
955 g_object_set_data(G_OBJECT(hc->combo), "history_combo_data", hc);
956 g_object_set_data(G_OBJECT(hc->entry), "history_combo_data", hc);
957 g_signal_connect(G_OBJECT(hc->combo), "destroy",
958 G_CALLBACK(history_combo_destroy), hc);
960 work = history_list_get_by_key(hc->history_key);
963 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hc->combo), (gchar *)work->data);
970 gtk_entry_set_text(GTK_ENTRY(hc->entry), text);
974 gtk_combo_box_set_active(GTK_COMBO_BOX(hc->combo), 0);
977 if (entry) *entry = hc->entry;
981 /* if text is NULL, current entry text is used
982 * widget can be the combo or entry widget
984 void history_combo_append_history(GtkWidget *widget, const gchar *text)
986 HistoryComboData *hc;
989 hc = g_object_get_data(G_OBJECT(widget), "history_combo_data");
992 log_printf("widget is not a history combo\n");
998 new_text = g_strdup(text);
1002 new_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(hc->entry)));
1005 if (new_text && strlen(new_text) > 0)
1007 GtkTreeModel *store;
1010 history_list_add_to_key(hc->history_key, new_text, hc->history_levels);
1012 gtk_combo_box_set_active(GTK_COMBO_BOX(hc->combo), -1);
1014 store = gtk_combo_box_get_model(GTK_COMBO_BOX(hc->combo));
1015 gtk_list_store_clear(GTK_LIST_STORE(store));
1017 work = history_list_get_by_key(hc->history_key);
1020 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hc->combo), (gchar *)work->data);
1027 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */