Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactoring and fixes in New File Browser #660

Merged
merged 10 commits into from
Jan 23, 2024
19 changes: 7 additions & 12 deletions src/NewTools-FileBrowser-Tests/StFileDialogTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ StFileDialogTest >> fileListAllMustBeFilterByPNGFIlter [

{ #category : 'running' }
StFileDialogTest >> setUp [

super setUp.
(dialog := self dialogClass owner: fileSystemPresenter on: fileSystemModel) defaultFolder: root
]
Expand Down Expand Up @@ -75,9 +76,12 @@ StFileDialogTest >> testOpenFolder [
{ #category : 'tests' }
StFileDialogTest >> testWhenAddACollectionOfBookmarkToCustomBookmarkShouldBeAddedToBookmarkTreeTable [
| aCollectionOfBookmark |
aCollectionOfBookmark := {(root / 'dir') asFileReference.
(root / 'dir.ext') asFileReference}
collect: [ :eachItem | StFileBrowserBookmark name: eachItem basename location: eachItem path icon: nil ].

aCollectionOfBookmark := {
(root / 'dir') asFileReference.
(root / 'dir.ext') asFileReference }
collect: [ :eachItem | StFileBrowserBookmark name: eachItem basename location: eachItem path icon: nil ].

dialog bookmarks: { (StFileBrowserGroupBookmark
name: 'aTestBookmark'
collection: aCollectionOfBookmark
Expand Down Expand Up @@ -124,12 +128,3 @@ StFileDialogTest >> testWhenAddingBookmarkOnIsolateBookmarksShouldBeAddToAllInst
assert: dialog bookmarksTreeTable roots
equals: anOtherInstance bookmarksTreeTable roots
]

{ #category : 'tests' }
StFileDialogTest >> testWhenChangeDirectoryShouldFilesListContainsHisChildren [
| newDirectory |
newDirectory := (root / 'dir') asFileReference.
dialog defaultFolder: newDirectory.
self
assert: (dialog fileReferenceTable items includesAll: newDirectory children)
]
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ StNavigationSystemTest >> testCustomizationWhenChangeCollectionOfPreviewerShould

{ #category : 'tests' }
StNavigationSystemTest >> testInitializeCurrentPathTextInputShouldSet [
self assert: dialog currentDirectory fullName equals: dialog currentPathTextInputPresenter entityText text
self assert: dialog currentDirectory fullName equals: dialog pathBreadcrumbPresenter entityText text
]

{ #category : 'tests' }
Expand Down Expand Up @@ -150,8 +150,8 @@ StNavigationSystemTest >> testWhenOpenADirectoryShouldDisplayHisChildrenFilterBy
{ #category : 'tests' }
StNavigationSystemTest >> testWhenPathTextInputPresenterAcceptShouldChangeFileListWithTheGoodContent [

dialog currentPathTextInputPresenter pathTextChangedTo:
(dialog currentPathTextInputPresenter entityText text asPath / 'dir')
dialog pathBreadcrumbPresenter pathTextChangedTo:
(dialog pathBreadcrumbPresenter entityText text asPath / 'dir')
pathString.
self
assertCollection:
Expand Down
10 changes: 10 additions & 0 deletions src/NewTools-FileBrowser-Tests/StOpenDirectoryDialogTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ StOpenDirectoryDialogTest >> testSelectNonexistingDirectory [
raise: DirectoryDoesNotExist.
self assert: dialog currentDirectory equals: root
]

{ #category : 'tests' }
StOpenDirectoryDialogTest >> testWhenChangeDirectoryShouldFilesListContainsHisChildren [
| newDirectory |
newDirectory := (root / 'dir') asFileReference.
dialog defaultFolder: newDirectory.

"Since we're only displaying directories, no files should appear in the reference table"
self assertEmpty: dialog fileReferenceTable items
]
9 changes: 9 additions & 0 deletions src/NewTools-FileBrowser-Tests/StOpenFileDialogTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ StOpenFileDialogTest >> testSelectFile [
dialog confirm.
self assert: selectedFile equals: root / 'sth.ext'
]

{ #category : 'tests' }
StOpenFileDialogTest >> testWhenChangeDirectoryShouldFilesListContainsHisChildren [
| newDirectory |
newDirectory := (root / 'dir') asFileReference.
dialog defaultFolder: newDirectory.
self
assert: (dialog fileReferenceTable items includesAll: newDirectory children)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Class {
#name : 'StDirectoryNavigationSystemPresenter',
#superclass : 'StFileNavigationSystemPresenter',
#category : 'NewTools-FileBrowser-UI',
#package : 'NewTools-FileBrowser',
#tag : 'UI'
}

{ #category : 'utilities' }
StDirectoryNavigationSystemPresenter >> updateFileReferenceTable [
"Update the receiver's contents according to the current directory and apply configured filters"

fileReferenceTable items:
(self currentDirectory children select: [ : c |
c exists and: [ c isDirectory ]]).
]
16 changes: 10 additions & 6 deletions src/NewTools-FileBrowser/StDirectoryTreePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ StDirectoryTreePresenter class >> buildCommandsGroupWith: presenterInstance forR

rootCommandGroup
register: (
(CmCommandGroup named: 'StFBDirectoryContextualMenu') asSpecGroup
(CmCommandGroup named: 'StFileBrowserDirectoryContextualMenu') asSpecGroup
register: StFileBrowserNewDirectoryCommand forSpec;
register: StFileBrowserRenameCommand forSpec;
register: StFileBrowserRemoveCommand forSpec;
Expand Down Expand Up @@ -81,15 +81,14 @@ StDirectoryTreePresenter >> initializePresenters [
roots: StFileSystemItemWrapper roots;
children: [ :aClass | aClass subdirectories ];
beResizable;
contextMenu: [ (self rootCommandsGroup / 'StFBDirectoryContextualMenu') beRoot asMenuPresenter ].
contextMenu: [ (self rootCommandsGroup / 'StFileBrowserDirectoryContextualMenu') beRoot asMenuPresenter ].
]

{ #category : 'utilities' }
StDirectoryTreePresenter >> openFolder: aFileReference [

model openFolder: aFileReference.
self owner updateWidgetWithFileReference: aFileReference.
self expandPath: aFileReference.

]

{ #category : 'accessing' }
Expand All @@ -107,9 +106,14 @@ StDirectoryTreePresenter >> shouldReparent [
]

{ #category : 'utilities' }
StDirectoryTreePresenter >> updateFileSystemContents [
StDirectoryTreePresenter >> updateFileDirectoryTree [

super updateFileSystemContents.
directoryTreePresenter roots: StFileSystemItemWrapper roots.
self expandPath: self currentDirectory.
]

{ #category : 'utilities' }
StDirectoryTreePresenter >> updateWidgetWithFileReference: aFileReference [

self expandPath: aFileReference.
]
132 changes: 37 additions & 95 deletions src/NewTools-FileBrowser/StFileBrowserAbstractPresenter.class.st
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Class {
#name : 'StFileBrowserAbstractPresenter',
#superclass : 'StPresenter',
#classTraits : 'TraitedClass',
#instVars : [
'bookmarksTreeTable',
'model'
],
#classVars : [
Expand All @@ -15,83 +13,49 @@ Class {
#tag : 'UI'
}

{ #category : 'accessing' }
StFileBrowserAbstractPresenter class >> defaultDirectory [
"Answer a <FileReference> with the default directory for opening the file browser and dialogs"

^ StFileBrowserSettings defaultDirectory
]

{ #category : 'class initialization' }
StFileBrowserAbstractPresenter class >> initialize [

self initializeBookmarks.
]

{ #category : 'class initialization' }
StFileBrowserAbstractPresenter class >> initializeBookmarks [

Bookmarks := StFileBrowserBookmark defaultBookmarks
]

{ #category : 'accessing' }
StFileBrowserAbstractPresenter class >> lastVisitedDirectory [
{ #category : 'instance creation' }
StFileBrowserAbstractPresenter class >> new [

(LastVisitedDirectory isNotNil and: [
[ LastVisitedDirectory exists ]
on: ResolutionRequest
do: [ false ] ]) ifFalse: [
LastVisitedDirectory := self defaultDirectory ].
^ LastVisitedDirectory
^ self on: StFileSystemModel new
]

{ #category : 'instance creation' }
StFileBrowserAbstractPresenter class >> open [

^ (self on: StFileSystemModel new) open
^ self new open
]

{ #category : 'adding' }
{ #category : 'accessing - bookmarks' }
StFileBrowserAbstractPresenter >> addBookmark: aFileReference [

self bookmarks add: (StFileBrowserBookmark
name: aFileReference basename
location: aFileReference
icon: (self iconNamed: #book)).
self owner addBookmark: aFileReference.


]

{ #category : 'accessing - bookmarks' }
StFileBrowserAbstractPresenter >> bookmarks [

Bookmarks
ifNil: [ self class initialize ].
^ Bookmarks
^ self model bookmarks.
]

{ #category : 'accessing - bookmarks' }
StFileBrowserAbstractPresenter >> bookmarks: aCollectionOfFDGroupBookMark [

Bookmarks := aCollectionOfFDGroupBookMark asOrderedCollection.
bookmarksTreeTable roots: Bookmarks
self owner bookmarks: aCollectionOfFDGroupBookMark
]

{ #category : 'accessing - bookmarks' }
StFileBrowserAbstractPresenter >> bookmarksTreeTable [
^ bookmarksTreeTable
]

{ #category : 'accessing - bookmarks' }
StFileBrowserAbstractPresenter >> bookmarksTreeTableItems: aCollection [
"Convenience method to set the receiver's bookmarks table items to aCollection"

bookmarksTreeTable roots: aCollection
^ self owner bookmarksTreeTable
]

{ #category : 'utilities' }
StFileBrowserAbstractPresenter >> createDirectory [

self model createDirectory.
self updateFileSystemContents.
self updateFileSystemPresenters.
]

{ #category : 'accessing' }
Expand All @@ -107,11 +71,21 @@ StFileBrowserAbstractPresenter >> currentDirectory: aFileReference [
self model currentDirectory: aFileReference.
]

{ #category : 'defaults' }
StFileBrowserAbstractPresenter >> defaultColumns [

^ {
StFileBrowserModificationDateColumn .
StFileBrowserSizeColumn .
StFileBrowserRightsColumn
}
]

{ #category : 'defaults' }
StFileBrowserAbstractPresenter >> defaultDirectory [
"See class side comment"

^ self class defaultDirectory.
^ self model defaultDirectory.
]

{ #category : 'accessing - history' }
Expand All @@ -126,34 +100,6 @@ StFileBrowserAbstractPresenter >> history: aConfigurableHistoryIterator [
self model history: aConfigurableHistoryIterator.
]

{ #category : 'initialization' }
StFileBrowserAbstractPresenter >> initialize [

super initialize.
(StFileBrowserSettings showAlwaysDefaultBookmarks and: [ self bookmarks isEmpty ])
ifTrue: [ self class initializeBookmarks ]
]

{ #category : 'initialization' }
StFileBrowserAbstractPresenter >> initializeBookmarksTreeTable [

bookmarksTreeTable := self newTreeTable.
bookmarksTreeTable
hideColumnHeaders;
addColumn: (SpCompositeTableColumn new
addColumn:
(SpImageTableColumn evaluated: [ :each | each icon ])
beNotExpandable;
addColumn:
(SpStringTableColumn evaluated: [ :groupBookMark |
groupBookMark name ]);
yourself);
roots: self bookmarks;
children: #children;
contextMenuFromCommandsGroup: [ self rootCommandsGroup / 'Menu' ];
expandRoots
]

{ #category : 'accessing - history' }
StFileBrowserAbstractPresenter >> initializeHistoryIteratorWith: aDirectory [

Expand All @@ -165,16 +111,11 @@ StFileBrowserAbstractPresenter >> initializeHistoryIteratorWith: aDirectory [
self history register: aDirectory
]

{ #category : 'initialization' }
StFileBrowserAbstractPresenter >> initializePresenters [

super initializePresenters.
self initializeBookmarksTreeTable
]

{ #category : 'accessing - history' }
StFileBrowserAbstractPresenter >> lastVisitedDirectory [
^ self class lastVisitedDirectory.
"Answer the <FileReference> of the last visited directory"

^ self model lastVisitedDirectory
]

{ #category : 'accessing' }
Expand All @@ -184,6 +125,12 @@ StFileBrowserAbstractPresenter >> model [
^ model
]

{ #category : 'hooks' }
StFileBrowserAbstractPresenter >> navigationSystemClass [

^ self class navigationSystemClass
]

{ #category : 'utilities' }
StFileBrowserAbstractPresenter >> openOnLastDirectory [
"Answer <true> if receiver should open in the last used directory"
Expand All @@ -195,22 +142,17 @@ StFileBrowserAbstractPresenter >> openOnLastDirectory [
StFileBrowserAbstractPresenter >> resetBookmarks [
"Reset bookmarks to their defaults"

self class initializeBookmarks
]

{ #category : 'accessing - bookmarks' }
StFileBrowserAbstractPresenter >> selectedBookMark [
^ bookmarksTreeTable selection selectedItem
self model resetBookmarks
]

{ #category : 'accessing - model' }
StFileBrowserAbstractPresenter >> setModelBeforeInitialization: aStFBFileSystemModel [
StFileBrowserAbstractPresenter >> setModelBeforeInitialization: aStFileSystemModel [

model := aStFBFileSystemModel
model := aStFileSystemModel
]

{ #category : 'utilities' }
StFileBrowserAbstractPresenter >> updateFileSystemContents [
StFileBrowserAbstractPresenter >> updateFileSystemPresenters [

self owner updateFileSystemContents
self owner updateFileSystemPresenters
]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ StFileBrowserAddBookmarkCommand >> execute [

fileReference := self context selectedEntry.
self context addBookmark: fileReference.
self context bookmarksTreeTableItems: self context bookmarks
self bookmarksTreeTable
roots: self context bookmarks;
expandRoots

]

{ #category : 'initialization' }
Expand Down
2 changes: 1 addition & 1 deletion src/NewTools-FileBrowser/StFileBrowserBookmark.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ StFileBrowserBookmark class >> defaultBookmarks [

^ OrderedCollection with:
(StFileBrowserGroupBookmark
name: 'Favourites'
name: 'Bookmarks'
collection: presets
iconName: #book)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ StFileBrowserCompressCommand >> execute [
zip addFile: self selectedEntry.
zip writeToFile: self selectedEntry parent / newZipName.
zip close.
self updateFileSystemContents
self updateFileSystemPresenters
]

{ #category : 'initialization' }
Expand Down
Loading
Loading