Function Repository Resource:

NotebookBlockingDialog

Source Notebook

Create a dialog on top of the current notebook

Contributed by: Bob Sandheinrich and Richard Hennigan

ResourceFunction["NotebookBlockingDialog"][NotebookObject[],dialog]

blocks the notebook with dialog.

ResourceFunction["NotebookBlockingDialog"][dialog]

blocks the current notebook with dialog.

ResourceFunction["NotebookBlockingDialog"][NotebookObject[]]

uses a default dialog.

ResourceFunction["NotebookBlockingDialog"]["Exit"]

when used within a blocking dialog, closes that dialog.

Details

Typical dialog expressions include: DialogNotebook, PaletteNotebook and Panel.
The dialog should always contain a button which either closes the notebook or uses NotebookButtonDialog["Exit"] to close the dialog.
Using default dialog buttons can result in a notebook with leftover attached cells and background color.
ResourceFunction["NotebookBlockingDialog"] does not perform well in Wolfram Cloud notebooks.
Some people constantly have dozens of notebooks open and keeping track of free floating dialog windows is difficult. This keeps the dialog with its parent notebook.

Examples

Basic Examples (2) 

Create a new notebook and block it with a default dialog:

In[1]:=
ResourceFunction["NotebookBlockingDialog"]@NotebookPut[]
Out[1]=

Create a notebook that prompts a user for a name and closes the dialog using NotebookBlockingDialog["Exit"]:

In[2]:=
name = nm = "Your name here";
ResourceFunction["NotebookBlockingDialog"][
 CreateDocument[{Dynamic[name]}],
 Panel[Column@{InputField[Dynamic[nm], String],
    Button["Done", name = nm;
     ResourceFunction["NotebookBlockingDialog"]["Exit"]]}]
 ]
Out[2]=

Scope (1) 

Block a definition notebook with a dialog that closes the notebook:

In[3]:=
ResourceFunction["NotebookBlockingDialog"][
 CreateNotebook["FunctionResource"], DialogNotebook[{TextCell[
    "Do you really think you can do better than bird say?"], Button["Nevermind", NotebookClose[EvaluationNotebook[]]]}, WindowElements -> {}, WindowFrame -> "Frameless"]
 ]
Out[3]=

Possible Issues (2) 

Using DefaultButton instead of NotebookBlockingDialog["Exit"] will close the entire notebook when the button is clicked:

In[4]:=
ResourceFunction["NotebookBlockingDialog"][CreateNotebook[], DialogNotebook[{TextCell["Click OK to close"], DefaultButton[]}]]
Out[4]=

Use NotebookBlockingDialog["Exit"] within DefaultButton instead:

In[5]:=
ResourceFunction["NotebookBlockingDialog"][CreateNotebook[], DialogNotebook[{TextCell["Click OK to close"], DefaultButton[
    ResourceFunction["NotebookBlockingDialog"]["Exit"]]}]]
Out[5]=

Publisher

Bob

Version History

  • 1.0.0 – 24 August 2021

Related Resources

Author Notes

Styling of the default dialog could be much better.

License Information