Spell checking on a Mac

Scott Morrow scott at elementarysoftware.com
Fri Oct 28 00:48:33 EDT 2011


On Oct 27, 2011, at 9:20 PM, Scott Morrow wrote:

> 
> Here is some code that might give you a start on rolling your own using the RunRevPlanet spell checker.

I forgot to include a frontscript for the right-click feature… which was the whole point  :  )
this frontscript "pops-up" a button named "PopUpMenu" which may contain menu items
in the lower portion and spelling suggestions at the top.



constant kMain = "ShortNameOfYourMainStack"
-------Front script
--the uSelectedChunk of stack kMain is used to track text selection

on mouseDown tMouseButton  -- POP-UP menu on right click
   put the long name of the target into tTarget
   if "field" <> (word 1 of tTarget) then
      pass mouseDown
   end if
   put the mouseChunk into tMouseChunk
   put the mouseText into tMouseText
   
   put the selectedChunk into tSelectedChunk
   
   
   if tMouseButton is 3 then
      
      put (word 1 to 4 of tSelectedChunk) && "of" && tTarget into tLongSelection
      set the uSpellCheckSingleWord of btn "PopUpMenu" of stack kMain to "false"
      set the uMouseChunk of btn "PopUpMenu" of stack kMain to empty
      
      
      if (tSelectedChunk is not empty) then --AND (word 1 of tTarget is "field") then
         set the uSelectedChunk of stack kMain to tLongSelection
         -- spell check the word that the mouse is hovering over
         -- offer suggestions if it is mispelled
         
         if ("rrpSpellCheck" is among the lines of the stacksInUse) AND (not ((tMouseText is empty) OR (tMouseChunk is empty))) AND (not rrpSpellValidWord(tMouseText)) then
            put Trim(rrpSpellSuggestions(tMouseText, 3)) &CR&\
            "(-" &CR&\
            (the uMenuItems of btn "PopUpMenu" of stack kMain) into tMenuConstruct 
            if line 1 of tMenuConstruct is empty then
               put "No suggested spelling" into line 1 of tMenuConstruct
            else
               set the uSpellCheckSingleWord of btn "PopUpMenu" of stack kMain to "true"
            end if
            set the text of btn "PopUpMenu" of stack kMain to tMenuConstruct
            put ((word 1 to 4 of tMouseChunk) && "of" && tTarget) into tLongMouseChunk
            set the uMouseChunk of btn "PopUpMenu" of stack kMain to tLongMouseChunk 
            -- store the textStyle of the word we are checking so that we can insert a correction with the correct style
            put the textStyle of tLongMouseChunk into tTextStyle
            if tTextStyle is not empty then
               do ("set the uSpellCheckSingleWordTextStyle of btn" &&QUOTE& "PopUpMenu"&QUOTE&& "of stack" &&QUOTE& kMain &QUOTE&& "to" && tTextStyle)
            end if
         else 
            -- normal field pop-up
            set the text of btn "PopUpMenu" of stack kMain to the uMenuItems of btn "PopUpMenu" of stack kMain
         end if
         --      else -- build a non text edit popUp menu
         --         set the text of btn "PopUpMenu" of stack kMain to line 8 to -1 of (the uMenuItems of btn "PopUpMenu" of stack kMain)
      end if
      
      popUp btn "PopUpMenu" of stack kMain
   else
      pass mouseDown
   end if
end mouseDown

-Scott Morrow



More information about the use-livecode mailing list