From: Vincent on
As I understand it, DynamicModule can be used to make a variable
maintain it's value across sessions, so that even if I close down
Mathematica and open it up again, the values localized by
DynamicModule should still work, using this with dynamic controls
works fine for me, however when I try to localize a directory path,
and use FileNameSetter to set the path, the button breaks whenever I
reopen Mathematica.
Does anyone have a good understanding of why this happens and could
help to avoid it?

Sample code:
DynamicModule[{dir}, {FileNameSetter[Dynamic[dir]],
Button["Home", dir = "Specific Dir"], Dynamic[dir]}]

The button works fine after a restart, it's only FileNameSetter which
stops working.

From: John Fultz on
Yes, I can reproduce the problem, and it's a bug (specifically with
FileNameSetter...it doesn't have anything to do with DynamicModule). Somewhat
surprisingly, it seems that the bug had never been reported before. I reported
the issue, and developed a workaround you can use. It just requires that you
add an Initialization option a DynamicModule encapsulating FileNameSetter. Like
so:

DynamicModule[{dir}, {FileNameSetter[Dynamic[dir]],
Button["Home", dir == "Specific Dir"], Dynamic[dir]},
Initialization :> MakeBoxes[FileNameSetter[], StandardForm]]

Sincerely,

John Fultz
jfultz(a)wolfram.com
User Interface Group
Wolfram Research, Inc.


On Mon, 7 Jun 2010 08:05:50 -0400 (EDT), Vincent wrote:
> As I understand it, DynamicModule can be used to make a variable
> maintain it's value across sessions, so that even if I close down
> Mathematica and open it up again, the values localized by
> DynamicModule should still work, using this with dynamic controls
> works fine for me, however when I try to localize a directory path,
> and use FileNameSetter to set the path, the button breaks whenever I
> reopen Mathematica.
> Does anyone have a good understanding of why this happens and could
> help to avoid it?
>
> Sample code:
> DynamicModule[{dir}, {FileNameSetter[Dynamic[dir]],
> Button["Home", dir == "Specific Dir"], Dynamic[dir]}]
>
> The button works fine after a restart, it's only FileNameSetter which
> stops working.