Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
thunar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Reuben Green
thunar
Commits
92b600fb
Commit
92b600fb
authored
May 16, 2020
by
Reuben Green
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented per-directory sort column and sort order
parent
ec0391ef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
159 additions
and
8 deletions
+159
-8
thunar/thunar-enum-types.c
thunar/thunar-enum-types.c
+42
-0
thunar/thunar-enum-types.h
thunar/thunar-enum-types.h
+4
-1
thunar/thunar-file.c
thunar/thunar-file.c
+8
-0
thunar/thunar-standard-view.c
thunar/thunar-standard-view.c
+105
-7
No files found.
thunar/thunar-enum-types.c
View file @
92b600fb
...
...
@@ -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
)
{
...
...
thunar/thunar-enum-types.h
View file @
92b600fb
...
...
@@ -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 ())
...
...
thunar/thunar-file.c
View file @
92b600fb
...
...
@@ -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
;
...
...
thunar/thunar-standard-view.c
View file @
92b600fb
...
...
@@ -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
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment