|
1 | | -'From Cuis 5.0 [latest update: #4208] on 8 June 2020 at 9:47:45 am'! |
| 1 | +'From Cuis7.1 [latest update: #6378] on 18 May 2024 at 4:27:24 pm'! |
2 | 2 | 'Description Useful Cuis code patterns, intended to help the programmer exploit some of the features of Cuis classes. These examples separate model from view and feature two styles: coupled and decoupled. |
3 | 3 |
|
4 | 4 | The coupled style employs the "dependency mechanism" and exposes the model to changes in the view and to views which were unanticipated. The primary methods of the dependency mechanism are #changed: and #update: . |
5 | 5 |
|
6 | 6 | The decoupled style employs the "observer pattern" which ensures that the model can remain unaffected by changes to the view or by additional views. The primary methods of the observer pattern are #triggerEvent: and #when:send:to: . This is the preferred style for Cuis, although both styles can be found in the base. |
7 | 7 | '! |
8 | | -!provides: 'Code-Patterns' 1 4! |
| 8 | +!provides: 'Code-Patterns' 1 5! |
9 | 9 | SystemOrganization addCategory: #'Code-Patterns'! |
10 | 10 |
|
11 | 11 |
|
@@ -283,25 +283,22 @@ authorIndex: anObject |
283 | 283 | initialize |
284 | 284 | super initialize! ! |
285 | 285 |
|
286 | | -!AnotherView methodsFor: 'initialization' stamp: 'dhn 1/4/2016 14:41'! |
| 286 | +!AnotherView methodsFor: 'initialization' stamp: 'jmv 5/17/2024 17:55:33'! |
287 | 287 | buildMorphicWindow |
288 | 288 | "Specify the layout of the view" |
289 | 289 | | listM | |
290 | 290 |
|
291 | 291 | self layoutMorph beRow "make use of the layoutMorph already in SystemWindow; change it from column to row" |
292 | 292 | name: #'Pattern Row'. "give the layoutMorph a name which will appear in the halos" |
293 | 293 |
|
294 | | - listM _ (PluggableListMorph |
295 | | - model: model "the object specified in self class open" |
| 294 | + listM := (PluggableListMorph |
| 295 | + withModel: model "the object specified in self class open" |
296 | 296 | listGetter: #authors "the method in 'model' which answers the list content" |
297 | 297 | indexGetter: #authorIndex "the method in 'model' which answers the selection made in the list" |
298 | | - indexSetter: #authorIndex: "the method in 'model' which sets the list index" |
299 | | - mainView: nil |
300 | | - menuGetter: nil |
301 | | - keystrokeAction: nil) |
| 298 | + indexSetter: #authorIndex: )"the method in 'model' which sets the list index" |
302 | 299 | name: #author. "give the PluggableListMorph a name which will appear in the halos" |
303 | 300 |
|
304 | | - textPane _ (TextModelMorph |
| 301 | + textPane := (TextModelMorph |
305 | 302 | withModel: (TextModel withText: 'foo')) "note the different model specification" |
306 | 303 | askBeforeDiscardingEdits: false; "discard changes to the text" |
307 | 304 | name: #quote. "give the TextModelMorph a name which will appear in the halos" |
@@ -567,22 +564,19 @@ title |
567 | 564 |
|
568 | 565 | ^ 'Buttons Up on the Decoupled Model'! ! |
569 | 566 |
|
570 | | -!CoupledView methodsFor: 'initialization' stamp: 'dhn 12/8/2015 12:55'! |
| 567 | +!CoupledView methodsFor: 'initialization' stamp: 'jmv 5/17/2024 17:54:20'! |
571 | 568 | buildMorphicWindow |
572 | 569 | "Specify the layout of the view" |
573 | 570 | | listM | |
574 | 571 |
|
575 | | - listM _ (PluggableListMorph |
576 | | - model: model "the object specified in self class open" |
| 572 | + listM := (PluggableListMorph |
| 573 | + withModel: model "the object specified in self class open" |
577 | 574 | listGetter: #authors "the method in 'model' which answers the list content" |
578 | 575 | indexGetter: #authorIndex "the method in 'model' which answers the selection made in the list" |
579 | | - indexSetter: #authorIndex: "the method in 'model' which sets the list index" |
580 | | - mainView: nil |
581 | | - menuGetter: nil |
582 | | - keystrokeAction: nil) |
| 576 | + indexSetter: #authorIndex: )"the method in 'model' which sets the list index" |
583 | 577 | name: #author. "give the PluggableListMorph a name which will appear in the halos" |
584 | 578 |
|
585 | | - textMorph _ (TextModelMorph |
| 579 | + textMorph := (TextModelMorph |
586 | 580 | withModel: (TextModel withText: 'foo')) "note the different model specification" |
587 | 581 | askBeforeDiscardingEdits: false; "discard changes to the text" |
588 | 582 | name: #quote. "give the TextModelMorph a name which will appear in the halos" |
@@ -650,25 +644,22 @@ open |
650 | 644 | or, use a Color class method" |
651 | 645 | ! ! |
652 | 646 |
|
653 | | -!DecoupledView methodsFor: 'initialization' stamp: 'dhn 1/4/2016 14:39'! |
| 647 | +!DecoupledView methodsFor: 'initialization' stamp: 'jmv 5/17/2024 17:55:51'! |
654 | 648 | buildMorphicWindow |
655 | 649 | "Specify the layout of the view" |
656 | 650 | | listM | |
657 | 651 |
|
658 | 652 | self layoutMorph beRow "make use of the layoutMorph already in SystemWindow; change it from column to row" |
659 | 653 | name: #'Pattern Row'. "give the layoutMorph a name which will appear in the halos" |
660 | 654 |
|
661 | | - listM _ (PluggableListMorph |
662 | | - model: model "the object specified in self class open" |
| 655 | + listM := (PluggableListMorph |
| 656 | + withModel: model "the object specified in self class open" |
663 | 657 | listGetter: #authors "the method in 'model' which answers the list content" |
664 | 658 | indexGetter: #authorIndex "the method in 'model' which answers the selection made in the list" |
665 | | - indexSetter: #authorIndex: "the method in 'model' which sets the list index" |
666 | | - mainView: nil |
667 | | - menuGetter: nil |
668 | | - keystrokeAction: nil) |
| 659 | + indexSetter: #authorIndex:) "the method in 'model' which sets the list index" |
669 | 660 | name: #author. "give the PluggableListMorph a name which will appear in the halos" |
670 | 661 |
|
671 | | - textPane _ (TextModelMorph |
| 662 | + textPane := (TextModelMorph |
672 | 663 | withModel: (TextModel withText: 'foo')) "note the different model specification" |
673 | 664 | askBeforeDiscardingEdits: false; "discard changes to the text" |
674 | 665 | name: #quote. "give the TextModelMorph a name which will appear in the halos" |
|
0 commit comments