BlockValue.st
author Stefan Vogel <sv@exept.de>
Wed, 29 Apr 2020 22:34:37 +0200
changeset 4460 e067415ddf46
parent 4457 8c328436fba9
permissions -rw-r--r--
#FEATURE by stefan class: ApplicationModel added: #isDialog changed: #doAccept
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
     1
"{ Encoding: utf8 }"
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
     2
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
     5
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
1665
096ca1b11ce1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
    14
"{ Package: 'stx:libview2' }"
096ca1b11ce1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
    15
3474
9e58c4c4dedb class: BlockValue
Stefan Vogel <sv@exept.de>
parents: 3349
diff changeset
    16
"{ NameSpace: Smalltalk }"
9e58c4c4dedb class: BlockValue
Stefan Vogel <sv@exept.de>
parents: 3349
diff changeset
    17
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
ValueModel subclass:#BlockValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'cachedValue arguments block'
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
    20
	classVariableNames:'NeverComputed'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Interface-Support-Models'
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    30
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
4257
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    44
    BlockValues depend on one or more other objects (typically valueHolders)
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    and recompute a value whenever one of them changes.
4257
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    46
    If the recomputed new value is different, it triggers itself a change to its dependents.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
4257
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    48
    A typical example use is to base an enableChannel's value on multiple other 
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    49
    boolean (or non-boolean) values. (See example for how this is done)
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    50
4257
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    51
    Notice, that a BlockValue can also be created without depending on any other
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    52
    object (i.e. BlockValue with:aBlock). In this case, a recomputation must be explicitly
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    53
    triggered by sending #recomputeValue to the blockValue instance.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
    54
    
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    55
    Notice: 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    56
        this class was implemented using protocol information
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    57
        from alpha testers - it may not be complete or compatible to
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    58
        the corresponding ST-80 class. 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    59
        If you encounter any incompatibilities, please forward a note 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    60
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    61
2760
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
    62
    Warning:
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
    63
        BlockValues only work ine one direction; changing the blockValue's value
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
    64
        does not affect the original model's value.
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
    65
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    66
    [author:]
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    67
        Claus Gittinger
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
examples
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    73
    checkToggle 3 shows the value of toggle1 AND toggle2
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    74
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    75
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    76
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    77
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    78
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    79
        both := BlockValue 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    80
                    with:[:v1 :v2 | 
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
    81
                            Transcript showCR:'evaluating ...'.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    82
                            v1 value and:[v2 value]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    83
                         ] 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    84
                    arguments:(Array with:val1 with:val2).
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    85
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    86
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    87
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    88
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    89
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    90
        box addCheckBox:'both' on:both.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
    91
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    92
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    93
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    94
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    95
    the same, using a convenient instance creation message:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    96
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    97
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    98
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    99
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   100
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   101
        both := BlockValue forLogical:val1 and:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   103
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   104
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   105
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   106
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   107
        (box addCheckBox:'both' on:both) disable.
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   108
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   109
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   110
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   111
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   112
    logical or:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   113
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   114
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   115
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   116
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   117
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   118
        both := BlockValue forLogical:val1 or:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   120
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   121
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   122
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   123
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   124
        box addCheckBox:'both' on:both.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   125
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   126
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   127
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   128
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   129
    example use: enabling an element depending on two others:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   130
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   131
        |val1 val2 enabler val3 box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   132
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   133
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   134
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   135
        val3 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   136
        enabler := BlockValue forLogical:val1 and:val2.
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   137
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   138
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   139
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   140
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   141
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   142
        (box addCheckBox:'three (both of the above)' on:val3) enableChannel:enabler.
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   143
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   144
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   145
                                                                        [exEnd]
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   146
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   147
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   148
    like above, using a logical-or block:
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   149
                                                                        [exBegin]
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   150
        |val1 val2 enabler val3 box|
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   151
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   152
        val1 := false asValue.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   153
        val2 := false asValue.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   154
        val3 := false asValue.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   155
        enabler := BlockValue forLogical:val1 or:val2.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   156
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   157
        box := Dialog new.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   158
        box addCheckBox:'one' on:val1.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   159
        box addCheckBox:'two' on:val2.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   160
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   161
        (box addCheckBox:'three (any of the above)' on:val3) enableChannel:enabler.
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   162
        box addOkButton.
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   163
        box open
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   164
                                                                        [exEnd]
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   165
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   166
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   167
    like above, using a bunch of toggles:
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   168
                                                                        [exBegin]
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   169
        |values anyValue box|
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   170
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   171
        values := (1 to:10) collect:[:i | false asValue].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   172
        anyValue := BlockValue forLogicalOrAll:values.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   173
        anyValue onChangeSend:#value to:[Transcript showCR:'any is true'].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   174
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   175
        box := Dialog new.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   176
        values keysAndValuesDo:[:index :aValueHolder |
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   177
            box addCheckBox:index printString on:aValueHolder.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   178
        ].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   179
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   180
        (box addOkButton) enableChannel:anyValue.
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   181
        box open
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   182
                                                                        [exEnd]
4257
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   183
    a logical-not block:
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   184
                                                                        [exBegin]
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   185
        |val1 valNot box|
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   186
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   187
        val1 := false asValue.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   188
        valNot := BlockValue forLogicalNot:val1.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   189
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   190
        box := Dialog new.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   191
        box addCheckBox:'one' on:val1.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   192
        box addHorizontalLine.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   193
        (box addCheckBox:'not one' on:valNot) enabled:false
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   194
        box addOkButton.
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   195
        box open
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   196
                                                                        [exEnd]
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   197
2f858dbfd25b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4242
diff changeset
   198
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   202
!BlockValue class methodsFor:'initialization'!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   203
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   204
initialize
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   205
    NeverComputed isNil ifTrue:[
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   206
	NeverComputed := Object new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   207
    ]
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   208
! !
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   209
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
!BlockValue class methodsFor:'instance creation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   212
block:aBlock arguments:aCollectionOfValueModels
979
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   213
    "return a new BlockValue computing aBlock.
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   214
     Same as #with:arguments: for ST80 compatibility"
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   215
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   216
    ^ self with:aBlock arguments:aCollectionOfValueModels
979
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   217
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   218
    "Created: / 20.6.1998 / 14:00:16 / cg"
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   219
!
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   220
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   221
forLogical:valueModel1 and:valueModel2
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   222
    "return a new BlockValue computing the logical AND of its args
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   223
     (which are usually other valueHolders)"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   224
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   225
    ^ (self new) 
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   226
        setBlock:[:a :b | a value and:[b value]]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   227
        arguments:(Array with:valueModel1 with:valueModel2)
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   228
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   229
    "Created: / 16.12.1995 / 19:20:14 / cg"
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   230
    "Modified: / 30.1.2000 / 23:24:50 / cg"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   231
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   232
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   233
forLogical:valueModel1 and:valueModel2 and:valueModel3
2800
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   234
    "return a new BlockValue computing the logical AND of its args
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   235
     (which are usually other valueHolders)"
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   236
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   237
    ^ (self new) 
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   238
        setBlock:[:a :b :c | a value and:[b value and:[c value]]]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   239
        arguments:(Array with:valueModel1 with:valueModel2 with:valueModel3)
2800
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   240
!
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   241
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   242
forLogical:valueModel1 or:valueModel2
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   243
    "return a new BlockValue computing the logical OR of its args
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   244
     (which are usually other valueHolders)"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   245
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   246
    ^ (self new) 
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   247
        setBlock:[:a :b | a value or:[b value]]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   248
        arguments:(Array with:valueModel1 with:valueModel2)
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   249
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   250
    "Created: / 16.12.1995 / 19:20:14 / cg"
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   251
    "Modified: / 30.1.2000 / 23:24:46 / cg"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   252
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   253
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   254
forLogical:valueModel1 or:valueModel2 or:valueModel3
2800
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   255
    "return a new BlockValue computing the logical OR of its args
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   256
     (which are usually other valueHolders)"
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   257
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   258
    ^ (self new) 
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   259
        setBlock:[:a :b :c | a value or:[b value or:[c value]]]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   260
        arguments:(Array with:valueModel1 with:valueModel2 with:valueModel3)
2800
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   261
!
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
   262
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   263
forLogicalAndAll:arrayOfValueModels
3474
9e58c4c4dedb class: BlockValue
Stefan Vogel <sv@exept.de>
parents: 3349
diff changeset
   264
    "return a new BlockValue computing the logical AND of all elements
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   265
     in the passed argArray (which are usually other valueHolders)"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   266
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   267
    ^ (self new) 
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   268
        setBlock:[:a | (arrayOfValueModels findFirst:[:a | a value not]) == 0]
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   269
        argumentArray:arrayOfValueModels asArray
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   270
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   271
    "Created: / 22.1.1997 / 19:12:44 / cg"
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   272
    "Modified: / 28.4.1998 / 20:16:38 / ca"
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   273
    "Modified: / 30.1.2000 / 23:24:40 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   274
!
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   275
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   276
forLogicalNot:aValueModel
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   277
    "return a new BlockValue computing the logical NOT of its arg 
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   278
     (which is usually another valueHolder)"
1045
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   279
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   280
    ^ (self new) 
4260
edc649421747 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   281
        setBlock:[:a | a not]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   282
        arguments:(Array with:aValueModel)
1045
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   283
3349
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   284
    "
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   285
        |v1 v2|
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   286
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   287
        v1 := ValueHolder new.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   288
        v1 value:true.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   289
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   290
        v2 := BlockValue forLogicalNot:v1.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   291
        v2 onChangeEvaluate:[ Transcript showCR:v2 value].
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   292
        Transcript showCR:v2 value.         'shows a false already'. 
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   293
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   294
        v1 value:true.                      'no change signalled here'.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   295
        v1 value:false.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   296
        v1 value:true.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   297
    "
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   298
4260
edc649421747 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   299
    "Created: / 17-08-1998 / 10:06:41 / cg"
edc649421747 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   300
    "Modified: / 30-01-2000 / 23:24:18 / cg"
edc649421747 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   301
    "Modified: / 18-07-2018 / 20:33:18 / Claus Gittinger"
1045
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   302
!
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   303
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   304
forLogicalOrAll:arrayOfValueModels
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   305
    "return a new BlockValue computing the logical OR of all elements
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   306
     in the passed argArray (which are usually other valueHolders)"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   307
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   308
    ^ (self new) 
606
8a8b36a9e67d removed debugHalt
Claus Gittinger <cg@exept.de>
parents: 491
diff changeset
   309
        setBlock:[:arg | (arg findFirst:[:el | el value]) ~~ 0]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   310
        argumentArray:arrayOfValueModels asArray
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   311
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   312
    "Created: / 22.1.1997 / 19:13:01 / cg"
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   313
    "Modified: / 28.4.1998 / 20:20:09 / ca"
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   314
    "Modified: / 30.1.2000 / 23:24:34 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   315
!
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   316
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   317
forValue:someValueModel equalTo:someConstant
3349
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   318
    "return a new BlockValue generating a true, 
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   319
     if someValue (usually another holder) contains a value equal to someConstant.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   320
     Useful, if the other valueHolder is a radioButton group model,
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   321
     and you want to automatically enable/disable other items based on the value
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   322
     (i.e. via the enableChannel)"
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   323
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   324
    ^ (self new) 
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   325
        setBlock:[:a | a = someConstant]
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   326
        arguments:(Array with:someValueModel)
3349
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   327
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   328
    "
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   329
        |v1 v2|
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   330
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   331
        v1 := ValueHolder new.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   332
        v1 value:'blah'.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   333
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   334
        v2 := BlockValue forValue:v1 equalTo:'hello'.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   335
        v2 onChangeEvaluate:[ Transcript showCR:v2 value].
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   336
        Transcript showCR:v2 value.         'shows a false already'. 
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   337
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   338
        v1 value:'blah'.                      'no change signalled here'.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   339
        v1 value:'oops'.                      'remains false'.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   340
        v1 value:'hello'.                     'changes to true'.
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   341
        v2 value      
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   342
    "
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   343
!
ffebc3c4e212 class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   344
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
with:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   348
    ^ (self new) setBlock:aBlock
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
    "Created: 16.12.1995 / 19:16:33 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   353
with:aBlock argument:aValueModel
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   354
    "return a new BlockValue computing aBlock"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   355
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   356
    ^ (self new) 
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   357
        setBlock:aBlock 
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   358
        arguments:(Array with:aValueModel)
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   359
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   360
    "Created: 16.12.1995 / 19:20:14 / cg"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   361
!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   362
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   363
with:aBlock argument:valueModel1 argument:valueModel2
1255
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   364
    "return a new BlockValue computing aBlock"
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   365
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   366
    ^ (self new) 
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   367
        setBlock:aBlock 
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   368
        arguments:(Array with:valueModel1 with:valueModel2)
1255
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   369
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   370
    "Created: 16.12.1995 / 19:20:14 / cg"
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   371
!
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   372
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   373
with:aBlock argument:valueModel1 argument:valueModel2 argument:valueModel3
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   374
    "return a new BlockValue computing aBlock"
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   375
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   376
    ^ (self new) 
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   377
        setBlock:aBlock 
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   378
        arguments:(Array with:valueModel1 with:valueModel2 with:valueModel3)
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   379
!
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   380
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   381
with:aBlock argument:valueModel1 argument:valueModel2 argument:valueModel3 argument:valueModel4
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   382
    "return a new BlockValue computing aBlock"
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   383
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   384
    ^ (self new) 
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   385
        setBlock:aBlock 
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   386
        arguments:(Array with:valueModel1 with:valueModel2 with:valueModel3 with:valueModel4)
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   387
!
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   388
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   389
with:aBlock arguments:aCollectionOfValueModels
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
1815
5f6fb98a3479 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1788
diff changeset
   392
    ^ (self new) 
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   393
        setBlock:aBlock 
4457
8c328436fba9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
   394
        arguments:aCollectionOfValueModels
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
    "Created: 16.12.1995 / 19:20:14 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
!BlockValue methodsFor:'accessing'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
3945
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   401
setArguments:aCollectionOfArguments
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   402
    "set the receiver's arguments to be passed to it.
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   403
     A change in any of the arguments will force reevaluation of the action
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   404
     block - possibly generating another change from myself"
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   405
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   406
    arguments notNil ifTrue:[
3946
3aa94b58d2b0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3945
diff changeset
   407
        arguments do:[:arg | arg removeDependent:self].
3945
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   408
    ].
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   409
    arguments := aCollectionOfArguments.
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   410
    arguments do:[:arg |
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   411
        "arg maybe some constant..."
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   412
        arg notNil ifTrue:[
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   413
            arg addDependent:self
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   414
        ].
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   415
    ].
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   416
    self recomputeValue.
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   417
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   418
    "Created: / 30-03-2017 / 14:00:27 / stefan"
3946
3aa94b58d2b0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3945
diff changeset
   419
    "Modified: / 31-03-2017 / 16:28:39 / stefan"
3945
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   420
!
6219257414cf #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3613
diff changeset
   421
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
setBlock:aBlock
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   423
    "set the receiver's action block"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   424
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
    arguments notNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   427
        self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
    arguments := nil.
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   430
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
    "Created: 16.12.1995 / 19:16:59 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   433
    "Modified: 22.1.1997 / 19:05:54 / cg"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   434
!
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   435
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   436
setBlock:aBlock argumentArray:anArgumentCollection
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   437
    "set the receiver's action block, and define an arguments collection
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   438
     to be passed to it.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   439
     A change in any element of the collection will force reevaluation of the 
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   440
     action block (passing the collection as a single argument)
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   441
     - possibly generating another change from myself"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   442
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   443
    block := aBlock.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   444
    arguments notNil ifTrue:[
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   445
        self release
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   446
    ].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   447
    arguments := Array with:anArgumentCollection.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   448
    anArgumentCollection do:[:arg |
2530
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   449
        arg notNil ifTrue:[
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   450
            arg addDependent:self
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   451
        ].
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   452
    ].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   453
    cachedValue := NeverComputed.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   454
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   455
    "Modified: 22.1.1997 / 19:08:51 / cg"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   456
    "Created: 22.1.1997 / 19:22:13 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
setBlock:aBlock arguments:aCollectionOfArguments
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   460
    "set the receiver's action block, and define arguments to be passed to it.
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   461
     A change in any of the arguments will force reevaluation of the action
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   462
     block - possibly generating another change from myself"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   463
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
    arguments notNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   466
        self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
    arguments := aCollectionOfArguments.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
    arguments do:[:arg |
2530
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   470
        "arg maybe some constant..."
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   471
        arg notNil ifTrue:[
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   472
            arg addDependent:self
a40d597a31ed Do not set dependencies on nil
Stefan Vogel <sv@exept.de>
parents: 1815
diff changeset
   473
        ].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    ].
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   475
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
    "Created: 16.12.1995 / 19:21:41 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   478
    "Modified: 22.1.1997 / 19:08:51 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   481
setValue:newValue 
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   482
    "physically set my value, without change notifications.
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   483
     This is a noop here, since my value is computed."
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   484
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   485
    ^ self
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   486
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   487
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   488
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   489
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
value
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   491
    "retrieve my value - this does not always evaluate the action block,
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   492
     since the returned value is cached internally"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   493
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   494
    cachedValue == NeverComputed ifTrue:[
491
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   495
        cachedValue := self computeValue
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   496
    ].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
    ^ cachedValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
    "Created: 16.12.1995 / 19:23:26 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   500
    "Modified: 22.1.1997 / 19:06:59 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
347
2a795646e985 category rename
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
   503
!BlockValue methodsFor:'change & update'!
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
1788
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   505
recomputeValue
4242
dee79356dad2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3946
diff changeset
   506
    "force reevaluation of my actionBlock, 
dee79356dad2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3946
diff changeset
   507
     and possibly send a change notification to my dependents"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   508
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    |oldValue|
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    oldValue := cachedValue.
491
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   512
    cachedValue := self computeValue.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    oldValue ~~ cachedValue ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   514
        self changed:#value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
    ].
4242
dee79356dad2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3946
diff changeset
   516
dee79356dad2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3946
diff changeset
   517
    "Modified (comment): / 05-03-2019 / 21:40:21 / Claus Gittinger"
1788
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   518
!
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   519
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   520
update:something with:aParameter from:someone
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   521
    "the one I depend on has changed - reevaluate my actionBlock,
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   522
     and possibly send a change notification to my dependents"
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   523
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   524
    self recomputeValue
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
    "Created: 16.12.1995 / 19:22:54 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   527
    "Modified: 22.1.1997 / 19:07:39 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
2985
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   530
!BlockValue methodsFor:'dependents access'!
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   531
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   532
release
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   533
    "release any dependencies upon the arguments"
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   534
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   535
    arguments notNil ifTrue:[
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   536
        arguments do:[:arg | arg removeDependent:self].
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   537
    ].
3291
8690be2779fc class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 2985
diff changeset
   538
    super release
2985
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   539
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   540
    "Modified: 22.1.1997 / 19:08:06 / cg"
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   541
! !
bcda0efbb554 category of: #release
Claus Gittinger <cg@exept.de>
parents: 2800
diff changeset
   542
1788
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   543
!BlockValue methodsFor:'misc'!
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   544
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   545
computeValue
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   546
    "evaluate the receiver's action block"
1788
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   547
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   548
    |sz arg1 arg2 argValues|
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   549
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   550
    arguments isNil ifTrue:[
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   551
        ^ block value
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   552
    ].
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   553
    sz := arguments size.
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   554
    sz == 0 ifTrue:[
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   555
        ^ block value
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   556
    ].
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   557
    arg1 := (arguments at:1) value.
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   558
    sz == 1 ifTrue:[
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   559
        ^ block value:arg1
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   560
    ].
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   561
    arg2 := (arguments at:2) value.
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   562
    sz == 2 ifTrue:[
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   563
        ^ block value:arg1 value:arg2
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   564
    ].
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   565
    "/ do not evaluate arg[1-2] twice
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   566
    argValues := Array new:arguments size.
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   567
    argValues at:1 put:arg1.    "/ do not evaluate twice
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   568
    argValues at:2 put:arg2.    "/ do not evaluate twice
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   569
    3 to:arguments size do:[:i | argValues at:i put:(arguments at:i) value].
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   570
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   571
    ^ block valueWithArguments:argValues
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   572
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   573
    "Created: 16.12.1995 / 19:27:40 / cg"
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   574
    "Modified: 22.1.1997 / 19:05:57 / cg"
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   575
!
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   576
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   577
dependOn:someObject
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   578
    "arrange for the blockValue to be reevaluated, whenever someObject
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   579
     changes (i.e. sends a change notification)"
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   580
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   581
    arguments isNil ifTrue:[
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   582
        arguments := Array with:someObject
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   583
    ] ifFalse:[
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   584
        arguments := arguments copyWith:someObject
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   585
    ].
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   586
    someObject addDependent:self
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   587
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   588
    "Modified: 22.1.1997 / 19:05:26 / cg"
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   589
!
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   590
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   591
resetValue
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   592
    "evaluate the receiver's action block"
1788
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   593
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   594
    cachedValue := self computeValue
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   595
! !
7edafbabe844 +recomputeValue
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   596
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
version
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   600
    ^ '$Header$'
2760
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
   601
!
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
   602
653b3c3fd7a7 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
   603
version_CVS
3613
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
   604
    ^ '$Header$'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
! !
1665
096ca1b11ce1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
   606
3291
8690be2779fc class: BlockValue
Claus Gittinger <cg@exept.de>
parents: 2985
diff changeset
   607
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   608
BlockValue initialize!