--- a/KeyboardProcessor.st Tue Mar 09 19:10:06 1999 +0100
+++ b/KeyboardProcessor.st Wed Mar 10 01:00:08 1999 +0100
@@ -15,7 +15,8 @@
Object subclass:#KeyboardProcessor
- instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar'
+ instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar
+ autoAcceptListeners'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support-UI'
@@ -91,6 +92,9 @@
!KeyboardProcessor methodsFor:'accessing'!
escapeIsCancelInDialog:aBoolean
+ "set the escapeIsCancel flag.
+ If off, Escape is NOT handled as cancel (however, the default is true)"
+
escapeIsCancelInDialog := aBoolean
!
@@ -105,6 +109,9 @@
menuBar := something.!
returnIsOKInDialog:aBoolean
+ "set the returnIsOK flag.
+ If off, Return is NOT handled as accept (however, the default is true)"
+
returnIsOKInDialog := aBoolean
! !
@@ -112,6 +119,10 @@
!KeyboardProcessor methodsFor:'event handling'!
processEvent:event
+ "process a key-event; return true, if handled & eaten; false if not.
+ Here, Return and Escape are intercepted and lead to Accept & Cancel resp.
+ Also, in the future, menu-shortcuts will be handled here (does not work yet)"
+
|key topView app view|
view := event view.
@@ -124,21 +135,21 @@
topView isModal ifTrue:[
(returnIsOKInDialog and:[key == #Return]) ifTrue:[
app doAccept.
- ^ self
+ ^ true
].
(escapeIsCancelInDialog and:[key == #Escape]) ifTrue:[
app doCancel.
- ^ self
+ ^ true
].
].
"/ how about menu-shortkeys ?
(menuBar notNil and:[(menuBar processShortcutKeyEventInMenuBar:event)]) ifTrue:[
- ^ self
+ ^ true
]
].
- view dispatchEvent:event
+ ^ false
"/ let view dispatch it.
@@ -147,25 +158,41 @@
!
requestForWindowClose
- "about to close the window.
- If autoAccept is true, check for this, and only return true if all
- fields agree."
+ "about to close the window."
- ^ self requestGlobalAutoAccept
-
+ ^ true
!
requestGlobalAutoAccept
- "about to close the window.
- If autoAccept is true, check for this, and only return true if all
- fields agree."
+ "about to close the window via return ok accept.
+ Ask all acceptListeners to accept their value and return true, if all of those fields
+ did."
+ autoAcceptListeners notNil ifTrue:[
+ autoAcceptListeners do:[:aListener |
+ (aListener requestAutoAccept) ifFalse:[^ false]
+ ]
+ ].
^ true
! !
+!KeyboardProcessor methodsFor:'setup'!
+
+addAutoAcceptListener:aListener
+ "add a aListener to my autoAcceptListeners.
+ Typically, inputFields add themself, to be notified (via requestForAutoAccept)
+ when the dialog is about to be closed with returnIsOK or accept.
+ (of course, other listeners are also invited ;-)"
+
+ autoAcceptListeners isNil ifTrue:[
+ autoAcceptListeners := IdentitySet new.
+ ].
+ autoAcceptListeners add:aListener
+! !
+
!KeyboardProcessor class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.1 1999-03-09 16:40:36 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.2 1999-03-10 00:00:08 cg Exp $'
! !