As far as I can see reading your code, it does the following:
- Set the cantModify of the stack to true
- On close stack: ask user to save or not
- if save then you just save the stack
- If it is not save then reset the stack to it's default
- And finally: implement a complicated method for pasting into a stack with cantModify = true.
If it works for you it works for you, and no question.
But I have to ask, what added benefit there is to all of this instead of just:
Code: Select all
on preOpenStack
set the style of this stack to "modeless"
// do preferences stuff here
end preOpenStack
on closeStackRequest // built-in close box
answer "Save data?" with "No" and "Save"
if it is "Save" then
save me
// maybe do some preferences stuff here, no cleanup needed
end if
pass closeStackRequest
end closeStackRequest
Yes, the code above doesn't cater for quitting the IDE, but neither does yours as far as I can see?
With modeless you can close without the save stack dialog and you can both type and paste in any way (not just command/ctrl-V), and no need to introduce an extra 20 lines of code?
I'll admit I don't see the point in complicating things more than needed.
For an excellent example in how a modeless stack works, checkout the
LiveCode Error Lookup stack jointly created by Richard and Jaqueline (it's available in Sample Stacks, or it's web-facing site liveCodeShare (terribly, painfully sloooowwww..., but then so is Sample Stacks) at
https://livecodeshare.runrev.com/stack/ ... ror-Lookup