Commit bebdc608 authored by John Sullivan's avatar John Sullivan

Sort directories by item count when sorting by size.

parent 21ca57f8
2000-02-10 John Sullivan <sullivan@eazel.com>
Used directory item count hack when comparing by size, so
the item counts are sorted correctly. This is horribly
inefficient, but isn't actually horribly slow in most cases.
This will be fixed when we switch the item count calculation
to use the deferred-result architecture.
* libnautilus/nautilus-directory.c:
(nautilus_file_compare_by_size_with_directories): New function,
uses item count hack, as well as putting directories before
non-directories.
(nautilus_file_compare_for_sort_internal): Uses
nautilus_file_compare_by_size_with_directories to handle
directories, falls through to GnomeVFS rules for other cases.
2000-02-10 John Sullivan <sullivan@eazel.com>
Put in quick hack for showing directory item counts under icons
......
......@@ -77,6 +77,10 @@ enum
LAST_SIGNAL
};
/* FIXME: This hack needs to die eventually. See comments with function */
static int get_directory_item_count_hack (NautilusFile *file, gboolean ignore_invisible_items);
static guint nautilus_directory_signals[LAST_SIGNAL];
static void nautilus_directory_initialize_class (gpointer klass);
......@@ -1182,6 +1186,45 @@ nautilus_file_detach (NautilusFile *file)
gnome_vfs_file_info_unref (file->info);
}
static int
nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFile *file_2)
{
gboolean is_directory_1;
gboolean is_directory_2;
int item_count_1;
int item_count_2;
is_directory_1 = file_1->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY;
is_directory_2 = file_2->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY;
if (is_directory_1 && !is_directory_2)
return -1;
if (is_directory_2 && !is_directory_1)
return +1;
if (!is_directory_1 && !is_directory_2)
return 0;
/* Both are directories, compare by item count. */
/* FIXME: get_directory_item_count_hack is slow, and calling
* it for every pairwise comparison here is nasty. Need to
* change this to (not-yet-existent) architecture where the
* item count can be calculated once in a deferred way, and
* then stored or cached.
*/
item_count_1 = get_directory_item_count_hack (file_1, FALSE);
item_count_2 = get_directory_item_count_hack (file_2, FALSE);
if (item_count_1 < item_count_2)
return -1;
if (item_count_2 < item_count_1)
return +1;
return 0;
}
static int
nautilus_file_compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
{
......@@ -1248,11 +1291,20 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
rules[1] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case NAUTILUS_FILE_SORT_BY_SIZE:
rules = ALLOC_RULES (4);
rules[0] = GNOME_VFS_DIRECTORY_SORT_DIRECTORYFIRST;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYSIZE;
rules[2] = GNOME_VFS_DIRECTORY_SORT_BYNAME_IGNORECASE;
rules[3] = GNOME_VFS_DIRECTORY_SORT_NONE;
/* Compare directory sizes ourselves, then if necessary
* use GnomeVFS to compare file sizes.
*/
{
int size_compare;
size_compare = nautilus_file_compare_by_size_with_directories (file_1, file_2);
if (size_compare != 0)
return size_compare;
}
rules = ALLOC_RULES (3);
rules[0] = GNOME_VFS_DIRECTORY_SORT_BYSIZE;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYNAME_IGNORECASE;
rules[2] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case NAUTILUS_FILE_SORT_BY_TYPE:
/* GnomeVFS doesn't know about our special text for certain
......
......@@ -77,6 +77,10 @@ enum
LAST_SIGNAL
};
/* FIXME: This hack needs to die eventually. See comments with function */
static int get_directory_item_count_hack (NautilusFile *file, gboolean ignore_invisible_items);
static guint nautilus_directory_signals[LAST_SIGNAL];
static void nautilus_directory_initialize_class (gpointer klass);
......@@ -1182,6 +1186,45 @@ nautilus_file_detach (NautilusFile *file)
gnome_vfs_file_info_unref (file->info);
}
static int
nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFile *file_2)
{
gboolean is_directory_1;
gboolean is_directory_2;
int item_count_1;
int item_count_2;
is_directory_1 = file_1->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY;
is_directory_2 = file_2->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY;
if (is_directory_1 && !is_directory_2)
return -1;
if (is_directory_2 && !is_directory_1)
return +1;
if (!is_directory_1 && !is_directory_2)
return 0;
/* Both are directories, compare by item count. */
/* FIXME: get_directory_item_count_hack is slow, and calling
* it for every pairwise comparison here is nasty. Need to
* change this to (not-yet-existent) architecture where the
* item count can be calculated once in a deferred way, and
* then stored or cached.
*/
item_count_1 = get_directory_item_count_hack (file_1, FALSE);
item_count_2 = get_directory_item_count_hack (file_2, FALSE);
if (item_count_1 < item_count_2)
return -1;
if (item_count_2 < item_count_1)
return +1;
return 0;
}
static int
nautilus_file_compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
{
......@@ -1248,11 +1291,20 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
rules[1] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case NAUTILUS_FILE_SORT_BY_SIZE:
rules = ALLOC_RULES (4);
rules[0] = GNOME_VFS_DIRECTORY_SORT_DIRECTORYFIRST;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYSIZE;
rules[2] = GNOME_VFS_DIRECTORY_SORT_BYNAME_IGNORECASE;
rules[3] = GNOME_VFS_DIRECTORY_SORT_NONE;
/* Compare directory sizes ourselves, then if necessary
* use GnomeVFS to compare file sizes.
*/
{
int size_compare;
size_compare = nautilus_file_compare_by_size_with_directories (file_1, file_2);
if (size_compare != 0)
return size_compare;
}
rules = ALLOC_RULES (3);
rules[0] = GNOME_VFS_DIRECTORY_SORT_BYSIZE;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYNAME_IGNORECASE;
rules[2] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case NAUTILUS_FILE_SORT_BY_TYPE:
/* GnomeVFS doesn't know about our special text for certain
......
......@@ -77,6 +77,10 @@ enum
LAST_SIGNAL
};
/* FIXME: This hack needs to die eventually. See comments with function */
static int get_directory_item_count_hack (NautilusFile *file, gboolean ignore_invisible_items);
static guint nautilus_directory_signals[LAST_SIGNAL];
static void nautilus_directory_initialize_class (gpointer klass);
......@@ -1182,6 +1186,45 @@ nautilus_file_detach (NautilusFile *file)
gnome_vfs_file_info_unref (file->info);
}
static int
nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFile *file_2)
{
gboolean is_directory_1;
gboolean is_directory_2;
int item_count_1;
int item_count_2;
is_directory_1 = file_1->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY;
is_directory_2 = file_2->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY;
if (is_directory_1 && !is_directory_2)
return -1;
if (is_directory_2 && !is_directory_1)
return +1;
if (!is_directory_1 && !is_directory_2)
return 0;
/* Both are directories, compare by item count. */
/* FIXME: get_directory_item_count_hack is slow, and calling
* it for every pairwise comparison here is nasty. Need to
* change this to (not-yet-existent) architecture where the
* item count can be calculated once in a deferred way, and
* then stored or cached.
*/
item_count_1 = get_directory_item_count_hack (file_1, FALSE);
item_count_2 = get_directory_item_count_hack (file_2, FALSE);
if (item_count_1 < item_count_2)
return -1;
if (item_count_2 < item_count_1)
return +1;
return 0;
}
static int
nautilus_file_compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
{
......@@ -1248,11 +1291,20 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
rules[1] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case NAUTILUS_FILE_SORT_BY_SIZE:
rules = ALLOC_RULES (4);
rules[0] = GNOME_VFS_DIRECTORY_SORT_DIRECTORYFIRST;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYSIZE;
rules[2] = GNOME_VFS_DIRECTORY_SORT_BYNAME_IGNORECASE;
rules[3] = GNOME_VFS_DIRECTORY_SORT_NONE;
/* Compare directory sizes ourselves, then if necessary
* use GnomeVFS to compare file sizes.
*/
{
int size_compare;
size_compare = nautilus_file_compare_by_size_with_directories (file_1, file_2);
if (size_compare != 0)
return size_compare;
}
rules = ALLOC_RULES (3);
rules[0] = GNOME_VFS_DIRECTORY_SORT_BYSIZE;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYNAME_IGNORECASE;
rules[2] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case NAUTILUS_FILE_SORT_BY_TYPE:
/* GnomeVFS doesn't know about our special text for certain
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment