Edit cell in basic table field

Peter M. Brigham pmbrig at gmail.com
Sat Feb 22 11:00:03 EST 2014


Here's a function that may come in handy if you need to script something based on which table cell is clicked.

----------------

function gridCellClicked
   -- Designed for tab-delimited fields, ie., tables
   -- returns empty if the field doesn't contain a <tab> char,
   -- otherwise returns <lineNbr>,<colNbr>:
   --     <lineNbr> = number of the clicked line
   --     <colNbr> = number of the clicked column (item)
   -- uses the mouse position instead of the clickchunk,
   --     which is empty if you click on white space,
   --     works even if the field is horizontally scrolled
   -- call it like this in your field script:
   --     on mouseup
   --       put gridCellClicked() into g
   --       put item 1 of g into lineNbr
   --       put item 2 of g into colNbr
   --       -- use lineNbr and colNbr as needed here
   --     end mouseup
   
   if not (the target begins with "field") then return empty
   if not (target contains tab) then return empty
   
   put word 2 of the clickline into cLineNbr
   put item 1 of the clickloc into clickHorz
   
   put the tabstops of the target into fTabstops
   if fTabstops = empty then put 32 into fTabstops
   -- 32 is the effective tabstop for a field with tapstops = empty
   put the hscroll of the target into tHorzScroll
   put the left of the target into fLeft
   put the borderwidth of the target into fBordWidth
   put item 1 of the margins of the target into fLeftMargin
   put the number of items of fTabstops into nbrTabStops
   put (item -1 of fTabstops) - (item -2 of fTabstops) into lastTabGap
   -- that works even if only one tabstop
   
   put clickHorz - (fLeft + fBordWidth + fLeftMargin) + tHorzScroll into clickHorz
   put 0 into upToHere
   put 0 into whichTab
   repeat until upToHere > clickHorz
      add 1 to whichTab
      if whichTab > nbrTabStops then
         add lastTabGap to upToHere
      else
         put item whichTab of fTabstops into upToHere
      end if
   end repeat
   return cLineNbr,whichTab
end gridCellClicked

----------------

-- Peter

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

On Feb 22, 2014, at 1:21 AM, DunbarX at aol.com wrote:

> Bob is probably right about the fact that you may run out of functional power with a table field. But I use them whenever I can, since they are much simpler and easier to manage.
> 
> A phantom field is indeed created when you double-click on a "cell". Put this in the card script:
> 
> on selectionchanged
>   put the name of the last field
> end selectionchanged
> 
> Double click, and you can see that field. This may give you a pathway to fooling around with the table field workings. 
> 
> Craig NEwman
> 
>> -----Original Message-----
>> From: David Epstein <dfepstein at comcast.net>
>> To: use-livecode <use-livecode at lists.runrev.com>
>> Sent: Fri, Feb 21, 2014 11:00 pm
>> Subject: Edit cell in basic table field
>> 
>> 
>> If I check "basic table object" in the field property inspector, and  
>> check "Edit cell," clicking on the table field causes a small  
>> unlocked field to be created at the cell's location, which on tab or  
>> arrowkey has its contents written to the cell.
>> 
>> Is there some way to have a script trap the relevant information  
>> about what is going on, e.g., that a cell has just been "opened for  
>> editing", that a cell has just been edited, which cell it is, etc.?
>> 
>> I assume that this "Edit Cell" activity is governed by a script that  
>> is reading a custom property, but I see no indication that the field  
>> actually has such a property or where the script is.
>> 
>> Many thanks.
>> 
>> David Epstein




More information about the use-livecode mailing list