YesNoBox.st
author Claus Gittinger <cg@exept.de>
Mon, 11 Dec 1995 18:03:27 +0100
changeset 250 77012e65ac84
parent 243 5c411425097d
child 253 f071ff350cd5
permissions -rw-r--r--
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     1
"
5
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
     3
	      All Rights Reserved
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     4
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    11
"
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    12
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    13
WarningBox subclass:#YesNoBox
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    14
	 instanceVariableNames:''
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    15
	 classVariableNames:'RequestBitmap'
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    16
	 poolDictionaries:''
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    17
	 category:'Views-DialogBoxes'
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    18
!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    19
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    20
!YesNoBox class methodsFor:'documentation'!
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    21
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    22
copyright
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    23
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    25
	      All Rights Reserved
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    26
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    27
 This software is furnished under a license and may be used
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    28
 only in accordance with the terms of that license and with the
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    30
 be provided or otherwise made available to, or used by, any
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    31
 other person.  No title to or ownership of the software is
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    32
 hereby transferred.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    33
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    34
!
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    35
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    36
documentation
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    37
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    38
    this class implements yes-no boxes by adding another (no-) Button to the WarnBox-View.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    39
    They are created with:
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    40
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    41
	aBox := YesNoBox title:'some title'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    42
	aBox okAction:[ .. some action to be performed when ok is pressed ].
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    43
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    44
    and finally shown with:
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    45
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    46
	aBox showAtPointer
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    47
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    48
    The default box shows 'yes' and 'no' in its buttons; this can be changed with:
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    49
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    50
	aBox yesText:'some string'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    51
	aBox noText:'some string'.
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    52
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    53
    There is also protocol to set both button titles in one message.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    54
    Also, the action associated to the noButton can be changed.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    55
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    56
    For very simple yes/no queries, you can also use the much simpler confirm:.
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    57
    Since implemented in Object, everyone understands confirm. You can pass
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    58
    a question message (but not change the buttons labels).
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    59
    Use is:
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    60
	self confirm:'some question'  
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    61
    and will return true or false.
125
claus
parents: 119
diff changeset
    62
claus
parents: 119
diff changeset
    63
    For compatibility with ST-80, use:
claus
parents: 119
diff changeset
    64
	Dialog confirm:'hello'
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    65
"
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    66
!
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    67
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    68
examples
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    69
"
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    70
    Examples:
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    71
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    72
	|aBox|
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    73
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    74
	aBox := YesNoBox title:'Coffee or tee ?'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    75
	aBox noText:'tee'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    76
	aBox yesText:'coffee'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    77
	aBox yesAction:[Transcript showCr:'make coffee'].
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    78
	aBox noAction:[Transcript showCr:'make tee'].
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    79
	aBox showAtPointer.
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    80
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    81
    or, shorter:
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    82
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    83
	|aBox|
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    84
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    85
	aBox := YesNoBox new.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    86
	aBox title:'Coffee or Tee ?' 
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    87
	     yesAction:[Transcript showCr:'make coffee']
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    88
	     noAction:[Transcript showCr:'make tee'].
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    89
	aBox yesText:'Coffee' noText:'Tee'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    90
	aBox showAtPointer
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    91
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    92
    Also, have a look at the inherited protocol; for example, this allows changing
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
    93
    the bitmap (default: a question mark) and other properties.
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    94
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    95
    If the box is needed to ask for a simple boolean, you can also use the
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    96
    #confirm method, to bring up a box, let it ask for something and return
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    97
    true or false. 
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    98
    Example:
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
    99
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   100
	|box value|
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   101
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   102
	box := YesNoBox new.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   103
	value := box confirm:'yes or no:'.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   104
	value ifTrue:[
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   105
	    Transcript showCr:'yes'
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   106
	] ifFalse:[
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   107
	    Transcript showCr:'no'
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   108
	]
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   109
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   110
    of course, this can also be written shorter as:
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   111
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   112
	(YesNoBox new confirm:'yes or no:') ifTrue:[
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   113
	    Transcript showCr:'yes'
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   114
	] ifFalse:[
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   115
	    Transcript showCr:'no'
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   116
	]
125
claus
parents: 119
diff changeset
   117
claus
parents: 119
diff changeset
   118
    or:
claus
parents: 119
diff changeset
   119
claus
parents: 119
diff changeset
   120
	(Dialog confirm:'yes or no:') ifTrue:[
claus
parents: 119
diff changeset
   121
	    Transcript showCr:'yes'
claus
parents: 119
diff changeset
   122
	] ifFalse:[
claus
parents: 119
diff changeset
   123
	    Transcript showCr:'no'
claus
parents: 119
diff changeset
   124
	]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
   125
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
   126
! !
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   127
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   128
!YesNoBox class methodsFor:'instance creation'!
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   129
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   130
title:t yesText:yesString noText:noString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   131
    ^ (self new) title:t yesText:yesString noText:noString
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   132
! !
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   133
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   134
!YesNoBox class methodsFor:'icon bitmap'!
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   135
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   136
iconBitmap
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   137
    "return the bitmap shown as icon in my instances"
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   138
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   139
    RequestBitmap isNil ifTrue:[
109
0f014b33eba2 *** empty log message ***
claus
parents: 105
diff changeset
   140
	RequestBitmap := Image fromFile:'bitmaps/Request.xbm'. 
0f014b33eba2 *** empty log message ***
claus
parents: 105
diff changeset
   141
	RequestBitmap notNil ifTrue:[
0f014b33eba2 *** empty log message ***
claus
parents: 105
diff changeset
   142
	    RequestBitmap := RequestBitmap on:Display 
0f014b33eba2 *** empty log message ***
claus
parents: 105
diff changeset
   143
	].
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   144
    ].
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   145
    ^ RequestBitmap
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   146
! !
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   147
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   148
!YesNoBox class methodsFor:'styles'!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   149
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   150
updateStyleCache
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   151
    |img|
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   152
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   153
    img := StyleSheet at:'requestBoxIcon'.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   154
    img notNil ifTrue:[RequestBitmap := img on:Display].
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   155
! !
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   156
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   157
!YesNoBox methodsFor:'accessing'!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   158
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   159
noAction:aBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   160
    "define the action to be performed when no is pressed"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   161
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   162
    abortAction := aBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   163
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   164
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   165
noButton
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   166
    "return the no-button"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   167
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   168
    ^ abortButton
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   169
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   170
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   171
noText:aString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   172
    "define the label of the no-button"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   173
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   174
    aString ~= abortButton label ifTrue:[
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   175
	abortButton label:aString.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   176
	abortButton resize.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   177
	shown ifTrue:[self resize]
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   178
    ]
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   179
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   180
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   181
okText:yesString noText:noString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   182
    "define the labels of both buttons - same as yesText:noText"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   183
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   184
    ^ self yesText:yesString noText:noString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   185
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   186
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   187
title:aString yesAction:yesBlock noAction:noBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   188
    "define title and actions"
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   189
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   190
    self title:aString.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   191
    okAction := yesBlock.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   192
    abortAction := noBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   193
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   194
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   195
title:aString yesText:yesString noText:noString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   196
    "define title and button labels"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   198
    self title:aString.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   199
    self yesText:yesString noText:noString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   200
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   201
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   202
yesAction:aBlock 
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   203
    "define the action to be performed when yes is pressed"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   204
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   205
    okAction := aBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   206
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   207
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   208
yesAction:yesBlock noAction:noBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   209
    "define both actions"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   210
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   211
    okAction := yesBlock.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   212
    abortAction := noBlock
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   213
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   214
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   215
yesButton
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   216
    "return the yes-button"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   217
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   218
    ^ okButton
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   219
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   220
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   221
yesText:aString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   222
    "define the label of the yes-button"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   223
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   224
    self okText:aString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   225
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   226
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   227
yesText:yesString noText:noString
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   228
    "define the labels of both buttons"
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   229
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   230
    ((yesString ~= okButton label) or:[noString ~= abortButton label]) ifTrue:[
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   231
	okButton label:yesString.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   232
	abortButton label:noString.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   233
	okButton resize.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   234
	abortButton resize.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   235
	shown ifTrue:[self resize]
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   236
    ]
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   237
! !
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   238
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   239
!YesNoBox methodsFor:'initialization'!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   240
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   241
focusSequence
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   242
    ^ Array with:abortButton with:okButton 
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   243
!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   244
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   245
initialize
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   246
    super initialize.
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   247
150
claus
parents: 130
diff changeset
   248
    label := resources string:'Choose'.
79
6d917a89f7b7 *** empty log message ***
claus
parents: 63
diff changeset
   249
130
claus
parents: 125
diff changeset
   250
    buttonPanel horizontalLayout:#fitSpace.  "/ looks better; should it come from the StyleSheet ?
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   251
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   252
    textLabel label:'please Confirm'.
162
claus
parents: 150
diff changeset
   253
    okButton logo:(resources at:'yes').
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   254
162
claus
parents: 150
diff changeset
   255
    abortButton := Button abortButton.
claus
parents: 150
diff changeset
   256
    buttonPanel addSubView:abortButton before:okButton.
claus
parents: 150
diff changeset
   257
    abortButton logo:(resources at:'no').
claus
parents: 150
diff changeset
   258
    abortButton height:(okButton height).
claus
parents: 150
diff changeset
   259
    abortButton model:self; change:#noPressed
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   260
! !
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   261
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   262
!YesNoBox methodsFor:'queries'!
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   263
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   264
preferredExtent 
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   265
    |w h max|
79
6d917a89f7b7 *** empty log message ***
claus
parents: 63
diff changeset
   266
197
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   267
    "
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   268
     make the two buttons of equal size
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   269
    "
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   270
    max := okButton preferredExtent x max:abortButton preferredExtent x.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   271
    okButton width:max.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   272
    abortButton width:max.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   273
    w := (formLabel width + textLabel width) max:max * 2.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   274
    w := w + (3 * ViewSpacing) + (okButton borderWidth + abortButton borderWidth * 2).
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   275
    h := ViewSpacing
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   276
	 + ((formLabel height) max:(textLabel height))
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   277
	 + (ViewSpacing * 3)
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   278
	 + okButton heightIncludingBorder
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   279
	 + ViewSpacing.
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   280
00927189c882 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   281
    ^ (w @ h).
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   282
! !
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
   283
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   284
!YesNoBox methodsFor:'startup'!
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   285
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   286
confirm
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   287
    "open the receiver and return true for yes, false for no.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   288
     This is an easier interface to use, since no action blocks
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   289
     have to be defined. The title is used as previously defined."
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
   290
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   291
    self yesAction:[^ true] noAction:[^ false].
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   292
    self showAtPointer.
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   293
    self yesAction:nil noAction:nil. "/ clear actions for earlier release of context
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
   294
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   295
    "
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   296
     YesNoBox new confirm
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   297
    "
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   298
!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   299
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   300
confirm:aString
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   301
    "open the receiver and return true for yes, false for no.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   302
     This is an easier interface to use, since no action blocks
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   303
     have to be defined."
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 9
diff changeset
   304
59
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   305
    self title:aString.
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   306
    ^ self confirm
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   307
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   308
    "
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   309
     YesNoBox new confirm:'really ?'
450ce95a72a4 *** empty log message ***
claus
parents: 55
diff changeset
   310
    "
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   311
! !
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   312
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   313
!YesNoBox methodsFor:'user interaction'!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   314
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   315
noPressed
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   316
    "user pressed the no-button;
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   317
     hide myself and evaluate the action"
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   318
162
claus
parents: 150
diff changeset
   319
    abortButton turnOffWithoutRedraw.
claus
parents: 150
diff changeset
   320
    self hideAndEvaluate:abortAction
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   321
! !
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   322
243
5c411425097d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   323
!YesNoBox class methodsFor:'documentation'!
5c411425097d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   324
5c411425097d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   325
version
5c411425097d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   326
    ^ '$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.21 1995-12-07 22:24:08 cg Exp $'
5c411425097d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   327
! !