Menu creation and invocation

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

Menu creation and invocation

Fernando olivero-2
I want to give the thanks to Alain, for the excellent work on
PragmaMenuBuilder!
Making menus is elegant and straightforward this way!

I post here how i'm using them:

MyMorph>>mouseDown: aMouseEvent
        aMouseEvent redButtonPressed ifTrue:[ self click: aMouseEvent ].
        aMouseEvent yellowButtonPressed ifTrue:[ self leftClick: aMouseEvent ].
       
MyMorph>>leftClick: aMouseEvent
        self menuBuilder menu popUpInWorld

MyMorph>>menuBuilder
        ^ (PragmaMenuBuilder pragmaKeyword: 'tileMenu' model: self)

And you can nicely decouple the menu invocation from the menu creation!

Thanks!

Fernando

Reply | Threaded
Open this post in threaded view
|

Re: Menu creation and invocation

Alain Plantec-3
he he he.
thanks Fernando.
and really really happy that you find it useful.

but is see maybe an issue here. It concerns the pragma keyword.
It is currently a global keyword.
Maybe one should also allow a way to specify where the pragma are to be
collected.
maybe something like:

MyMorph>>menuBuilder
        ^ (PragmaMenuBuilder localPragmaKeyword: 'tileMenu' model: self )

notice the #localPragmaKeyword:model selector instead of #pragmaKeyword:model.
it would constraint the builder to only search pragma locally.
does it make sense to you ?

Cheers
Alain




Le 17/02/2011 21:15, Fernando Olivero a écrit :

> I want to give the thanks to Alain, for the excellent work on
> PragmaMenuBuilder!
> Making menus is elegant and straightforward this way!
>
> I post here how i'm using them:
>
> MyMorph>>mouseDown: aMouseEvent
> aMouseEvent redButtonPressed ifTrue:[ self click: aMouseEvent ].
> aMouseEvent yellowButtonPressed ifTrue:[ self leftClick: aMouseEvent ].
>
> MyMorph>>leftClick: aMouseEvent
> self menuBuilder menu popUpInWorld
>
> MyMorph>>menuBuilder
> ^ (PragmaMenuBuilder pragmaKeyword: 'tileMenu' model: self)
>
> And you can nicely decouple the menu invocation from the menu creation!
>
> Thanks!
>
> Fernando
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Menu creation and invocation

Henrik Sperre Johansen
On Feb 17, 2011, at 9:51 47PM, Alain Plantec wrote:

> he he he.
> thanks Fernando.
> and really really happy that you find it useful.
>
> but is see maybe an issue here. It concerns the pragma keyword.
> It is currently a global keyword.
> Maybe one should also allow a way to specify where the pragma are to be collected.
> maybe something like:
>
> MyMorph>>menuBuilder
> ^ (PragmaMenuBuilder localPragmaKeyword: 'tileMenu' model: self )
>
> notice the #localPragmaKeyword:model selector instead of #pragmaKeyword:model.
> it would constraint the builder to only search pragma locally.
> does it make sense to you ?
>
> Cheers
> Alain

Yes, searching the class only would be a good idea, I'd almost consider making it the default and rename #pragmaKeyword: to #globalPragmaKeyword:.
It's faster, and in most cases it does what you need, also in the case where you want  extensibility (through extension methods, only risk is clashing names)

Cheers,
Henry
Reply | Threaded
Open this post in threaded view
|

Re: Menu creation and invocation

Fernando olivero-2
On Fri, Feb 18, 2011 at 10:40 AM, Henrik Johansen
<[hidden email]> wrote:

> On Feb 17, 2011, at 9:51 47PM, Alain Plantec wrote:
>
>> he he he.
>> thanks Fernando.
>> and really really happy that you find it useful.
>>
>> but is see maybe an issue here. It concerns the pragma keyword.
>> It is currently a global keyword.
>> Maybe one should also allow a way to specify where the pragma are to be collected.
>> maybe something like:
>>
>> MyMorph>>menuBuilder
>>       ^ (PragmaMenuBuilder localPragmaKeyword: 'tileMenu' model: self )
>>
>> notice the #localPragmaKeyword:model selector instead of #pragmaKeyword:model.
>> it would constraint the builder to only search pragma locally.
>> does it make sense to you ?
>>
>> Cheers
>> Alain
>
> Yes, searching the class only would be a good idea, I'd almost consider making it the default and rename #pragmaKeyword: to #globalPragmaKeyword:.
> It's faster, and in most cases it does what you need, also in the case where you want  extensibility (through extension methods, only risk is clashing names)
>
> Cheers,
> Henry
>

Hi, since i'm new to pragmas  could you please explain me the
diference between global and local searches.
I dont understand to whom the local and global context applies to,
when using #localPragmaKeyword:model: as oposed to
#pragmaKeyword:model:.

Fernando

Reply | Threaded
Open this post in threaded view
|

Re: Menu creation and invocation

Henrik Sperre Johansen

On Feb 18, 2011, at 11:31 48AM, Fernando Olivero wrote:

> On Fri, Feb 18, 2011 at 10:40 AM, Henrik Johansen
> <[hidden email]> wrote:
>> On Feb 17, 2011, at 9:51 47PM, Alain Plantec wrote:
>>
>>> he he he.
>>> thanks Fernando.
>>> and really really happy that you find it useful.
>>>
>>> but is see maybe an issue here. It concerns the pragma keyword.
>>> It is currently a global keyword.
>>> Maybe one should also allow a way to specify where the pragma are to be collected.
>>> maybe something like:
>>>
>>> MyMorph>>menuBuilder
>>>       ^ (PragmaMenuBuilder localPragmaKeyword: 'tileMenu' model: self )
>>>
>>> notice the #localPragmaKeyword:model selector instead of #pragmaKeyword:model.
>>> it would constraint the builder to only search pragma locally.
>>> does it make sense to you ?
>>>
>>> Cheers
>>> Alain
>>
>> Yes, searching the class only would be a good idea, I'd almost consider making it the default and rename #pragmaKeyword: to #globalPragmaKeyword:.
>> It's faster, and in most cases it does what you need, also in the case where you want  extensibility (through extension methods, only risk is clashing names)
>>
>> Cheers,
>> Henry
>>
>
> Hi, since i'm new to pragmas  could you please explain me the
> diference between global and local searches.
> I dont understand to whom the local and global context applies to,
> when using #localPragmaKeyword:model: as oposed to
> #pragmaKeyword:model:.
>
> Fernando
>

If I understood him correctly, essentially, you limit the scope of a menu symbol.

When using globalPragmaKeyword: (pragmaKeyword: today) it will search for  methods containing the pragma in the  entire system, which means you can have multiple classes defining menu entries in the same (global) menu.
When using pragmaKeyword: (or what Alain calls localPragmaKeyword: ), only the hierarchy of the class in in which the method defining the PragmaMenuBuilder would be searched.
Thus, you could have two different morph classes both defining <menu: #rightClickMenu> entries, and have their menu builders only pick up those defined for that class.

Cheers,
Henry
Reply | Threaded
Open this post in threaded view
|

Re: Menu creation and invocation

Alain Plantec-3
In reply to this post by Henrik Sperre Johansen
Le 18/02/2011 10:40, Henrik Johansen a écrit :
> Yes, searching the class only would be a good idea, I'd almost consider making it the default and rename #pragmaKeyword: to #globalPragmaKeyword:.
yes, I will do it.
> It's faster, and in most cases it does what you need, also in the case where you want  extensibility (through extension methods, only risk is clashing names)
>
> Cheers,
> Henry


Reply | Threaded
Open this post in threaded view
|

Re: Menu creation and invocation

Alain Plantec-3
In reply to this post by Henrik Sperre Johansen
exactly.
We have to specify where to search for the pragmas in order
to be able to use the same menu pragma keyword in different contexts.
I can't dig into it now but this is the idea.
Cheers
Alain

Le 18/02/2011 11:41, Henrik Johansen a écrit :
> If I understood him correctly, essentially, you limit the scope of a menu symbol.
>
> When using globalPragmaKeyword: (pragmaKeyword: today) it will search for  methods containing the pragma in the  entire system, which means you can have multiple classes defining menu entries in the same (global) menu.
> When using pragmaKeyword: (or what Alain calls localPragmaKeyword: ), only the hierarchy of the class in in which the method defining the PragmaMenuBuilder would be searched.
> Thus, you could have two different morph classes both defining<menu: #rightClickMenu>  entries, and have their menu builders only pick up those defined for that class.
>
> Cheers,
> Henry
>