From a5fdf3b9f21c4191434022e6088c481d6ed4172e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Tue, 12 Mar 2024 21:44:31 +0100 Subject: [PATCH] Add pre-filling the name text presenter in file dialogs. Add tests. --- .../StSaveFilePresenterTest.class.st | 34 +++++++++++++++++++ .../StFileDialogPresenter.class.st | 13 +++++++ .../StFileNavigationSystemPresenter.class.st | 23 ++++++++----- 3 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 src/NewTools-FileBrowser-Tests/StSaveFilePresenterTest.class.st diff --git a/src/NewTools-FileBrowser-Tests/StSaveFilePresenterTest.class.st b/src/NewTools-FileBrowser-Tests/StSaveFilePresenterTest.class.st new file mode 100644 index 00000000..a30c786d --- /dev/null +++ b/src/NewTools-FileBrowser-Tests/StSaveFilePresenterTest.class.st @@ -0,0 +1,34 @@ +Class { + #name : 'StSaveFilePresenterTest', + #superclass : 'StFilePresenterTest', + #category : 'NewTools-FileBrowser-Tests-UI', + #package : 'NewTools-FileBrowser-Tests', + #tag : 'UI' +} + +{ #category : 'accessing' } +StSaveFilePresenterTest >> dialogClass [ + + ^ StSaveFilePresenter +] + +{ #category : 'tests' } +StSaveFilePresenterTest >> testSetNameText [ + + | preFillDocName | + + preFillDocName := 'mydocument.doc'. + dialog nameText: preFillDocName. + self + assert: dialog nameText + equals: preFillDocName +] + +{ #category : 'tests' } +StSaveFilePresenterTest >> testWhenChangeDirectoryShouldFilesListContainsHisChildren [ + | newDirectory | + newDirectory := (root / 'dir') asFileReference. + dialog defaultFolder: newDirectory. + self + assert: (dialog fileReferenceTable items includesAll: newDirectory children) +] diff --git a/src/NewTools-FileBrowser/StFileDialogPresenter.class.st b/src/NewTools-FileBrowser/StFileDialogPresenter.class.st index 112de6e3..cd3bb8fc 100644 --- a/src/NewTools-FileBrowser/StFileDialogPresenter.class.st +++ b/src/NewTools-FileBrowser/StFileDialogPresenter.class.st @@ -291,6 +291,19 @@ StFileDialogPresenter >> isolate [ ] +{ #category : 'accessing - ui' } +StFileDialogPresenter >> nameText [ + "Answer a with the text in the name presenter used to display the currently selected file/directory or a manually entered name" + + ^ fileNavigationSystem nameText text. +] + +{ #category : 'accessing' } +StFileDialogPresenter >> nameText: aString [ + + fileNavigationSystem nameText: aString +] + { #category : 'api - customization' } StFileDialogPresenter >> okAction: aOneArgBlock [ okAction := aOneArgBlock diff --git a/src/NewTools-FileBrowser/StFileNavigationSystemPresenter.class.st b/src/NewTools-FileBrowser/StFileNavigationSystemPresenter.class.st index 651e5780..679d3b92 100644 --- a/src/NewTools-FileBrowser/StFileNavigationSystemPresenter.class.st +++ b/src/NewTools-FileBrowser/StFileNavigationSystemPresenter.class.st @@ -179,10 +179,11 @@ StFileNavigationSystemPresenter >> defaultPreviewer [ StFileNavigationSystemPresenter >> fileNameLayout [ ^ SpBoxLayout newLeftToRight - vAlignCenter; - add: nameText; - add: filtersDropList expand: false; - yourself + spacing: 2; + vAlignCenter; + add: nameText; + add: filtersDropList expand: false; + yourself ] { #category : 'accessing' } @@ -195,11 +196,6 @@ StFileNavigationSystemPresenter >> filesListAction [ | previewProcess | - fileReferenceTable - transmitTo: nameText - transform: [ :selectedItem | - selectedItem ifNotNil: [ selectedItem basename ] ifNil: [ '' ] ]. - fileReferenceTable whenActivatedDo: [ :selectedItem | previewProcess ifNotNil: [ previewProcess isTerminated ifFalse: [ previewProcess terminate ] ]. @@ -264,6 +260,8 @@ StFileNavigationSystemPresenter >> initializeFilesTable [ beResizable; columns: StFileBrowserAbstractColumn columns; sortingBlock: self defaultFileSortBlock; + whenSelectedItemChangedDo: [ : selectedItem | + selectedItem ifNotNil: [ self nameText: selectedItem basename ] ]; contextMenuFromCommandsGroup: [ self rootCommandsGroup / 'StFileBrowserNavigationMenu' ] ] @@ -326,6 +324,13 @@ StFileNavigationSystemPresenter >> nameText [ ^ nameText ] +{ #category : 'accessing' } +StFileNavigationSystemPresenter >> nameText: aString [ + "Set the receive's name text to aString. This is displayed in a text presenter to display the currently selected file, or the name of a new file to be saved" + + nameText text: aString. +] + { #category : 'actions' } StFileNavigationSystemPresenter >> nameTextAction [