A problem, though -- see below

On Jan 3, 2011, at 4:49 AM, Sivakatirswami wrote:

Aloha Peter:

Now this what i call a Prime New Year gift!

Sweet.

And, yes, I do work a lot with list fields and to make lists editable I had to add this to your script

     set the listBehavior of the target to not tf

but then this toggles all fields to listbehavior when locked... . so it required more....

the problem is you can determine if a field has listbehavior when it is set, but if you turn listbehavior off, then one needs a way to preserve the fact that this is a list field, even when it's listbehavior is off.

So I added a custom prop to list fields so that they maintain their list property thru the editing session. Perhaps there is a better way, but this works:

by adding this to your setProp handler

     if the listbehavior of the target is true then
        set the uList of the target to true
     end if
     if the uList of target = true then
        set the listBehavior of the target to not tf
     end if




On 1/2/11 3:28 AM, Peter Brigham MD wrote:

I use a virtual property:

on mouseup theBtn
  if theBtn = 1 and "field" is in the target and the \
             commandkey is down and the shiftkey is down then
     set the writable of the target to not the writable of the target
  else
     pass mouseup
  end if
end mouseup

setprop writable tf
  if "field" is not in the target then exit writable
  try
     if the listbehavior of the target is true then
        set the uList of the target to true
     end if
     if the uList of target = true then
        set the listBehavior of the target to not tf
     end if
     set the locktext of the target to not tf
     set the traversalon of the target to tf
     set the autohilite of the target to tf
set the listBehavior of the target to not tf # required for list fields

The line above will set the listbehavior of all fields to true when setting the writable to false, and it's not necessary.

     --  catch tError
     --    beep
     --    answer tError
  end try
end writable

getprop writable
  if "field" is not in the target then return ""
  try
     put the locktext of the target into L
     put the traversalon of the target into T
     put the autohilite of the target into A
     if T and A and not L then return true
     return false
  end try
end writable

Put this in a library stack or a frontscript and it will work everywhere -- command-shift-click on any field and toggle the writable of the field. I use it constantly. You can revise this to just toggle the locktext if you work with list fields a lot, so that the usual hiliting and line selection are preserved, locked or unlocked.

-- Peter

Peter M. Brigham
pmb...@gmail.com
http://home.comcast.net/~pmbrig

So we have then:

setprop writable tf
   if "field" is not in the target then exit writable
   try
      if the listbehavior of the target is true then -- *** see below
         set the uListBehav of the target to true -- *** see below
      end if -- *** see below
      if the uListBehav of the target = true then
         set the listBehavior of the target to not tf
      end if
      set the locktext of the target to not tf
      set the traversalon of the target to tf
      set the autohilite of the target to tf
   end try
end writable

getprop writable
   if "field" is not in the target then return ""
   try
      put the locktext of the target into L
      put the traversalon of the target into T
      put the autohilite of the target into A
      if T and A and not L then return true
      return false
   end try
end writable

on mouseup theBtn
   if theBtn = 1 and "field" is in the target and the \
              commandkey is down and the shiftkey is down then
      set the writable of the target to not the writable of the target
   else
      pass mouseup
   end if
end mouseup

But you have to add the mouserelease handler below, since clicking on a blank line of a list field doesn't send mouseup, it sends mouserelease instead.

on mouserelease theBtn
   if theBtn = 1 and "field" is in the target and the \
              commandkey is down and the shiftkey is down then
      set the writable of the target to not the writable of the target
   else
      pass mouserelease
   end if
end mouserelease

The only problem with the final result is that if you set the listbehavior of a field to true, then toggle the writable, then set the listbehavior of the field to false, it is still flagged in the customprop as being a list field, and when you toggle writable again it will revert to being a list field again. So you have to delete the customprop by hand to get it to behave correctly. This could be solved with a preopencard handler as follows:

on preopencard
   if "field" is not in the target then pass preopencard
   repeat with n = 1 to the number of fields
      set the uListBehav of the target to \
               the listbehavior of the target
   end repeat
end preopencard

then take out the starred lines in the setprop handler, since the fields start out being labeled before you touch them.

This is getting quite baroque in its complexity, but if you work with list fields a lot it might be worth the hassle. I think I will just ignore the list field wrinkles in my stacks, since I only have one list field that I use and I rarely have to edit its contents.

-- Peter

Peter M. Brigham
pmb...@gmail.com
http://home.comcast.net/~pmbrig



_______________________________________________
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