How to trap a spacebar keypress event in a list?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to trap a spacebar keypress event in a list?

Tim M
How do I trap a keypress event in a list presenter?

I thought it would be to register a when: #keyPressed: sendTo: self  in my
main shell but that doesn't seem to do the trick?

Also is there an easy way to figure out all of the events that are supported
by different presenters?

Thanks for any pointers,

Tim


Reply | Threaded
Open this post in threaded view
|

Re: How to trap a spacebar keypress event in a list?

Eric Taylor
Hello Tim,

>
Also is there an easy way to figure out all of the events that are
supported by different presenters?
>

When you say "supported," what exactly do you mean?  Are you referring
to the triggering of the event, or the processing of the event?  There
are various "event_" categories that can help you identify
event-oriented methods, on either side of the equation.  Alternatively,
you can send the #publishedEventsOfInstances message to a class and the
class will answer with a Set of its instances' events.  If subclasses
extend the list of supported events (and remember to supersend), they
will be included in the set as well.

NOTE: If you attempt to send #publishedEventsOfInstances to an instance,
you'll get a walkback.  This is a class-side method.

If you're interested in which Presenters _process_ which events, then
you can look in any of three places: a) at the class's #connect methods,
b) at all the methods that begin with #on, or c) by clicking on the
various "event" categories

Cheers,

Eric

> -----Original Message-----
> From: Tim M [mailto:[hidden email]]
> Posted At: Sunday, July 16, 2006 4:23 PM
> Posted To: comp.lang.smalltalk.dolphin
> Conversation: How to trap a spacebar keypress event in a list?
> Subject: How to trap a spacebar keypress event in a list?
>
> How do I trap a keypress event in a list presenter?
>
> I thought it would be to register a when: #keyPressed: sendTo: self
in my
> main shell but that doesn't seem to do the trick?
>
> Also is there an easy way to figure out all of the events that are
> supported
> by different presenters?
>
> Thanks for any pointers,
>
> Tim


Reply | Threaded
Open this post in threaded view
|

Re: How to trap a spacebar keypress event in a list?

Steve Alan Waring
In reply to this post by Tim M
Hi Tim,

> How do I trap a keypress event in a list presenter?
> I thought it would be to register a when: #keyPressed: sendTo: self  in my
> main shell but that doesn't seem to do the trick?

By trap, I assume you mean you don't want to do default windows
processing on the event?

My rule of thumb is if you want to stop default windows processing, you
need to implement your own custom presenter (or in extreme cases a
custom view). In your example that would be a subclass of ListPresenter
that implements #onKeyPressed:.

A parent presenter (like your shell), which registers for an event from
one of its sub presenters, can't stop default windows processing, or
more generally change the behavior of how the sub view handles the
event. The exceptions to this rule are the events that send around a
valueModel like #closeRequested:

However, the view's own presenter can change the behavior by
implementing #onKeyPressed: and, for example, not sending it on to its
view.

Implement the following method in ListPresenter and you should see it
picking up the space.

onKeyPressed: aKeyEvent
        Transcript
                display: aKeyEvent;
                cr.
        ^super onKeyPressed: aKeyEvent.

If you implement the following method, it stops the down arrow from
changing the selection.

onKeyPressed: aKeyEvent
        aKeyEvent code == VK_DOWN ifTrue: [^0].
        ^super onKeyPressed: aKeyEvent.

One last tip, (although not relevant in this case as I think the list
view does it for you) ... if you run into problems detecting key
presses, a common cause is that you need to implement
#onInputMaskRequired: in your presenter and return one of the DLGC_
flags.

Steve