The behaviour is indeed inconsistent: CreateDialog
uses the option WindowSize -> All
, where All
(god knows why) causes the unexpected behaviour with dynamic content. See resolution of the problem at the end of the post.
The following even more simple example clearly shows that something fishy is going on: only path2
can be set via the second button but not path1
:
DynamicModule[{path1 = "path #1", path2 = "path #2"},
CreateDialog@Grid@{
{FileNameSetter[Dynamic@path1,
"Open", {"Mathematica Notebook" -> {"*.nb"}}], Dynamic@path1},
{FileNameSetter[Dynamic@path2,
"Open", {"Excel files" -> {"*.xls", "*.xlsx"}}], Dynamic@path2}
}];
Removing the CreateDialog
wrapper causes both FileNameSetter
s to work as expected, which indicates that it is the special context of the dialog window that causes the erroneous behaviour. Since CreateDialog[expr]
is just a specialized CreateWindow[DocumentNotebook[expr]]
, we have to look at the options CreateDialog
uses as defaults for its internal CreateWindow
. As it turns out, the blame lies with WindowSize
. Compare the behavior of the following two examples where only the value of WindowSize
differs.
This is faulty:
DynamicModule[{path1 = "path #1", path2 = "path #2"},
CreateWindow[DocumentNotebook@Grid@{
{FileNameSetter[Dynamic@path1,
"Open", {"Mathematica Notebook" -> {"*.nb"}}], Dynamic@path1},
{FileNameSetter[Dynamic@path2,
"Open", {"Excel files" -> {"*.xls", "*.xlsx"}}], Dynamic@path2}
}, WindowSize -> All]]
This works as expected:
DynamicModule[{path1 = "path #1", path2 = "path #2"},
CreateWindow[DocumentNotebook@Grid@{
{FileNameSetter[Dynamic@path1,
"Open", {"Mathematica Notebook" -> {"*.nb"}}], Dynamic@path1},
{FileNameSetter[Dynamic@path2,
"Open", {"Excel files" -> {"*.xls", "*.xlsx"}}], Dynamic@path2}
}, WindowSize -> {200, 200}]]
And then I remembered: Strange behavior of CreateDialog in (Dynamic)Module
The options for CreateWindow
(to make it look like it is a dialog) are:
{WindowSize -> {200, 200}, Deployed -> True, ShowCellBracket -> False,
WindowFloating -> False, StyleDefinitions -> "Dialog.nb",
WindowFrame -> "ModelessDialog"}