Skip to content

Commit

Permalink
plus example_contactList example
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Dec 7, 2023
1 parent 5d9c676 commit 7ae6d7b
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Toplo-Examples/ToContactExample.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Class {
#name : 'ToContactExample',
#superclass : 'Object',
#instVars : [
'name',
'phoneNumber',
'address'
],
#category : 'Toplo-Examples',
#package : 'Toplo-Examples'
}

{ #category : 'accessing' }
ToContactExample >> address [

^ address
]

{ #category : 'accessing' }
ToContactExample >> address: anObject [

address := anObject
]

{ #category : 'accessing' }
ToContactExample >> name [

^ name
]

{ #category : 'accessing' }
ToContactExample >> name: anObject [

name := anObject
]

{ #category : 'accessing' }
ToContactExample >> phoneNumber [

^ phoneNumber
]

{ #category : 'accessing' }
ToContactExample >> phoneNumber: anObject [

phoneNumber := anObject
]
100 changes: 100 additions & 0 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,106 @@ ToSandBox class >> example_buttonWithLabel [
^ but
]

{ #category : 'list' }
ToSandBox class >> example_contactList [

| panel button list contacts contact nameTxtF phoneTxtF addressTxtF inputPane |
panel := ToPane vertical.
panel constraints horizontal matchParent.
panel layout cellSpacing: 10.

list := ToList new.

nameTxtF := ToTextField new
width: 100;
placeholderBuilder: [ :placeholder :e |
placeholder padding: e padding.
placeholder addChild: (ToLabel new
text:
('Name' asRopedText foreground: Color lightGray);
yourself) ].
phoneTxtF := ToTextField new
width: 100;
placeholderBuilder: [ :placeholder :e |
placeholder padding: e padding.
placeholder addChild: (ToLabel new
text:
('Phone' asRopedText foreground: Color lightGray);
yourself) ].
addressTxtF := ToTextField new
width: 200;
placeholderBuilder: [ :placeholder :e |
placeholder padding: e padding.
placeholder addChild: (ToLabel new
text:
('Adress' asRopedText foreground:
Color lightGray);
yourself) ].
button := ToButton new label: (ToLabel text: 'Update table').
button whenClickedDo: [
| n p a c idx |
n := nameTxtF text asString.
p := phoneTxtF text asString.
a := addressTxtF text asString.
idx := list data detectIndex: [ :e | e name = n ] ifNone: [ ].
c := ToContactExample new
name: n;
phoneNumber: p;
address: a;
yourself.
idx
ifNotNil: [ list data at: idx put: c ]
ifNil: [ list data add: c ] ].
inputPane := ToPane horizontal.
inputPane layout cellSpacing: 10.
inputPane addChildren: {
nameTxtF.
phoneTxtF.
addressTxtF.
button }.
contacts := OrderedCollection new.
contact := ToContactExample new.
contact name: 'Patty'.
contact phoneNumber: '0299041101'.
contact address: 'Brest'.
contacts add: contact.
contact := ToContactExample new.
contact name: 'Paulie'.
contact phoneNumber: '0298010101'.
contact address: 'Brest'.
contacts add: contact.
list nodeBuilder: [ :node :holder |
| line remBut |
line := ToPane horizontal.
line addChild: (ToLabel new
text: holder data name;
width: 100;
margin: (BlInsets right: 10)).
line addChild: (ToLabel new
text: holder data phoneNumber;
width: 100;
margin: (BlInsets right: 10)).
line addChild: (ToLabel new
text: holder data address;
width: 200;
margin: (BlInsets right: 10)).
line addChild: ToElement new matchParent.
remBut := ToButton new.
remBut defaultSkin: ToNullSkin new.
remBut icon: (ToImage inner: (self iconNamed: #windowClose)).
remBut constraintsDo: [ :c | c linear vertical alignCenter ].
remBut
when: BlClickEvent
do: [ :event |
holder infiniteElement data removeAt: holder position ].
line addChild: remBut.
node addChild: line ].
list data addAll: contacts.
panel addChild: inputPane.
panel addChild: list.
panel openInSpace
]

{ #category : 'context menu + menubar' }
ToSandBox class >> example_contextMenu [

Expand Down
21 changes: 21 additions & 0 deletions src/Toplo/TToObservableCollection.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ TToObservableCollection >> detect: aBlock ifNone: exceptionBlock [
^ list detect: aBlock ifNone: exceptionBlock
]

{ #category : 't - observable collection - enumerating' }
TToObservableCollection >> detectIndex: aBlock [

"Return index of first element that satisfies aBlock.
If no matching element is found, raise an error."

^ list detectIndex: aBlock
]

{ #category : 't - observable collection - enumerating' }
TToObservableCollection >> detectIndex: aBlock ifNone: exceptionBlock [

"Return index of first element that satisfies aBlock.
If no matching element is found, evaluate exceptionBlock."

"(#(1 5 10) detectIndex: [ :each | each > 3 ] ifNone: ['Not found']) >>> 2"
"(#(1 5 10) detectIndex: [ :each | each > 15 ] ifNone: ['Not found']) >>> 'Not found'"

^ list detectIndex: aBlock ifNone: exceptionBlock
]

{ #category : 't - observable collection - enumerating' }
TToObservableCollection >> do: aBlock [

Expand Down

0 comments on commit 7ae6d7b

Please sign in to comment.