+ defaultAnswerInDialog
authorClaus Gittinger <cg@exept.de>
Sat, 22 Nov 2008 11:45:20 +0100
changeset 11364 217571ef0914
parent 11363 de78c218cc36
child 11365 5b8d580b8df5
+ defaultAnswerInDialog added documentation
UserConfirmation.st
--- a/UserConfirmation.st	Fri Nov 21 16:09:30 2008 +0100
+++ b/UserConfirmation.st	Sat Nov 22 11:45:20 2008 +0100
@@ -12,7 +12,7 @@
 "{ Package: 'stx:libbasic' }"
 
 UserNotification subclass:#UserConfirmation
-	instanceVariableNames:'canCancel'
+	instanceVariableNames:'canCancel defaultAnswerInDialog'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Kernel-Exceptions-Notifications'
@@ -32,6 +32,33 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
+!
+
+documentation
+"
+    This confirmation query is used when a user confirmation is required
+    somewhere within a model's operation (i.e. in non-GUI code).
+    Instead of directly asking via Dialog confirm... messages,
+    this should be raised. 
+    Its default behavior is the same as the above dialog.
+    However, the query can be cought and answered by an exceoptn (a query-) handler,
+    to suppress these GUI interactions in situations, where they are not wanted.
+
+    This is a much better approach to the alternatives:
+        passing additional 'doConfirm' arguments down from the high level caller
+        keeping the doConfirm settings in a passed down flag object
+        keeping the flag in a global (very bad)
+        keeping it in a class var (almost as bad)
+
+    Notice: thats one of the nice consequences of proceedable exceptions.
+
+    [authors:]
+        Stefan Vogel
+        Claus Gittinger
+
+    [see also:]
+        Query Notification Exception    
+"
 ! !
 
 !UserConfirmation methodsFor:'accessing'!
@@ -59,6 +86,22 @@
 
 canCancel:something
     canCancel := something.
+!
+
+defaultAnswerInDialog
+    "used to pass information from the raiser to the GUI dialog.
+     Specifies, which answer of the three (yes/no/cancel) should be the return-key-default.
+     If not specified, the cancel-key will be the default"
+
+    ^ defaultAnswerInDialog
+!
+
+defaultAnswerInDialog:aBooleanOrNil
+    "used to pass information from the raiser to the GUI dialog.
+     Specifies, which answer of the three (yes/no/cancel) should be the return-key-default.
+     If not specified, the cancel-key will be the default"
+
+    defaultAnswerInDialog := aBooleanOrNil
 ! !
 
 !UserConfirmation methodsFor:'default actions'!
@@ -67,15 +110,15 @@
     "Default action for confirmations: open a info box with description.
      If no GUI present, assume that the user pressed 'yes'"
 
-    |text|
+    |text retVal retValText|
 
     text := self description.
 
     self hasDialog ifTrue:[
         self canCancel ifTrue:[
-            ^ Dialog confirmWithCancel:text
+            ^ Dialog confirmWithCancel:text default:defaultAnswerInDialog
         ] ifFalse:[
-            ^ Dialog confirm:text
+            ^ Dialog confirm:text default:defaultAnswerInDialog
         ].
     ].
 
@@ -83,14 +126,27 @@
      on systems without GUI, simply show
      the message on the Transcript and assume, that he would have typed 'yes'.
     "
-    self canCancel ifTrue:[    
-        Transcript show:'User confirmation requested (assuming cancel): '; showCR:text.
-        ^ nil
+    retVal := defaultAnswerInDialog notNil 
+                ifTrue:[ defaultAnswerInDialog ]
+                ifFalse:[ 
+                    self canCancel 
+                        ifTrue:[ nil ]
+                        ifFalse:[ true ].
+                ].
+
+    retVal isNil ifTrue:[    
+        retValText := 'cancel'.
     ] ifFalse:[
-        Transcript show:'User confirmation requested (assuming yes): '; showCR:text.
-        ^ true
+        retVal ifTrue:[    
+            retValText := 'yes'.
+        ] ifFalse:[
+            retValText := 'no'.
+        ].
     ].
-
+    Transcript 
+        show:('User confirmation requested (assuming %1): ' bindWith:retValText); 
+        showCR:text.
+    ^ retVal
 
     "
       UserConfirmation raiseRequestErrorString:'Please click yes or no!!'
@@ -100,5 +156,5 @@
 !UserConfirmation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UserConfirmation.st,v 1.3 2008-10-04 08:42:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UserConfirmation.st,v 1.4 2008-11-22 10:45:20 cg Exp $'
 ! !