Auto save on close stack

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Contact:

Auto save on close stack

Post by AlexAdams »

How can I have a stack save itself everytime it closes without a user dialog? Is there a preCloseStack message or something similar?

Thanks,
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus »

Hi Alex,

omit the "pre" and you are done :-)

Add these lines to your closestack handler, that will do the trick:

Code: Select all

on closestack
  save this stack
end closestack
Best

Klaus
AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Contact:

Save prompt comes before the closeStack message is sent

Post by AlexAdams »

Klaus,

I am prompted to save the stack before the closeStack message handler has a chance to do anything.

Any other ideas?
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus »

Hi Alex,

ah, yes, that is an ugly inconvenience of the IDE that you cannot switch off :(
But this will NOT happen in a standalone, if that is what you mean.


Best

Klaus
AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Contact:

I wondered about that

Post by AlexAdams »

Thanks. I'll setup a machine to test that. Does it work the same if the person is using Revolution Player?
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus »

Hi Alex,

yes the Rev Player behaves like a standalone.


Best

Klaus
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark »

Hi,

I would recommend using closeStackRequest instead of closeStack. In the closeStackRequest handler, you still have the possibility to cancel the close "message". For example:

Code: Select all

on closeStackRequest
  -- you might remove the line below, the next line and the
  -- last line if you want to auto-save without asking the user
  answer "Really?" with "Yes" or "No"
  if it is "Yes" then
    save this stack
    if the result is empty then
      lock messages
      -- do any additional cleaning up here
      if the environment contains "dev" then
        close this stack
      else
        quit
      end if
    else
      beep
      answer "Could not save. Want to close anyway?" with "Yes" or "No"
      if it is "Yes" then
        lock messages
        -- do any additional cleaning up here
        if the environment contains "dev" then
          close this stack
        else
          quit
        end if
      end if
    end if
  end if
end closeStackRequest
You might want to replace the quit command with this handler. Just make sure to just it in case you don't use MySQL or if there are any other libraries and externals that need to be stopped before quitting.

If you open the stack as modeless inside the IDE, the IDE won't ask you whether to save it and the only messages would be those from the script above.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Post Reply