Page 1 of 1

Undo does not work in this field

Posted: Wed Oct 31, 2012 1:11 pm
by japino
I have a field which has this field script:

Code: Select all

on textChanged
   send mouseup to btn "Update" of stack "My list"
end textChanged
Any changes I apply to this field, for example typing text, can not be undone by selecting "Undo" from the Edit menu. "Undo" works fine for other fields. Can I have a field with an "on textChanged" handler and still use "Undo" for that field?

Re: Undo does not work in this field

Posted: Wed Oct 31, 2012 8:51 pm
by dunbarx
Hi.

I have no problem with this. There must be something else you are doing. To test, I made the two objects you describe. In the button script, I simply said:

put fld 1 --the field with the "textChanged" handler

When I type into the field, the field text appears in msg. When I undo, the last typed text is removed from the field, and also from msg.

Craig Newman

Re: Undo does not work in this field

Posted: Wed Oct 31, 2012 10:18 pm
by japino
Thanks for your reply! I don't know what to say, it does not work for me. Undo does not work when I have the code in my field. When I comment out the code in the field, Undo works. I have nothing else in the field script, nothing in the card script, and only a closeStack handler in the stack script. :roll: I'm using 5.5.3 on a Mac.

Re: Undo does not work in this field

Posted: Thu Nov 01, 2012 3:32 am
by dunbarx
If you duplicate what I did, from scratch, do you get the same behavior I do?

Re: Undo does not work in this field

Posted: Thu Nov 01, 2012 9:48 am
by japino
Yes, I do. So it does work with a new stack. But it beats me why it doesn't work with my original stack. I only have that script in the field and when I comment the script out, it works. I now suspect that there might be an issue with my script in the "Update" button which somehow prevents Undo from working? Hmmm, weird stuff. Anyway, thanks, this was helpful!

Re: Undo does not work in this field

Posted: Thu Nov 01, 2012 4:24 pm
by japino
My Update button script looks like this (cleaned up a bit to only show the essential parts):

Code: Select all

on mouseUp
   put empty into field "ToDo"
   repeat with x = 1 to the number of cds of stack "MainApplication"
      put field "ProjectID" of cd x of stack "MainApplication" & " - " & field "ProjectName" of cd x of stack "MainApplication" & return after field "ToDo"
      repeat with y = 1 to the number of buttons of cd x of stack "MainApplication"
         put name of button y of cd x of stack "MainApplication" into myButtonName
         put (the number of chars of myButtonName)-1 into myNumberofChars
         if char myNumberofChars of myButtonName = "•" then 
            if  the enabled of btn myButtonName of cd x of stack "MainApplication" and not the hilite of btn myButtonName of cd x of stack "MainApplication" then put myButtonName & return after field "ToDo"
         end if
      end repeat
      put field "Other" of cd x of stack "MainApplication" & return after field "ToDo"
      put return after field "ToDo"
   end repeat
end mouseUp
I'm guessing that when you select "Undo" my application tries to undo actions performed by this script instead of trying to undo the input typed by the user. When I comment out this essential part of the script, Undo works as expected.

Now beating my brain to get Undo to work while still performing the actions from this script...

Re: Undo does not work in this field

Posted: Fri Nov 02, 2012 5:53 am
by dunbarx
Hi.

The offending line is:

put return after field "ToDo"

Comment it out, and all is well. You may just be undoing the return, which may not have any apparent effect. But I understand from the dictionary that script invoked actions are not undoable, only user actions.

This needs more study.

Craig Newman

Re: Undo does not work in this field

Posted: Fri Nov 02, 2012 9:25 am
by japino
Thanks Craig. I tried it out, but just commenting out that line does not solve the issue. I need to comment out every line where the put command puts something into the field before Undo start working the way I want.

I will study more. :lol:

Re: Undo does not work in this field

Posted: Fri Nov 02, 2012 8:04 pm
by jacque
You could try a little hack. Use the "type" command instead of "put". That simulates a user action.

On second thought though, it will make your script very slow. You could set the typingRate to something fast, maybe that would help, but it probably won't be perfect.