Commit 92b600fb authored by Reuben Green's avatar Reuben Green

implemented per-directory sort column and sort order

parent ec0391ef
......@@ -121,6 +121,48 @@ thunar_column_get_type (void)
const gchar*
thunar_column_string_from_value (ThunarColumn value)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
enum_class = g_type_class_ref (THUNAR_TYPE_COLUMN);
enum_value = g_enum_get_value (enum_class, value);
g_type_class_unref (enum_class);
if (enum_value != NULL)
return enum_value->value_name;
else
return NULL;
}
gboolean
thunar_column_value_from_string (const gchar *value_string,
gint *value)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
enum_class = g_type_class_ref (THUNAR_TYPE_COLUMN);
enum_value = g_enum_get_value_by_name (enum_class, value_string);
g_type_class_unref (enum_class);
if (enum_value != NULL)
{
*value = enum_value->value;
return TRUE;
}
else
return FALSE;
}
GType
thunar_icon_size_get_type (void)
{
......
......@@ -116,7 +116,10 @@ typedef enum
THUNAR_N_VISIBLE_COLUMNS = THUNAR_COLUMN_FILE,
} ThunarColumn;
GType thunar_column_get_type (void) G_GNUC_CONST;
GType thunar_column_get_type (void) G_GNUC_CONST;
const gchar* thunar_column_string_from_value (ThunarColumn value);
gboolean thunar_column_value_from_string (const gchar *value_string,
gint *value);
#define THUNAR_TYPE_ICON_SIZE (thunar_icon_size_get_type ())
......
......@@ -4528,6 +4528,10 @@ thunar_file_get_view_setting (ThunarFile *file,
if (g_strcmp0 (setting_name, "view-type") == 0)
attr_name = "metadata::thunar::view-type";
else if (g_strcmp0 (setting_name, "sort-column") == 0)
attr_name = "metadata::thunar::sort-column";
else if (g_strcmp0 (setting_name, "sort-order") == 0)
attr_name = "metadata::thunar::sort-order";
else
return NULL;
......@@ -4552,6 +4556,10 @@ thunar_file_set_view_setting (ThunarFile *file,
if (g_strcmp0 (setting_name, "view-type") == 0)
attr_name = "metadata::thunar::view-type";
else if (g_strcmp0 (setting_name, "sort-column") == 0)
attr_name = "metadata::thunar::sort-column";
else if (g_strcmp0 (setting_name, "sort-order") == 0)
attr_name = "metadata::thunar::sort-order";
else
return;
......
......@@ -132,6 +132,8 @@ static ThunarZoomLevel thunar_standard_view_get_zoom_level (Thu
static void thunar_standard_view_set_zoom_level (ThunarView *view,
ThunarZoomLevel zoom_level);
static void thunar_standard_view_reset_zoom_level (ThunarView *view);
static void thunar_standard_view_apply_per_directory (ThunarStandardView *standard_view,
ThunarFile *directory);
static void thunar_standard_view_set_per_directory (ThunarStandardView *standard_view,
gboolean per_directory);
static void thunar_standard_view_reload (ThunarView *view,
......@@ -1299,6 +1301,10 @@ thunar_standard_view_set_current_directory (ThunarNavigator *navigator,
/* store the directory in the history */
thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (standard_view->priv->history), current_directory);
/* if per-directory settings are enabled, set the sort column and sort order*/
if (standard_view->priv->per_directory)
thunar_standard_view_apply_per_directory (standard_view, current_directory);
/* We drop the model from the view as a simple optimization to speed up
* the process of disconnecting the model data from the view.
*/
......@@ -1553,12 +1559,82 @@ thunar_standard_view_reset_zoom_level (ThunarView *view)
void
static void
thunar_standard_view_apply_per_directory (ThunarStandardView *standard_view,
ThunarFile *directory)
{
gchar *sort_column_name;
gchar *sort_order_name;
gint sort_column;
GtkSortType sort_order;
/* get the current sort column and sort order */
gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), &sort_column, &sort_order);
/* get the stored per-directory settings (if any) */
sort_column_name = thunar_file_get_view_setting (directory, "sort-column");
sort_order_name = thunar_file_get_view_setting (directory, "sort-order");
/* convert the sort column name to a value */
if (sort_column_name != NULL)
thunar_column_value_from_string (sort_column_name, &sort_column);
/* convert the sort order name to a value */
if (sort_order_name != NULL)
{
if (g_strcmp0 (sort_order_name, "GTK_SORT_ASCENDING") == 0)
sort_order = GTK_SORT_ASCENDING;
if (g_strcmp0 (sort_order_name, "GTK_SORT_DESCENDING") == 0)
sort_order = GTK_SORT_DESCENDING;
}
/* thunar_standard_view_sort_column_changed saves the per-directory settings to the directory, but we do not
* want that behaviour here so we disconnect the signal before calling gtk_tree_sortable_set_sort_column_id */
g_signal_handlers_disconnect_by_func (G_OBJECT (standard_view->model),
G_CALLBACK (thunar_standard_view_sort_column_changed),
standard_view);
/* apply the sort column and sort order */
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), sort_column, sort_order);
/* keep the currently selected files selected after the change */
thunar_component_restore_selection (THUNAR_COMPONENT (standard_view));
/* reconnect the signal */
g_signal_connect (G_OBJECT (standard_view->model),
"sort-column-changed",
G_CALLBACK (thunar_standard_view_sort_column_changed),
standard_view);
}
static void
thunar_standard_view_set_per_directory (ThunarStandardView *standard_view,
gboolean per_directory)
{
/* save the setting */
standard_view->priv->per_directory = per_directory;
/* if there is no current directory then return */
if (standard_view->priv->current_directory == NULL)
return;
/* apply the appropriate settings */
if (per_directory)
{
/* apply the per-directory settings (if any) */
thunar_standard_view_apply_per_directory (standard_view, standard_view->priv->current_directory);
}
else
{
gint sort_column;
GtkSortType sort_order;
/* apply the last sort column and sort order */
g_object_get (G_OBJECT (standard_view->preferences), "last-sort-column", &sort_column, "last-sort-order", &sort_order, NULL);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), sort_column, sort_order);
}
}
......@@ -3042,14 +3118,36 @@ thunar_standard_view_sort_column_changed (GtkTreeSortable *tree_sortable,
/* keep the currently selected files selected after the change */
thunar_component_restore_selection (THUNAR_COMPONENT (standard_view));
/* determine the new sort column and sort order */
/* determine the new sort column and sort order, and save them */
if (gtk_tree_sortable_get_sort_column_id (tree_sortable, &sort_column, &sort_order))
{
/* remember the new values as default */
g_object_set (G_OBJECT (standard_view->preferences),
"last-sort-column", sort_column,
"last-sort-order", sort_order,
NULL);
if (!standard_view->priv->per_directory)
{
/* remember the new values as default */
g_object_set (G_OBJECT (standard_view->preferences),
"last-sort-column", sort_column,
"last-sort-order", sort_order,
NULL);
}
else
{
const gchar *sort_column_name;
const gchar *sort_order_name;
/* save the sort column name */
sort_column_name = thunar_column_string_from_value (sort_column);
if (sort_column_name != NULL)
thunar_file_set_view_setting (standard_view->priv->current_directory, "sort-column", sort_column_name);
/* convert the sort order to a string */
if (sort_order == GTK_SORT_ASCENDING)
sort_order_name = "GTK_SORT_ASCENDING";
if (sort_order == GTK_SORT_DESCENDING)
sort_order_name = "GTK_SORT_DESCENDING";
/* save the sort order */
thunar_file_set_view_setting (standard_view->priv->current_directory, "sort-order", sort_order_name);
}
}
}
......
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