<div dir="ltr"><div>Hello Ken<br></div><div><br></div><div>You're right, I didn't think about the wasHandled: method before and it's a better solution than the one I proposed (assuming the methods isFindClassShortcut and isCloseWindowShortcut and Franco's isFullScreenShortcut would be moved into handleKeyEvent and the processKey* ones would have their return removed).</div><div><br></div><div>It would look something like:</div><div><br></div><div>
vvv============vvv<br>
KeyBoardEvent>><br>
<br>
sentTo: aMorph localPosition: positionInAMorph<br>
<br>
"Dispatch the receiver into anObject"<span class="gmail-im"><br>
</span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">
type == #keystroke ifTrue: [<br>
aMorph <br></span></div><div><span class="gmail-im"> processKeystroke: self<br>
localPosition: positionInAMorph ].<br>
type == #keyDown ifTrue: [<br>
aMorph<br>
processKeyDown: self<br>
localPosition: positionInAMorph ].<br>
type == #keyUp ifTrue: [<br>
aMorph<br>
processKeyUp: self<br>
localPosition: positionInAMorph ].<br>
<br></span>
(self wasHandled)<br>
ifTrue: [^aMorph] "done"<br>
ifFalse: [<globaldefaultKeyHandler> handleKeyEvent: self]<br>
<br>
<br>
^^^============^^^
</div><div> "Inside globaldefaultKeyHandler, of course if someone thinks this object shouldn't exist you could just put it's content on the ifFalse closure. Also technically the ifFalse is unnecessary, but it does provide a lot of clarity."<br></div><div>handleKeyEvent: aKeyboardEvent<br></div><div>
<br>
aKeyboardEvent isFindClassShortcut<br>
ifTrue: [ ^ BrowserWindow findClass].<br>
aKeyboardEvent
isCloseWindowShortcut<br>
ifTrue: [ ^
aKeyboardEvent
closeCurrentWindowOf: aMorph <br></div><div>
aKeyboardEvent
isFullScreenShortcut<br>
ifTrue: [ ^ Display toggleFullScreen ]
</div><div>
<br>
^^^============^^^ <br></div><div><br></div><div>We would have to refactor the current senders of wasHandled: to take into account this change.</div><div><br></div><div>Thinking on the readability of this method and it might be a bit hard to follow the wasHandled method call for someone who is first discovering it, since they potentially might not understand how keyboardEvent knows the event was handled.<br></div><div><br></div><div>I do approve of the idea of having global keystrokes be in a separate object than the standard keyboardEvent, I think it would give clarity to the chain of responsibility if it goes into the morph and then into a global keystroke handler object.</div><div><br></div><div>Thinking about it from an usability standpoint using franco's full screen shorcut (alt + enter) we would have to (with both of the proposed implementations) make the isFullScreenShortcut check on the keyboardEvent inside the target morph to avoid processing the input at the morph level and marking it as handled.</div><div><br></div><div>What I mean with this is that all morphs would be responsible of knowing what inputs they should ignore because the keystrokes that we want to capture for system events would also be considered valid inside the morph and would be executed.</div><div><br></div><div>For example if you press shift enter while writing in a method editor the innerTextPane will happily process the input, put the newline into the pane and mark the event as handled, following that the keyboardEvent will say "ah, well that is done with then, moving on" and the findClass dialogue won't pop up, to avoid this you'd have to check whether the current keystroke is one of the system ones inside the morph's execution chain.</div><div><br></div><div>While I do like your implementation significantly more I think the one I recommended earlier gets around this issue. Since it becomes something optional, your morph can decide if it wants to override certain keystrokes or not but if you don't implement the method shouldOverride (Note: this is a bad name for this method) then you go back to the current behaviour.</div><div><br></div><div>Basically one option gives the morph the choice to tell you if it wants to override or not. The other one gives the morph the responsibility of telling you whether you should override or not.<br></div><div>
<div><br></div><div>And I still feel keyboardEvent should have a hierarchy of the 3 types of keyboard events rather than having a type instance variable.</div><div><br></div><div>I just want to clarify I quite enjoy writing walls of text and this is intended as constructive brainstorming. I'm sorry if it comes out as anything but. <br></div>
</div><div> </div><div><br></div><div>Cheers!</div><div><b>Mauro Rizzi</b><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El dom, 20 dic 2020 a las 20:54, <<a href="mailto:ken.dickey@whidbey.com">ken.dickey@whidbey.com</a>> escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2020-12-20 21:25, Mauro Rizzi wrote:<br>
<br>
..<br>
> shouldOverride := aMorph shouldOverride: self<br>
<br>
I am suggesting that if the Morph processes the keystroke, it _has_ <br>
overriden and _does NOT need_ a #shouldOverride method.<br>
<br>
So<br>
vvv============vvv<br>
KeyBoardEvent>><br>
<br>
sentTo: aMorph localPosition: positionInAMorph<br>
<br>
"Dispatch the receiver into anObject"<br>
<br>
type == #keystroke ifTrue: [<br>
self isFindClassShortcut<br>
ifTrue: [ ^ BrowserWindow findClass].<br>
self isCloseWindowShortcut<br>
ifTrue: [ ^ self closeCurrentWindowOf: aMorph ].<br>
^ aMorph processKeystroke: self<br>
localPosition: positionInAMorph ].<br>
type == #keyDown ifTrue: [<br>
^ aMorph<br>
processKeyDown: self<br>
localPosition: positionInAMorph ].<br>
type == #keyUp ifTrue: [<br>
^ aMorph<br>
processKeyUp: self<br>
localPosition: positionInAMorph ].<br>
<br>
(self wasHandled)<br>
ifTrue: [^aMorph] "done"<br>
ifFalse: [<globaldefaultKeyHandler> handleKeyEvent: self]<br>
<br>
<br>
^^^============^^^<br>
<br>
Note: I am not an expert here. Just a guess..<br>
<br>
Prototype is best.<br>
-KenD<br>
</blockquote></div>