Skip to content

Commit

Permalink
new notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Nov 19, 2023
1 parent 95b9a16 commit b74ea95
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 83 deletions.
46 changes: 42 additions & 4 deletions src/Toplo-Incubator/ToNotebook.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Class {
#name : 'ToNotebook',
#superclass : 'ToPane',
#instVars : [
'rebuildPaneOnSelect',
'header',
'body'
],
Expand All @@ -21,7 +22,7 @@ ToNotebook >> addButtonWithText: aText withPaneBuilder: aValuable [
| but |
but := ToNotebookButton new labelText: aText asString.
but paneBuilder: aValuable.
header addChild: but
self addButton: but
]

{ #category : 'accessing' }
Expand All @@ -30,26 +31,63 @@ ToNotebook >> body [
^ body
]

{ #category : 'accessing' }
ToNotebook >> body: anObject [

body := anObject
]

{ #category : 'accessing' }
ToNotebook >> header [

^ header
]

{ #category : 'accessing' }
ToNotebook >> header: anObject [

header := anObject
]

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

super initialize.
rebuildPaneOnSelect := false.
self beVertical.
self matchParent.
header := ToNotebookHeader horizontal.
body := ToNotebookBody vertical matchParent.
body := ToPane vertical matchParent.
self addChild: header as: #header.
self addChild: body as: #body
]

{ #category : 'adding-removing' }
ToNotebook >> removeButton: aButton [
ToNotebook >> onButtonRemoved: aButton [


]

{ #category : 'accessing' }
ToNotebook >> preservePaneOnSelect [

^ self rebuildPaneOnSelect not
]

{ #category : 'accessing' }
ToNotebook >> preservePaneOnSelect: aBoolean [

self rebuildPaneOnSelect: aBoolean not
]

{ #category : 'accessing' }
ToNotebook >> rebuildPaneOnSelect [

^ rebuildPaneOnSelect
]

{ #category : 'accessing' }
ToNotebook >> rebuildPaneOnSelect: aBoolean [

header removeChild: aButton
rebuildPaneOnSelect := aBoolean
]
12 changes: 0 additions & 12 deletions src/Toplo-Incubator/ToNotebookBody.class.st

This file was deleted.

62 changes: 37 additions & 25 deletions src/Toplo-Incubator/ToNotebookButton.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,16 @@ Class {
{ #category : 'accessing' }
ToNotebookButton >> body [

^ self parent body
]

{ #category : 'hooks - children' }
ToNotebookButton >> buildNewInnerPane [

innerPane := ToPane new
matchParent;
yourself.
self paneBuilder value: innerPane value: self body parent
^ self notebook body
]

{ #category : 'hooks - children' }
ToNotebookButton >> checkableCheckEvent: event [

self isChecked ifTrue: [
innerPane ifNil: [ self buildNewInnerPane].
self body addChild: innerPane.
self onSelected.
^ self ].
innerPane ifNil: [ ^ self ].
self removeInnerPane
self onDeselected
]

{ #category : 'accessing' }
Expand All @@ -50,9 +39,7 @@ ToNotebookButton >> closable: aBoolean [
| but |
but := ToButton new.
but defaultSkin: ToNotebookInnerCloseButtonSkin new.
but icon:
(ToImage new innerImage:
(Smalltalk ui icons iconNamed: #windowClose)).
but icon: (ToImage inner: (Smalltalk ui icons iconNamed: #windowClose)).
but constraintsDo: [ :c | c linear vertical alignCenter ].
but when: BlClickEvent do: [ :event | self removeFromParent ].
but id: #innerCloseButton.
Expand Down Expand Up @@ -138,31 +125,56 @@ ToNotebookButton >> newRawSkin [
^ ToNotebookButtonSkin new
]

{ #category : 'accessing' }
ToNotebookButton >> notebook [

^ self parent notebook
]

{ #category : 'hooks - children' }
ToNotebookButton >> onAddedToParent [

super onAddedToParent.
self parent group add: self.
self parent buttons add: self.
self parent onButtonAdded: self.
checkHandler := BlEventHandler
on: ToCheckableCheckEvent
do: [ :event | self checkableCheckEvent: event ].
self addEventHandler: checkHandler
]

{ #category : 'hooks - children' }
ToNotebookButton >> onDeselected [

self removeInnerPaneFromBody.
self notebook preservePaneOnSelect ifFalse: [ innerPane := nil ]
]

{ #category : 'hooks - children' }
ToNotebookButton >> onRemovedFromParent: aParentElement [

aParentElement group remove: self.
aParentElement buttons remove: self.
self removeEventHandler: checkHandler.
checkHandler := nil.
innerPane ifNil: [ ^ self ].
self removeInnerPane.
innerPane := nil.
innerPane ifNotNil: [
self removeInnerPaneFromBody.
innerPane := nil ].
aParentElement onButtonRemoved: self.
super onRemovedFromParent: aParentElement
]

{ #category : 'hooks - children' }
ToNotebookButton >> onSelected [

(self notebook preservePaneOnSelect and: [ innerPane notNil ])
ifTrue: [
self body addChild: innerPane.
^ self ].
innerPane := ToPane new
matchParent;
yourself.
self paneBuilder value: innerPane value: self body parent.
self body addChild: innerPane
]

{ #category : 'accessing' }
ToNotebookButton >> paneBuilder [

Expand Down Expand Up @@ -202,7 +214,7 @@ ToNotebookButton >> rawGroup: aGroup [
]

{ #category : 'hooks - children' }
ToNotebookButton >> removeInnerPane [
ToNotebookButton >> removeInnerPaneFromBody [

innerPane removeFromParent
]
Expand Down
32 changes: 32 additions & 0 deletions src/Toplo-Incubator/ToNotebookExamples.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ToNotebookExamples class >> example_closeableTabs [

| nb but |
nb := ToNotebook new.
nb preservePaneOnSelect: false.
(Color wheel: 5) withIndexDo: [ :eachColor :index |
but := ToNotebookButton new.
but closable: true.
Expand All @@ -19,11 +20,42 @@ ToNotebookExamples class >> example_closeableTabs [
nb openInSpace
]

{ #category : 'tabs' }
ToNotebookExamples class >> example_notPreservingPane [

| nb but |
nb := ToNotebook new.
nb preservePaneOnSelect: false.
1 to: 5 do: [ :index |
but := ToNotebookButton new.
but closable: true.
but labelText: 'Button ' , index asString.
but paneBuilder: [ :pane :theNoteBook | pane background: Color random ].
nb addButton: but ].
nb openInSpace
]

{ #category : 'tabs' }
ToNotebookExamples class >> example_preservingPane [

| nb but |
nb := ToNotebook new.
nb preservePaneOnSelect: true.
1 to: 5 do: [ :index |
but := ToNotebookButton new.
but closable: true.
but labelText: 'Button ' , index asString.
but paneBuilder: [ :pane :theNoteBook | pane background: Color random ].
nb addButton: but ].
nb openInSpace
]

{ #category : 'tabs' }
ToNotebookExamples class >> example_tabsWith2Pages [

| aNotebook redPage greenPage redCount greenCount |
aNotebook := ToNotebook new.
aNotebook rebuildPaneOnSelect: true.

redCount := 0.
redPage := aNotebook
Expand Down
32 changes: 27 additions & 5 deletions src/Toplo-Incubator/ToNotebookHeader.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
{ #category : 'accessing' }
ToNotebookHeader >> body [

^ self parent body
^ self notebook body
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -43,14 +43,36 @@ ToNotebookHeader >> initialize [
buttons := OrderedCollection new
]

{ #category : 'accessing' }
ToNotebookHeader >> notebook [

^ self parent
]

{ #category : 'add-remove' }
ToNotebookHeader >> onButonAdded: aButton [
ToNotebookHeader >> onButtonAdded: aButton [

self buttons add: aButton
self group add: aButton.
self buttons add: aButton.

]

{ #category : 'add-remove' }
ToNotebookHeader >> onButonRemoved: aButton [
ToNotebookHeader >> onButtonRemoved: aButton [

| index nextSelected |
self notebook onButtonRemoved: aButton.
index := aButton isSelected
ifTrue: [ self buttons indexOf: aButton ]
ifFalse: [ 0 ].

self buttons remove: aButton.
self group remove: aButton.
index > 0 ifFalse: [ ^ self ].
self buttons ifEmpty: [ ^ self ].

self buttons remove: aButton
nextSelected := self buttons size < index
ifTrue: [ self buttons last ]
ifFalse: [ self buttons at: index ].
nextSelected checked: true
]
74 changes: 37 additions & 37 deletions src/Toplo-Incubator/ToNotebookTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,6 @@ ToNotebookTest >> setUp [
space root addChild: notebook.
]

{ #category : 'tests' }
ToNotebookTest >> testBodyFactoryIsValuedOnSelect [

| redPage greenPage redCount greenCount |
redCount := 0.
redPage := notebook
addPageEntitled: 'Red'
withBodyBuilder: [
redCount := redCount + 1.
BlTextElement new
text: (redCount asRopedText foreground: Color red darker);
yourself ].

greenCount := 0.
greenPage := notebook
addPageEntitled: 'Green'
withBodyBuilder: [
greenCount := greenCount + 1.
BlTextElement new
text: (greenCount asRopedText foreground: Color green muchDarker);
yourself ].

self waitTestingSpaces.
self assert: redCount equals: 1.
self assert: greenCount equals: 0.

BlSpace simulateClickOn: greenPage button.
self waitTestingSpaces.
self assert: redCount equals: 1.
self assert: greenCount equals: 1.

BlSpace simulateClickOn: redPage button.
self waitTestingSpaces.
self assert: redCount equals: 2.
self assert: greenCount equals: 1
]

{ #category : 'tests' }
ToNotebookTest >> testCloseLastPage [

Expand Down Expand Up @@ -170,3 +133,40 @@ ToNotebookTest >> testIsSelected [
self deny: orangePage isSelected.

]

{ #category : 'tests' }
ToNotebookTest >> testPaneBuilderIsValuedOnSelect [

| redPage greenPage redCount greenCount |
redCount := 0.
redPage := notebook
addPageEntitled: 'Red'
withBodyBuilder: [
redCount := redCount + 1.
BlTextElement new
text: (redCount asRopedText foreground: Color red darker);
yourself ].

greenCount := 0.
greenPage := notebook
addPageEntitled: 'Green'
withBodyBuilder: [
greenCount := greenCount + 1.
BlTextElement new
text: (greenCount asRopedText foreground: Color green muchDarker);
yourself ].

self waitTestingSpaces.
self assert: redCount equals: 1.
self assert: greenCount equals: 0.

BlSpace simulateClickOn: greenPage button.
self waitTestingSpaces.
self assert: redCount equals: 1.
self assert: greenCount equals: 1.

BlSpace simulateClickOn: redPage button.
self waitTestingSpaces.
self assert: redCount equals: 2.
self assert: greenCount equals: 1
]

0 comments on commit b74ea95

Please sign in to comment.