0
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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...

$\endgroup$
  • $\begingroup$ Oh, yeah! Pane is great, get new skill. Thank you so much $\endgroup$ – matheorem Jan 24 '18 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.