Page 1 of 1

if cancel end mouseup ?

Posted: Tue May 31, 2016 12:05 am
by kresten
Scripting a button to ask for content in a textbutton, I find it hard to avoid execution of the further lines of the script, if user shall be able to escape.

The original script goes:
on mouseUp
ask"Give a short name to a new textbutton"
put it into knapnavn
clone button "prototext" of stack "Mindmapping"
set the visible of it to true
set the name of it to knapnavn
set the width of btn knapnavn to the formattedWidth of btn knapnavn
set the height of btn knapnavn to the formattedheight of btn knapnavn
set the loc of it to 997,14
set the textfont of it to "Arial"
end mouseUp

But if user regrets and clicks cancel, the cloning takes place and delivers a nameless button- So i need an if clause before the cloning . But failed to find the way to script it. Neither the info on ask or info on cancel in the LC library gives me a clue.
Hope for help
Kresten Bjerg

Re: if cancel end mouseup ?

Posted: Tue May 31, 2016 1:04 am
by ClipArtGuy

Code: Select all

on mouseUp
   ask"Give a short name to a new textbutton"
   if it is empty then
      exit mouseup
   else
      put it into knapnavn
      clone button "prototext" of stack "Mindmapping"
      set the visible of it to true
      set the name of it to knapnavn
      set the width of btn knapnavn to the formattedWidth of btn knapnavn 
      set the height of btn knapnavn to the formattedheight of btn knapnavn
      set the loc of it to 997,14
      set the textfont of it to "Arial"
  end if
end mouseUp

Re: if cancel end mouseup ?

Posted: Tue May 31, 2016 1:33 am
by kresten
So simple !
Thank you very much !
Maybe a note about this should be added to the "ask" and the "cancel" in the LC library

Re: if cancel end mouseup ?

Posted: Tue May 31, 2016 1:07 pm
by Klaus
Well: From the dictionary about "ask file..."
...
If the user cancels the dialog, the it variable is set to empty, and the result function returns cancel.
...
8)

Re: if cancel end mouseup ?

Posted: Wed Jun 01, 2016 11:45 am
by kresten
The ASK specification could helpfully include the following lines :idea: :

"If the ask-script involves further operations, these are not cancelled. To escape from this trap, user has to include
   if it is empty then
      exit mouseup
   else"