Message Boards Message Boards

0
|
2092 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to create a notebook without save prompt?

Posted 1 year ago

I want to display some data in a notebook created from scratch. I do not want the notebook to be saved, nor do I want the user to be prompted with the standard save dialog when closing the notebook. Only when the user edits the notebook himself, he should be prompted to save as usual.

If I create and write the notebook with one singe CreateDocument this works as desired:

data = Style[Row[{"data = ", {1, 2, 4, 8, 16}}], Blue, Bold];
nb = CreateDocument[{
    TextCell["Some data", "Chapter"], 
    ExpressionCell[data, "Output"]}];

But if I write some more data into the notebook by NotebookWrite, the user will be prompted to save the notebook.

data = Style[Row[{"data = ", {1, 2, 4, 8, 16}}], Blue, Bold];
data2 = Row[{"Some more data = ", 4711}];
nb = CreateDocument[{
    TextCell["Some data", "Chapter"], ExpressionCell[data, "Output"]}];
SelectionMove[nb, After, Notebook];
NotebookWrite[nb, Cell[data2, "Output"]];

There must some kind of "dirty-flag" for the notebook which is reset after CreateDocument and set after NotebookWrite. I would have to reset that flag after all my writing. But I cannot find how to reset that dirty-flag.

I assume it's some of the notebooks options, but I don't see something alike within option inspector.

POSTED BY: Werner Geiger
2 Replies
Posted 1 year ago

Basically this seems to work:

data = Style[Row[{"data = ", {1, 2, 4, 8, 16}}], Blue, Bold];

nb=CreateDocument[
  {TextCell["Some data","Chapter"],ExpressionCell[data,"Output"]}
];
SetOptions[nb, "ClosingSaveDialog" -> False];

SelectionMove[nb, After, Notebook];
NotebookWrite[nb, Cell[data2, "Output"]];

But it will not satisfy your wish below:

Only when the user edits the notebook himself, he should be prompted to save as usual.

POSTED BY: Hans Milton
Posted 1 year ago

Yes Hans, that's the problem. Actually, it's not severe. What I'm doing is:

  • Prepare the list of all cells
  • Use CreateDocument with that complete list.

Actually, I was just wondering where this "dirty-flag" is hidden, or how it can be controlled respectively.

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract