Eliminate a FIXME: Collection window position
[geeqie.git] / src / collect.c
index 7542a29..695133a 100644 (file)
@@ -1,32 +1,42 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
+ * Copyright (C) 2006 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.
  */
 
-
-#include "gqview.h"
+#include "main.h"
 #include "collect.h"
 
 #include "collect-dlg.h"
 #include "collect-io.h"
 #include "collect-table.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "img-view.h"
-#include "info.h"
 #include "layout.h"
 #include "layout_image.h"
+#include "misc.h"
 #include "pixbuf_util.h"
 #include "print.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_tree_edit.h"
+#include "utilops.h"
+#include "window.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
@@ -47,6 +57,8 @@ static void collection_window_update(CollectWindow *cw, CollectInfo *ci);
 
 static void collection_window_close(CollectWindow *cw);
 
+static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data);
+
 /*
  *-------------------------------------------------------------------
  * data, list handling
@@ -90,29 +102,21 @@ void collection_info_set_thumb(CollectInfo *ci, GdkPixbuf *pixbuf)
        ci->pixbuf = pixbuf;
 }
 
-gint collection_info_load_thumb(CollectInfo *ci)
+gboolean collection_info_load_thumb(CollectInfo *ci)
 {
        if (!ci) return FALSE;
 
        collection_info_free_thumb(ci);
 
-       printf("collection_info_load_thumb not implemented!\n(because an instant thumb loader not implemented)");
+       log_printf("collection_info_load_thumb not implemented!\n(because an instant thumb loader not implemented)");
        return FALSE;
-#if 0  
-       if (create_thumbnail(ci->fd->path, &ci->pixmap, &ci->mask) < 0) return FALSE;
-
-       if (ci->pixmap) gdk_pixmap_ref(ci->pixmap);
-       if (ci->mask) gdk_bitmap_ref(ci->mask);
-
-       return TRUE;
-#endif
 }
 
 void collection_list_free(GList *list)
 {
        GList *work;
        work = list;
-       while(work)
+       while (work)
                {
                collection_info_free((CollectInfo *)work->data);
                work = work->next;
@@ -128,8 +132,10 @@ static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
        const CollectInfo *cia = a;
        const CollectInfo *cib = b;
 
-       switch(collection_list_sort_method)
+       switch (collection_list_sort_method)
                {
+               case SORT_NAME:
+                       break;
                case SORT_NONE:
                        return 0;
                        break;
@@ -143,21 +149,27 @@ static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
                        if (cia->fd->date > cib->fd->date) return 1;
                        return 0;
                        break;
+               case SORT_CTIME:
+                       if (cia->fd->cdate < cib->fd->cdate) return -1;
+                       if (cia->fd->cdate > cib->fd->cdate) return 1;
+                       return 0;
+                       break;
                case SORT_PATH:
-                       return CASE_SORT(cia->fd->path, cib->fd->path);
+                       return utf8_compare(cia->fd->path, cib->fd->path, options->file_sort.case_sensitive);
                        break;
 #ifdef HAVE_STRVERSCMP
                case SORT_NUMBER:
                        return strverscmp(cia->fd->name, cib->fd->name);
                        break;
 #endif
-               case SORT_NAME:
                default:
-                       return CASE_SORT(cia->fd->name, cib->fd->name);
                        break;
                }
 
-       return 0;
+       if (options->file_sort.case_sensitive)
+               return strcmp(cia->fd->collate_key_name, cib->fd->collate_key_name);
+       else
+               return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase);
 }
 
 GList *collection_list_sort(GList *list, SortType method)
@@ -169,6 +181,30 @@ GList *collection_list_sort(GList *list, SortType method)
        return g_list_sort(list, collection_list_sort_cb);
 }
 
+GList *collection_list_randomize(GList *list)
+{
+       guint random, length, i;
+       gpointer tmp;
+       GList *nlist, *olist;
+
+       length = g_list_length(list);
+       if (!length) return NULL;
+
+       srand((unsigned int)time(NULL)); // Initialize random generator (hasn't to be that much strong)
+
+       for (i = 0; i < length; i++)
+               {
+               random = (guint) (1.0 * length * rand()/(RAND_MAX + 1.0));
+               olist = g_list_nth(list, i);
+               nlist = g_list_nth(list, random);
+               tmp = olist->data;
+               olist->data = nlist->data;
+               nlist->data = tmp;
+               }
+
+       return list;
+}
+
 GList *collection_list_add(GList *list, CollectInfo *ci, SortType method)
 {
        if (method != SORT_NONE)
@@ -209,52 +245,20 @@ GList *collection_list_remove(GList *list, CollectInfo *ci)
        return list;
 }
 
-CollectInfo *collection_list_find(GList *list, const gchar *path)
+CollectInfo *collection_list_find_fd(GList *list, FileData *fd)
 {
        GList *work = list;
 
-       while(work)
-               {
-               CollectInfo *ci = work->data;
-               if (strcmp(ci->fd->path, path) == 0) return ci;
-               work = work->next;
-               }
-
-       return NULL;
-}
-
-#if 0
-static GList *collection_list_find_link(GList *list, gchar *path)
-{
-       GList *work = list;
-
-       while(work)
+       while (work)
                {
                CollectInfo *ci = work->data;
-               if (strcmp(ci->fd->path, path) == 0) return work;
+               if (ci->fd == fd) return ci;
                work = work->next;
                }
 
        return NULL;
 }
 
-static gint collection_list_find_index(GList *list, gchar *path)
-{
-       gint c = 0;
-       GList *work = list;
-
-       while(work)
-               {
-               CollectInfo *ci = work->data;
-               if (strcmp(ci->fd->path, path) == 0) return c;
-               work = work->next;
-               c++;
-               }
-
-       return -1;
-}
-#endif
-
 GList *collection_list_to_filelist(GList *list)
 {
        GList *filelist = NULL;
@@ -316,22 +320,11 @@ CollectionData *collection_new(const gchar *path)
 
        cd = g_new0(CollectionData, 1);
 
-       collection_list = g_list_append(collection_list, cd);
-
        cd->ref = 1;    /* starts with a ref of 1 */
-
-       cd->list = NULL;
        cd->sort_method = SORT_NONE;
-       cd->thumb_loader = NULL;
-       cd->info_updated_func = NULL;
-
-       cd->window_read = FALSE;
-       cd->window_x = 0;
-       cd->window_y = 0;
        cd->window_w = COLLECT_DEF_WIDTH;
        cd->window_h = COLLECT_DEF_HEIGHT;
-
-       cd->changed = FALSE;
+       cd->existence = g_hash_table_new(NULL, NULL);
 
        if (path)
                {
@@ -341,8 +334,6 @@ CollectionData *collection_new(const gchar *path)
                }
        else
                {
-               cd->path = NULL;
-
                if (untitled_counter == 0)
                        {
                        cd->name = g_strdup(_("Untitled"));
@@ -355,6 +346,11 @@ CollectionData *collection_new(const gchar *path)
                untitled_counter++;
                }
 
+       file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM);
+
+
+       collection_list = g_list_append(collection_list, cd);
+
        return cd;
 }
 
@@ -362,13 +358,17 @@ void collection_free(CollectionData *cd)
 {
        if (!cd) return;
 
-       if (debug) printf("collection \"%s\" freed\n", cd->name);
+       DEBUG_1("collection \"%s\" freed", cd->name);
 
        collection_load_stop(cd);
        collection_list_free(cd->list);
 
+       file_data_unregister_notify_func(collection_notify_cb, cd);
+
        collection_list = g_list_remove(collection_list, cd);
 
+       g_hash_table_destroy(cd->existence);
+
        g_free(cd->path);
        g_free(cd->name);
 
@@ -379,14 +379,14 @@ void collection_ref(CollectionData *cd)
 {
        cd->ref++;
 
-       if (debug) printf("collection \"%s\" ref count = %d\n", cd->name, cd->ref);
+       DEBUG_1("collection \"%s\" ref count = %d", cd->name, cd->ref);
 }
 
 void collection_unref(CollectionData *cd)
 {
        cd->ref--;
 
-       if (debug) printf("collection \"%s\" ref count = %d\n", cd->name, cd->ref);
+       DEBUG_1("collection \"%s\" ref count = %d", cd->name, cd->ref);
 
        if (cd->ref < 1)
                {
@@ -412,44 +412,43 @@ CollectionData *collection_from_number(gint n)
 CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list)
 {
        CollectionData *cd;
-       gint n;
+       gint collection_number;
+       const gchar *ptr;
+
+       if (list) *list = NULL;
+       if (info_list) *info_list = NULL;
 
        if (strncmp(data, "COLLECTION:", 11) != 0) return NULL;
 
-       n = (gint)strtol(data + 11, NULL, 10);
-       cd = collection_from_number(n);
+       ptr = data + 11;
 
-       if (!cd || (!list && !info_list))
-               {
-               return cd;
-               }
-       else
-               {
-               GList *work = NULL;
-               GList *infol = NULL;
-               gint b, e;
+       collection_number = atoi(ptr);
+       cd = collection_from_number(collection_number);
+       if (!cd) return NULL;
 
-               b = 0;
-               while(data[b] != '\0' && data[b] != '\n' ) b++;
-               b++;
-               e = b;
+       if (!list && !info_list) return cd;
 
-               while (data[b] != '\0')
-                       {
-                       CollectInfo *info;
+       while (*ptr != '\0' && *ptr != '\n' ) ptr++;
+       if (*ptr == '\0') return cd;
+       ptr++;
 
-                       while (data[e] != '\n' && data[e] != '\0') e++;
-                       n = (gint)strtol(data + b, NULL, 10);
+       while (*ptr != '\0')
+               {
+               guint item_number;
+               CollectInfo *info;
 
-                       info = g_list_nth_data(cd->list, n);
-                       if (info && list) work = g_list_append(work, file_data_ref(info->fd));
-                       if (info && info_list) infol = g_list_append(infol, info);
+               item_number = (guint) atoi(ptr);
+               while (*ptr != '\n' && *ptr != '\0') ptr++;
+               if (*ptr == '\0')
+                       break;
+               else
+                       while (*ptr == '\n') ptr++;
 
-                       while (data[e] == '\n') e++;
-                       b = e;
-                       }
-               if (list) *list = work;
-               if (info_list) *info_list = infol;
+               info = g_list_nth_data(cd->list, item_number);
+               if (!info) continue;
+
+               if (list) *list = g_list_append(*list, file_data_ref(info->fd));
+               if (info_list) *info_list = g_list_append(*info_list, info);
                }
 
        return cd;
@@ -457,63 +456,59 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList
 
 gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length)
 {
-       gchar *uri_text = NULL;
-       gint total;
        GList *work;
-       gint n;
-       GList *temp;
+       GList *temp = NULL;
        gchar *ptr;
+       gchar *text;
+       gchar *uri_text;
+       gint collection_number;
 
-       n = collection_to_number(cd);
+       *length = 0;
+       if (!list) return NULL;
 
-       if (!list || n < 0)
-               {
-               *length = 0;
-               return NULL;
-               }
+       collection_number = collection_to_number(cd);
+       if (collection_number < 0) return NULL;
+
+       text = g_strdup_printf("COLLECTION:%d\n", collection_number);
+       *length += strlen(text);
+       temp = g_list_prepend(temp, text);
 
-       temp = NULL;
-       temp = g_list_prepend(temp, g_strdup_printf("COLLECTION:%d\n", n));
        work = list;
-       while(work)
+       while (work)
                {
-               n = g_list_index(cd->list, work->data);
-               if (n >= 0)
-                       {
-                       temp = g_list_prepend(temp, g_strdup_printf("%d\n", n));
-                       }
-               work = work->next;
-               }
+               gint item_number = g_list_index(cd->list, work->data);
 
-       total = 0;
-       work = temp;
-       while(work)
-               {
-               total += strlen((gchar *)work->data);
                work = work->next;
+
+               if (item_number < 0) continue;
+
+               text = g_strdup_printf("%d\n", item_number);
+               temp = g_list_prepend(temp, text);
+               *length += strlen(text);
                }
-       total += 1;
 
-       uri_text = g_malloc(total);
+       *length += 1; /* ending nul char */
+
+       uri_text = g_malloc(*length);
        ptr = uri_text;
 
        work = g_list_last(temp);
-       while(work)
+       while (work)
                {
+               gint len;
                gchar *text = work->data;
 
                work = work->prev;
 
-               strcpy(ptr, text);
-               ptr += strlen(text);
+               len = strlen(text);
+               memcpy(ptr, text, len);
+               ptr += len;
                }
 
        ptr[0] = '\0';
 
        string_list_free(temp);
 
-       *length = total;
-
        return uri_text;
 }
 
@@ -579,6 +574,17 @@ void collection_set_sort_method(CollectionData *cd, SortType method)
        collection_window_refresh(collection_window_find(cd));
 }
 
+void collection_randomize(CollectionData *cd)
+{
+       if (!cd) return;
+
+       cd->list = collection_list_randomize(cd->list);
+       cd->sort_method = SORT_NONE;
+       if (cd->list) cd->changed = TRUE;
+
+       collection_window_refresh(collection_window_find(cd));
+}
+
 void collection_set_update_info_func(CollectionData *cd,
                                     void (*func)(CollectionData *, CollectInfo *, gpointer), gpointer data)
 {
@@ -586,10 +592,25 @@ void collection_set_update_info_func(CollectionData *cd,
        cd->info_updated_data = data;
 }
 
-gint collection_add_check(CollectionData *cd, FileData *fd, gint sorted, gint must_exist)
+static CollectInfo *collection_info_new_if_not_exists(CollectionData *cd, struct stat *st, FileData *fd)
+{
+       CollectInfo *ci;
+
+       if (g_hash_table_lookup(cd->existence, fd->path)) return NULL;
+
+       ci = collection_info_new(fd, st, NULL);
+       if (ci) g_hash_table_insert(cd->existence, fd->path, "");
+       return ci;
+}
+
+gboolean collection_add_check(CollectionData *cd, FileData *fd, gboolean sorted, gboolean must_exist)
 {
        struct stat st;
-       gint valid;
+       gboolean valid;
+
+       if (!fd) return FALSE;
+
+       g_assert(fd->magick == FD_MAGICK);
 
        if (must_exist)
                {
@@ -605,7 +626,11 @@ gint collection_add_check(CollectionData *cd, FileData *fd, gint sorted, gint mu
        if (valid)
                {
                CollectInfo *ci;
-               ci = collection_info_new(fd, &st, NULL);
+
+               ci = collection_info_new_if_not_exists(cd, &st, fd);
+               if (!ci) return FALSE;
+               DEBUG_3("add to collection: %s", fd->path);
+
                cd->list = collection_list_add(cd->list, ci, sorted ? cd->sort_method : SORT_NONE);
                cd->changed = TRUE;
 
@@ -622,12 +647,12 @@ gint collection_add_check(CollectionData *cd, FileData *fd, gint sorted, gint mu
        return valid;
 }
 
-gint collection_add(CollectionData *cd, FileData *fd, gint sorted)
+gboolean collection_add(CollectionData *cd, FileData *fd, gboolean sorted)
 {
        return collection_add_check(cd, fd, sorted, TRUE);
 }
 
-gint collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gint sorted)
+gboolean collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gboolean sorted)
 {
        struct stat st;
 
@@ -636,7 +661,12 @@ gint collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci,
        if (stat_utf8(fd->path, &st) >= 0 && !S_ISDIR(st.st_mode))
                {
                CollectInfo *ci;
-               ci = collection_info_new(fd, &st, NULL);
+
+               ci = collection_info_new_if_not_exists(cd, &st, fd);
+               if (!ci) return FALSE;
+
+               DEBUG_3("insert in collection: %s", fd->path);
+
                cd->list = collection_list_insert(cd->list, ci, insert_ci, sorted ? cd->sort_method : SORT_NONE);
                cd->changed = TRUE;
 
@@ -648,14 +678,16 @@ gint collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci,
        return FALSE;
 }
 
-gint collection_remove(CollectionData *cd, FileData *fd)
+gboolean collection_remove(CollectionData *cd, FileData *fd)
 {
        CollectInfo *ci;
 
-       ci = collection_list_find(cd->list, fd->path);
+       ci = collection_list_find_fd(cd->list, fd);
 
        if (!ci) return FALSE;
 
+       g_hash_table_remove(cd->existence, fd->path);
+
        cd->list = g_list_remove(cd->list, ci);
        cd->changed = TRUE;
 
@@ -690,7 +722,7 @@ void collection_remove_by_info_list(CollectionData *cd, GList *list)
                }
 
        work = list;
-       while(work)
+       while (work)
                {
                cd->list = collection_list_remove(cd->list, work->data);
                work = work->next;
@@ -700,17 +732,13 @@ void collection_remove_by_info_list(CollectionData *cd, GList *list)
        collection_window_refresh(collection_window_find(cd));
 }
 
-gint collection_rename(CollectionData *cd, FileData *fd)
+gboolean collection_rename(CollectionData *cd, FileData *fd)
 {
        CollectInfo *ci;
-       const gchar *source = fd->change->source;
-//     const gchar *dest = fd->change->dest;
-       ci = collection_list_find(cd->list, source);
+       ci = collection_list_find_fd(cd->list, fd);
 
        if (!ci) return FALSE;
 
-//     g_free(ci->path);
-//     ci->path = g_strdup(dest); FIXME
        cd->changed = TRUE;
 
        collection_window_update(collection_window_find(cd), ci);
@@ -729,53 +757,43 @@ void collection_update_geometry(CollectionData *cd)
  *-------------------------------------------------------------------
  */
 
-void collection_maint_removed(FileData *fd)
+static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
-       GList *work;
-
-       work = collection_list;
-       while(work)
-               {
-               CollectionData *cd = work->data;
-               work = work->next;
+       CollectionData *cd = data;
 
-               while(collection_remove(cd, fd));
-               }
-#if 0
-       /* Do we really need to do this? removed files are
-        * automatically ignored when loading a collection.
-        */
-       collect_manager_moved(fd, NULL);
-#endif
-}
+       if (!(type & NOTIFY_CHANGE) || !fd->change) return;
 
-void collection_maint_renamed(FileData *fd)
-{
-       GList *work;
+       DEBUG_1("Notify collection: %s %04x", fd->path, type);
 
-       work = collection_list;
-       while(work)
+       switch (fd->change->type)
                {
-               CollectionData *cd = work->data;
-               work = work->next;
-
-               while(collection_rename(cd, fd));
+               case FILEDATA_CHANGE_MOVE:
+               case FILEDATA_CHANGE_RENAME:
+                       collection_rename(cd, fd);
+                       break;
+               case FILEDATA_CHANGE_COPY:
+                       break;
+               case FILEDATA_CHANGE_DELETE:
+                       while (collection_remove(cd, fd));
+                       break;
+               case FILEDATA_CHANGE_UNSPECIFIED:
+               case FILEDATA_CHANGE_WRITE_METADATA:
+                       break;
                }
 
-       collect_manager_moved(fd);
 }
 
+
 /*
  *-------------------------------------------------------------------
  * window key presses
  *-------------------------------------------------------------------
  */
 
-static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        CollectWindow *cw = data;
-       gint stop_signal = FALSE;
-       gint edit_val = -1;
+       gboolean stop_signal = FALSE;
        GList *list;
 
        if (event->state & GDK_CONTROL_MASK)
@@ -784,34 +802,15 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
                switch (event->keyval)
                        {
                        case '1':
-                               edit_val = 0;
-                               break;
                        case '2':
-                               edit_val = 1;
-                               break;
                        case '3':
-                               edit_val = 2;
-                               break;
                        case '4':
-                               edit_val = 3;
-                               break;
                        case '5':
-                               edit_val = 4;
-                               break;
                        case '6':
-                               edit_val = 5;
-                               break;
                        case '7':
-                               edit_val = 6;
-                               break;
                        case '8':
-                               edit_val = 7;
-                               break;
                        case '9':
-                               edit_val = 8;
-                               break;
                        case '0':
-                               edit_val = 9;
                                break;
                        case 'A': case 'a':
                                if (event->state & GDK_SHIFT_MASK)
@@ -843,9 +842,6 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
                        case 'D': case 'd':
                                file_util_delete(NULL, collection_table_selection_get_list(cw->table), cw->window);
                                break;
-                       case 'P': case 'p':
-                               info_window_new(NULL, collection_table_selection_get_list(cw->table));
-                               break;
                        case 'S': case 's':
                                collection_dialog_save_as(NULL, cw->cd);
                                break;
@@ -862,7 +858,7 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
                stop_signal = TRUE;
                switch (event->keyval)
                        {
-                       case GDK_Return: case GDK_KP_Enter:
+                       case GDK_KEY_Return: case GDK_KEY_KP_Enter:
                                layout_image_set_collection(NULL, cw->cd,
                                        collection_table_get_focus_info(cw->table));
                                break;
@@ -874,10 +870,10 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
                                if (!cw->cd->path)
                                        {
                                        collection_dialog_save_as(NULL, cw->cd);
-                                       }
+                                       }
                                else if (!collection_save(cw->cd, cw->cd->path))
                                        {
-                                       printf("failed saving to collection path: %s\n", cw->cd->path);
+                                       log_printf("failed saving to collection path: %s\n", cw->cd->path);
                                        }
                                break;
                        case 'A': case 'a':
@@ -912,7 +908,13 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
                                        collection_set_sort_method(cw->cd, SORT_PATH);
                                        }
                                break;
-                       case GDK_Delete: case GDK_KP_Delete:
+                       case 'R': case 'r':
+                               if (event->state & GDK_MOD1_MASK)
+                                       {
+                                               options->collections.rectangular_selection = !(options->collections.rectangular_selection);
+                                       }
+                               break;
+                       case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
                                list = g_list_copy(cw->table->selection);
                                if (list)
                                        {
@@ -924,19 +926,14 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
                                        collection_remove_by_info(cw->cd, collection_table_get_focus_info(cw->table));
                                        }
                                break;
+                       case GDK_KEY_F1:
+                               help_window_show("GuideReferenceKeyboardShortcuts.html#CollectionsKeyboardShortcuts");
+                               break;
                        default:
                                stop_signal = FALSE;
                                break;
                        }
                }
-
-       if (edit_val != -1)
-               {
-               list = collection_table_selection_get_list(cw->table);
-               start_editor_from_filelist(edit_val, list);
-               filelist_free(list);
-               }
-
        return stop_signal;
 }
 
@@ -948,12 +945,15 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
 static void collection_window_get_geometry(CollectWindow *cw)
 {
        CollectionData *cd;
+       GdkWindow *window;
 
        if (!cw) return;
 
        cd = cw->cd;
-       gdk_window_get_position (cw->window->window, &cd->window_x, &cd->window_y);
-       gdk_drawable_get_size(cw->window->window, &cd->window_w, &cd->window_h);
+       window = gtk_widget_get_window(cw->window);
+       gdk_window_get_position(window, &cd->window_x, &cd->window_y);
+       cd->window_w = gdk_window_get_width(window);
+       cd->window_h = gdk_window_get_height(window);
        cd->window_read = TRUE;
 }
 
@@ -966,11 +966,24 @@ static void collection_window_refresh(CollectWindow *cw)
 
 static void collection_window_update_title(CollectWindow *cw)
 {
+       gboolean free_name = FALSE;
+       gchar *name;
        gchar *buf;
 
        if (!cw) return;
 
-       buf = g_strdup_printf(_("%s - Geeqie Collection"), cw->cd->name);
+       if (file_extension_match(cw->cd->name, GQ_COLLECTION_EXT))
+               {
+               name = remove_extension_from_path(cw->cd->name);
+               free_name = TRUE;
+               }
+       else
+               {
+               name = cw->cd->name;
+               }
+
+       buf = g_strdup_printf(_("%s - Collection - %s"), name, GQ_APPNAME);
+       if (free_name) g_free(name);
        gtk_window_set_title(GTK_WINDOW(cw->window), buf);
        g_free(buf);
 }
@@ -999,13 +1012,6 @@ static void collection_window_insert(CollectWindow *cw, CollectInfo *ci)
        if (!cw) return;
 }
 
-#if 0
-static void collection_window_move(CollectWindow *cw, CollectInfo *ci)
-{
-       if (!cw) return;
-}
-#endif
-
 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci)
 {
        if (!cw) return;
@@ -1044,7 +1050,7 @@ static void collection_close_save_cb(GenericDialog *gd, gpointer data)
        generic_dialog_close(gd);
 
        if (!cw->cd->path)
-                {
+               {
                collection_dialog_save_close(NULL, cw->cd);
                return;
                }
@@ -1089,7 +1095,7 @@ static void collection_close_dlg_show(CollectWindow *cw)
                }
 
        gd = generic_dialog_new(_("Close collection"),
-                               GQ_WMCLASS, "close_collection", cw->window, FALSE,
+                               "close_collection", cw->window, FALSE,
                                collection_close_cancel_cb, cw);
        generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION,
                                   _("Close collection"),
@@ -1122,7 +1128,7 @@ void collection_window_close_by_collection(CollectionData *cd)
        if (cw) collection_window_close_final(cw);
 }
 
-gint collection_window_modified_exists(void)
+gboolean collection_window_modified_exists(void)
 {
        GList *work;
 
@@ -1137,7 +1143,7 @@ gint collection_window_modified_exists(void)
        return FALSE;
 }
 
-static gint collection_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
+static gboolean collection_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
        CollectWindow *cw = data;
        collection_window_close(cw);
@@ -1156,27 +1162,24 @@ CollectWindow *collection_window_new(const gchar *path)
 
        cw = g_new0(CollectWindow, 1);
 
-       cw->close_dialog = NULL;
-
        collection_window_list = g_list_append(collection_window_list, cw);
 
        cw->cd = collection_new(path);
 
-       cw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-       window_set_icon(cw->window, PIXBUF_INLINE_ICON_BOOK, NULL);
+       cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, NULL, NULL);
 
-       geometry.min_width = 32;
-       geometry.min_height = 32;
+       geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
+       geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
        geometry.base_width = COLLECT_DEF_WIDTH;
        geometry.base_height = COLLECT_DEF_HEIGHT;
        gtk_window_set_geometry_hints(GTK_WINDOW(cw->window), NULL, &geometry,
                                      GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
 
 
-       if (save_window_positions && path && collection_load_only_geometry(cw->cd, path))
+       if (options->save_window_positions && path && collection_load_only_geometry(cw->cd, path))
                {
-               /* FIXME: x, y is not implemented */
                gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h);
+               gtk_window_move(GTK_WINDOW(cw->window), cw->cd->window_x, cw->cd->window_y);
                }
        else
                {
@@ -1185,13 +1188,12 @@ CollectWindow *collection_window_new(const gchar *path)
 
        gtk_window_set_resizable(GTK_WINDOW(cw->window), TRUE);
        collection_window_update_title(cw);
-       gtk_window_set_wmclass(GTK_WINDOW(cw->window), "collection", GQ_WMCLASS);
-       gtk_container_set_border_width (GTK_CONTAINER (cw->window), 0);
+       gtk_container_set_border_width(GTK_CONTAINER(cw->window), 0);
 
        g_signal_connect(G_OBJECT(cw->window), "delete_event",
                         G_CALLBACK(collection_window_delete), cw);
 
-       g_signal_connect(G_OBJECT(cw->window),"key_press_event",
+       g_signal_connect(G_OBJECT(cw->window), "key_press_event",
                         G_CALLBACK(collection_window_keypress), cw);
 
        vbox = gtk_vbox_new(FALSE, 0);
@@ -1217,6 +1219,10 @@ CollectWindow *collection_window_new(const gchar *path)
 
        extra_label = gtk_progress_bar_new();
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(extra_label), 0.0);
+#if GTK_CHECK_VERSION(3,0,0)
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(extra_label), "");
+       gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(extra_label), TRUE);
+#endif
        gtk_box_pack_start(GTK_BOX(cw->status_box), extra_label, TRUE, TRUE, 0);
        gtk_widget_show(extra_label);
 
@@ -1227,8 +1233,8 @@ CollectWindow *collection_window_new(const gchar *path)
 
        collection_set_update_info_func(cw->cd, collection_window_update_info, cw);
 
-       if (path && *path == '/') collection_load_begin(cw->cd, NULL, FALSE);
+       if (path && *path == G_DIR_SEPARATOR) collection_load_begin(cw->cd, NULL, COLLECTION_LOAD_NONE);
 
        return cw;
 }
-
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */