You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -585,7 +591,7 @@ Note that a good evolution would be to decouple the model from its user interfac
585
591
586
592
```
587
593
TinyChat >> start
588
-
console := TCConsole attach: self.
594
+
console := TCConsolePresenter attach: self.
589
595
self sendNewMessage: (TCMessage from: login text: 'I joined the chat room').
590
596
lastMessageIndex := self readLastMessageID.
591
597
self refreshMessages.
@@ -598,46 +604,51 @@ TinyChat >> start
598
604
The user interface is composed of a window with a list and an input field as shown in Figure *@tinychatclient@*.
599
605
600
606
```
601
-
ComposablePresenter << #TCConsole
607
+
SpPresenter << #TCConsolePresenter
602
608
slots: {#chat . #list . #input};
603
609
package: 'TinyChat-client'
604
610
```
605
611
606
612
607
-
Note that the class `TCConsole` inherits from `ComposablePresenter`. This class is the root of the user interface logic classes.
608
-
`TCConsole` defines the logic of the client interface (i.e. what happens when we enter text in the input field...). Based on the information given in this class, the Spec user interface builder automatically builds the visual representation.
609
-
The `chat` instance variable is a reference to an instance of the client model `TinyChat` and requires a setter method (`chat:`). The `list` and `input` instance variables both require an accessor. This is required by the User Interface builder.
613
+
Note that the class `TCConsolePresenter` inherits from `SpPresenter`. This class is the root of the user interface logic classes.
614
+
`TCConsolePresenter` defines the logic of the client interface (i.e. what happens when we enter text in the input field...).
615
+
Based on the information given in this class, the Spec user interface builder automatically builds the visual representation.
616
+
The `chat` instance variable is a reference to an instance of the client model `TinyChat` and requires a setter method (`chat:`). The `list` and `input` instance variables both require an accessor.
617
+
This is required by the User Interface builder.
610
618
611
619
```
612
-
TCConsole >> input
620
+
TCConsolePresenter >> input
613
621
^ input
614
-
615
-
TCConsole >> list
622
+
```
623
+
```
624
+
TCConsolePresenter >> list
616
625
^ list
617
-
618
-
TCConsole >> chat: anObject
626
+
```
627
+
```
628
+
TCConsolePresenter >> chat: anObject
619
629
chat := anObject
620
630
```
621
631
622
632
623
633
We set the title of the window by defining the method `title`.
624
634
625
635
```
626
-
TCConsole >> title
636
+
TCConsolePresenter >> title
627
637
^ 'TinyChat'
628
638
```
629
639
630
640
631
641
Now we should specify the layout of the graphical elements that compose the client.
632
-
To do so we define the class method `TCConsole class>>defaultSpec`. Here we need a column with a list and an input field placed right below.
642
+
To do so we define the class method `TCConsolePresenter>>defaultLayout`. Here we need a column with a list and an input field placed right below.
633
643
634
644
```
635
-
TCConsole class >> defaultSpec
636
-
<spec: #default>
645
+
TCConsolePresenter >> defaultLayout
646
+
647
+
^ SpBoxLayout newTopToBottom
648
+
add: list;
649
+
add: input ;
650
+
yourself
637
651
638
-
^ SpecLayout composed
639
-
newColumn: [ :c |
640
-
c add: #list; add: #input height: 30 ]; yourself
641
652
```
642
653
643
654
@@ -647,13 +658,14 @@ The message `acceptBlock:` defines the action to be executed then the text is en
647
658
Here we send it to the chat model and empty it.
648
659
649
660
```
650
-
TCConsole >> initializeWidgets
661
+
TCConsolePresenter >> initializeWidgets
662
+
663
+
list := self newList.
651
664
652
-
list := ListModel new.
653
-
input := TextInputFieldModel new
654
-
ghostText: 'Type your message here...';
655
-
enabled: true;
656
-
acceptBlock: [ :string |
665
+
input := self newTextInput.
666
+
input
667
+
placeholder: 'Type your message here...';
668
+
whenSubmitDo: [ :string |
657
669
chat send: string.
658
670
input text: '' ].
659
671
self focusOrder add: input.
@@ -673,15 +685,13 @@ Finally we need to define the class method `TCConsole class>>attach:` that gets
673
685
This method opens the graphical elements and puts in place a mechanism that will close the connection as soon as the client closes the window.
0 commit comments