Skip to content

Commit

Permalink
PathColumn : Allow sorting of FileIconPathColumn
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
murraystevenson committed Sep 4, 2024
1 parent 2293ae1 commit e0055bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
10 changes: 9 additions & 1 deletion src/GafferUI/PathColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const FileSystemPath>( &path ) )
{
Expand All @@ -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
Expand Down

0 comments on commit e0055bc

Please sign in to comment.