10845
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2007 by eXept Software AG
|
16564
|
3 |
All Rights Reserved
|
10845
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
10518
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
19929
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
14950
|
16 |
Notification subclass:#UserConfirmation
|
11365
|
17 |
instanceVariableNames:'canCancel defaultAnswerInDialog defaultAnswer'
|
10518
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
11196
|
20 |
category:'Kernel-Exceptions-Notifications'
|
10518
|
21 |
!
|
|
22 |
|
10845
|
23 |
!UserConfirmation class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2007 by eXept Software AG
|
16564
|
28 |
All Rights Reserved
|
10845
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
11364
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
This confirmation query is used when a user confirmation is required
|
|
42 |
somewhere within a model's operation (i.e. in non-GUI code).
|
|
43 |
Instead of directly asking via Dialog confirm... messages,
|
16564
|
44 |
this should be raised.
|
11364
|
45 |
Its default behavior is the same as the above dialog.
|
16564
|
46 |
However, the query can be caught and answered by an exceoptn (a query-) handler,
|
11364
|
47 |
to suppress these GUI interactions in situations, where they are not wanted.
|
|
48 |
|
|
49 |
This is a much better approach to the alternatives:
|
16564
|
50 |
passing additional 'doConfirm' arguments down from the high level caller
|
|
51 |
keeping the doConfirm settings in a passed down flag object
|
|
52 |
keeping the flag in a global (very bad)
|
|
53 |
keeping it in a class var (almost as bad)
|
11364
|
54 |
|
14951
|
55 |
Notice: that's one of the nice consequences of proceedable exceptions.
|
11364
|
56 |
|
|
57 |
[authors:]
|
16564
|
58 |
Stefan Vogel
|
|
59 |
Claus Gittinger
|
11364
|
60 |
|
|
61 |
[see also:]
|
16564
|
62 |
Query Notification Exception
|
11364
|
63 |
"
|
10845
|
64 |
! !
|
10518
|
65 |
|
|
66 |
!UserConfirmation methodsFor:'accessing'!
|
|
67 |
|
|
68 |
aspect
|
16564
|
69 |
"the aspect the user is asked. Set this to a symbol.
|
10518
|
70 |
It can be used by a exception handler"
|
|
71 |
|
|
72 |
^ parameter
|
|
73 |
!
|
|
74 |
|
|
75 |
aspect:aSymbol
|
16564
|
76 |
"the aspect the user is asked. Set this to a symbol.
|
10518
|
77 |
It can be used by a exception handler"
|
|
78 |
|
|
79 |
parameter := aSymbol
|
|
80 |
!
|
|
81 |
|
|
82 |
canCancel
|
|
83 |
"answer true, if the user is allowed to press the cancel button
|
|
84 |
in a confirmation dialog"
|
|
85 |
|
|
86 |
^ canCancel ? false
|
|
87 |
!
|
|
88 |
|
|
89 |
canCancel:something
|
|
90 |
canCancel := something.
|
11364
|
91 |
!
|
|
92 |
|
11365
|
93 |
defaultAnswer
|
11364
|
94 |
"used to pass information from the raiser to the GUI dialog.
|
|
95 |
Specifies, which answer of the three (yes/no/cancel) should be the return-key-default.
|
|
96 |
If not specified, the cancel-key will be the default"
|
|
97 |
|
11365
|
98 |
^ defaultAnswer
|
11364
|
99 |
!
|
|
100 |
|
11365
|
101 |
defaultAnswer:aBooleanOrNil
|
11364
|
102 |
"used to pass information from the raiser to the GUI dialog.
|
|
103 |
Specifies, which answer of the three (yes/no/cancel) should be the return-key-default.
|
|
104 |
If not specified, the cancel-key will be the default"
|
|
105 |
|
11365
|
106 |
defaultAnswer := aBooleanOrNil
|
10518
|
107 |
! !
|
|
108 |
|
|
109 |
!UserConfirmation methodsFor:'default actions'!
|
|
110 |
|
|
111 |
defaultAction
|
|
112 |
"Default action for confirmations: open a info box with description.
|
|
113 |
If no GUI present, assume that the user pressed 'yes'"
|
|
114 |
|
11364
|
115 |
|text retVal retValText|
|
10518
|
116 |
|
|
117 |
text := self description.
|
|
118 |
|
|
119 |
self hasDialog ifTrue:[
|
16564
|
120 |
self canCancel ifTrue:[
|
|
121 |
^ Dialog confirmWithCancel:text default:defaultAnswer
|
|
122 |
] ifFalse:[
|
|
123 |
^ Dialog confirm:text default:defaultAnswer
|
|
124 |
].
|
10518
|
125 |
].
|
|
126 |
|
|
127 |
"
|
|
128 |
on systems without GUI, simply show
|
11365
|
129 |
the message on the Transcript and assume, that he would have typed 'yes' (or the defaultAnswer).
|
10518
|
130 |
"
|
16564
|
131 |
retVal := defaultAnswer notNil
|
|
132 |
ifTrue:[ defaultAnswer ]
|
|
133 |
ifFalse:[
|
|
134 |
self canCancel
|
|
135 |
ifTrue:[ nil ]
|
|
136 |
ifFalse:[ true ]].
|
11364
|
137 |
|
11365
|
138 |
retValText := retVal isNil
|
16564
|
139 |
ifTrue:[ 'cancel' ]
|
|
140 |
ifFalse:[
|
|
141 |
retVal
|
|
142 |
ifTrue:[ 'yes' ]
|
|
143 |
ifFalse:[ 'no' ]].
|
11365
|
144 |
|
16564
|
145 |
Transcript
|
|
146 |
show:('User confirmation requested (assuming %1): ' bindWith:retValText);
|
|
147 |
showCR:text.
|
11364
|
148 |
^ retVal
|
10518
|
149 |
|
|
150 |
"
|
|
151 |
UserConfirmation raiseRequestErrorString:'Please click yes or no!!'
|
|
152 |
"
|
|
153 |
! !
|
|
154 |
|
19929
|
155 |
!UserConfirmation methodsFor:'queries'!
|
|
156 |
|
|
157 |
askingContext
|
|
158 |
"return the context which did the confirm-request"
|
|
159 |
|
|
160 |
|con|
|
|
161 |
|
|
162 |
con := self suspendedContext.
|
|
163 |
[
|
|
164 |
(con selector startsWith:'confirm')
|
|
165 |
and:[ con method mclass == Object ]
|
|
166 |
] whileTrue:[
|
|
167 |
con := con sender.
|
|
168 |
].
|
|
169 |
^con
|
|
170 |
! !
|
|
171 |
|
10518
|
172 |
!UserConfirmation class methodsFor:'documentation'!
|
|
173 |
|
|
174 |
version
|
19929
|
175 |
^ '$Header$'
|
14951
|
176 |
!
|
|
177 |
|
|
178 |
version_CVS
|
19929
|
179 |
^ '$Header$'
|
10518
|
180 |
! !
|
19929
|
181 |
|