Skip to content

Commit

Permalink
Add ToTab and ToTabPane
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyan11 committed Sep 27, 2024
1 parent 1ce760b commit 2750771
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Toplo-Serialization-Stash/TToCheckable.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ TToCheckable >> stashAccessorsForTToCheckable [

<stashAccessors>
| settersAndGetters |
self class == ToTab ifTrue: [ ^ { } ].
self isCheckable ifFalse: [ ^ { } ].

settersAndGetters := OrderedCollection new.
settersAndGetters add: #initializeCheckable onlySetOnStash.

self class == ToToggleButton ifFalse: [ settersAndGetters add: #initializeCheckable onlySetOnStash ].
self checked ifTrue: [ settersAndGetters add: #checked ].
self group ifNotNil: [ settersAndGetters add: #group ].
^ settersAndGetters
Expand Down
32 changes: 32 additions & 0 deletions src/Toplo-Serialization-Stash/ToTab.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Extension { #name : #ToTab }

{ #category : #'*Toplo-Serialization-Stash' }
ToTab >> firstElement [

| first |
first := self children first.
first == filler ifTrue: [ ^ nil ].
^ first
]

{ #category : #'*Toplo-Serialization-Stash' }
ToTab >> firstElement: anElement [

anElement ifNil: [ ^ self ].
self addChild: anElement at: 1
]

{ #category : #'*Toplo-Serialization-Stash' }
ToTab >> stashElement [

<stashAccessors>
self firstElement ifNil: [ ^ { } ].
^ { (#firstElement: -> #firstElement) }
]

{ #category : #'*Toplo-Serialization-Stash' }
ToTab >> stashPaneBuilder [

<stashAccessors>
^ { #paneBuilder }
]
14 changes: 14 additions & 0 deletions src/Toplo-Serialization-Stash/ToTabPane.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Extension { #name : #ToTabPane }

{ #category : #'*Toplo-Serialization-Stash' }
ToTabPane >> stashAddAllTabs: aCollectionOfTabs [

aCollectionOfTabs do: [ :each | self addTab: each ].
]

{ #category : #'*Toplo-Serialization-Stash' }
ToTabPane >> stashTabs [

<stashAccessors>
^ { #stashAddAllTabs: -> #tabs }
]
113 changes: 113 additions & 0 deletions src/Toplo-Serialization-Tests/ToSerializerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,119 @@ ToSerializerTest >> testToLabel [
on: [ :element | self assert: element text asString equals: 'hello' ]
]

{ #category : #tests }
ToSerializerTest >> testToTabPane1 [

| origin |
origin := ToTabPane new.
origin resizablePanes: true.
1 to: 3 do: [ :index | | tab |
tab := ToTab new.
tab closable: true.
tab labelText: 'Button ' , index asString.
tab paneBuilder: [ :pane :theNoteBook |
pane background: Color random ].
origin addTab: tab ].

self test: origin on: [ :element |
self assert: element tabs size equals: 3 ]
]

{ #category : #tests }
ToSerializerTest >> testToTabPane2 [

| origin |
origin := ToTabPane new.
origin resizablePanes: true.
1 to: 100 do: [ :index |
| tab |
tab := ToTab new.
tab closable: true.
tab labelText: 'Button ' , index asString.
tab paneBuilder: [ :pane :theNoteBook |
pane background: Color random ].
origin addTab: tab ].

self
test: origin
on: [ :element | self assert: element tabs size equals: 100 ]
]

{ #category : #tests }
ToSerializerTest >> testToTabPane3 [

| origin |
origin := ToTabPane new.
origin resizablePanes: true.
1 to: 0 do: [ :index |
| tab |
tab := ToTab new.
tab closable: true.
tab labelText: 'Button ' , index asString.
tab paneBuilder: [ :pane :theNoteBook |
pane background: Color random ].
origin addTab: tab ].

self
test: origin
on: [ :element | self assert: element tabs size equals: 0 ]
]

{ #category : #tests }
ToSerializerTest >> testToTabPane4 [

| origin |
origin := ToTabPane new.
origin resizablePanes: true.
1 to: 3 do: [ :index |
| tab |
tab := ToTab new.
tab closable: true.
tab labelText: 'Button ' , index asString.
tab paneBuilder: [ :pane :theNoteBook |
pane background: Color random ].
origin addTab: tab ].

self test: origin on: [ :element |
self assert: element tabs size equals: 3.
self
assert: element tabs first firstElement text asString
equals: 'Button 1'.
self
assert: element tabs second firstElement text asString
equals: 'Button 2'.
self
assert: element tabs third firstElement text asString
equals: 'Button 3' ]
]

{ #category : #tests }
ToSerializerTest >> testToTabPane5 [

| origin |
origin := ToTabPane new.
origin resizablePanes: true.
1 to: 3 do: [ :index |
| tab |
tab := ToTab new.
tab closable: true.
tab labelText: 'Button ' , index asString.
tab paneBuilder: [ :pane :theNoteBook | #test ].
origin addTab: tab ].

self test: origin on: [ :element |
self assert: element tabs size equals: 3.
self
assert: (element tabs first paneBuilder value: nil value: nil)
equals: #test.
self
assert: (element tabs second paneBuilder value: nil value: nil)
equals: #test.
self
assert: (element tabs third paneBuilder value: nil value: nil)
equals: #test ]
]

{ #category : #tests }
ToSerializerTest >> testTokens [

Expand Down

0 comments on commit 2750771

Please sign in to comment.