#FEATURE
class: KeyboardProcessor
class definition
added:
#cancelAction:
#returnAction:
changed: #processEvent:forModalView:
--- a/KeyboardProcessor.st Tue Dec 22 04:42:02 2015 +0000
+++ b/KeyboardProcessor.st Sun Jan 17 03:43:28 2016 +0100
@@ -11,10 +11,12 @@
"
"{ Package: 'stx:libview2' }"
+"{ NameSpace: Smalltalk }"
+
Object subclass:#KeyboardProcessor
instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar
autoAcceptListeners globalAccelerators componentWithInitialFocus
- altFunctionWasExecuted eventFilter'
+ altFunctionWasExecuted eventFilter returnAction cancelAction'
classVariableNames:''
poolDictionaries:''
category:'Interface-Framework'
@@ -169,6 +171,13 @@
globalAccelerators at:aKey put:aSelectorOrBlock
!
+cancelAction:aBlock
+ "this entry allows for another cancel action to be installed,
+ to overwrite the default action, which closes a dialog without accept"
+
+ cancelAction := aBlock.
+!
+
componentWithInitialFocus
^ componentWithInitialFocus
!
@@ -200,6 +209,13 @@
menuBar := something.
!
+returnAction:aBlock
+ "this entry allows for another return action to be installed,
+ to overwrite the default action, which closes a dialog with acccept"
+
+ returnAction := aBlock.
+!
+
returnIsOKInDialog:aBoolean
"set the returnIsOK flag.
If off, Return is NOT handled as accept (the builder defaults it to true,)"
@@ -281,30 +297,53 @@
].
topView isModal ifTrue:[
- (key == #Return and:[returnIsOKInDialog ? true]) ifTrue:[
- (wg notNil
- and:[(explicitFocusView := wg explicitFocusView) isNil
- or:[ false "explicitFocusView isKeyboardConsumer not"
- or:[ explicitFocusView isInputField ]]
- ]) ifTrue:[
- ((focusView := wg focusView) notNil and:[focusView isTextView]) ifTrue:[
- focusView isInputField ifFalse:[
- "/ modalBox with a TextView
+ (key == #Return) ifTrue:[
+ returnAction notNil ifTrue:[
+ returnAction value.
+ ^ true.
+ ].
+ (returnIsOKInDialog ? true) ifTrue:[
+ (wg notNil
+ and:[(explicitFocusView := wg explicitFocusView) isNil
+ or:[ false "explicitFocusView isKeyboardConsumer not"
+ or:[ explicitFocusView isInputField ]]
+ ]) ifTrue:[
+ ((focusView := wg focusView) notNil and:[focusView isTextView]) ifTrue:[
+ focusView isInputField ifFalse:[
+ "/ modalBox with a TextView
+ ^ false
+ ].
+ "/ this is a kludge for subcanvases input-fields, which
+ "/ are not affected by #requestGlobalAutoAccept below.
+ focusView isAcceptOnReturn ifTrue:[
+ focusView accept
+ ].
+ ].
+
+ self requestGlobalAutoAccept ifFalse:[^ true].
+
+ "/ only care for RETURN and ESC if the window is the
+ "/ apps topView (not if its a popup or dialog of it)
+ (app notNil and:[app window == topView]) ifTrue:[
+ app doAcceptByReturnKey.
+ ] ifFalse:[
+ "/ oldStyle modalBox - for now, let Box handle it itself
^ false
].
- "/ this is a kludge for subcanvases input-fields, which
- "/ are not affected by #requestGlobalAutoAccept below.
- focusView isAcceptOnReturn ifTrue:[
- focusView accept
- ].
+ ^ true
].
-
- self requestGlobalAutoAccept ifFalse:[^ true].
-
+ ].
+ ].
+ (key == #Escape) ifTrue:[
+ cancelAction notNil ifTrue:[
+ cancelAction value.
+ ^ true.
+ ].
+ (escapeIsCancelInDialog ? true) ifTrue:[
"/ only care for RETURN and ESC if the window is the
"/ apps topView (not if its a popup or dialog of it)
(app notNil and:[app window == topView]) ifTrue:[
- app doAcceptByReturnKey.
+ app doCancelByEscapeKey.
] ifFalse:[
"/ oldStyle modalBox - for now, let Box handle it itself
^ false
@@ -312,17 +351,6 @@
^ true
].
].
- (key == #Escape and:[escapeIsCancelInDialog ? true]) ifTrue:[
- "/ only care for RETURN and ESC if the window is the
- "/ apps topView (not if its a popup or dialog of it)
- (app notNil and:[app window == topView]) ifTrue:[
- app doCancelByEscapeKey.
- ] ifFalse:[
- "/ oldStyle modalBox - for now, let Box handle it itself
- ^ false
- ].
- ^ true
- ].
].
wg notNil ifTrue:[
@@ -395,10 +423,10 @@
!KeyboardProcessor class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.50 2013-08-30 22:54:36 cg Exp $'
+ ^ '$Header$'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.50 2013-08-30 22:54:36 cg Exp $'
+ ^ '$Header$'
! !