diff options
author | ZenWalker <[email protected]> | 2016-06-10 10:41:11 +0200 |
---|---|---|
committer | ZenWalker <[email protected]> | 2016-06-10 10:41:11 +0200 |
commit | af154fdd494b90adae5be5783bb725194fcf1d6b (patch) | |
tree | 251b542943ba6cee52f117ba5737c54b47f16031 /src | |
parent | 25c3dccb52628440615f97c9877f7dacd37d6646 (diff) | |
download | engrampa-af154fdd494b90adae5be5783bb725194fcf1d6b.tar.bz2 engrampa-af154fdd494b90adae5be5783bb725194fcf1d6b.tar.xz |
use natural order when sorting by filename
file-roller commit:
https://git.gnome.org/browse/file-roller/commit/?id=8703609e95dcee3abbec39dea567137c7fff23e9
Fixes #143
Diffstat (limited to 'src')
-rw-r--r-- | src/file-data.c | 38 | ||||
-rw-r--r-- | src/file-data.h | 22 | ||||
-rw-r--r-- | src/fr-window.c | 13 |
3 files changed, 46 insertions, 27 deletions
diff --git a/src/file-data.c b/src/file-data.c index 8905b96..d7a39a2 100644 --- a/src/file-data.c +++ b/src/file-data.c @@ -37,7 +37,7 @@ file_data_new (void) fdata->content_type = NULL; fdata->free_original_path = FALSE; fdata->dir_size = 0; - + return fdata; } @@ -54,6 +54,7 @@ file_data_free (FileData *fdata) g_free (fdata->path); g_free (fdata->link); g_free (fdata->list_name); + g_free (fdata->sort_key); g_free (fdata); } @@ -67,7 +68,7 @@ file_data_copy (FileData *src) fdata->original_path = g_strdup (src->original_path); fdata->free_original_path = TRUE; - + fdata->full_path = g_strdup (src->full_path); fdata->link = g_strdup (src->link); fdata->size = src->size; @@ -81,6 +82,7 @@ file_data_copy (FileData *src) fdata->list_dir = src->list_dir; fdata->list_name = g_strdup (src->list_name); + fdata->sort_key = g_strdup (src->sort_key); return fdata; } @@ -90,10 +92,10 @@ GType file_data_get_type (void) { static GType type = 0; - + if (type == 0) type = g_boxed_type_register_static ("FRFileData", (GBoxedCopyFunc) file_data_copy, (GBoxedFreeFunc) file_data_free); - + return type; } @@ -101,10 +103,9 @@ file_data_get_type (void) void file_data_update_content_type (FileData *fdata) { - - if (fdata->dir) + if (fdata->dir) fdata->content_type = MIME_TYPE_DIRECTORY; - else + else fdata->content_type = get_static_string (g_content_type_guess (fdata->full_path, NULL, 0, NULL)); } @@ -116,13 +117,28 @@ file_data_is_dir (FileData *fdata) } +void +file_data_set_list_name (FileData *fdata, + const char *value) +{ + g_free (fdata->list_name); + fdata->list_name = g_strdup (value); + + g_free (fdata->sort_key); + if (fdata->list_name != NULL) + fdata->sort_key = g_utf8_collate_key_for_filename (fdata->list_name, -1); + else + fdata->sort_key = NULL; +} + + int file_data_compare_by_path (gconstpointer a, gconstpointer b) { FileData *data_a = *((FileData **) a); FileData *data_b = *((FileData **) b); - + return strcmp (data_a->full_path, data_b->full_path); } @@ -158,12 +174,12 @@ find_path_in_file_data_array (GPtrArray *array, } if (cmp == 0) - return p; + return p; else if (cmp < 0) right = p; - else + else left = p + 1; } - + return -1; } diff --git a/src/file-data.h b/src/file-data.h index 60d81b6..84adcd6 100644 --- a/src/file-data.h +++ b/src/file-data.h @@ -40,13 +40,14 @@ typedef struct { gboolean dir; /* Whether this is a directory listed in the archive */ goffset dir_size; const char *content_type; - + /* Additional data. */ gboolean list_dir; /* Whether this entry is used to show * a directory. */ char *list_name; /* The string visualized in the list * view. */ + char *sort_key; /* Private data */ @@ -57,14 +58,15 @@ typedef struct { GType file_data_get_type (void); FileData * file_data_new (void); -FileData * file_data_copy (FileData *src); -void file_data_free (FileData *fdata); -void file_data_update_content_type (FileData *fdata); -gboolean file_data_is_dir (FileData *fdata); - -int file_data_compare_by_path (gconstpointer a, - gconstpointer b); -int find_path_in_file_data_array (GPtrArray *array, - const char *path); +FileData * file_data_copy (FileData *src); +void file_data_free (FileData *fdata); +void file_data_update_content_type (FileData *fdata); +gboolean file_data_is_dir (FileData *fdata); +void file_data_set_list_name (FileData *fdata, + const char *value); +int file_data_compare_by_path (gconstpointer a, + gconstpointer b); +int find_path_in_file_data_array (GPtrArray *array, + const char *path); #endif /* FILE_DATA_H */ diff --git a/src/fr-window.c b/src/fr-window.c index 522b194..c57f453 100644 --- a/src/fr-window.c +++ b/src/fr-window.c @@ -944,7 +944,7 @@ sort_by_name (gconstpointer ptr1, return 1; } - return strcasecmp (fdata1->list_name, fdata2->list_name); + return strcmp (fdata1->sort_key, fdata2->sort_key); } @@ -1118,7 +1118,7 @@ compute_file_list_name (FrWindow *window, return FALSE; if (window->priv->list_mode == FR_WINDOW_LIST_MODE_FLAT) { - fdata->list_name = g_strdup (fdata->name); + file_data_set_list_name (fdata, fdata->name); if (fdata->dir) fdata->dir_size = 0; return FALSE; @@ -1135,7 +1135,7 @@ compute_file_list_name (FrWindow *window, scan = fdata->full_path + current_dir_len; end = strchr (scan, '/'); if ((end == NULL) && ! fdata->dir) { /* file */ - fdata->list_name = g_strdup (scan); + file_data_set_list_name (fdata, scan); } else { /* folder */ char *dir_name; @@ -1154,8 +1154,10 @@ compute_file_list_name (FrWindow *window, if ((end != NULL) && (*(end + 1) != '\0')) fdata->list_dir = TRUE; - fdata->list_name = dir_name; + file_data_set_list_name (fdata, dir_name); fdata->dir_size = get_dir_size (window, current_dir, dir_name); + + g_free (dir_name); } return TRUE; @@ -1181,8 +1183,7 @@ fr_window_compute_list_names (FrWindow *window, for (i = 0; i < files->len; i++) { FileData *fdata = g_ptr_array_index (files, i); - g_free (fdata->list_name); - fdata->list_name = NULL; + file_data_set_list_name (fdata, NULL); fdata->list_dir = FALSE; /* the files array is sorted by path, when the visible list |