Contextual Menus

Alex Shaw alex at harryscollar.com
Sun Jul 27 10:33:15 EDT 2008


Hi

Here's some stripped down code I've been using that works ok on mac & pc.

Not tested on linux. Any improvements appreciated.

To test, create a new stack, place a few fields onto the first card. Set 
the script of the card or stack to the code text below.

regards
alex

--> start code

global gHilitedText

ON mouseDown pMouseBtnNum
     local tID
     put the id of the target into tID
     IF (pMouseBtnNum is 3) AND (word 1 of the target is "field") AND 
(word 2 of the selectedfield is the number of fld id tID) THEN

         IF (the selectedfield is not empty) THEN
             showEditOptionsMenu "SimpleEditOptions"
         END IF

     END IF
     pass mouseDown
END mouseDown


PRIVATE COMMAND showEditOptionsMenu pMenuList
     local tPath,tStackPath,tMenu
     lock screen

     put the selectedchunk into gHilitedText["chunk"]
     put the selectedtext into gHilitedText["text"]

     put 
"Cut"&cr&"Copy"&cr&"Paste"&cr&"Clear"&cr&"-"&cr&"Plain"&cr&"Bold"&cr&"Italic" 
into tMenu
     IF there is not a btn ".OptionsMenu" THEN
         create invisible btn ".OptionsMenu"
         set the style of btn ".OptionsMenu" to "menu"
     END IF
     set the text of btn ".OptionsMenu" of the topstack to tMenu
     popup btn ".OptionsMenu" of the topstack
     IF the platform is "Win32" THEN select gHilitedText["chunk"]
     unlock screen
END showEditOptionsMenu


ON menuPick pChosen
     EditOptionHTML pChosen
END menuPick


PRIVATE command EditOptionHTML pChosen
     local tStyle,tOld
     SWITCH pChosen
         CASE "Cut"
             select gHilitedText["chunk"]
             cut
             break
         CASE "Copy"
             select gHilitedText["chunk"]
             copy
             break
         CASE "Paste"
             select gHilitedText["chunk"]
             paste
             break
         CASE "Plain"
             IF gHilitedText["chunk"] is not empty THEN
                 set the textstyle of gHilitedText["chunk"] to "plain"
                 select gHilitedText["chunk"]
             END IF
             break
         CASE "Clear"
             put empty into fld (word -1 of gHilitedText["chunk"])
             break
         CASE "Bold"
             IF gHilitedText["chunk"] is not empty THEN
                 put the textstyle of gHilitedText["chunk"] into tStyle
                 IF (tStyle is empty) OR (tStyle is "plain") OR (tStyle 
is "mixed") THEN
                     set the textstyle of gHilitedText["chunk"] to "bold"
                 ELSE
                     put ",bold" after tStyle
                     set the textstyle of gHilitedText["chunk"] to tStyle
                 END IF
                 select gHilitedText["chunk"]
             END IF
             break
         CASE "Italic"
             IF gHilitedText["chunk"] is not empty THEN
                 put the textstyle of gHilitedText["chunk"] into tStyle
                 IF (tStyle is empty) OR (tStyle is "plain") OR (tStyle 
is "mixed") THEN
                     set the textstyle of gHilitedText["chunk"] to "italic"
                 ELSE
                     put ",italic" after tStyle
                     set the textstyle of gHilitedText["chunk"] to tStyle
                 END IF
                 select gHilitedText["chunk"]
             END IF
             break
         CASE "Underline"
             IF gHilitedText["chunk"] is not empty THEN
                 put the textstyle of gHilitedText["chunk"] into tStyle
                 IF (tStyle is empty) OR (tStyle is "plain") OR (tStyle 
is "mixed") THEN
                     set the textstyle of gHilitedText["chunk"] to 
"underline"
                 ELSE
                     put ",underline" after tStyle
                     set the textstyle of gHilitedText["chunk"] to tStyle
                 END IF
                 select gHilitedText["chunk"]
             END IF
             break
         DEFAULT

     END switch
END EditOptionHTML

--> end code



More information about the use-livecode mailing list