@@ -164,8 +164,9 @@ static GQuark attribute_name_q,
164164 attribute_link_target_q ,
165165 attribute_volume_q ,
166166 attribute_free_space_q ,
167- attribute_search_result_snippet_q ,
168- attribute_search_result_count_q ;
167+ attribute_extension_q ,
168+ attribute_search_result_snippet_q ,
169+ attribute_search_result_count_q ;
169170
170171static void nemo_file_info_iface_init (NemoFileInfoInterface * iface );
171172
@@ -3226,6 +3227,48 @@ compare_by_type (NemoFile *file_1, NemoFile *file_2, gboolean detailed)
32263227 return result ;
32273228}
32283229
3230+ static int
3231+ compare_by_extension (NemoFile * file_1 , NemoFile * file_2 )
3232+ {
3233+ const char * name_1 , * name_2 ;
3234+ char * ext_1 , * ext_2 ;
3235+ char * ext_1_folded , * ext_2_folded ;
3236+ int result ;
3237+
3238+ name_1 = nemo_file_peek_display_name (file_1 );
3239+ name_2 = nemo_file_peek_display_name (file_2 );
3240+
3241+ ext_1 = eel_filename_get_extension_offset (name_1 );
3242+ ext_2 = eel_filename_get_extension_offset (name_2 );
3243+
3244+ if (ext_1 == NULL && ext_2 == NULL ) {
3245+ return 0 ;
3246+ }
3247+
3248+ if (ext_1 == NULL ) {
3249+ return -1 ;
3250+ }
3251+
3252+ if (ext_2 == NULL ) {
3253+ return 1 ;
3254+ }
3255+
3256+ /* Skip the dot */
3257+ ext_1 ++ ;
3258+ ext_2 ++ ;
3259+
3260+ /* Case-insensitive comparison */
3261+ ext_1_folded = g_utf8_casefold (ext_1 , -1 );
3262+ ext_2_folded = g_utf8_casefold (ext_2 , -1 );
3263+
3264+ result = g_utf8_collate (ext_1_folded , ext_2_folded );
3265+
3266+ g_free (ext_1_folded );
3267+ g_free (ext_2_folded );
3268+
3269+ return result ;
3270+ }
3271+
32293272static int
32303273compare_by_time (NemoFile * file_1 , NemoFile * file_2 , NemoDateType type )
32313274{
@@ -3410,6 +3453,12 @@ nemo_file_compare_for_sort (NemoFile *file_1,
34103453 if (result == 0 ) {
34113454 result = compare_by_full_path (file_1 , file_2 );
34123455 }
3456+ break ;
3457+ case NEMO_FILE_SORT_BY_EXTENSION :
3458+ result = compare_by_extension (file_1 , file_2 );
3459+ if (result == 0 ) {
3460+ result = compare_by_full_path (file_1 , file_2 );
3461+ }
34133462 break ;
34143463 case NEMO_FILE_SORT_BY_MTIME :
34153464 result = compare_by_time (file_1 , file_2 , NEMO_DATE_TYPE_MODIFIED );
@@ -3500,6 +3549,13 @@ nemo_file_compare_for_sort_by_attribute_q (NemoFile *file_1,
35003549 favorites_first ,
35013550 reversed ,
35023551 search_dir );
3552+ } else if (attribute == attribute_extension_q ) {
3553+ return nemo_file_compare_for_sort (file_1 , file_2 ,
3554+ NEMO_FILE_SORT_BY_EXTENSION ,
3555+ directories_first ,
3556+ favorites_first ,
3557+ reversed ,
3558+ search_dir );
35033559 } else if (attribute == attribute_modification_date_q ||
35043560 attribute == attribute_date_modified_q ||
35053561 attribute == attribute_date_modified_with_time_q ||
@@ -6724,6 +6780,16 @@ nemo_file_get_string_attribute_q (NemoFile *file, GQuark attribute_q)
67246780 if (attribute_q == attribute_name_q ) {
67256781 return nemo_file_get_display_name (file );
67266782 }
6783+ if (attribute_q == attribute_extension_q ) {
6784+ const char * name ;
6785+ char * ext ;
6786+ name = nemo_file_peek_display_name (file );
6787+ ext = eel_filename_get_extension_offset (name );
6788+ if (ext ) {
6789+ return g_strdup (ext + 1 );
6790+ }
6791+ return NULL ;
6792+ }
67276793 if (attribute_q == attribute_type_q ) {
67286794 return nemo_file_get_type_as_string (file );
67296795 }
@@ -8959,6 +9025,7 @@ nemo_file_class_init (NemoFileClass *class)
89599025 attribute_link_target_q = g_quark_from_static_string ("link_target" );
89609026 attribute_volume_q = g_quark_from_static_string ("volume" );
89619027 attribute_free_space_q = g_quark_from_static_string ("free_space" );
9028+ attribute_extension_q = g_quark_from_static_string ("extension" );
89629029 attribute_search_result_snippet_q = g_quark_from_string ("search_result_snippet" );
89639030 attribute_search_result_count_q = g_quark_from_string ("search_result_count" );
89649031
0 commit comments