[Pharo-project] shortcuts in PluggableTextMorph
Hi, I need a bit of help in trying to add some kind of shortcuts to PluggableTextMorph. The following code used to work for shortcuts like "CMD+o": (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel; GLMTextModel>>keystroke: anEvent from: aMorph anEvent anyModifierKeyPressed ifTrue: [ "check the do the shortcut work" ] However, in the recent Pharo 1.3, if I press "CMD+o", first the "o" is added to the text as a regular character, and then keystroke:from: is executed. Is there a way of capturing the event before it gets interpreted by the Morph? Or is there another solution? Cheers, Doru -- www.tudorgirba.com "Every now and then stop and ask yourself if the war you're fighting is the right one."
In OB we use aPluggableTextMorph textMorph on: #keyStroke send: #keyStroke: to: self. Lukas On 13 July 2011 10:34, Tudor Girba <tudor@tudorgirba.com> wrote:
Hi,
I need a bit of help in trying to add some kind of shortcuts to PluggableTextMorph. The following code used to work for shortcuts like "CMD+o":
 (PluggableTextMorph         on: textModel         ...)         onKeyStrokeSend: #keystroke:from: to: textModel; GLMTextModel>>keystroke: anEvent from: aMorph     anEvent anyModifierKeyPressed ifTrue: [ "check the do the shortcut work" ]
However, in the recent Pharo 1.3, if I press "CMD+o", first the "o" is added to the text as a regular character, and then keystroke:from: is executed.
Is there a way of capturing the event before it gets interpreted by the Morph? Or is there another solution?
Cheers, Doru
-- www.tudorgirba.com
"Every now and then stop and ask yourself if the war you're fighting is the right one."
-- Lukas Renggli www.lukas-renggli.ch
Note that your handler method must return either true or false, depending if it handled the event or not. Lukas On 13 July 2011 10:43, Lukas Renggli <renggli@gmail.com> wrote:
In OB we use
 aPluggableTextMorph textMorph    on: #keyStroke send: #keyStroke: to: self.
Lukas
On 13 July 2011 10:34, Tudor Girba <tudor@tudorgirba.com> wrote:
Hi,
I need a bit of help in trying to add some kind of shortcuts to PluggableTextMorph. The following code used to work for shortcuts like "CMD+o":
 (PluggableTextMorph         on: textModel         ...)         onKeyStrokeSend: #keystroke:from: to: textModel; GLMTextModel>>keystroke: anEvent from: aMorph     anEvent anyModifierKeyPressed ifTrue: [ "check the do the shortcut work" ]
However, in the recent Pharo 1.3, if I press "CMD+o", first the "o" is added to the text as a regular character, and then keystroke:from: is executed.
Is there a way of capturing the event before it gets interpreted by the Morph? Or is there another solution?
Cheers, Doru
-- www.tudorgirba.com
"Every now and then stop and ask yourself if the war you're fighting is the right one."
-- Lukas Renggli www.lukas-renggli.ch
-- Lukas Renggli www.lukas-renggli.ch
Hi, This is what I am doing right now and it does not work: (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel ... GLMTextModel>>keystroke: anEvent from: aMorph anEvent anyModifierKeyPressed ifTrue: [ "check the do the shortcut work" ] When it gets to GLMTextModel>>keystroke:from:, the text model is already modified. Cheers, Doru On 13 Jul 2011, at 10:45, Lukas Renggli wrote:
Note that your handler method must return either true or false, depending if it handled the event or not.
Lukas
On 13 July 2011 10:43, Lukas Renggli <renggli@gmail.com> wrote:
In OB we use
aPluggableTextMorph textMorph on: #keyStroke send: #keyStroke: to: self.
Lukas
On 13 July 2011 10:34, Tudor Girba <tudor@tudorgirba.com> wrote:
Hi,
I need a bit of help in trying to add some kind of shortcuts to PluggableTextMorph. The following code used to work for shortcuts like "CMD+o":
(PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel GLMTextModel>>keystroke: anEvent from: aMorph anEvent anyModifierKeyPressed ifTrue: [ "check the do the shortcut work" ]
However, in the recent Pharo 1.3, if I press "CMD+o", first the "o" is added to the text as a regular character, and then keystroke:from: is executed.
Is there a way of capturing the event before it gets interpreted by the Morph? Or is there another solution?
Cheers, Doru
-- www.tudorgirba.com
"Every now and then stop and ask yourself if the war you're fighting is the right one."
-- Lukas Renggli www.lukas-renggli.ch
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com "Relationships are of two kinds: those we choose and those that happen. They both matter."
This is what I am doing right now and it does not work:  (PluggableTextMorph on: textModel ...)        onKeyStrokeSend: #keystroke:from: to: textModel         ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper. Lukas -- Lukas Renggli www.lukas-renggli.ch
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work: (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose: PluggableTextMorph>>onKeyStrokeSend: sel to: recipient textMorph on: #keyStroke send: sel to: recipient. But this still does not seem to work. Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com "Speaking louder won't make the point worthier."
And you return true, if you handled the request? On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work:  (PluggableTextMorph on: textModel ...)        onKeyStrokeSend: #keystroke:from: to: textModel         ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient     textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
Yes. But as I said, the value of "self text" is already modified when it gets to the #keystroke:from: GLMTextModel>>keystroke: anEvent from: aMorph self text inspect. ^ true So, I am stuck again :(. Doru On 13 Jul 2011, at 11:22, Lukas Renggli wrote:
And you return true, if you handled the request?
On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work: (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com "Be rather willing to give than demanding to get."
What about using the keyDown event then? Lukas On 13 July 2011 13:05, Tudor Girba <tudor@tudorgirba.com> wrote:
Yes. But as I said, the value of "self text" is already modified when it gets to the #keystroke:from:
GLMTextModel>>keystroke: anEvent from: aMorph     self text inspect.     ^ true
So, I am stuck again :(.
Doru
On 13 Jul 2011, at 11:22, Lukas Renggli wrote:
And you return true, if you handled the request?
On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work:  (PluggableTextMorph on: textModel ...)        onKeyStrokeSend: #keystroke:from: to: textModel         ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient     textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Be rather willing to give than demanding to get."
-- Lukas Renggli www.lukas-renggli.ch
Maybe you could intercept the event in the editorView ... I dunno :) Ben On Jul 13, 2011, at 1:07 PM, Lukas Renggli wrote:
What about using the keyDown event then?
Lukas
On 13 July 2011 13:05, Tudor Girba <tudor@tudorgirba.com> wrote:
Yes. But as I said, the value of "self text" is already modified when it gets to the #keystroke:from:
GLMTextModel>>keystroke: anEvent from: aMorph self text inspect. ^ true
So, I am stuck again :(.
Doru
On 13 Jul 2011, at 11:22, Lukas Renggli wrote:
And you return true, if you handled the request?
On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work: (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Be rather willing to give than demanding to get."
-- Lukas Renggli www.lukas-renggli.ch
Hi, Ok, I found a solution (inspired by OB): - GLMPluggableTextMorph subclasses PluggableTextMorph - GLMTextMorphForEditView subclasses TextMorphForEditView - GLMPluggableTextMorph>>textMorphClass ^ GLMTextMorphForEditView - GLMTextMorphForEditView>>keyStroke: anEvent | isHandledByModel | isHandledByModel := self editView model keystroke: anEvent from: self editView. isHandledByModel ifFalse: [ super keyStroke: anEvent ] This is messy, to put it mildly :). Are there other options? Cheers, Doru On 13 Jul 2011, at 13:07, Lukas Renggli wrote:
What about using the keyDown event then?
Lukas
On 13 July 2011 13:05, Tudor Girba <tudor@tudorgirba.com> wrote:
Yes. But as I said, the value of "self text" is already modified when it gets to the #keystroke:from:
GLMTextModel>>keystroke: anEvent from: aMorph self text inspect. ^ true
So, I am stuck again :(.
Doru
On 13 Jul 2011, at 11:22, Lukas Renggli wrote:
And you return true, if you handled the request?
On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work: (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Be rather willing to give than demanding to get."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com "Not knowing how to do something is not an argument for how it cannot be done."
Probably not :-) Whenever you want to change something in the default behavior of PluggableList/Editor you need to subclass many classes. Lukas On Thursday, 14 July 2011, Tudor Girba <tudor@tudorgirba.com> wrote:
Hi,
Ok, I found a solution (inspired by OB):
- GLMPluggableTextMorph subclasses PluggableTextMorph - GLMTextMorphForEditView subclasses TextMorphForEditView - GLMPluggableTextMorph>>textMorphClass     ^ GLMTextMorphForEditView - GLMTextMorphForEditView>>keyStroke: anEvent     | isHandledByModel |     isHandledByModel := self editView model keystroke: anEvent from: self editView.     isHandledByModel ifFalse: [ super keyStroke: anEvent ]
This is messy, to put it mildly :). Are there other options?
Cheers, Doru
On 13 Jul 2011, at 13:07, Lukas Renggli wrote:
What about using the keyDown event then?
Lukas
On 13 July 2011 13:05, Tudor Girba <tudor@tudorgirba.com> wrote:
Yes. But as I said, the value of "self text" is already modified when it gets to the #keystroke:from:
GLMTextModel>>keystroke: anEvent from: aMorph     self text inspect.     ^ true
So, I am stuck again :(.
Doru
On 13 Jul 2011, at 11:22, Lukas Renggli wrote:
And you return true, if you handled the request?
On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work:  (PluggableTextMorph on: textModel ...)        onKeyStrokeSend: #keystroke:from: to: textModel         ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient     textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Be rather willing to give than demanding to get."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Not knowing how to do something is not an argument for how it cannot be done."
-- Lukas Renggli www.lukas-renggli.ch
We should really change that. Benjamin this would a good case for the Summertalk Stef On Jul 14, 2011, at 11:33 AM, Lukas Renggli wrote:
Probably not :-)
Whenever you want to change something in the default behavior of PluggableList/Editor you need to subclass many classes.
Lukas
On Thursday, 14 July 2011, Tudor Girba <tudor@tudorgirba.com> wrote:
Hi,
Ok, I found a solution (inspired by OB):
- GLMPluggableTextMorph subclasses PluggableTextMorph - GLMTextMorphForEditView subclasses TextMorphForEditView - GLMPluggableTextMorph>>textMorphClass ^ GLMTextMorphForEditView - GLMTextMorphForEditView>>keyStroke: anEvent | isHandledByModel | isHandledByModel := self editView model keystroke: anEvent from: self editView. isHandledByModel ifFalse: [ super keyStroke: anEvent ]
This is messy, to put it mildly :). Are there other options?
Cheers, Doru
On 13 Jul 2011, at 13:07, Lukas Renggli wrote:
What about using the keyDown event then?
Lukas
On 13 July 2011 13:05, Tudor Girba <tudor@tudorgirba.com> wrote:
Yes. But as I said, the value of "self text" is already modified when it gets to the #keystroke:from:
GLMTextModel>>keystroke: anEvent from: aMorph self text inspect. ^ true
So, I am stuck again :(.
Doru
On 13 Jul 2011, at 11:22, Lukas Renggli wrote:
And you return true, if you handled the request?
On 13 July 2011 11:18, Tudor Girba <tudor@tudorgirba.com> wrote:
On 13 Jul 2011, at 11:08, Lukas Renggli wrote:
This is what I am doing right now and it does not work: (PluggableTextMorph on: textModel ...) onKeyStrokeSend: #keystroke:from: to: textModel ...
You have to attach your handler on the text morph itself, not on the pluggable morph which is just a wrapper.
This is just a helper method in PluggableTextMorph that does what you propose:
PluggableTextMorph>>onKeyStrokeSend: sel to: recipient textMorph on: #keyStroke send: sel to: recipient.
But this still does not seem to work.
Cheers, Doru
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Speaking louder won't make the point worthier."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Be rather willing to give than demanding to get."
-- Lukas Renggli www.lukas-renggli.ch
-- www.tudorgirba.com
"Not knowing how to do something is not an argument for how it cannot be done."
-- Lukas Renggli www.lukas-renggli.ch
participants (4)
-
Benjamin -
Lukas Renggli -
Stéphane Ducasse -
Tudor Girba