How can a Morph display a context menu on a mouse click?
Hi, Letâs say that we have a StringMorph: âHello' asMorph. Can I attach a MenuMorph (or a menu building logic) and display the context menu on a mouse click in the StringMorph? Or the only way to do it is to subclass the StringMorph and write the logic in the #mouseDown: method? Thanks! Juraj
Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
Letâs say that we have a StringMorph: âHello' asMorph. Can I attach a MenuMorph (or a menu building logic) and display the context menu on a mouse click in the StringMorph?
Or the only way to do it is to subclass the StringMorph and write the logic in the #mouseDown: method?
#when:send:to:, or replace the eventhandler, or subclass Stephan
Thank you Stephan! There is my exercise: âwhen:send:to" morph := 'Hello' asMorph. morph when: #click send: #traceCr: to: morph. morph openInWindow. â> it does not work for me. I do not know what the announcement should be "Handler" morph := 'Hello' asMorph. morph eventHandler: MorphicEventHandler new. morph eventHandler on: #click send: #traceCr: to: morph. morph openInWindow. â> It works and there are examples in MorphicEventHandlerTest Thanks!
El 02-02-2018, a las 03:43, Stephan Eggermont <stephan@stack.nl> escribió:
Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
Letâs say that we have a StringMorph: âHello' asMorph. Can I attach a MenuMorph (or a menu building logic) and display the context menu on a mouse click in the StringMorph?
Or the only way to do it is to subclass the StringMorph and write the logic in the #mouseDown: method?
#when:send:to:, or replace the eventhandler, or subclass
Stephan
On 02-02-18 15:19, Juraj Kubelka wrote:
Thank you Stephan!
There is my exercise:
âwhen:send:to" morph := 'Hello' asMorph. morph when: #click send: #traceCr: to: morph. morph openInWindow.
Sorry morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow.
El 03-02-2018, a las 07:26, stephan <stephan@stack.nl> escribió:
On 02-02-18 15:19, Juraj Kubelka wrote:
Thank you Stephan! There is my exercise: âwhen:send:to" morph := 'Hello' asMorph. morph when: #click send: #traceCr: to: morph. morph openInWindow.
Sorry
morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow.
This does not work for me either. I am fine with the MorphicEventHandler solution. Thanks! Juraj
Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow.
This does not work for me either. I am fine with the MorphicEventHandler solution.
Not at all? Or do you just need to use the variant sending #value: to a block with the morph as an argument? Stephan
Hi Stephan,
El 05-02-2018, a las 11:27, Stephan Eggermont <stephan@stack.nl> escribió:
Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow.
This does not work for me either. I am fine with the MorphicEventHandler solution.
Not at all? Or do you just need to use the variant sending #value: to a block with the morph as an argument?
I am not sure if we understand each other. The example: morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow does not work for me. Actually I have not found a code that triggers #mouseUp event neither. The example: morph := 'Hello' asMorph. morph eventHandler: MorphicEventHandler new. morph eventHandler on: #click send: #traceCr: to: morph. morph openInWindow. works well and this is what I use. All tested on Pharo 6.1. Cheers, Juraj
Stephan
Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
I am not sure if we understand each other. The example:
morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow
does not work for me. Actually I have not found a code that triggers #mouseUp event neither.
Well, it works for me on 60528 on Windows. Did you open the transcript window before running the example? Stephan
On 8 Feb 2018, at 08:16, Stephan Eggermont <stephan@stack.nl> wrote:
Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
I am not sure if we understand each other. The example:
morph := 'Hello' asMorph. morph on: #mouseUp send: #traceCr: to: morph. morph openInWindow
does not work for me. Actually I have not found a code that triggers #mouseUp event neither.
Well, it works for me on 60528 on Windows. Did you open the transcript window before running the example?
Stephan
Works fine for me in Pharo 7. You do click, do you ? Her is a variation: morph := 'Click me' asMorph. morph on: #mouseUp send: #value to: [ self inform: 'You clicked me!' ]. morph openInWindow.
And your original question morph := 'Hello' asMorph. colorBlock := [ :colorName | morph color: (Color perform: colorName)]. morph on: #mouseUp send: value to: [ |menu| menu := MenuMorph new. menu add: 'orange' target: colorBlock selector: #value: argument: #orange. menu add: 'blue' target: colorBlock selector: #value: argument: #blue. menu popUpInWorld]. morph openInWindow
Thanks to all answers! It finally works. :-) I am not sure where I did a mistake before. Juraj
On Feb 8, 2018, at 05:33, Stephan Eggermont <stephan@stack.nl> wrote:
And your original question
morph := 'Hello' asMorph. colorBlock := [ :colorName | morph color: (Color perform: colorName)]. morph on: #mouseUp send: value to: [ |menu| menu := MenuMorph new. menu add: 'orange' target: colorBlock selector: #value: argument: #orange. menu add: 'blue' target: colorBlock selector: #value: argument: #blue. menu popUpInWorld]. morph openInWindow
participants (4)
-
Juraj Kubelka -
stephan -
Stephan Eggermont -
Sven Van Caekenberghe