AW: Answer dialog enhancement...

Paul Dupuis paul at researchware.com
Wed Apr 1 14:46:17 EDT 2020


So I have a working mechanism to add a "Don't Ask Again" check box to 
the existing standard Answer Dialog on the fly. I offer it up to the 
community for anyone who needs it and for anyone who may want to improve 
the code. The scripts are below. There is a sample usage you can place 
in a clickable button and below that is a BEHAVIOR script that must be 
in button whose name matches what is used in the clickable button.

This is the first time I have really found a use for the "before" and 
"after" handlers. What a great addition to LiveCode!

Essentially, I add a behavior to the card of the standard "Answer 
Dialog" that positions and cleans up the Don't Ask Again check box AFTER 
the proOpenCard handler has positioned everything else AND a BEFORE 
mouseUp handler to trap clicks for changing the checkbox hilite that 
would otherwise close the dialog and return a clicked button name.

I needed to set a number of properties for the checkbox because the 
preOpenCard treats ANY button in the Answer Dialog like regular buttons 
and hides those not in use by making them 1px in size and moving them 
off screen. I may not have needed to change every property I did, but I 
didn't have the time to go through the Answer Dialog card script to 
determine exactly what properties those scripts were changing that I 
needed to reset.

I think it would be great in LC, Ltd. could fold this into the standard 
'answer' command some how.


-- Sent when the mouse is released after clicking
-- pMouseButton specifies which mouse button was pressed
on mouseUp pMouseButton
   dontaskagain "on"
   answer warning "Some message I may not want to see again." with 
"Cancel" or "OK" titled "A Message"
   put it into tAnswer
   put dontaskstatus() into tDontAskAgain
   dontaskagain "off"
   --
   put "Don't Ask is:"&&tDontAskAgain &&"And button clicked is:"&&tAnswer
end mouseUp

command dontaskagain pActivate
   switch pActivate
     case "on"
       set the behavior of cd 1 of stack "Answer Dialog" to the long id 
of btn "DontAskBehavior" of this cd
       break
     case "off"
       set the behavior of cd 1 of stack "Answer Dialog" to empty
       delete btn "DontAskAgain" of cd 1 of stack "Answer Dialog"
       break
   end switch
end dontaskagain

function dontaskstatus
   if exists(btn "DontAskAgain" of cd 1 of stack "Answer Dialog") then
     put the hilite of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" into tDontAskAgain
     return tDontAskAgain
   else
     return false
   end if
end dontaskstatus

BEHAVIOR BUTTON SCRIPT

after preOpenCard
   if exists(btn "DontAskAgain" of cd 1 of stack "Answer Dialog") then
     set the style        of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to "checkbox"
     set the autoHilite   of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the opaque       of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the threeD       of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the showBorder   of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the hiliteBorder of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false

     set the height       of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to 25
     set the width        of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to 120
     set the bottomLeft   of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to the bottomLeft of cd 1 of stack "Answer Dialog"
   else
     -- setup the templateButton
     set the style of the templateButton to "checkbox"
     set the label of the templateButton to "Don't Ask Again."
     --
     create btn "DontAskAgain" in cd 1 of stack "Answer Dialog"
     --
     reset the templateButton
     --
     set the style        of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to "checkbox"
     set the autoHilite   of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the opaque       of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the threeD       of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the showBorder   of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false
     set the hiliteBorder of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to false

     set the height       of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to 25
     set the width        of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to 120
     set the bottomLeft   of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to the bottomLeft of cd 1 of stack "Answer Dialog"
   end if
end preOpenCard

before mouseUp pMouseButton
   -- if the target is the check box, check the box and do not pass mouseUp
   if the long ID of the target = the long id of btn "DontAskAgain" of 
cd 1 of stack "Answer Dialog" then
     set the hilite of btn "DontAskAgain" of cd 1 of stack "Answer 
Dialog" to not (the hilite of btn "DontAskAgain" of cd 1 of stack 
"Answer Dialog")
     exit to top
   end if
end mouseUp





More information about the use-livecode mailing list