cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
nikles
Level VI

Method to prevent "Do you want to save" message?

Hi.  I'm wondering if there is a way I can prevent the "Do you want to save..." message when a table is closed?  That is, this message:

nikles_0-1659042298514.png

Why?  Because I want to allow the user to make changes to the table, but I want to force them to save as a csv because we have other apps that require csv format.  To do this, I'm adding an " << On Close" script: 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
a = dt << is Dirty;
Show(a);
dt << add rows(5);
b = dt << is dirty;
Show(b);
dt << On Close(
	dt = CurrentDataTable();
	If(dt << Is Dirty,
		dt << Save As("$DESKTOP/file.csv")
	)
);

However, the "Do you want to save..." message still always appears prior to saving the csv.  I really don't want the user to save as both a jmp table and csv file, because then it creates 2 copies of the same doc, which will lead to confusion.  

 

Specs:

JMP Pro 16.2.0

macOS Big Sur: 11.6.7

 

Thanks!

6 REPLIES 6
Craige_Hales
Super User

Re: Method to prevent "Do you want to save" message?

dt<<setDirty(0);

will mark the table "not dirty", preventing the save prompt.

Craige
nikles
Level VI

Re: Method to prevent "Do you want to save" message?

Hi Craige.  I assume you mean to add that line to the "On Close" script.  I tried that too.  The problem is that the save prompt appears prior to the On Close script being executed.  

Craige_Hales
Super User

Re: Method to prevent "Do you want to save" message?

Set the not dirty state right after the table is loaded or modified. I sometimes do that for temporary tables I might want to examine but don't want to keep. The idea is that any time a table is different from the version saved on disk it is not a clean copy of what is on disk and needs to be saved. A new table that has not been saved is dirty, but you can change it.

edit: since you are testing the dirty flag to decide it it needs saving, you'll need another approach, perhaps always saving it.

Craige
nikles
Level VI

Re: Method to prevent "Do you want to save" message?

Aha - yes, that's the issue.  To prevent the save prompt by setting the non-dirty state when the table is loaded: easy.  To set the non-dirty state after anytime the user modifies the table: I'm not aware of any way to do this (such as an " << On Change()" message).  Maybe there's just no solution.  

jthi
Super User

Re: Method to prevent "Do you want to save" message?

Depending on what you are trying to do and what modifications you allow users to do, maybe you could use New Data Box()

-Jarmo
Craige_Hales
Super User

Re: Method to prevent "Do you want to save" message?

The dirty flag is set each time a change is made. But if it is set when the table is closed, then you will get a save prompt. You could try an experiment where you save it as a CSV file early on, I'm not sure where it will save it later after another change is made. I think it might still remember that it's saving to the CSV file.
Craige