On Aug 21, 2016, at 10:24 AM, m...@jerrydaniels.com wrote:

> Trapping the commankeydown message is the easiest way to automate quoting. 
> Rather than altering the script field behavior, I'd recommend using a front 
> script. Just make sure you pass the keys you're not using!

Here's my version of Jacques' frontscript. It includes Jacques' "script paint" 
for the script editor (hover over a word and press the key combination, and the 
word hovered over is put into the current selection) — very useful to avoid 
mistyping of variable names. I also incorporated her "getPaint" function 
(select an image in LC, type the key combination, and choose a png or jpg from 
disc and that image will be poured into the selected LC image object). Also, I 
incorporated an insertDate() function.

In my version, all these shortcuts are triggered by a control-option-<keypress> 
(I work on a Mac), but you could change this easily.

-- Peter

Peter M. Brigham
pmb...@gmail.com

---------

on controlkeydown whichKey
   -- put this in a frontscript universally available in LC
   put the long name of the target into tarName
   put the shiftkey is down into shK
   switch whichKey
      case "'" -- put quotes around the selection
         if not shK then pass controlkeydown
         if "field" is not in tarName then pass controlkeydown
         if "revNewScriptEditor" is not in tarName then pass controlkeydown
         -- you could take the above line out if you want this in all LC fields
         get the selection
         put q(it) into the selection
         if it = "" then
            put the selectedChunk into tSel
            put word 4 of tSel into word 2 of tSel
            put (word 4 of tSel) - 1 into word 4 of tSel
            select tSel
         end if
         break
      case "9"
      case "0" -- put parens around the selection
         if not shK then pass controlkeydown
         if "field" is not in tarName then pass controlkeydown
         if "revNewScriptEditor" is not in tarName then pass controlkeydown
         -- you could take the above line out if you want this in all LC fields
         get the selection
         put "(" & it & ")" into the selection
         if it = "" then
            put the selectedChunk into tSel
            put word 4 of tSel into word 2 of tSel
            put (word 4 of tSel) - 1 into word 4 of tSel
            select tSel
         end if
         break
      case "["
      case "]" -- put brackets around the selection
         if not shK then pass controlkeydown
         if "field" is not in tarName then pass controlkeydown
         if "revNewScriptEditor" is not in tarName then pass controlkeydown
         -- you could take the above line out if you want this in all LC fields
         get the selection
         put "[" & it & "]" into the selection
         if it = "" then
            put the selectedChunk into tSel
            put word 4 of tSel into word 2 of tSel
            put (word 4 of tSel) - 1 into word 4 of tSel
            select tSel
         end if
         break
      case " " -- scriptPaint
         if not shK then pass controlkeydown
         if "field" is not in tarName then pass controlkeydown
         if "revNewScriptEditor" is not in tarName then pass controlkeydown
         put the mouseText into the selection
         break
      case "d"
         -- insert date
         put the shiftKey is down into wantLongDate
         insertDate wantLongDate
         break
      case "i" -- getPaint
         if not shK then exit controlkeydown
         if the selobj = "" then
            answer "Select an image first."
            exit controlkeydown
         else if word 1 of (the name of the selobj) <> "image" then
            answer "You must select an image."
            exit controlkeydown
         end if
         answer file "Choose replacement image:"
         if it = empty then exit to top
         put url ("binfile:" & it) into the selobj
         break
      default
         pass controlkeydown
   end switch
end controlkeydown

on insertDate getLongDate
   -- control-d inserts short date, control-shift-d inserts long date
   --     see the controlkeydown handler for implementation
   -- note: Windows users can implement this with other modifier keys
   -- put these scripts into a frontscript so it is available anywhere in LC
   -- requires controlkeydown
   
   put the selectedChunk into selCh
   if selCh = empty then exit insertDate
   put word -1 of selCh into fldNbr
   put word 4 of selCh into theCharNbr
   put the selectedtext into selText
   put length(selText) into origLength
   if getLongDate then
      -- long date
      put sr(item 2 to 3 of the long date) into tDate
   else
      -- short date
      put the short date into tDate
   end if
   put tDate into the selectedchunk
   select after char (theCharNbr + length(tDate) - origLength) of fld fldNbr
end insertDate
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to