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