author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 13 Jun 2018 14:39:23 +0000 | |
branch | jv |
changeset 23108 | 77cd6e1625e1 |
parent 19812 | 0866264d6eed |
permissions | -rw-r--r-- |
4466
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
1 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
3 |
All Rights Reserved |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
4 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
5 |
This software is furnished under a license and may be used |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
10 |
hereby transferred. |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
11 |
" |
6206 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17598 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
8817
387971ee2b30
Notification is not an exception.
Claus Gittinger <cg@exept.de>
parents:
8778
diff
changeset
|
16 |
GenericException subclass:#Notification |
13674 | 17 |
instanceVariableNames:'tag' |
4443 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Kernel-Exceptions' |
|
21 |
! |
|
22 |
||
23 |
!Notification class methodsFor:'documentation'! |
|
24 |
||
4466
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
25 |
copyright |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
26 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
28 |
All Rights Reserved |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
29 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
30 |
This software is furnished under a license and may be used |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
31 |
only in accordance with the terms of that license and with the |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
32 |
inclusion of the above copyright notice. This software may not |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
33 |
be provided or otherwise made available to, or used by, any |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
34 |
other person. No title to or ownership of the software is |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
35 |
hereby transferred. |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
36 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
37 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
38 |
! |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
39 |
|
4443 | 40 |
documentation |
41 |
" |
|
12277 | 42 |
Notification is the superclass of all notification signals in the system. |
11200 | 43 |
contrast to regular exceptions, Notifications are ignored, if no handler is present |
44 |
and a default value is returned from the raise. |
|
15680 | 45 |
When a handler finishes, the do-block is proceeded with the exception handler's value |
8701
bd5034470a47
Optional code to make the default handler action to proceed.
Stefan Vogel <sv@exept.de>
parents:
8698
diff
changeset
|
46 |
(an Exception does a return in this case.). |
4443 | 47 |
|
11200 | 48 |
Thanks to proceedable exceptions, Notifications allow for non-GUI model code to provide |
49 |
user notifications which are optionally shown. |
|
50 |
Very useful, for example to provide progress information from a method which can be |
|
51 |
invoked both from a GUI-Tool (where notifications are wanted) and also from the system, |
|
52 |
where such notifications are not desired. |
|
53 |
||
4443 | 54 |
[author:] |
55 |
Stefan Vogel |
|
56 |
||
57 |
[see also:] |
|
15668 | 58 |
Signal QuerySignal Query |
4443 | 59 |
" |
60 |
! |
|
61 |
||
4550 | 62 |
examples |
4443 | 63 |
" |
6431 | 64 |
an up-notification from a deeply nested operation to a higher level: |
4550 | 65 |
[exBegin] |
66 |
|zero| |
|
67 |
||
68 |
zero := 0. |
|
6431 | 69 |
Notification handle:[:n | |
70 |
Transcript showCR:'Please note that: ' , n description. |
|
71 |
n proceedWith:true |
|
4550 | 72 |
] do:[ |
73 |
'nesting'. |
|
74 |
[ |
|
75 |
[ |
|
8516 | 76 |
Error handle:[:ex | |
4550 | 77 |
Transcript showCR:'some error: ' , ex errorString. |
78 |
ex proceed |
|
79 |
] do:[ |
|
80 |
[ |
|
81 |
1 // zero. 'an error which is caught in the handler'. |
|
6431 | 82 |
Notification notify:'hello world' |
4550 | 83 |
] value |
84 |
] |
|
85 |
] value |
|
86 |
] value |
|
87 |
] |
|
88 |
[exEnd] |
|
4443 | 89 |
" |
90 |
! ! |
|
91 |
||
92 |
!Notification class methodsFor:'initialization'! |
|
93 |
||
94 |
initialize |
|
95 |
||
4550 | 96 |
NotifierString := 'Notification:' |
97 |
! ! |
|
98 |
||
99 |
!Notification class methodsFor:'answering queries'! |
|
100 |
||
101 |
answer:someAnswer do:aBlock |
|
102 |
"evaluate the argument, aBlock. |
|
12060 | 103 |
If the receiver is queried during evaluation, answer and proceed with someAnswer. |
4550 | 104 |
This is a wrapper for #handle:do: for lazy typists; no new functionality." |
105 |
||
8698
948da171e6e5
Make #handle - contexts also #return-able
Stefan Vogel <sv@exept.de>
parents:
8692
diff
changeset
|
106 |
<context: #return> |
4550 | 107 |
<exception: #handle> |
108 |
||
109 |
"/ thisContext markForHandle. -- same as above pragma |
|
5227
73a2dc34cb42
#answer:do: now returns the evaluated blocks value
Claus Gittinger <cg@exept.de>
parents:
4605
diff
changeset
|
110 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
4550 | 111 |
|
112 |
" |
|
113 |
Notification answer:true do:[ |
|
114 |
Transcript showCR:'query answers: ' , (Query query printString). |
|
115 |
] |
|
116 |
" |
|
4443 | 117 |
|
118 |
" |
|
4550 | 119 |
Notification answer:false do:[ |
120 |
Transcript showCR:'first query answers: ' , (Query query printString). |
|
121 |
Query answer:true do:[ |
|
122 |
Transcript showCR:'second query answers: ' , (Query query printString). |
|
123 |
] |
|
124 |
] |
|
4443 | 125 |
" |
126 |
||
4550 | 127 |
"Created: / 10.7.1996 / 15:08:20 / cg" |
128 |
"Modified: / 14.10.1996 / 16:59:18 / cg" |
|
129 |
"Modified: / 25.7.1999 / 23:12:19 / stefan" |
|
130 |
! ! |
|
131 |
||
12084 | 132 |
|
4550 | 133 |
!Notification class methodsFor:'queries'! |
134 |
||
135 |
accepts:aSignal |
|
136 |
"return true, if the receiver accepts the argument, aSignal. |
|
137 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
138 |
||
139 |
|s| |
|
140 |
||
141 |
self == aSignal ifTrue:[^ true]. |
|
142 |
aSignal isQuerySignal ifFalse:[^ false]. |
|
143 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
144 |
s := aSignal parent. |
4550 | 145 |
[s notNil] whileTrue:[ |
146 |
self == s ifTrue:[^ true]. |
|
147 |
s := s parent |
|
148 |
]. |
|
149 |
^ false |
|
150 |
||
151 |
"Modified: / 22.3.1999 / 12:45:32 / stefan" |
|
152 |
"Created: / 23.7.1999 / 15:18:00 / stefan" |
|
153 |
! |
|
154 |
||
155 |
defaultAnswer |
|
156 |
"Return the default answer to the Query. This method is called, |
|
157 |
if nobody catches the signal. |
|
158 |
||
159 |
Subclasses may redefine this method." |
|
160 |
||
19778 | 161 |
"Calling raiseRequest here will execute the exception's action method |
162 |
which returns the defaultResumeValue." |
|
4550 | 163 |
|
19778 | 164 |
^ super raiseRequest |
4550 | 165 |
|
166 |
"Created: / 23.7.1999 / 15:16:03 / stefan" |
|
167 |
! |
|
168 |
||
169 |
handlerForSignal:signal context:theContext originator:originator |
|
170 |
"answer the handler block for the signal from originator. |
|
171 |
The block is retrieved from aContext. |
|
172 |
Answer nil if the signal is not handled" |
|
173 |
||
174 |
|arg| |
|
175 |
||
176 |
theContext selector == #'answer:do:' ifTrue:[ |
|
177 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
|
178 |
arg := theContext argAt:1. |
|
179 |
^ [:ex| ex proceedWith:arg]. |
|
180 |
] |
|
181 |
] ifFalse:[ |
|
182 |
^ super handlerForSignal:signal context:theContext originator:originator. |
|
183 |
]. |
|
184 |
||
185 |
^ nil |
|
186 |
||
187 |
"Created: / 25.7.1999 / 23:11:55 / stefan" |
|
188 |
! |
|
189 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
190 |
handles:anException |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
191 |
"return true, if the receiver handles the argument, anException. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
192 |
(i.e. the receiver is anExceptions signal or a parent of it)" |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
193 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
194 |
|signal| |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
195 |
|
15114
77142b5c937a
use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents:
14948
diff
changeset
|
196 |
signal := anException creator. |
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
197 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
198 |
self == signal ifTrue:[^ true]. "quick check" |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
199 |
anException isNotification ifFalse:[^ false]. "speed up non-queries by not traversing the parent chain" |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
200 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
201 |
[(signal := signal parent) notNil] whileTrue:[ |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
202 |
self == signal ifTrue:[^ true]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
203 |
]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
204 |
^ false |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
205 |
! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
206 |
|
4550 | 207 |
isQuerySignal |
4605 | 208 |
"return true, if this is a querySignal - always return true here" |
4550 | 209 |
|
210 |
^ true |
|
211 |
||
212 |
"Created: / 23.7.1999 / 14:59:50 / stefan" |
|
213 |
! |
|
214 |
||
6431 | 215 |
notify:aMessageString |
15680 | 216 |
"raise the query - return the handler's value, or the default |
6431 | 217 |
value, if there is no handler." |
218 |
||
16283 | 219 |
"/ cg: must be redefined, so we get a reasonable originator |
220 |
"/ some apps depend on aoriginator being the non-exception context here. |
|
221 |
"/ (do not do a self raiseRequestErrorString: here) |
|
222 |
^ self basicNew |
|
223 |
raiseRequestErrorString:aMessageString in:thisContext sender |
|
6431 | 224 |
! |
225 |
||
19796 | 226 |
notify:aMessageString with:aParameter |
227 |
"raise the query - return the handler's value, or the default |
|
228 |
value, if there is no handler." |
|
229 |
||
230 |
"/ cg: must be redefined, so we get a reasonable originator |
|
231 |
"/ some apps depend on an originator being the non-exception context here. |
|
232 |
"/ (do not do a self raiseRequestErrorString: here) |
|
233 |
^ self basicNew |
|
234 |
parameter:aParameter; |
|
235 |
raiseRequestErrorString:aMessageString in:thisContext sender |
|
236 |
! |
|
237 |
||
4550 | 238 |
query |
15680 | 239 |
"raise the query - return the handler's value, or the default |
4550 | 240 |
value, if there is no handler. |
241 |
Invoking the handler is exactly the functionality of Signal>>raiseRequest, |
|
8778 | 242 |
but we can do it faster here (avoiding the construction of an exception instance)." |
4550 | 243 |
|
19777 | 244 |
^ self raiseAsQuery |
4550 | 245 |
! |
246 |
||
247 |
raise |
|
15849 | 248 |
"Notifications are proceedable by definition, |
4550 | 249 |
so they should be raised with #query or #raiseRequest" |
250 |
||
251 |
^ self shouldNotImplement |
|
252 |
||
253 |
"Created: / 23.7.1999 / 15:19:17 / stefan" |
|
254 |
! |
|
255 |
||
256 |
raiseRequest |
|
257 |
"redefined to use #query" |
|
258 |
||
19777 | 259 |
^ self raiseAsQuery |
4550 | 260 |
|
261 |
"Created: / 25.7.1999 / 23:25:59 / stefan" |
|
4443 | 262 |
! ! |
263 |
||
15849 | 264 |
!Notification class methodsFor:'utilities'! |
265 |
||
266 |
deprecated |
|
267 |
"invoked by some open source packages (SOAP and YAXO, for example)" |
|
268 |
||
269 |
self notify:'called deprecated interface' |
|
270 |
! ! |
|
271 |
||
13674 | 272 |
!Notification methodsFor:'accessing'! |
273 |
||
274 |
tag |
|
275 |
"for squeak compatibility" |
|
276 |
||
277 |
^ tag |
|
278 |
||
279 |
"Modified (comment): / 11-09-2011 / 16:40:54 / cg" |
|
280 |
! |
|
281 |
||
282 |
tag:aSzmbol |
|
283 |
"for squeak compatibility" |
|
284 |
||
285 |
tag := aSzmbol. |
|
286 |
||
287 |
"Modified (format): / 11-09-2011 / 16:41:01 / cg" |
|
288 |
! ! |
|
289 |
||
4443 | 290 |
!Notification methodsFor:'default actions'! |
291 |
||
4525 | 292 |
defaultAction |
4550 | 293 |
"the default action is to return the default value. |
294 |
Subclasses may redefine this" |
|
4443 | 295 |
|
8683
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
296 |
|handlerBlock| |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
297 |
|
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
298 |
"try per signal handler. |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
299 |
I may have been created from a QuerySignal" |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
300 |
|
15285 | 301 |
(handlerBlock := self creator handlerBlock) notNil ifTrue:[ |
8683
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
302 |
"... and call it" |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
303 |
^ handlerBlock value:self. |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
304 |
]. |
6451
f22b12c0349a
renamed #defaultValue -> #defaultResumeValue (vw54 compat.)
Claus Gittinger <cg@exept.de>
parents:
6431
diff
changeset
|
305 |
^ self defaultResumeValue |
4443 | 306 |
|
4550 | 307 |
"Modified: / 23.7.1999 / 15:13:34 / stefan" |
4443 | 308 |
! ! |
309 |
||
14948 | 310 |
!Notification methodsFor:'helpers'! |
311 |
||
312 |
hasDialog |
|
313 |
"answer true, if we can use a Dialog window" |
|
314 |
||
315 |
(Smalltalk isInitialized |
|
316 |
and:[Dialog notNil |
|
317 |
and:[Screen notNil |
|
318 |
and:[Screen current notNil |
|
319 |
and:[Screen current isOpenAndDispatching |
|
320 |
]]]]) ifTrue:[ |
|
321 |
Dialog autoload. "in case its autoloaded" |
|
322 |
^ true. |
|
323 |
]. |
|
324 |
^ false |
|
325 |
! ! |
|
326 |
||
12042 | 327 |
!Notification methodsFor:'queries'! |
328 |
||
19796 | 329 |
notify |
330 |
"notice the implementation on the class-side: if no additional parameters are to be passed, |
|
331 |
we do not even arrive here, because query has inlined the raiseRequest code" |
|
332 |
||
333 |
^ self raiseRequestIn:thisContext sender |
|
334 |
! |
|
335 |
||
336 |
notify:aMessageString |
|
337 |
"notice the implementation on the class-side: if no additional parameters are to be passed, |
|
338 |
we do not even arrive here, because query has inlined the raiseRequest code" |
|
339 |
||
340 |
^ self raiseRequestErrorString:aMessageString in:thisContext sender |
|
341 |
! |
|
342 |
||
12042 | 343 |
query |
344 |
"notice the implementation on the class-side: if no additional parameters are to be passed, |
|
345 |
we do not even arrive here, because query has inlined the raiseRequest code" |
|
346 |
||
19796 | 347 |
^ self raiseRequestIn:thisContext sender |
12042 | 348 |
! ! |
349 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
350 |
!Notification methodsFor:'testing'! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
351 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
352 |
isNotification |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
353 |
^ true |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
354 |
! ! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
355 |
|
4443 | 356 |
!Notification class methodsFor:'documentation'! |
357 |
||
358 |
version |
|
18675 | 359 |
^ '$Header$' |
12042 | 360 |
! |
361 |
||
362 |
version_CVS |
|
18675 | 363 |
^ '$Header$' |
4443 | 364 |
! ! |
8516 | 365 |
|
14948 | 366 |
|
4443 | 367 |
Notification initialize! |