Commit 6e7ca6f3 authored by John Sullivan's avatar John Sullivan

Column headers now sort in list view; added Type column.

parent 17c50ced
2000-01-18 John Sullivan <sullivan@eazel.com>
* src/file-manager/fm-directory-view.h:
(enum _FMDirectoryViewSortType): added FM_DIRECTORY_VIEW_SORT_NONE
and FM_DIRECTORY_VIEW_SORT_BYMTIME
(fm_directory_view_sort): added reverse_sort parameter.
(nautilus_file_date_as_string):
(nautilus_file_size_as_string): Changed parameter for these two
functions to be GnomeVFSFileInfo so they can handle special cases better.
(nautilus_file_type_as_string): New function
* src/file-manager/fm-directory-view.c
(stop_load): Removed code resetting directory_list and current_position.
This was the wrong place for it, and resetting directory_list was leaking.
(directory_load_cb): Changed commented assignment to assert.
(fm_directory_view_load_uri): Reset directory_list (without leaking old
value) and current_position here.
(fm_directory_view_sort): Pass through new reverse_sort parameter to
gnome_vfs_directory_view_sort; add new case for
FM_DIRECTORY_VIEW_SORT_BYMTIME; don't put directories first when sorting
by name.
(nautilus_file_date_as_string): Now takes a GnomeVFSFileInfo pointer
instead of a time_t (assumes mtime, with comment explaining why).
(nautilus_file_size_as_string): Now takes a GnomeVFSFileInfo pointer
instead of a size; uses this to special-case "--" for directory size.
(nautilus_file_type_as_string): New function, special-cases directories
to return "directory", otherwise returns mime_type.
* src/file-manager/fm-directory-view-list.h
Added private details structure to FMDirectoryViewList.
* src/file-manager/fm-directory-view-list.c
Added _FMDirectoryViewListDetails struct, containing sort_type and
sort_reversed.
(fm_directory_view_initialize): initialize details struct.
(column_clicked_cb): New function, sorts list by clicked column.
If list already sorted by that column, reverses sort. Still need
visual indicator of sort direction.
(create_flist): Added Type column, tweaked column widths, added
signal connection for "click_column"
(add_to_flist): now passes GnomeVFSFileInfo to
nautilus_file_size_as_string and nautilus_file_date_as_string;
uses new nautilus_file_type_as_string for type column.
2000-01-18 Andy Hertzfeld <andy@eazel.com>
* libnautilus/nautilus-directory:
......
......@@ -34,11 +34,20 @@
static FMDirectoryViewClass *parent_class = NULL;
struct _FMDirectoryViewListDetails
{
FMDirectoryViewSortType sort_type;
gboolean sort_reversed;
};
/* forward declarations */
static void add_to_flist (FMIconCache *icon_manager,
GtkFList *flist,
GnomeVFSFileInfo *info);
static void column_clicked_cb (GtkCList *ignored,
gint column,
gpointer user_data);
static GtkFList *create_flist (FMDirectoryViewList *list_view);
static void flist_activate_cb (GtkFList *ignored,
gpointer entry_data,
......@@ -87,10 +96,18 @@ fm_directory_view_list_initialize_class (gpointer klass)
static void
fm_directory_view_list_initialize (gpointer object, gpointer klass)
{
FMDirectoryViewList *list_view;
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (object));
g_return_if_fail (GTK_BIN (object)->child == NULL);
list_view = FM_DIRECTORY_VIEW_LIST (object);
list_view->details = g_new0 (FMDirectoryViewListDetails, 1);
list_view->details->sort_type = FM_DIRECTORY_VIEW_SORT_NONE;
list_view->details->sort_reversed = FALSE;
create_flist (object);
create_flist (list_view);
}
static void
......@@ -104,10 +121,53 @@ fm_directory_view_list_destroy (GtkObject *object)
#define LIST_VIEW_COLUMN_ICON 0
#define LIST_VIEW_COLUMN_NAME 1
#define LIST_VIEW_COLUMN_SIZE 2
#define LIST_VIEW_COLUMN_DATE_MODIFIED 3
#define LIST_VIEW_COLUMN_COUNT 4
#define LIST_VIEW_COLUMN_MIME_TYPE 3
#define LIST_VIEW_COLUMN_DATE_MODIFIED 4
#define LIST_VIEW_COLUMN_COUNT 5
static void
column_clicked_cb (GtkCList *ignored, gint column, gpointer user_data)
{
FMDirectoryViewList *list_view;
FMDirectoryViewSortType sort_type;
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (user_data));
list_view = FM_DIRECTORY_VIEW_LIST (user_data);
switch (column)
{
case LIST_VIEW_COLUMN_ICON:
sort_type = FM_DIRECTORY_VIEW_SORT_BYTYPE;
break;
case LIST_VIEW_COLUMN_NAME:
sort_type = FM_DIRECTORY_VIEW_SORT_BYNAME;
break;
case LIST_VIEW_COLUMN_SIZE:
sort_type = FM_DIRECTORY_VIEW_SORT_BYSIZE;
break;
case LIST_VIEW_COLUMN_DATE_MODIFIED:
sort_type = FM_DIRECTORY_VIEW_SORT_BYMTIME;
break;
case LIST_VIEW_COLUMN_MIME_TYPE:
sort_type = FM_DIRECTORY_VIEW_SORT_BYTYPE;
break;
default: g_assert_not_reached();
}
if (sort_type == list_view->details->sort_type)
list_view->details->sort_reversed = !list_view->details->sort_reversed;
else
list_view->details->sort_reversed = FALSE;
list_view->details->sort_type = sort_type;
fm_directory_view_sort (FM_DIRECTORY_VIEW (list_view),
list_view->details->sort_type,
list_view->details->sort_reversed
);
}
static GtkFList *
create_flist (FMDirectoryViewList *list_view)
......@@ -117,12 +177,14 @@ create_flist (FMDirectoryViewList *list_view)
NULL,
_("Name"),
_("Size"),
_("Type"),
_("Date Modified"),
};
uint widths[] = {
20, /* Icon */
150, /* Name */
75, /* Size */
130, /* Name */
55, /* Size */
95, /* Type */
100, /* Modified */
};
int i;
......@@ -150,6 +212,10 @@ create_flist (FMDirectoryViewList *list_view)
"selection_changed",
GTK_SIGNAL_FUNC (flist_selection_changed_cb),
list_view);
gtk_signal_connect (GTK_OBJECT (flist),
"click_column",
column_clicked_cb,
list_view);
gtk_container_add (GTK_CONTAINER (list_view), GTK_WIDGET (flist));
gtk_widget_show (GTK_WIDGET (flist));
......@@ -188,40 +254,31 @@ add_to_flist (FMIconCache *icon_manager,
{
GtkCList *clist;
gchar *text[LIST_VIEW_COLUMN_COUNT];
gchar *size_string = NULL;
gchar *modified_string = NULL;
gchar *size_string;
gchar *modified_string;
gchar *type_string;
/* FIXME: Icon column needs a pixmap */
text[LIST_VIEW_COLUMN_ICON] = NULL;
text[LIST_VIEW_COLUMN_NAME] = info->name;
if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
{
text[LIST_VIEW_COLUMN_SIZE] = "--";
}
else
{
size_string = nautilus_file_size_as_string (info->size);
text[LIST_VIEW_COLUMN_SIZE] = size_string;
}
size_string = nautilus_file_size_as_string (info);
text[LIST_VIEW_COLUMN_SIZE] = size_string;
/* Note: There's also accessed time and changed time.
* Accessed time doesn't seem worth showing to the user.
* Changed time is only subtly different from modified time
* (changed time includes "metadata" changes like file permissions).
* We should not display both, but we might change our minds as to
* which one is better.
*/
modified_string = nautilus_file_date_as_string (info->mtime);
modified_string = nautilus_file_date_as_string (info);
text[LIST_VIEW_COLUMN_DATE_MODIFIED] = modified_string;
type_string = nautilus_file_type_as_string (info);
text[LIST_VIEW_COLUMN_MIME_TYPE] = type_string;
clist = GTK_CLIST (flist);
gtk_clist_append (clist, text);
gtk_clist_set_row_data (clist, clist->rows - 1, info);
g_free (size_string);
g_free (modified_string);
g_free (type_string);
}
static GtkFList *
......
......@@ -36,8 +36,11 @@ typedef struct _FMDirectoryViewListClass FMDirectoryViewListClass;
#define FM_IS_DIRECTORY_VIEW_LIST(obj) (GTK_CHECK_TYPE ((obj), FM_TYPE_DIRECTORY_VIEW_LIST))
#define FM_IS_DIRECTORY_VIEW_LIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), FM_TYPE_DIRECTORY_VIEW_LIST))
typedef struct _FMDirectoryViewListDetails FMDirectoryViewListDetails;
struct _FMDirectoryViewList {
FMDirectoryView parent;
FMDirectoryViewListDetails *details;
};
struct _FMDirectoryViewListClass {
......
......@@ -173,7 +173,7 @@ fm_directory_view_initialize (gpointer object, gpointer klass)
NAUTILUS_CONTENT_VIEW_FRAME (gtk_widget_new
(nautilus_content_view_frame_get_type(),
NULL));
gtk_signal_connect (GTK_OBJECT(directory_view->details->view_frame),
"stop_location_change",
GTK_SIGNAL_FUNC (stop_location_change_cb),
......@@ -301,9 +301,6 @@ stop_load (FMDirectoryView *view, gboolean error)
view->details->display_timeout_id = 0;
}
view->details->current_position = GNOME_VFS_DIRECTORY_LIST_POSITION_NONE;
view->details->directory_list = NULL;
memset(&pri, 0, sizeof(pri));
pri.amount = 100.0;
pri.type = error ? Nautilus_PROGRESS_DONE_ERROR : Nautilus_PROGRESS_DONE_OK;
......@@ -422,10 +419,8 @@ directory_load_cb (GnomeVFSAsyncHandle *handle,
view->details->directory_list = list;
/* FIXME just to make sure. But this should be
already set somewhere else. */
view->details->current_position
= GNOME_VFS_DIRECTORY_LIST_POSITION_NONE;
g_assert (view->details->current_position
== GNOME_VFS_DIRECTORY_LIST_POSITION_NONE);
if (result != GNOME_VFS_ERROR_EOF)
view->details->display_timeout_id
......@@ -677,6 +672,11 @@ fm_directory_view_load_uri (FMDirectoryView *view,
gnome_vfs_uri_unref (view->details->uri);
view->details->uri = gnome_vfs_uri_new (uri);
if (view->details->directory_list != NULL)
gnome_vfs_directory_list_destroy (view->details->directory_list);
view->details->current_position = GNOME_VFS_DIRECTORY_LIST_POSITION_NONE;
memset(&pri, 0, sizeof(pri));
pri.type = Nautilus_PROGRESS_UNDERWAY;
pri.amount = 0;
......@@ -729,11 +729,13 @@ fm_directory_view_stop (FMDirectoryView *view)
* Reorder the items in this view.
* @view: FMDirectoryView whose items will be reordered.
* @sort_type: FMDirectoryViewSortType specifying what new order to use.
* @reverse_sort: TRUE if items should be sorted in reverse of standard order.
*
**/
void
fm_directory_view_sort (FMDirectoryView *view,
FMDirectoryViewSortType sort_type)
FMDirectoryViewSortType sort_type,
gboolean reverse_sort)
{
GnomeVFSDirectorySortRule *rules;
......@@ -747,10 +749,14 @@ fm_directory_view_sort (FMDirectoryView *view,
switch (sort_type) {
case FM_DIRECTORY_VIEW_SORT_BYNAME:
rules = ALLOC_RULES (3);
rules[0] = GNOME_VFS_DIRECTORY_SORT_DIRECTORYFIRST;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYNAME;
rules[2] = GNOME_VFS_DIRECTORY_SORT_NONE;
rules = ALLOC_RULES (2);
/* Note: This used to put directories first. I
* thought that was counterproductive and removed it,
* but I can imagine discussing this further.
* John Sullivan <sullivan@eazel.com>
*/
rules[0] = GNOME_VFS_DIRECTORY_SORT_BYNAME;
rules[1] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case FM_DIRECTORY_VIEW_SORT_BYSIZE:
rules = ALLOC_RULES (4);
......@@ -766,13 +772,19 @@ fm_directory_view_sort (FMDirectoryView *view,
rules[2] = GNOME_VFS_DIRECTORY_SORT_BYNAME;
rules[3] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
case FM_DIRECTORY_VIEW_SORT_BYMTIME:
rules = ALLOC_RULES (3);
rules[0] = GNOME_VFS_DIRECTORY_SORT_BYMTIME;
rules[1] = GNOME_VFS_DIRECTORY_SORT_BYNAME;
rules[2] = GNOME_VFS_DIRECTORY_SORT_NONE;
break;
default:
g_warning ("fm_directory_view_sort: Unknown sort mode %d\n",
sort_type);
return;
}
gnome_vfs_directory_list_sort (view->details->directory_list, FALSE, rules);
gnome_vfs_directory_list_sort (view->details->directory_list, reverse_sort, rules);
fm_directory_view_populate (view);
......@@ -782,20 +794,28 @@ fm_directory_view_sort (FMDirectoryView *view,
/**
* nautilus_file_date_as_string:
*
* Get a user-displayable string representing a file date. The caller
* is responsible for g_free-ing this string.
* @bytes: The date of the file.
* Get a user-displayable string representing a file modification date.
* The caller is responsible for g_free-ing this string.
* @file_info: GnomeVFSFileInfo representing the file in question.
*
* Returns: Newly allocated string ready to display to the user.
*
**/
gchar *
nautilus_file_date_as_string (time_t date)
nautilus_file_date_as_string (GnomeVFSFileInfo *file_info)
{
/* Note: There's also accessed time and changed time.
* Accessed time doesn't seem worth showing to the user.
* Changed time is only subtly different from modified time
* (changed time includes "metadata" changes like file permissions).
* We should not display both, but we might change our minds as to
* which one is better.
*/
/* Note that ctime is a funky function that returns a
* string that you're not supposed to free.
*/
return g_strdup (ctime (&date));
return g_strdup (ctime (&file_info->mtime));
}
/**
......@@ -803,13 +823,42 @@ nautilus_file_date_as_string (time_t date)
*
* Get a user-displayable string representing a file size. The caller
* is responsible for g_free-ing this string.
* @bytes: The size of the file in bytes.
* @file_info: GnomeVFSFileInfo representing the file in question.
*
* Returns: Newly allocated string ready to display to the user.
*
**/
gchar *
nautilus_file_size_as_string (GnomeVFSFileInfo *file_info)
{
if (file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
{
return g_strdup(_("--"));
}
return gnome_vfs_file_size_to_string (file_info->size);
}
/**
* nautilus_file_type_as_string:
*
* Get a user-displayable string representing a file type. The caller
* is responsible for g_free-ing this string.
* @file_info: GnomeVFSFileInfo representing the file in question.
*
* Returns: Newly allocated string ready to display to the user.
*
**/
gchar *
nautilus_file_size_as_string (GnomeVFSFileSize bytes)
nautilus_file_type_as_string (GnomeVFSFileInfo *file_info)
{
return gnome_vfs_file_size_to_string (bytes);
if (file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
{
/* Special-case this so it isn't "special/directory".
* Should this be "folder" instead?
*/
return g_strdup(_("directory"));
}
return g_strdup (file_info->mime_type);
}
......@@ -32,9 +32,11 @@
enum _FMDirectoryViewSortType {
FM_DIRECTORY_VIEW_SORT_NONE,
FM_DIRECTORY_VIEW_SORT_BYNAME,
FM_DIRECTORY_VIEW_SORT_BYSIZE,
FM_DIRECTORY_VIEW_SORT_BYTYPE
FM_DIRECTORY_VIEW_SORT_BYTYPE,
FM_DIRECTORY_VIEW_SORT_BYMTIME
};
typedef enum _FMDirectoryViewSortType FMDirectoryViewSortType;
......@@ -116,7 +118,8 @@ GnomeVFSURI *fm_directory_view_get_uri (FMDirectoryView *view);
GList * fm_directory_view_get_selection (FMDirectoryView *view);
void fm_directory_view_stop (FMDirectoryView *view);
void fm_directory_view_sort (FMDirectoryView *view,
FMDirectoryViewSortType sort_type);
FMDirectoryViewSortType sort_type,
gboolean reverse_sort);
/* Wrappers for signal emitters. These are normally called
* only by FMDirectoryView itself. They have corresponding signals
......@@ -140,7 +143,8 @@ void fm_directory_view_populate (FMDirectoryView *view);
/* Utility functions for formatting file-related information.
* FIXME: Probably these should be moved to some appropriate place in libnautilus.
*/
gchar *nautilus_file_date_as_string (time_t date);
gchar *nautilus_file_size_as_string (GnomeVFSFileSize bytes);
gchar *nautilus_file_date_as_string (GnomeVFSFileInfo *file_info);
gchar *nautilus_file_size_as_string (GnomeVFSFileInfo *file_info);
gchar *nautilus_file_type_as_string (GnomeVFSFileInfo *file_info);
#endif /* FM_DIRECTORY_VIEW_H */
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