0

I have a dynamicSelectDir which serves as dynamic select folders

ClearAll[dynamicSelectDir];
Attributes[dynamicSelectDir]=HoldFirst;
dynamicSelectDir[dirVariable_,baseDir_]:=DynamicModule[{tmpDirVar=baseDir},
ClearAll[dirVariable];
Manipulate[
dirVariable=tmpDirVar;
SetDirectory[tmpDirVar];
Column[{"sub directorys",
SetterBar[Dynamic[tmpDirVar],Select[DirectoryQ]@FileNames["*",tmpDirVar],Appearance->"Vertical"]}],
Button["reset to baseDir",tmpDirVar=baseDir],
Button["cd ..",tmpDirVar=ParentDirectory[tmpDirVar]],
{i,1,1}]]

The interface is something like

enter image description here

A naive way to make it a palette is simply warp Manipulate into CreatePalette like this

ClearAll[dynamicSelectDir];
Attributes[dynamicSelectDir]=HoldFirst;
dynamicSelectDir[dirVariable_,baseDir_]:=DynamicModule[{tmpDirVar=baseDir},
ClearAll[dirVariable];
CreatePalette[Manipulate[
dirVariable=tmpDirVar;
SetDirectory[tmpDirVar];
Column[{"sub directorys",
SetterBar[Dynamic[tmpDirVar],Select[DirectoryQ]@FileNames["*",tmpDirVar],Appearance->"Vertical"]}],
Button["reset to baseDir",tmpDirVar=baseDir],
Button["cd ..",tmpDirVar=ParentDirectory[tmpDirVar]],
{i,1,1}]],WindowSize->{Fit,Fit},WindowElements->{"VerticalScrollBar","HorizontalScrollBar"}]

However, there is a problem. If the folder list is too long, the palette won't show, even if I already added {"VerticalScrollBar","HorizontalScrollBar"}. There is no scrollBar!!

enter image description here

How to make a scrollable palette for my function?

matheorem
  • 17,132
  • 8
  • 45
  • 115

1 Answers1

2

I would throw in a Pane for the scrollbars:

ClearAll[dynamicSelectDir];

Attributes[dynamicSelectDir]=HoldFirst;

dynamicSelectDir[dirVariable_,baseDir_]:=
  DynamicModule[        
    {tmpDirVar=baseDir},        
    ClearAll[dirVariable];
    CreatePalette[
        Manipulate[                             
            dirVariable=tmpDirVar;
            SetDirectory[tmpDirVar];
            Pane[                   
                Column[
                    {                           
                        "sub directorys",
                        SetterBar[                              
                            Dynamic[tmpDirVar],
                            Select[DirectoryQ]@FileNames["*",tmpDirVar],
                            Appearance->"Vertical"
                        ]
                    }
                ],
                {700,300},
                Scrollbars->Automatic
            ],
            Button["reset to baseDir",tmpDirVar=baseDir],
            Button["cd ..",tmpDirVar=ParentDirectory[tmpDirVar]],
            {i,1,1}
        ]
    ],
    WindowElements->{}
]

I guess you are aware of SystemDialogInput["Directory"]? Wouldn't that give a more conventional user interface for the same purpose? If you have reasons to rewrite that, I would suggest to rewrite this with DynamicModule instead of Manipulate, it doesn't really give you any advantages here in my opinion...

Albert Retey
  • 23,585
  • 60
  • 104