Commit 9c1fa94e authored by Reuben Green's avatar Reuben Green
Browse files

Implement directory specific saving of sort-column and sort-order (#8)

Implements the saving of sort-column and sort-order for each directory.
parent f96b78a4
Pipeline #1367 passed with stages
in 5 minutes and 55 seconds
......@@ -121,6 +121,46 @@ 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 NULL;
return enum_value->value_name;
}
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)
return FALSE;
*value = enum_value->value;
return TRUE;
}
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 ())
......
......@@ -4628,9 +4628,15 @@ thunar_file_clear_directory_specific_settings (ThunarFile *file)
return;
g_file_info_remove_attribute (file->info, "metadata::thunar-view-type");
g_file_info_remove_attribute (file->info, "metadata::thunar-sort-column");
g_file_info_remove_attribute (file->info, "metadata::thunar-sort-order");
g_file_set_attribute (file->gfile, "metadata::thunar-view-type", G_FILE_ATTRIBUTE_TYPE_INVALID,
NULL, G_FILE_QUERY_INFO_NONE, NULL, NULL);
g_file_set_attribute (file->gfile, "metadata::thunar-sort-column", G_FILE_ATTRIBUTE_TYPE_INVALID,
NULL, G_FILE_QUERY_INFO_NONE, NULL, NULL);
g_file_set_attribute (file->gfile, "metadata::thunar-sort-order", G_FILE_ATTRIBUTE_TYPE_INVALID,
NULL, G_FILE_QUERY_INFO_NONE, NULL, NULL);
thunar_file_changed (file);
}
......@@ -4655,6 +4661,10 @@ thunar_file_has_directory_specific_settings (ThunarFile *file)
if (g_file_info_has_attribute (file->info, "metadata::thunar-view-type"))
return TRUE;
if (g_file_info_has_attribute (file->info, "metadata::thunar-sort-column"))
return TRUE;
if (g_file_info_has_attribute (file->info, "metadata::thunar-sort-order"))
return TRUE;
return FALSE;
}
......@@ -380,7 +380,7 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog)
button = gtk_check_button_new_with_mnemonic (_("_Remember view settings for each folder"));
exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-directory-specific-settings", G_OBJECT (button), "active");
gtk_widget_set_tooltip_text (button,
_("Select this option to remember view type individually for each folder"));
_("Select this option to remember view type, sort column, and sort order individually for each folder"));
gtk_widget_set_hexpand (button, TRUE);
gtk_grid_attach (GTK_GRID (grid), button, 0, 2, 1, 1);
gtk_widget_show (button);
......
......@@ -71,6 +71,7 @@ enum
PROP_SHOW_HIDDEN,
PROP_STATUSBAR_TEXT,
PROP_ZOOM_LEVEL,
PROP_DIRECTORY_SPECIFIC_SETTINGS,
PROP_THUMBNAIL_DRAW_FRAMES,
PROP_ACCEL_GROUP,
N_PROPERTIES
......@@ -131,6 +132,10 @@ 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_directory_specific_settings (ThunarStandardView *standard_view,
ThunarFile *directory);
static void thunar_standard_view_set_directory_specific_settings (ThunarStandardView *standard_view,
gboolean directory_specific_settings);
static void thunar_standard_view_reload (ThunarView *view,
gboolean reload_info);
static gboolean thunar_standard_view_get_visible_range (ThunarView *view,
......@@ -275,6 +280,9 @@ struct _ThunarStandardViewPrivate
/* zoom-level support */
ThunarZoomLevel zoom_level;
/* directory specific settings */
gboolean directory_specific_settings;
/* scroll_to_file support */
GHashTable *scroll_to_files;
......@@ -435,6 +443,18 @@ thunar_standard_view_class_init (ThunarStandardViewClass *klass)
NULL,
EXO_PARAM_READABLE);
/**
* ThunarStandardView:directory-specific-settings:
*
* Whether to use directory specific settings.
**/
standard_view_props[PROP_DIRECTORY_SPECIFIC_SETTINGS] =
g_param_spec_boolean ("directory-specific-settings",
"directory-specific-settings",
"directory-specific-settings",
FALSE,
EXO_PARAM_READWRITE);
/**
* ThunarStandardView:thumbnail-draw-frames:
*
......@@ -702,6 +722,10 @@ thunar_standard_view_constructor (GType type,
g_signal_connect (adjustment, "value-changed",
G_CALLBACK (thunar_standard_view_scrolled), object);
/* synchronise the "directory-specific-settings" property with the global "misc-directory-specific-settings" property */
exo_binding_new (G_OBJECT (standard_view->preferences), "misc-directory-specific-settings",
G_OBJECT (standard_view), "directory-specific-settings");
/* done, we have a working object */
return object;
}
......@@ -921,6 +945,10 @@ thunar_standard_view_set_property (GObject *object,
thunar_view_set_zoom_level (THUNAR_VIEW (object), g_value_get_enum (value));
break;
case PROP_DIRECTORY_SPECIFIC_SETTINGS:
thunar_standard_view_set_directory_specific_settings (standard_view, g_value_get_boolean (value));
break;
case PROP_THUMBNAIL_DRAW_FRAMES:
g_object_set (G_OBJECT (standard_view->icon_factory), "thumbnail-draw-frames", g_value_get_boolean (value), NULL);
thunar_standard_view_reload(THUNAR_VIEW (object), TRUE);
......@@ -1277,6 +1305,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 directory specific settings are enabled, apply them */
if (standard_view->priv->directory_specific_settings)
thunar_standard_view_apply_directory_specific_settings (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.
*/
......@@ -1531,6 +1563,86 @@ thunar_standard_view_reset_zoom_level (ThunarView *view)
static void
thunar_standard_view_apply_directory_specific_settings (ThunarStandardView *standard_view,
ThunarFile *directory)
{
const gchar *sort_column_name;
const gchar *sort_order_name;
gint sort_column;
GtkSortType sort_order;
/* get the default sort column and sort order */
g_object_get (G_OBJECT (standard_view->preferences), "last-sort-column", &sort_column, "last-sort-order", &sort_order, NULL);
/* get the stored directory specific settings (if any) */
sort_column_name = thunar_file_get_metadata_setting (directory, "sort-column");
sort_order_name = thunar_file_get_metadata_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 directory specific 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_directory_specific_settings (ThunarStandardView *standard_view,
gboolean directory_specific_settings)
{
/* save the setting */
standard_view->priv->directory_specific_settings = directory_specific_settings;
/* if there is no current directory then return */
if (standard_view->priv->current_directory == NULL)
return;
/* apply the appropriate settings */
if (directory_specific_settings)
{
/* apply the directory specific settings (if any) */
thunar_standard_view_apply_directory_specific_settings (standard_view, standard_view->priv->current_directory);
}
else /* apply the shared settings to the current view */
{
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);
}
}
static void
thunar_standard_view_reload (ThunarView *view,
gboolean reload_info)
......@@ -1551,6 +1663,11 @@ thunar_standard_view_reload (ThunarView *view,
thunar_standard_view_current_directory_destroy (file, standard_view);
}
/* if directory specific settings are enabled, apply them. the reload might have been triggered */
/* specifically to ensure that any change in these settings is applied */
if (standard_view->priv->directory_specific_settings)
thunar_standard_view_apply_directory_specific_settings (standard_view, standard_view->priv->current_directory);
/* schedule thumbnail reload update */
if (!standard_view->priv->thumbnailing_scheduled)
thunar_standard_view_schedule_thumbnail_idle (standard_view);
......@@ -3010,14 +3127,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->directory_specific_settings)
{
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_metadata_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_metadata_setting (standard_view->priv->current_directory, "sort-order", sort_order_name);
}
else
{
/* 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);
}
}
}
......
......@@ -2673,6 +2673,7 @@ static void
thunar_window_action_clear_directory_specific_settings (ThunarWindow *window)
{
GType view_type;
gboolean result;
/* clear the settings */
thunar_file_clear_directory_specific_settings (window->current_directory);
......@@ -2680,6 +2681,9 @@ thunar_window_action_clear_directory_specific_settings (ThunarWindow *window)
/* get the correct view type for the current directory */
view_type = thunar_window_view_type_for_directory (window, window->current_directory);
/* force the view to reload so that any changes to the settings are applied */
g_signal_emit (G_OBJECT (window), window_signals[RELOAD], 0, TRUE, &result);
/* replace the active view with a new one of the correct type */
thunar_window_replace_view (window, window->view, view_type);
}
......@@ -2725,6 +2729,10 @@ thunar_window_replace_view (ThunarWindow *window,
_thunar_return_if_fail (view_type != G_TYPE_NONE);
/* if the view already has the correct type then just return */
if (view != NULL && G_TYPE_FROM_INSTANCE (view) == view_type)
return;
/* is the view we are replacing the active view?
* (note that this will be true if both view and window->view are NULL) */
is_current_view = (view == window->view);
......
......@@ -48,7 +48,8 @@ G_BEGIN_DECLS
"trash::*," \
"unix::gid,unix::uid,unix::mode," \
"metadata::emblems," \
"metadata::thunar-view-type"
"metadata::thunar-view-type," \
"metadata::thunar-sort-column,metadata::thunar-sort-order"
......
Supports Markdown
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