Quitting while saving changes

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Quitting while saving changes

Post by lohill » Tue Sep 21, 2010 1:32 am

I would like my stand alone application to save the changes to the various datagrids in it. In the development mode it always seems to save everything. As a standalone it does not save anything. On an application quit or the close of the main stack, I would like to offer a chance to save, not save or cancel the quit. My application has a splash stack and a main stack with a few substacks. It is the data in the main stack I would like to be saved or not as the user chooses.

I have code that looks like this in the script for the main stack:

Code: Select all

on CloseStackRequest
   answer question "Do you want to save database changes?" & return & return & \
          "(Web changes are already in effect.)" with "No" or "Cancel" or "Yes" titled "Application Close"
   if it is "Yes" then
      save this stack
      --pass closeStackRequest
      --quit
      close this stack
   else
      if it is "NO" then 
         --pass closeStackRequest
         --quit
         close this stack
      else
         exit closeStackRequest
      end if
   end if
end CloseStackRequest

on shutDownRequest
   send "closeStackRequest" to stack "DAStoPF"
   pass shutDownRequest
end shutDownRequest
The lines which are commented out have been tried in various combinations but I can't seem to get it right.

Suggestions or references to documentation would be appreciated.
Thanks,
Larry

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Location: Philippines
Contact:

Re: Quitting while saving changes

Post by shadowslash » Tue Sep 21, 2010 3:40 am

The reason why you're code doesn't work as a standalone is because an executable (EXE) file is like a solid rock. If you want to save changes like data, etc, you need to find a storage approach for it. The simplest option I can suggest is to use CSV or Comma Separated Values on your DataGrid contents. If you need a head start on that, just let me know. Image
Parañaque, Philippines
Image
Image

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: Quitting while saving changes

Post by lohill » Tue Sep 21, 2010 6:05 pm

shadowslash,
The reason why you're code doesn't work as a standalone is because an executable (EXE) file is like a solid rock.
I apologize for not being clear enough here. It is not the .exe file I want to save. The .exe is my splash stack which has no data that needs saving. It is a simple splash screen that opens and then calls the main stack. It is the main stack, a .rev file that I want to offer the user a chance to save or not. If I did not want to make such an offer, I could just put 'save this stack' in the 'closeStack' script and the data is automatically saved.
The simplest option I can suggest is to use CSV or Comma Separated Values on your DataGrid contents.
I do offer the user a chance to backup their data already as a menu option. Since these are datagrids the 'simplest' way is to write to .txt files rather than to .csv. That is because the dgText is already tab delimited data.

Getting back to what I'm looking for is a way to offer the user a chance to save the stack, not save the stack or even cancel the quit. I want this to happen on either the close of the stack or when the quit application is chosen.

Larry

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Location: Philippines
Contact:

Re: Quitting while saving changes

Post by shadowslash » Tue Sep 21, 2010 6:26 pm

Hmm, just a random question but is this an application that you will have other people use in the future? Or will it only be used by you or a few people whom you personally made the software for? The reason I'm asking is because while it is the easiest to save the stack to the rev file, it would still be best to use another storage medium aside from the rev file. For example, instead of having the DataGrid data be saved to the stack it resides on, you can have it be saved to an SQLite database which is in the form of a local file. Also there's the arrayEncode function that you can use so that you can store the data to an array variable then output it to a local file. If it is just a personal project for use by few people you know or just yourself, I guess it's okay (although I still won't recommend) saving it to the stack where the DataGrid resides on.
lohill wrote:Since these are datagrids the 'simplest' way is to write to .txt files rather than to .csv. That is because the dgText is already tab delimited data.
There's also another problem here, as you update or try to implement new features or columns to your DataGrid, you will see that relying solely on the tab delimited items will be a problem in the future if you will be dealing with binary data. As for the .txt and .csv difference, you can simply parse the contents with a command like

Code: Select all

replace tab with comma in tMyVariable
with tMyVariable being the one that contains those tab-delimited DataGrid contents. A CSV is simply a text file with contents that are comma delimited. Image
lohill wrote:Getting back to what I'm looking for is a way to offer the user a chance to save the stack, not save the stack or even cancel the quit. I want this to happen on either the close of the stack or when the quit application is chosen.
You lost me at the underlined words above. Image
Parañaque, Philippines
Image
Image

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Quitting while saving changes

Post by Dixie » Tue Sep 21, 2010 6:47 pm

Iohill...

Have a look at the 'saveStackRequest' and 'quit' entries in the dictionary... putting them both to use will allow you to do what you need.
be well

Dixie

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: Quitting while saving changes

Post by lohill » Tue Sep 21, 2010 6:55 pm

This appears to be working for me:

Code: Select all

on CloseStackRequest
   answer question "Do you want to save database changes?" & return & return & \
          "(Any web changes are already in effect.)" with "No" or "Cancel" or "Yes" titled "Application Close"
   if it is "Yes" then
      save this stack
      close this stack
   else
      if it is "NO" then 
         close this stack
       end if
   end if
end CloseStackRequest

on shutDownRequest
   send "closeStackRequest" to stack "DAStoPF"
end shutDownRequest
Of course it causes my application to have a behavior that is one of my pet peeves - namely that it asks you if you want to save change when you have done nothing other than open it.

Larry

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”