Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Sep 20, 2020 3:18 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Automatic Contextual Menu Handling
PostPosted: Tue Mar 29, 2011 1:01 pm 
Offline

Joined: Mon Jul 17, 2006 10:39 am
Posts: 1718
I just stumbled upon a handy tip for all of you who want to add contextual menus to your controls. If your contextual menu has the same function as an already existing menu item, use the menu item object directly! This saves you from dynamically creating a new menu item with the same properties, and from writing additional code to handle its action.

For example, let's say you have a menu item "Foo" in your File menu, and you have already created the appropriate menu handler to make it work. To set up a contextual menu with this item in a control, all you need to do is implement its ConstructContextualMenu event so that the "Foo" MenuItem (which you have probably named FileFoo by default) is added, like so:

Event Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
base.Append(FileFoo)
Return True
End Function


Note that there is no additional code necessary to handle the menu item. The appropriate menu handler is called automatically when the item is selected.

This tip applies to menus displayed though PopUp() as well, in case ConstructContextualMenu does not fit your needs.

_________________
Kenneth McCleary
ken@mccleary.me


Top
 Profile  
Reply with quote  
 Post subject: Re: Automatic Contextual Menu Handling
PostPosted: Tue Mar 29, 2011 1:08 pm 
Offline

Joined: Fri Jan 23, 2009 9:18 am
Posts: 104
Location: Summerfield, Florida
But beware:

http://www.realsoftwareblog.com/2011/03 ... lones.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Automatic Contextual Menu Handling
PostPosted: Tue Mar 29, 2011 1:22 pm 
Offline

Joined: Mon Jul 17, 2006 10:39 am
Posts: 1718
Yes, as RS rolls out the new changes, you will need to Clone() the menu item before adding it, à la:

base.Append(FileFoo.Clone())


A minor change, to be sure.

_________________
Kenneth McCleary
ken@mccleary.me


Top
 Profile  
Reply with quote  
 Post subject: Re: Automatic Contextual Menu Handling
PostPosted: Fri Apr 22, 2011 6:28 pm 
Offline

Joined: Mon Jul 31, 2006 1:44 am
Posts: 1300
Note that on Macintosh the Contextual Menu Items should not have any menu short-cuts. They need to be removed and then added again ....

_________________
REAL Studio 2011 r3 OS X 10.8 Mountain Lion
SEEdit THE HTML5 EDITOR FOR MACINTOSH


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group