fixed cursor-wrapping in multiple-editfield boxes; added acceptCheck-block
authorClaus Gittinger <cg@exept.de>
Wed, 10 Jan 1996 19:54:33 +0100
changeset 280 f7d45bfb6d13
parent 279 b9fa9180aca4
child 281 0f41c95fa722
fixed cursor-wrapping in multiple-editfield boxes; added acceptCheck-block which allows suppressing accept if entered values are invalid.
DialogBox.st
--- a/DialogBox.st	Wed Jan 10 15:48:41 1996 +0100
+++ b/DialogBox.st	Wed Jan 10 19:54:33 1996 +0100
@@ -10,11 +10,13 @@
  hereby transferred.
 "
 
+'From Smalltalk/X, Version:2.10.8 on 10-jan-1996 at 15:47:31'                   !
+
 ModalBox subclass:#DialogBox
 	instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
 		acceptReturnAsOK yPosition leftIndent rightIndent bindings
 		addedComponents inputFieldGroup acceptOnLeave acceptValue
-		tabableElements'
+		tabableElements hideOnAccept acceptCheck'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-DialogBoxes'
@@ -1100,6 +1102,21 @@
     abortAction := aBlock
 !
 
+acceptCheck:aBlock
+    "if nonNil, the acceptCheck-block is evaluated when the dialog is
+     accepted (ok-button or Return-key). If it returns true, the box is closed,
+     otherwise not."
+
+    acceptCheck := aBlock
+!
+
+acceptOnLeave:aBoolean
+    "define the behavior when the last input field is left via cursor keys.
+     The default is to accept & close the dialog"
+
+    acceptOnLeave := aBoolean.
+!
+
 acceptReturnAsOK:aBoolean
     "turn on/off interpretation of return-key as ok.
      Default is on"
@@ -1119,6 +1136,24 @@
     self okAction:aBlock
 !
 
+focusOnField:anInputField
+    inputFieldGroup makeActive:anInputField
+
+
+
+
+
+
+
+!
+
+hideOnAccept:aBoolean
+    "control if the dialog should close when accepted.
+     The default is true"
+
+    hideOnAccept := aBoolean
+!
+
 okAction:aBlock
     "define the action to be performed when ok is pressed"
 
@@ -1148,6 +1183,10 @@
     ^ bindings at:name ifAbsent:nil
 !
 
+inputFieldGroup
+    ^ inputFieldGroup
+!
+
 name:element as:name
     bindings isNil ifTrue:[
 	bindings := IdentityDictionary new.
@@ -1167,6 +1206,13 @@
      is used to force an accept, not to return some valueHolder ...)."
 
     ^ acceptValue
+!
+
+acceptChannel:aValueHolder
+    "set the valueHolder which is set to true when the box
+     is accepted"
+
+    acceptValue := aValueHolder
 ! !
 
 !DialogBox methodsFor:'construction-adding'!
@@ -1761,14 +1807,15 @@
 
     acceptReturnAsOK := true.
     acceptOnLeave := true.
+    hideOnAccept := true.
 
     buttonPanel := HorizontalPanelView in:self.
     buttonPanel 
-	origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
-	bottomInset:mm; 
-	topInset:(font height + mm * 2) negated;
-	borderWidth:0;
-	horizontalLayout:#spread.
+        origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
+        bottomInset:mm; 
+        topInset:(font height + mm * 2) negated;
+        borderWidth:0;
+        horizontalLayout:#spread.
 
     yPosition := ViewSpacing.
     leftIndent := rightIndent := ViewSpacing.
@@ -1953,9 +2000,10 @@
      when the last field is left by Return-key or NextField-key"
 
     acceptOnLeave ifTrue:[
-	acceptValue value:true. 
-	self okPressed
+        acceptValue value:true. 
+        self okPressed
     ].
+    inputFieldGroup activateFirst
 !
 
 okPressed
@@ -1963,14 +2011,23 @@
      - make myself invisible and if an action was specified do it"
 
     okButton notNil ifTrue:[okButton turnOffWithoutRedraw].
+
     self doAccept.
 
-    "/ actually, only hides if I have been opened modal
-    self hideAndEvaluate:okAction.
+    acceptCheck notNil ifTrue:[
+        acceptCheck value ifFalse:[^ self]
+    ].
+
+    hideOnAccept ifTrue:[
+        "/ actually, only hides if I have been opened modal
+        self hideAndEvaluate:okAction.
+    ] ifFalse:[
+        okAction value
+    ]
 ! !
 
 !DialogBox class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.33 1996-01-10 13:34:31 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.34 1996-01-10 18:54:33 cg Exp $'
 ! !