Contextual (popup) menus and their options

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sun Aug 24 18:05:58 EDT 2008


Bonjour Mark,

An Edit menu, if you want to stay compliant with all platforms  
guidelines, should always show the 'Cut, Copy, Paste' trilogy as a  
minimum.
Of course, you can disable the menu items you don't want the user to  
use but they *must* be there with their usual shortcuts :-)
So in your case, just build the menu on-the-fly at mouseDown and  
disable the Copy item according to the value of the selectedChunk:
It's always something like char 4 to 3 of field 1 (insertion point is  
placed after char 3 but there is no text selection), char 4 to 4 of  
field 1 (char 4 is selected), char 1 to 4 of field 1 (char 1 to 4 is  
selected)...

on mouseDown pButton
   local tMenu
   -----
   if pButton = 3 then
     if the selectedField = empty or target = empty then exit mouseDown
     if the short name of the selectedField = the short name of the  
target then
       -- it's the right field
       put "(Cut/X,Copy/C,(Paste/V,-,Select All/A" into tMenu
       -- easier to build the menu using commas
       replace comma with cr in tMenu
       -- cut and paste are always disabled
       if word 4 of the selectedChunk < word 2 of the selectedChunk then
         put "(" before line 2 of tMenu
         -- there is nothing to copy: copy is disabled
       end if
       put tMenu into btn "MyMenu"
       popup btn "MyMenu"
     end if
   else pass mouseDown
end mouseDown

Of course you'll set the traversalOn of the popup menu button to  
false to avoid text deselection.

Le 24 août 08 à 22:56, Mark Stuart a écrit :

> Hi All,
>
>
>
> I have a contextual menu (popup) on a text field with several  
> options. One
> of them is Select All.
>
> This allows the user to select all the text in this field.
>
> If the user actuates the contextual menu again, the Select All  
> option should
> still be there, but also a new option is selectable - Copy - copies  
> all
> selected text to the clipboard.
>
>
>
> So the question is, how do I detect if text is selected in a text  
> field, and
> then dynamically "change out" the menu option by adding "Copy" to it?
>
>
>
> Regards,
>
> Mark Stuart


Best regards from Paris,
Eric Chatonet.
----------------------------------------------------------------
Plugins and tutorials for Revolution: http://www.sosmartsoftware.com/
Email: eric.chatonet at sosmartsoftware.com/
----------------------------------------------------------------





More information about the use-livecode mailing list