Using Behaviors for Triggering UI Design - Run Time

Peter M. Brigham pmbrig at gmail.com
Thu Mar 31 09:07:08 EDT 2016


On Mar 30, 2016, at 9:53 AM, Richard Gaskin wrote:

> In all cases, once set a behavior is resolved to a "rugged long ID", a long ID where the stack portion is changed from the full file path as we normally find it to just the stack name, allowing portability.
> 
> For example:
> 
>   button id 1004 of cd id 1003 of stack "/home/rg/something/rsrc.livecode"
> 
> ...becomes:
> 
>   button id of cd id 1003 of stack "rsrc"
> 
> 
> So when using a stack as a behavior you can write:
> 
>   set the behavior of btn "Something" to the long id of stack "rsrc"
> 
> ...or even more simply, since stack names are already unique:
> 
>   set the behavior of btn "Something" to the name of stack "rsrc"

FWIW, here are some handlers that return these "rugged" object references.

-- Peter

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

--------

getProp robustID
   ----  a virtual property  ----
   -- getting the long id of a control can result in different values depending on
   --    (a) where the stack is stored on the user's disk and
   --    (b) which card is the currentcard when the property is fetched
   -- the robustID is consistent no matter what card is current
   --    and no matter which folder the user has stored the stack in;
   -- format: button id 1039 of bkgnd id 1003 of stack "subStack1"
   --            of stack "tMainStack"
   -- the robustID can be used as a complete object reference,
   --    just like the long ID
   -- requires q()
   
   put the long id of the target into tLongID
   if not (there is a tLongID) then
      -- in case the group is not placed on the currentcard
      replace "group " with "bkgnd " in tLongID
      if not (there is a tLongID) then
         return "robustID: no such object." -- error
      end if
   end if
   replace " stack " with cr in tLongID
   put line -1 of tLongID into mainStackFileName
   replace quote with empty in mainStackFileName
   put the short name of stack mainStackFileName into mainStackName
   put q(mainStackName) into line -1 of tLongID
   replace cr with "stack " in tLongID
   replace " of " with cr in tLongID
   put lineoffset(cr & "card ",cr & tLongID) into cdLineNbr
   if cdLineNbr > 1 then delete line cdLineNbr of tLongID
   replace cr with " of " in tLongID
   return tLongID
end robustID

getProp robustName
   ----  a virtual property  ----
   -- getting the long name of a control can result in different values depending on
   --    (a) where the stack is stored on the user's disk and
   --    (b) which card is the currentcard when the property is fetched
   -- the robustName is consistent no matter what card is current
   --    and no matter which folder the user has stored the stack in;
   -- format: button "copyText" of bkgnd "fieldGp" of stack "substack1"
   --            of stack "myMainStack"
   -- the robustName can be used as a complete object reference,
   --    just like the long name
   -- requires q()
   
   put the long name of the target into tLongName
   if not (there is a tLongName) then
      -- in case the group is not placed on the currentcard
      replace "group " with "bkgnd " in tLongName
      if not (there is a tLongName) then
         return "robustName: no such object." -- error
      end if
   end if
   replace " stack " with cr in tLongName
   put line -1 of tLongName into mainStackFileName
   if the number of lines of tLongName = 1 then
      return the name of mainStackFileName
   end if
   replace quote with empty in mainStackFileName
   put the short name of stack mainStackFileName into mainStackName
   put q(mainStackName) into line -1 of tLongName
   replace cr with " stack " in tLongName
   replace " of " with cr in tLongName
   put lineoffset(cr & "card ", cr & tLongName) into cdLineNbr
   if cdLineNbr > 1 then delete line cdLineNbr of tLongName
   repeat with c = 1 to the number of lines of tLongName
      put line c to -1 of tLongName into ctrlName
      replace cr with " of " in ctrlName
      put the name of ctrlName into thisName
      put thisName into line c of tLongName
   end repeat
   replace cr with " of " in tLongName
   return tLongName
end robustName

function q pStr
   -- quote
   return quote & pStr & quote
end q





More information about the use-livecode mailing list