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

File Browser: Enable multiple file selection for opening files or directories #792

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ Class {

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

super setUp.
windowPathUI := StPathBreadcrumbPresenter
owner: fileSystemPresenter
on: fileSystemModel
windowPathUI := StPathBreadcrumbPresenter
owner: fileSystemPresenter
on: fileSystemModel
]

{ #category : 'running' }
StBreadcrumbPresenterTest >> tearDown [

windowPathUI withWindowDo: [ :window | window close ].
super tearDown
]
Expand Down
53 changes: 53 additions & 0 deletions src/NewTools-FileBrowser-Tests/StOpenFilePresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,59 @@ StOpenFilePresenterTest >> testSelectFile [
self assert: selectedFile equals: root / 'sth.ext'
]

{ #category : 'tests' }
StOpenFilePresenterTest >> testSelectFileWithMultipleSelection [

| selectedFile |
dialog beMultipleSelection.
window := dialog openDialog.
self assert: dialog currentDirectory equals: root.
dialog selectFile: root / 'sth.ext'.

self assert: dialog selectedEntry equals: root / 'sth.ext'.

selectedFile := dialog confirm.

self assert: selectedFile equals: root / 'sth.ext'
]

{ #category : 'tests' }
StOpenFilePresenterTest >> testSelectFileWithMultipleSelectionAccessingEntries [

| selectedFile |
dialog beMultipleSelection.
window := dialog openDialog.
self assert: dialog currentDirectory equals: root.
dialog selectFile: root / 'sth.ext'.

"Multiple selection mode in tables only set the 'first' item and ignores the remaining items"
self assertCollection: dialog selectedEntries hasSameElements: { root / 'sth.ext' }.

selectedFile := dialog confirm.

self assert: selectedFile equals: root / 'sth.ext'
]

{ #category : 'tests' }
StOpenFilePresenterTest >> testSelectedEntriesMultipleSelection [

window := dialog openDialog.
dialog selectFiles: { root / 'sth.ext' . root / 'patate.png' }.
self
assertCollection: dialog selectedEntries
hasSameElements: { root / 'sth.ext' . root / 'patate.png' }.

]

{ #category : 'tests' }
StOpenFilePresenterTest >> testSelectedEntriesSingleSelection [

window := dialog openDialog.
dialog selectFile: root / 'sth.ext'.
self assertCollection: dialog selectedEntries hasSameElements: { root / 'sth.ext' }.

]

{ #category : 'tests' }
StOpenFilePresenterTest >> testSetTitle [

Expand Down
9 changes: 4 additions & 5 deletions src/NewTools-FileBrowser/StFileDialogPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ StFileDialogPresenter >> isolate [
{ #category : 'accessing - ui' }
StFileDialogPresenter >> nameText [
"Answer a <String> with the text in the name presenter used to display the currently selected file/directory or a manually entered name"

^ fileNavigationSystem nameText text.

^ fileNavigationSystem nameText text

]

{ #category : 'accessing' }
Expand All @@ -316,12 +317,10 @@ StFileDialogPresenter >> open [
^ self openDialog
]

{ #category : 'opening' }
{ #category : 'showing' }
StFileDialogPresenter >> openModal [

super openModal cancelled ifTrue: [ ^ nil ].
self isMultipleSelection
ifFalse: [ ^ self selectedEntry ].
^ self selectedEntries
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ StFileNavigationSystemPresenter >> fileNameLayout [

{ #category : 'accessing' }
StFileNavigationSystemPresenter >> fileReferenceTable [

^ fileReferenceTable
]

Expand Down Expand Up @@ -444,6 +445,13 @@ StFileNavigationSystemPresenter >> previousButton [
^ previousButton
]

{ #category : 'menu - accessing' }
StFileNavigationSystemPresenter >> selectEntries: aCollection [
"Set a <Collection> of <FileReference> representing user's selections"

self fileReferenceTable selectItems: aCollection
]

{ #category : 'menu - accessing' }
StFileNavigationSystemPresenter >> selectedEntries [
"Answer a <Collection> of <FileReference> representing user's selections"
Expand Down Expand Up @@ -496,6 +504,7 @@ StFileNavigationSystemPresenter >> updateFileReferenceTable [
"Update the receiver's contents according to the current directory and apply configured filters"

| items |

items := (filtersDropList selectedItem ifNil: [ filter ]) applyOn: self currentDirectoryChildren.
StFileBrowserSettings showHiddenFiles ifFalse: [ items := items reject: [ :file | file isHidden ] ].
fileReferenceTable items: items
Expand Down
1 change: 1 addition & 0 deletions src/NewTools-FileBrowser/StFileSystemPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ StFileSystemPresenter >> expandPath: aFileReference [

{ #category : 'accessing' }
StFileSystemPresenter >> fileNavigationSystem [

^ fileNavigationSystem
]

Expand Down
22 changes: 22 additions & 0 deletions src/NewTools-FileBrowser/StOpenFileOrDirectoryPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,25 @@ StOpenFileOrDirectoryPresenter >> confirmLabel [
StOpenFileOrDirectoryPresenter >> initialTitle [
^ self subclassResponsibility
]

{ #category : 'utilities' }
StOpenFileOrDirectoryPresenter >> selectFiles: aCollectionOfFiles [
"Be ware that updating the name text from the file navigation system, would unselect all files"

self beMultipleSelection.
self fileNavigationSystem selectedEntries = aCollectionOfFiles
ifFalse: [ self fileNavigationSystem selectEntries: aCollectionOfFiles ]
]

{ #category : 'menu - accessing' }
StOpenFileOrDirectoryPresenter >> selectedEntries [
"Answer a <Collection> of user's selected <FileReference>s "

| entries |
((entries := self fileNavigationSystem selectedEntries)
anySatisfy: [ : entry | (entry exists not and: [ entry isDirectory ]) ])
ifTrue: [
self inform: 'Only files could be selected (no directories)'.
^ nil ].
^ entries
]
13 changes: 0 additions & 13 deletions src/NewTools-FileBrowser/StOpenFilePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,3 @@ StOpenFilePresenter >> isMultipleSelection [

^ self fileNavigationSystem isMultipleSelection
]

{ #category : 'menu - accessing' }
StOpenFilePresenter >> selectedEntries [
"Answer a <Collection> of user's selected <FileReference>s "

| entries |
((entries := self fileNavigationSystem selectedEntries)
anySatisfy: [ : entry | (entry exists not and: [ entry isDirectory ]) ])
ifTrue: [
self inform: 'Only files could be selected (no directories)'.
^ nil ].
^ entries
]
Loading