Setting a dirty flag for a file

Devin Asay devin_asay at byu.edu
Thu Jul 21 15:28:21 EDT 2011


On Jul 21, 2011, at 1:20 PM, Richard Gaskin wrote:

> Charles Szasz wrote:
> 
>> I am using Rev. 4.0. How do you set a "dirty flag" for a data
>> file that that has been saved but still open in your app stack?
>> My app creates a data file that saves the contents of 16 fields.
>> I have code to show an initial save dialog when the user makes
>> changes. I want to use a dirty flag to show another save box only
>> when closing the file if the user makes subsequent changes in the
>> data file.  Otherwise when the user closes the data file without
>> additional change no save dialog will be presented.
> 
> You can use a custom property for that, setting it to true whenever a 
> closeField triggers, and clearing it on save.
> 
> But better still would be to use the modifiedMark property of the stack, 
> which has the additional benefit of indicating unsaved changes by 
> darkening the closeBox on OS X.

But don't forget that the modifiedMark property only showed up in LC 4.6, and Charles said he's using v. 4.0.
> 
> Whichever flag you use, you'll want to check it in a closeStackRequest 
> handler, so you can prompt the user to save if needed.

For actually setting the flag you can do something as simple as comparing the contents of a field with the contents of an external file with each keystroke:

on rawKeyUp
# where tFilepath is a variable storing the full path to the saved file
if field "mycontent" = url ("file:" & tFilepath) then
  set the dirtyStack of this stack to true
else
  set the dirtyStack of this stack to false
end if
end rawKeyUp

HTH

Devin


Devin Asay
Humanities Technology and Research Support Center
Brigham Young University





More information about the use-livecode mailing list