Pull the search UI construction code out into a distinct function.
[geeqie.git] / src / ui_bookmark.c
index 3a0e5eb..ae9a0fc 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -439,20 +448,20 @@ static gboolean bookmark_keypress_cb(GtkWidget *button, GdkEventKey *event, gpoi
 
        switch (event->keyval)
                {
-               case GDK_F10:
+               case GDK_KEY_F10:
                        if (!(event->state & GDK_CONTROL_MASK)) return FALSE;
-               case GDK_Menu:
+               case GDK_KEY_Menu:
                        bookmark_menu_popup(bm, button, 0, event->time, TRUE);
                        return TRUE;
                        break;
-               case GDK_Up:
+               case GDK_KEY_Up:
                        if (event->state & GDK_SHIFT_MASK)
                                {
                                bookmark_move(bm, button, -1);
                                return TRUE;
                                }
                        break;
-               case GDK_Down:
+               case GDK_KEY_Down:
                        if (event->state & GDK_SHIFT_MASK)
                                {
                                bookmark_move(bm, button, 1);
@@ -470,33 +479,31 @@ static void bookmark_drag_set_data(GtkWidget *button,
 {
        BookMarkData *bm = data;
        BookButtonData *b;
-       gchar *uri_text = NULL;
-       gint length = 0;
        GList *list = NULL;
 
-//     if (context->dest_window == bm->widget->window) return;
+#if GTK_CHECK_VERSION(3,0,0)
+       return;
+       if (gdk_drag_context_get_dest_window(context) == gtk_widget_get_window(bm->widget)) return;
+#else
+       if (context->dest_window == bm->widget->window) return;
+#endif
 
        b = g_object_get_data(G_OBJECT(button), "bookbuttondata");
        if (!b) return;
 
        list = g_list_append(list, b->path);
 
-       switch (info)
+       gchar **uris = uris_from_pathlist(list);
+       gboolean ret = gtk_selection_data_set_uris(selection_data, uris);
+       if (!ret)
                {
-               case TARGET_URI_LIST:
-                       uri_text = uri_text_from_list(list, &length, FALSE);
-                       break;
-               case TARGET_TEXT_PLAIN:
-                       uri_text = uri_text_from_list(list, &length, TRUE);
-                       break;
+               char *str = g_strjoinv("\r\n", uris);
+               ret = gtk_selection_data_set_text(selection_data, str, -1);
+               g_free(str);
                }
 
+       g_strfreev(uris);
        g_list_free(list);
-
-       if (!uri_text) return;
-
-       gtk_selection_data_set_text(selection_data, uri_text, length);
-       g_free(uri_text);
 }
 
 static void bookmark_drag_begin(GtkWidget *button, GdkDragContext *context, gpointer data)
@@ -505,16 +512,28 @@ static void bookmark_drag_begin(GtkWidget *button, GdkDragContext *context, gpoi
        GdkModifierType mask;
        gint x, y;
        GtkAllocation allocation;
-       
+#if GTK_CHECK_VERSION(3,0,0)
+       GdkDeviceManager *device_manager;
+       GdkDevice *device;
+#endif
+
        gtk_widget_get_allocation(button, &allocation);
 
+#if GTK_CHECK_VERSION(3,0,0)
+       pixbuf = gdk_pixbuf_get_from_window(gtk_widget_get_window(button),
+                                           allocation.x, allocation.y,
+                                           allocation.width, allocation.height);
+       device_manager = gdk_display_get_device_manager(gdk_window_get_display(gtk_widget_get_window(button)));
+       device = gdk_device_manager_get_client_pointer(device_manager);
+       gdk_window_get_device_position(gtk_widget_get_window(button), device, &x, &y, &mask);
+#else
        pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
                                allocation.width, allocation.height);
        gdk_pixbuf_get_from_drawable(pixbuf, gtk_widget_get_window(button), NULL,
                                     allocation.x, allocation.y,
                                     0, 0, allocation.width, allocation.height);
-
        gdk_window_get_pointer(gtk_widget_get_window(button), &x, &y, &mask);
+#endif
 
        gtk_drag_set_icon_pixbuf(context, pixbuf,
                                 x - allocation.x, y - allocation.y);
@@ -548,6 +567,10 @@ static void bookmark_populate(BookMarkData *bm)
                        history_list_add_to_key(bm->key, buf, 0);
                        g_free(buf);
 
+                       buf = bookmark_string(".", g_strdup(history_list_find_last_path_by_key("path_list")), NULL);
+                       history_list_add_to_key(bm->key, buf, 0);
+                       g_free(buf);
+
                        path = g_build_filename(homedir(), "Desktop", NULL);
                        if (isname(path))
                                {
@@ -568,7 +591,14 @@ static void bookmark_populate(BookMarkData *bm)
                        path = work->data;
                        work = work->next;
 
-                       buf = bookmark_string(name, path, NULL);
+                       if (strcmp(name, ".") == 0)
+                               {
+                               buf = bookmark_string(name, g_strdup(history_list_find_last_path_by_key("path_list")), NULL);
+                               }
+                       else
+                               {
+                               buf = bookmark_string(name, path, NULL);
+                               }
                        history_list_add_to_key(bm->key, buf, 0);
                        g_free(buf);
                        }
@@ -583,6 +613,16 @@ static void bookmark_populate(BookMarkData *bm)
                b = bookmark_from_string(work->data);
                if (b)
                        {
+                       if (strcmp(b->name, ".") == 0)
+                               {
+                               gchar *buf;
+
+                               b->path = g_strdup(history_list_find_last_path_by_key("path_list"));
+                               buf = bookmark_string(".", b->path, b->icon);
+                               history_list_item_change("bookmarks", b->key, buf);
+                               b->key = g_strdup(buf);
+                               g_free(buf);
+                               }
                        GtkWidget *box;
 
                        b->button = gtk_button_new();
@@ -684,17 +724,20 @@ static void bookmark_dnd_get_data(GtkWidget *widget,
 {
        BookMarkData *bm = data;
        GList *list = NULL;
+       GList *errors = NULL;
        GList *work;
+       gchar **uris;
 
        if (!bm->editable) return;
 
-       switch (info)
+       uris = gtk_selection_data_get_uris(selection_data);
+       list = uri_pathlist_from_uris(uris, &errors);
+       if(errors)
                {
-               case TARGET_URI_LIST:
-               case TARGET_X_URL:
-                       list = uri_list_from_text((gchar *)gtk_selection_data_get_data(selection_data), FALSE);
-                       break;
+               warning_dialog_dnd_uri_error(errors);
+               string_list_free(errors);
                }
+       g_strfreev(uris);
 
        work = list;
        while (work)
@@ -876,10 +919,6 @@ GtkWidget *history_combo_new(GtkWidget **entry, const gchar *text,
        hc->history_levels = max_levels;
 
        hc->combo = gtk_combo_box_text_new_with_entry();
-#if 0
-       gtk_combo_set_case_sensitive(GTK_COMBO(hc->combo), TRUE);
-       gtk_combo_set_use_arrows(GTK_COMBO(hc->combo), FALSE);
-#endif
 
        hc->entry = gtk_bin_get_child(GTK_BIN(hc->combo));