diff --git a/Changes.md b/Changes.md index 63dfbc55e0..8e31449e04 100644 --- a/Changes.md +++ b/Changes.md @@ -7,6 +7,7 @@ Improvements - UI Editor : - Added the ability to edit the scale of node icons. - Improved layout of Box node plug creator visibility toggles. +- 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 8af129a815..2d2e9519ab 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