Skip to content

Commit

Permalink
Merge pull request #1542 from JanBliznicenko/Pharo13
Browse files Browse the repository at this point in the history
Fixed ntb page selection change announcement if built without pages
  • Loading branch information
jecisc authored May 16, 2024
2 parents 535b704 + 266b8ea commit 1b93c6d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/Spec2-Adapters-Morphic/SpMorphicNotebookAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,31 @@ SpMorphicNotebookAdapter >> addFocusRotationKeyBindings [
toAction: [ self focusPrevious ]
]

{ #category : 'factory' }
SpMorphicNotebookAdapter >> addModelTo: aNotebook [
{ #category : 'private' }
SpMorphicNotebookAdapter >> addInitialPagesTo: aNotebook [

self presenter pages ifEmpty: [ ^ self ].

self presenter pages do: [ :each |
"Since I do not have the page added, I need to take it from the list.
But I know this will be the last added :)"
But I know this will be the last added :)"
self addPage: each to: aNotebook ].

"force first page to be drawn"
self presenter selectedPage ifNil: [ self presenter selectPageIndex: 1 ].
aNotebook selectedPageIndex: self presenter selectedPageIndex.
aNotebook announcer
when: SpNotebookPageChanged
send: #pageChanged:
self presenter selectedPage ifNil: [
self presenter selectPageIndex: 1 ].

aNotebook selectedPageIndex: self presenter selectedPageIndex
]

{ #category : 'factory' }
SpMorphicNotebookAdapter >> addModelTo: aNotebook [

self addInitialPagesTo: aNotebook.

aNotebook announcer
when: SpNotebookPageChanged
send: #pageChanged:
to: self
]

Expand Down
18 changes: 18 additions & 0 deletions src/Spec2-Backend-Tests/SpNotebookAdapterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,21 @@ SpNotebookAdapterTest >> testSelectingPageShouldAnnounceChangeEvent [
self assert: change oldPage model title equals: 'Mock'.
self assert: change page model title equals: 'Mock2'
]

{ #category : 'tests' }
SpNotebookAdapterTest >> testSelectingPageShouldAnnounceChangeEventWithNoInitialPages [

| changed |
"start with no pages"
presenter removeAll.
presenter whenSelectedPageChangedDo: [ changed := true ].
"build without any pages"
self widget.
"add pages after build"
self initializeTestedInstance.
presenter selectPageIndex: 1.
changed := false.
"this should trigger the page change"
self widget updatePageIndex: 2 oldIndex: 1.
self assert: changed
]

0 comments on commit 1b93c6d

Please sign in to comment.