Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gresources/nemo-desktop-overlay.glade
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
<col id="1" translatable="yes">Date</col>
<col id="2">Desktop Sort by Date</col>
</row>
<row>
<col id="0">10</col>
<col id="1" translatable="yes">Extension</col>
<col id="2">Desktop Sort by Extension</col>
</row>
</data>
</object>
<object class="XAppGtkWindow" id="overlay_window">
Expand Down
10 changes: 6 additions & 4 deletions gresources/nemo-icon-view-ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<menuitem name="Sort by Type" action="Sort by Type"/>
<menuitem name="Sort by Detailed Type" action="Sort by Detailed Type"/>
<menuitem name="Sort by Modification Date" action="Sort by Modification Date"/>
<menuitem name="Sort by Trash Time" action="Sort by Trash Time"/>
</placeholder>
<menuitem name="Sort by Trash Time" action="Sort by Trash Time"/>
<menuitem name="Sort by Extension" action="Sort by Extension"/>
</placeholder>
<separator name="Layout separator"/>
<menuitem name="Reversed Order" action="Reversed Order"/>
</menu>
Expand All @@ -32,8 +33,9 @@
<menuitem name="Sort by Type" action="Sort by Type"/>
<menuitem name="Sort by Detailed Type" action="Sort by Detailed Type"/>
<menuitem name="Sort by Modification Date" action="Sort by Modification Date"/>
<menuitem name="Sort by Trash Time" action="Sort by Trash Time"/>
</placeholder>
<menuitem name="Sort by Trash Time" action="Sort by Trash Time"/>
<menuitem name="Sort by Extension" action="Sort by Extension"/>
</placeholder>
<separator name="Layout separator"/>
<menuitem name="Reversed Order" action="Reversed Order"/>
</menu>
Expand Down
7 changes: 7 additions & 0 deletions libnemo-private/nemo-column-utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ get_builtin_columns (void)
"label", _("MIME Type"),
"description", _("The mime type of the file."),
NULL));
columns = g_list_append (columns,
g_object_new (NEMO_TYPE_COLUMN,
"name", "extension",
"attribute", "extension",
"label", _("Extension"),
"description", _("The extension of the file."),
NULL));
#ifdef HAVE_SELINUX
columns = g_list_append (columns,
g_object_new (NEMO_TYPE_COLUMN,
Expand Down
71 changes: 69 additions & 2 deletions libnemo-private/nemo-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ static GQuark attribute_name_q,
attribute_link_target_q,
attribute_volume_q,
attribute_free_space_q,
attribute_search_result_snippet_q,
attribute_search_result_count_q;
attribute_extension_q,
attribute_search_result_snippet_q,
attribute_search_result_count_q;

static void nemo_file_info_iface_init (NemoFileInfoInterface *iface);

Expand Down Expand Up @@ -3226,6 +3227,48 @@ compare_by_type (NemoFile *file_1, NemoFile *file_2, gboolean detailed)
return result;
}

static int
compare_by_extension (NemoFile *file_1, NemoFile *file_2)
{
const char *name_1, *name_2;
char *ext_1, *ext_2;
char *ext_1_folded, *ext_2_folded;
int result;

name_1 = nemo_file_peek_display_name (file_1);
name_2 = nemo_file_peek_display_name (file_2);

ext_1 = eel_filename_get_extension_offset (name_1);
ext_2 = eel_filename_get_extension_offset (name_2);

if (ext_1 == NULL && ext_2 == NULL) {
return 0;
}

if (ext_1 == NULL) {
return -1;
}

if (ext_2 == NULL) {
return 1;
}

/* Skip the dot */
ext_1++;
ext_2++;

/* Case-insensitive comparison */
ext_1_folded = g_utf8_casefold (ext_1, -1);
ext_2_folded = g_utf8_casefold (ext_2, -1);

result = g_utf8_collate (ext_1_folded, ext_2_folded);

g_free (ext_1_folded);
g_free (ext_2_folded);

return result;
}

static int
compare_by_time (NemoFile *file_1, NemoFile *file_2, NemoDateType type)
{
Expand Down Expand Up @@ -3410,6 +3453,12 @@ nemo_file_compare_for_sort (NemoFile *file_1,
if (result == 0) {
result = compare_by_full_path (file_1, file_2);
}
break;
case NEMO_FILE_SORT_BY_EXTENSION:
result = compare_by_extension (file_1, file_2);
if (result == 0) {
result = compare_by_full_path (file_1, file_2);
}
break;
case NEMO_FILE_SORT_BY_MTIME:
result = compare_by_time (file_1, file_2, NEMO_DATE_TYPE_MODIFIED);
Expand Down Expand Up @@ -3500,6 +3549,13 @@ nemo_file_compare_for_sort_by_attribute_q (NemoFile *file_1,
favorites_first,
reversed,
search_dir);
} else if (attribute == attribute_extension_q) {
return nemo_file_compare_for_sort (file_1, file_2,
NEMO_FILE_SORT_BY_EXTENSION,
directories_first,
favorites_first,
reversed,
search_dir);
} else if (attribute == attribute_modification_date_q ||
attribute == attribute_date_modified_q ||
attribute == attribute_date_modified_with_time_q ||
Expand Down Expand Up @@ -6724,6 +6780,16 @@ nemo_file_get_string_attribute_q (NemoFile *file, GQuark attribute_q)
if (attribute_q == attribute_name_q) {
return nemo_file_get_display_name (file);
}
if (attribute_q == attribute_extension_q) {
const char *name;
char *ext;
name = nemo_file_peek_display_name (file);
ext = eel_filename_get_extension_offset (name);
if (ext) {
return g_strdup (ext + 1);
}
return NULL;
}
if (attribute_q == attribute_type_q) {
return nemo_file_get_type_as_string (file);
}
Expand Down Expand Up @@ -8959,6 +9025,7 @@ nemo_file_class_init (NemoFileClass *class)
attribute_link_target_q = g_quark_from_static_string ("link_target");
attribute_volume_q = g_quark_from_static_string ("volume");
attribute_free_space_q = g_quark_from_static_string ("free_space");
attribute_extension_q = g_quark_from_static_string ("extension");
attribute_search_result_snippet_q = g_quark_from_string ("search_result_snippet");
attribute_search_result_count_q = g_quark_from_string ("search_result_count");

Expand Down
8 changes: 4 additions & 4 deletions libnemo-private/nemo-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ typedef enum {
NEMO_FILE_SORT_BY_MTIME,
NEMO_FILE_SORT_BY_ATIME,
NEMO_FILE_SORT_BY_TRASHED_TIME,
NEMO_FILE_SORT_BY_BTIME,
NEMO_FILE_SORT_BY_SEARCH_RESULT_COUNT
} NemoFileSortType;

NEMO_FILE_SORT_BY_BTIME,
NEMO_FILE_SORT_BY_SEARCH_RESULT_COUNT,
NEMO_FILE_SORT_BY_EXTENSION
} NemoFileSortType;
typedef enum {
NEMO_REQUEST_NOT_STARTED,
NEMO_REQUEST_IN_PROGRESS,
Expand Down
11 changes: 10 additions & 1 deletion src/nemo-desktop-icon-grid-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ static const DesktopSortCriterion sort_criteria[] = {
"Desktop Sort by Date",
"modification date",
NEMO_FILE_SORT_BY_MTIME
},
{
"Desktop Sort by Extension",
"extension",
NEMO_FILE_SORT_BY_EXTENSION
}
};

Expand Down Expand Up @@ -1085,7 +1090,11 @@ static const GtkRadioActionEntry desktop_sort_radio_entries[] = {
{ "Desktop Sort by Date", NULL,
N_("Date"), NULL,
NULL,
NEMO_FILE_SORT_BY_MTIME }
NEMO_FILE_SORT_BY_MTIME },
{ "Desktop Sort by Extension", NULL,
N_("Extension"), NULL,
NULL,
NEMO_FILE_SORT_BY_EXTENSION }
};

static const GtkActionEntry desktop_grid_entries[] = {
Expand Down
3 changes: 3 additions & 0 deletions src/nemo-desktop-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ sync_controls (NemoDesktopOverlay *overlay,
case NEMO_FILE_SORT_BY_MTIME:
combo_id = "Desktop Sort by Date";
break;
case NEMO_FILE_SORT_BY_EXTENSION:
combo_id = "Desktop Sort by Extension";
break;
case NEMO_FILE_SORT_BY_DISPLAY_NAME:
default:
combo_id = "Desktop Sort by Name";
Expand Down
25 changes: 18 additions & 7 deletions src/nemo-icon-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,20 @@ static const SortCriterion sort_criteria[] = {
N_("by Modification _Date"),
N_("Keep icons sorted by modification date in rows")
},
{
NEMO_FILE_SORT_BY_TRASHED_TIME,
"trashed",
"Sort by Trash Time",
N_("by T_rash Time"),
N_("Keep icons sorted by trash time in rows")
}
{
NEMO_FILE_SORT_BY_TRASHED_TIME,
"trashed",
"Sort by Trash Time",
N_("by T_rash Time"),
N_("Keep icons sorted by trash time in rows")
},
{
NEMO_FILE_SORT_BY_EXTENSION,
"extension",
"Sort by Extension",
N_("by _Extension"),
N_("Keep icons sorted by extension in rows")
}
};

static void nemo_icon_view_set_directory_sort_by (NemoIconView *icon_view,
Expand Down Expand Up @@ -1448,6 +1455,10 @@ static const GtkRadioActionEntry arrange_radio_entries[] = {
N_("By T_rash Time"), NULL,
N_("Keep icons sorted by trash time in rows"),
NEMO_FILE_SORT_BY_TRASHED_TIME },
{ "Sort by Extension", NULL,
N_("By _Extension"), NULL,
N_("Keep icons sorted by extension in rows"),
NEMO_FILE_SORT_BY_EXTENSION },
};

static void
Expand Down