'From Cuis 1.0 of 4 September 2009 [latest update: #290] on 18 September 2009 at 12:28:19 pm'!

!EventManager commentStamp: '<historical>' prior: 0!
Part of update 5005u16-Events.cs:

"Change Set:		Events
Date:			11 February 2002
Author:			Rob Withers et al.

Published to 3.3a as 4756Events.cs

The NuBlue events code. Finally..."

The new event model, originally from VisualSmalltalk.
This includes #when:send:to: and friends, in Object (generic implementation) and EventManager (optimized implementation).
It renders the old change/update mechanism in Object and Model as obsolete, although still used.
Includes code from John Sarkela (reThink), Andres Valloud (SqR) and Stefan Matthias Aust (sma).
7/24/2008 jmv

The old Model class should be deleted, but do not contaminate this class with its ugly protocol!!!


!Object methodsFor: 'events-accessing' stamp: 'jmv 9/17/2009 23:48'!
actionForEvent: anEventSelector
    "Answer the action to be evaluated when <anEventSelector> has been triggered."

	^self actionMap ifNotNil: [ :map |
		map
			at: anEventSelector asSymbol
			ifAbsent: []]! !

!Object methodsFor: 'events-accessing' stamp: 'jmv 9/18/2009 12:25'!
actionSequenceForEvent: anEventSelector

	^self actionMap
		ifNotNil: [ :map |
			(map
				at: anEventSelector asSymbol
				ifAbsent: [ WeakActionSequence new ])
					asActionSequence ]
		ifNil: [ WeakActionSequence new ]! !

!Object methodsFor: 'events-accessing' stamp: 'jmv 9/18/2009 00:00'!
actionsDo: aBlock

	self actionMap ifNotNil: [ :map |
		map do: aBlock ]! !

!Object methodsFor: 'events-removing' stamp: 'jmv 9/18/2009 00:01'!
removeActionsForEvent: anEventSelector

	| map |
	map _ self actionMap.
	map ifNotNil: [
		map removeKey: anEventSelector asSymbol ifAbsent: [].
		map isEmpty
			ifTrue: [ self releaseActionMap ]]! !

!Object methodsFor: 'events-removing' stamp: 'jmv 9/18/2009 00:02'!
removeActionsSatisfying: aBlock

	self actionMap ifNotNil: [ :map |
		map keys do: [ :eachEventSelector |
			self
   				removeActionsSatisfying: aBlock
				forEvent: eachEventSelector ]]! !

!Object methodsFor: 'events-removing' stamp: 'jmv 9/18/2009 00:07'!
removeActionsWithReceiver: anObject

	self actionMap ifNotNil: [ :map |
		map keys do: [ :eachEventSelector |
			self
   				removeActionsSatisfying: [:anAction | anAction receiver == anObject]
				forEvent: eachEventSelector ]]! !


!Debugger methodsFor: 'notifier menu' stamp: 'jmv 9/18/2009 00:28'!
debug
	"Open a full DebuggerView."
	| topView |
	topView _ self topView.
	topView model: nil.  "so close won't release me."
	self breakDependents.
	topView delete.
	^ self openFullMorphicLabel: topView label! !


!Encoder methodsFor: 'error handling' stamp: 'jmv 9/18/2009 00:17'!
notify: string
	"Put a separate notifier on top of the requestor's window"
	| req |
	requestor ifNotNil: [
		req _ requestor.
		requestor _ nil.
		req notify: string ].
	^false! !

!Encoder methodsFor: 'error handling' stamp: 'jmv 9/18/2009 00:17'!
notify: string at: location

	| req |
	requestor ifNotNil: [
		req _ requestor.
		requestor _ nil.
		req notify: string at: location].
	^false! !


!EventManager methodsFor: 'copying' stamp: 'jmv 9/18/2009 00:18'!
copy

	| answer |
	answer := super copy.
	answer releaseActionMap.
	^answer! !

!EventManager methodsFor: 'accessing' stamp: 'jmv 9/18/2009 00:10'!
actionMap

    ^actionMap! !

!EventManager methodsFor: 'accessing' stamp: 'jmv 9/18/2009 00:12'!
updateableActionMap

	actionMap ifNil: [
		actionMap _ IdentityDictionary new ].
	^actionMap! !


!EventManager class methodsFor: 'accessing' stamp: 'jmv 9/18/2009 00:11'!
actionMapFor: anObject

    ^self actionMaps
        at: anObject
        ifAbsent: []! !

!EventManager class methodsFor: 'accessing' stamp: 'jmv 9/18/2009 00:14'!
actionMaps

	ActionMaps ifNil: [
		ActionMaps _ WeakIdentityKeyDictionary new ].
	^ActionMaps! !

!EventManager class methodsFor: 'accessing' stamp: 'jmv 9/18/2009 00:13'!
updateableActionMapFor: anObject

	^self actionMaps
		at: anObject
		ifAbsentPut: [ IdentityDictionary new ]! !


!Inspector methodsFor: 'menu commands' stamp: 'jmv 9/17/2009 23:36'!
inspectorKey: aChar from: view
	"Respond to a Command key issued while the cursor is over my field list"

	aChar == $i ifTrue: [^ self selection inspect].
	aChar == $I ifTrue: [^ self selection explore].
	aChar == $b ifTrue:[^ self browseMethodFull].
	aChar == $h ifTrue:[^ self classHierarchy].
	aChar == $c ifTrue: [^ self copyName].
	aChar == $p ifTrue: [^ self browseFullProtocol].
	aChar == $N ifTrue: [^ self browseClassRefs].

	^ self arrowKey: aChar from: view! !


!Morph methodsFor: 'events-accessing' stamp: 'jmv 9/18/2009 00:11'!
actionMap
	"Answer an action map"
	"Do NOT duplicate this in Morphic3 / LightWidgets
	Views should not trigger events!!"

	^self valueOfProperty: #actionMap! !

!Morph methodsFor: 'events-accessing' stamp: 'jmv 9/18/2009 00:12'!
updateableActionMap
	"Answer an updateable action map, saving it in my #actionMap property"
	"Do NOT duplicate this in Morphic3 / LightWidgets
	Views should not trigger events!!"
	
	| actionMap |
	actionMap _ self valueOfProperty: #actionMap.
	actionMap ifNil: [
		actionMap _ IdentityDictionary new.
		self setProperty: #actionMap toValue: actionMap].
	^ actionMap! !


!SystemEventManager methodsFor: 'events-accessing' stamp: 'jmv 9/18/2009 12:25'!
actionSequenceForEvent: anEventSelector

	^self actionMap
		ifNotNil: [ :map |
			(map
				at: anEventSelector asSymbol
				ifAbsent: [ WeakActionSequenceTrappingErrors new ])
					asActionSequenceTrappingErrors ]
		ifNil: [ WeakActionSequenceTrappingErrors new ]! !


!SystemWindow methodsFor: 'open/close' stamp: 'jmv 9/18/2009 00:24'!
delete
	| thisWorld |
	model okToChange ifFalse: [^self].
	thisWorld _ self world.
	super delete.
	model windowIsClosing.
	model _ nil.
	SystemWindow noteTopWindowIn: thisWorld! !


!WeakMessageSend methodsFor: 'converting' stamp: 'jmv 9/18/2009 12:27'!
asActionSequence

	^WeakActionSequence with: self! !

!WeakMessageSend methodsFor: 'converting' stamp: 'jmv 9/18/2009 12:28'!
asActionSequenceTrappingErrors

	^WeakActionSequenceTrappingErrors with: self! !

UndefinedObject removeSelector: #release!
TranscriptStream removeSelector: #release!
ObjectExplorer removeSelector: #release!
FileList removeSelector: #release!
DualChangeSorter removeSelector: #release!
DisplayScreen removeSelector: #release!
Debugger removeSelector: #release!
ContextPart removeSelector: #release!
Object removeSelector: #actionForEvent:ifAbsent:!
Object removeSelector: #asActionSequence!
Object removeSelector: #asActionSequenceTrappingErrors!
Object removeSelector: #createActionMap!
Object removeSelector: #release!
Object removeSelector: #triggerEvent:ifNotHandled:!
Object removeSelector: #triggerEvent:with:ifNotHandled:!
Object removeSelector: #triggerEvent:withArguments:ifNotHandled:!
Smalltalk removeClassNamed: #ActiveModel!
