# Problems with visual update in GUI

Consider the following. When clicking in "Browse" and then choosing a file, the path will remain the original one and won't change to the one of the file I chose:

nb = EvaluationNotebook[];

DynamicModule[
{path1 = FileNameJoin[{$HomeDirectory, "Desktop", "file.nb"}], path2 = FileNameJoin[{$HomeDirectory, "Desktop", "file.xls"}]},
CreateDialog[
Column[{Row[{InputField[Dynamic[path1], String, Enabled -> False],
FileNameSetter[Dynamic[path1],
"Open", {"Mathematica Notebook" -> {"*.nb"}}]}],
Row[{InputField[Dynamic[path2], String, Enabled -> False],
FileNameSetter[Dynamic[path2],
"Open", {"Excel files" -> {"*.xls", "*.xlsx"}}]}]}],
NotebookEventActions :> {"WindowClose" :> (SetOptions[nb,
Visible -> True])}]
]

-
John, before you post a question you should try to narrow down the problem to the shortest section of code that displays it as I have done for you. You will get a much better response to your questions if readers do not have as much code to wade through. This is a good question, by the way, and has my vote! –  Mr.Wizard Jun 30 '12 at 8:23

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 FileNameSetters 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}]]


The options for CreateWindow (to make it look like it is a dialog) are:
{WindowSize -> {200, 200}, Deployed -> True, ShowCellBracket -> False,