How can a Morph display a context menu on a mouse click?

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

How can a Morph display a context menu on a mouse click?

Juraj Kubelka
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


Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Stephan Eggermont-3
Juraj Kubelka <[hidden email]>
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



Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Juraj Kubelka
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 <[hidden email]> escribió:
>
> Juraj Kubelka <[hidden email]>
> 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
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Stephan Eggermont-3
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.


Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Juraj Kubelka


> El 03-02-2018, a las 07:26, stephan <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Stephan Eggermont-3
Juraj Kubelka <[hidden email]>
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



Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Juraj Kubelka
Hi Stephan,

> El 05-02-2018, a las 11:27, Stephan Eggermont <[hidden email]> escribió:
>
> Juraj Kubelka <[hidden email]>
> 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
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Stephan Eggermont-3
Juraj Kubelka <[hidden email]>
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




Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Sven Van Caekenberghe-2


> On 8 Feb 2018, at 08:16, Stephan Eggermont <[hidden email]> wrote:
>
> Juraj Kubelka <[hidden email]>
> 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.


Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Stephan Eggermont-3
In reply to this post by Stephan Eggermont-3
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


Reply | Threaded
Open this post in threaded view
|

Re: How can a Morph display a context menu on a mouse click?

Juraj Kubelka
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 <[hidden email]> 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
>
>