Skip to content

Commit

Permalink
Merge pull request #924 from guillep/table-sorting
Browse files Browse the repository at this point in the history
fix(sorting): Make many tables in inspector extensions properly sortable
  • Loading branch information
Ducasse authored Jan 13, 2025
2 parents 872ff2f + 2fb8e3b commit 650ffca
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 155 deletions.
10 changes: 0 additions & 10 deletions src/NewTools-FileBrowser/DateAndTime.extension.st

This file was deleted.

5 changes: 5 additions & 0 deletions src/NewTools-FileBrowser/StFileBrowserAbstractColumn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ StFileBrowserAbstractColumn class >> evaluateOn: aFileReference [
^ self subclassResponsibility
]

{ #category : 'templateMethod' }
StFileBrowserAbstractColumn class >> formatOn: aValue [
^ self subclassResponsibility
]

{ #category : 'testing' }
StFileBrowserAbstractColumn class >> isAbstract [

Expand Down
13 changes: 3 additions & 10 deletions src/NewTools-FileBrowser/StFileBrowserCreationDateColumn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@ I'm a column use to display the creation date of a file in a File dialog.
"
Class {
#name : 'StFileBrowserCreationDateColumn',
#superclass : 'StFileBrowserAbstractColumn',
#superclass : 'StFileBrowserDateColumn',
#category : 'NewTools-FileBrowser-Columns',
#package : 'NewTools-FileBrowser',
#tag : 'Columns'
}

{ #category : 'adding' }
StFileBrowserCreationDateColumn class >> addConstraintTo: aTableColumn [

aTableColumn
width: 150;
beSortable
]

{ #category : 'templateMethod' }
StFileBrowserCreationDateColumn class >> evaluateOn: aFileReference [
^ aFileReference creationTime fileDialogFormat

^ aFileReference creationTime
]

{ #category : 'sorting' }
Expand Down
33 changes: 33 additions & 0 deletions src/NewTools-FileBrowser/StFileBrowserDateColumn.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Class {
#name : 'StFileBrowserDateColumn',
#superclass : 'StFileBrowserAbstractColumn',
#category : 'NewTools-FileBrowser-Columns',
#package : 'NewTools-FileBrowser',
#tag : 'Columns'
}

{ #category : 'adding' }
StFileBrowserDateColumn class >> addConstraintTo: aTableColumn [

aTableColumn
width: 150;
formatted: [ :v | self formatOn: v ];
beSortable
]

{ #category : 'templateMethod' }
StFileBrowserDateColumn class >> formatOn: aValue [

aValue ifNil: [ ^ 'N/A' ].
^ '{1} {2} {3} {4}' format: {
aValue dayOfMonth asString.
aValue monthAbbreviation.
aValue year asString.
(aValue asTime print24 first: 5) }
]

{ #category : 'testing' }
StFileBrowserDateColumn class >> isAbstract [

^ self == StFileBrowserDateColumn
]
13 changes: 3 additions & 10 deletions src/NewTools-FileBrowser/StFileBrowserLastOpenDateColumn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@ I'm a column use to display the last access date of a file in a File dialog.
"
Class {
#name : 'StFileBrowserLastOpenDateColumn',
#superclass : 'StFileBrowserAbstractColumn',
#superclass : 'StFileBrowserDateColumn',
#category : 'NewTools-FileBrowser-Columns',
#package : 'NewTools-FileBrowser',
#tag : 'Columns'
}

{ #category : 'adding' }
StFileBrowserLastOpenDateColumn class >> addConstraintTo: aTableColumn [

aTableColumn
width: 150;
beSortable
]

{ #category : 'templateMethod' }
StFileBrowserLastOpenDateColumn class >> evaluateOn: aFileReference [
^ aFileReference accessTime fileDialogFormat

^ aFileReference accessTime
]

{ #category : 'sorting' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ I'm a column use to display the modification date of a file in a File dialog.
"
Class {
#name : 'StFileBrowserModificationDateColumn',
#superclass : 'StFileBrowserAbstractColumn',
#superclass : 'StFileBrowserDateColumn',
#category : 'NewTools-FileBrowser-Columns',
#package : 'NewTools-FileBrowser',
#tag : 'Columns'
}

{ #category : 'adding' }
StFileBrowserModificationDateColumn class >> addConstraintTo: aTableColumn [

aTableColumn
width: 150;
beSortable
]

{ #category : 'templateMethod' }
StFileBrowserModificationDateColumn class >> evaluateOn: aFileReference [

^ [ aFileReference modificationTime fileDialogFormat ]
^ [ aFileReference modificationTime ]
on: Error
do: [ 'N/A' ]
do: [ nil ]
]

{ #category : 'sorting' }
Expand Down
16 changes: 13 additions & 3 deletions src/NewTools-FileBrowser/StFileBrowserSizeColumn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Class {
StFileBrowserSizeColumn class >> addConstraintTo: aTableColumn [

aTableColumn
formatted: [ :e | self formatOn: e ];
width: 70;
beSortable
]
Expand All @@ -21,11 +22,20 @@ StFileBrowserSizeColumn class >> addConstraintTo: aTableColumn [
StFileBrowserSizeColumn class >> evaluateOn: aFileReference [

^ aFileReference isDirectory
ifTrue: [ '--' ]
ifTrue: [ 0 ]
ifFalse: [
[ aFileReference humanReadableSize ]
[ aFileReference size ]
on: Error
do: [ 'N/A' ] ]
do: [ 0 ] ]
]

{ #category : 'templateMethod' }
StFileBrowserSizeColumn class >> formatOn: aSize [

^ aSize ifNil: [ 'N/A' ] ifNotNil: [
[ aSize humanReadableSISizeString ]
on: Error
do: [ 'N/A' ] ]
]

{ #category : 'sorting' }
Expand Down
140 changes: 73 additions & 67 deletions src/NewTools-Inspector-Extensions/AbstractFileReference.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@ Extension { #name : 'AbstractFileReference' }

{ #category : '*NewTools-Inspector-Extensions' }
AbstractFileReference >> inspectionCompressedItems [

<inspectorPresentationOrder: 0 title: 'Compressed Items'>
| items children root |

root := (FileSystem zip: self) open workingDirectory.
children := root directories, root files.
items := self isRoot
ifTrue: [ children ]
ifFalse: [
children asOrderedCollection
addFirst: self parent;
yourself ].
children := root directories , root files.
items := self isRoot
ifTrue: [ children ]
ifFalse: [
children asOrderedCollection
addFirst: self parent;
yourself ].

^ SpTablePresenter new
items: items;
addColumn: (SpCompositeTableColumn new
title: 'Name';
addColumn: (SpImageTableColumn evaluated: [ :each |
self iconNamed: (each isDirectory
ifTrue: [ #folder ]
ifFalse: [ #browse ]) ]);
addColumn: (SpStringTableColumn evaluated: [ :each |
self parent = each
ifTrue: [ '..' ]
ifFalse: [ each basename ] ]));
addColumn: (SpStringTableColumn
title: 'Size'
evaluated: [ :each | each humanReadableSize ]);
addColumn: (SpStringTableColumn
title: 'Creation'
evaluated: [ :each |
String streamContents: [ :stream |
each creationTime printYMDOn: stream.
stream nextPut: Character space.
each creationTime printHMSOn: stream ] ])
items: items;
addColumn: (SpCompositeTableColumn new
title: 'Name';
addColumn: (SpImageTableColumn evaluated: [ :each |
self iconNamed: (each isDirectory
ifTrue: [ #folder ]
ifFalse: [ #browse ]) ]);
addColumn: (SpStringTableColumn evaluated: [ :each |
self parent = each
ifTrue: [ '..' ]
ifFalse: [ each basename ] ]));
addColumn: (SpStringTableColumn new
title: 'Size';
evaluated: [ :each | each size ];
formatted: [ :size | size humanReadableSISizeString ]);
addColumn: (SpStringTableColumn new
title: 'Creation';
evaluated: [ :each | each creationTime ];
formatted: [ :time |
[
String streamContents: [ :s |
time printYMDOn: s.
s nextPut: Character space.
time printHMSOn: s ] ]
on: Error
do: [ 'N/A' translated ] ];
beSortable)
]

{ #category : '*NewTools-Inspector-Extensions' }
Expand Down Expand Up @@ -103,46 +109,46 @@ AbstractFileReference >> inspectionGifContext: aContext [

{ #category : '*NewTools-Inspector-Extensions' }
AbstractFileReference >> inspectionItems [

<inspectorPresentationOrder: 0 title: 'Items'>
| items |

items := self directories, self files.
self isRoot ifFalse: [
items := items copyWithFirst: self parent ].

^ SpTablePresenter new
beResizable;
items: items;
addColumn: (SpCompositeTableColumn new
title: 'Name';
width: 300;
addColumn: (SpImageTableColumn evaluated: [ :each |
each isDirectory
ifTrue: [ self iconNamed: #folder ]
ifFalse: [ self iconNamed: #browse ] ])
beNotExpandable;
addColumn: (SpStringTableColumn evaluated: [ :each |
(self isChildOf: each)
ifTrue: [ '..' ]
ifFalse: [ each basename ] ]);
yourself);
addColumn: (SpStringTableColumn new
title: 'Size';
width: 100;
evaluated: [ :each |
[ each humanReadableSize ]
on: Error
do: [ 'N/A' translated ] ]);
addColumn: (SpStringTableColumn
title: 'Creation'
evaluated: [ :each |
[ String streamContents: [ :s |
each creationTime printYMDOn: s.
s nextPut: Character space.
each creationTime printHMSOn: s ] ]
on: Error
do: [ 'N/A' translated ] ]);
yourself
items := self directories , self files.
self isRoot ifFalse: [ items := items copyWithFirst: self parent ].

^ SpTablePresenter new
beResizable;
items: items;
addColumn: (SpCompositeTableColumn new
title: 'Name';
width: 300;
addColumn: (SpImageTableColumn evaluated: [ :each |
each isDirectory
ifTrue: [ self iconNamed: #folder ]
ifFalse: [ self iconNamed: #browse ] ]) beNotExpandable;
addColumn: (SpStringTableColumn evaluated: [ :each |
(self isChildOf: each)
ifTrue: [ '..' ]
ifFalse: [ each basename ] ]);
yourself);
addColumn: (SpStringTableColumn new
title: 'Size';
width: 100;
evaluated: [ :each | each size ];
formatted: [ :size | size humanReadableSISizeString ];
beSortable);
addColumn: (SpStringTableColumn new
title: 'Creation';
evaluated: [ :each | each creationTime ];
formatted: [ :time |
[
String streamContents: [ :s |
time printYMDOn: s.
s nextPut: Character space.
time printHMSOn: s ] ]
on: Error
do: [ 'N/A' translated ] ];
beSortable);
yourself
]

{ #category : '*NewTools-Inspector-Extensions' }
Expand Down
9 changes: 4 additions & 5 deletions src/NewTools-Inspector-Extensions/Bag.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ Bag >> inspectionItems: aBuilder [
^ aBuilder newTable
addColumn: (SpStringTableColumn new
title: 'Items';
evaluated: [ :each |
StObjectPrinter asTruncatedTextFrom: each key ];
evaluated: [ :each | each key ];
formatted: [ :each | StObjectPrinter asTruncatedTextFrom: each ];
beNotExpandable;
beSortable;
yourself);
addColumn: (SpStringTableColumn new
title: 'Occurences';
evaluated: [ :each |
StObjectPrinter asTruncatedTextFrom:
(self occurrencesOf: each key) ];
evaluated: [ :each | self occurrencesOf: each key ];
formatted: [ :each | StObjectPrinter asTruncatedTextFrom: each ];
beSortable;
yourself);
items: (contents associations sort: sortFuction);
Expand Down
30 changes: 17 additions & 13 deletions src/NewTools-Inspector-Extensions/Dictionary.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ Extension { #name : 'Dictionary' }

{ #category : '*NewTools-Inspector-Extensions' }
Dictionary >> inspectionItems: aBuilder [
<inspectorPresentationOrder: 0 title: 'Items'>

^ aBuilder newTable
addColumn: (SpStringTableColumn
title: 'Key'
evaluated: [ :each | StObjectPrinter asTruncatedTextFrom: each key ])
beSortable;
addColumn: (SpStringTableColumn
title: 'Value'
evaluated: [ :each | StObjectPrinter asTruncatedTextFrom: each value ])
beSortable;
items: (self associations collect: [:e | StInspectorAssociationNode hostObject: e ]);
yourself

<inspectorPresentationOrder: 0 title: 'Items'>
^ aBuilder newTable
addColumn: (SpStringTableColumn new
title: 'Key';
evaluated: [ :each | each key ];
formatted: [ :key | StObjectPrinter asTruncatedTextFrom: key ];
beSortable);
addColumn: (SpStringTableColumn new
title: 'Value';
evaluated: [ :each | each value ];
formatted: [ :value |
StObjectPrinter asTruncatedTextFrom: value ];
beSortable);
items: (self associations collect: [ :e |
StInspectorAssociationNode hostObject: e ]);
yourself
]
Loading

0 comments on commit 650ffca

Please sign in to comment.