From e0055bcf867ed1de26514e0f2495088d15f6b326 Mon Sep 17 00:00:00 2001 From: Murray Stevenson <50844517+murraystevenson@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:21:04 -0700 Subject: [PATCH] PathColumn : Allow sorting of FileIconPathColumn Sorting by file extension is an approximation of sorting by file type, but is likely enough for our purposes. `std::filesystem::path::extension()` returns the last part of the filename from the rightmost `.`, which means "foo.tar.gz" will sort with "foo.gz", but this is preferable to a more greedy approach that would treat "foo.0001.exr" as having an extension of "0001.exr". --- Changes.md | 1 + src/GafferUI/PathColumn.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index 8bd57cfd402..a06c19bca22 100644 --- a/Changes.md +++ b/Changes.md @@ -13,6 +13,7 @@ Improvements - Added the ability to edit the scale of node icons. - Improved layout of Box node plug creator visibility toggles. - ArnoldShader : Moved the `toon` shader's `*_tonemap_hue_saturation` parameters to appropriate sections in the UI. +- File Browser : The "Type" column can now be sorted. This sorts directories separately from files, which are sorted by their extension. API --- diff --git a/src/GafferUI/PathColumn.cpp b/src/GafferUI/PathColumn.cpp index 8af129a815b..2d2e9519ab0 100644 --- a/src/GafferUI/PathColumn.cpp +++ b/src/GafferUI/PathColumn.cpp @@ -241,6 +241,8 @@ FileIconPathColumn::FileIconPathColumn( SizeMode sizeMode ) PathColumn::CellData FileIconPathColumn::cellData( const Gaffer::Path &path, const IECore::Canceller *canceller ) const { + CellData result; + std::string s = path.string(); if( const FileSystemPath *fileSystemPath = runTimeCast( &path ) ) { @@ -256,7 +258,13 @@ PathColumn::CellData FileIconPathColumn::cellData( const Gaffer::Path &path, con } } - return CellData( /* value = */ nullptr, /* icon = */ new StringData( "fileIcon:" + s ) ); + result.icon = new StringData( "fileIcon:" + s ); + const auto p = std::filesystem::path( s ); + // Use a sortValue of `extension:stem` to allow sorting by extension + // while maintaining a reasonable ordering within each extension. + result.sortValue = new StringData( ( std::filesystem::is_directory( p ) ? " " : p.extension().string() ) + ":" + p.stem().string() ); + + return result; } PathColumn::CellData FileIconPathColumn::headerData( const IECore::Canceller *canceller ) const