Message Boards Message Boards

Make an index with a popup menu?

Posted 7 years ago

I am looking for san index, small and versatil, like a popup menu, may be with hyperlinks. I have a few notebooks, say nb1, nb2, nb3, nb4. I would like to make small "Index" with a popupmenu so that when a clicked in each item,l abeled nb1, nb2,..., then the respective notebook open.

I've been very cheeky trying to create some code, but of course this far from working well. My code is

DynamicModule[{var = "nb1.nb", 
  nb1lst = {"nb1.nb", "nb2.nb", "nb3.nb", "nb4.nb"}},
 Column[{
   PopupMenu[
    Dynamic[var], {1 -> "nb1", 2 -> "nb2", 3 -> "nb3", 4 -> "nb4"}],
   PaneSelector[{
     1 -> 
      Dynamic@NotebookOpen[
        FileNameJoin[{NotebookDirectory[], 
          TextString[nb1lst[[var]]]}]],
     2 -> 
      Dynamic@NotebookOpen[
        FileNameJoin[{NotebookDirectory[], 
          TextString[nb1lst[[var]]]}]],
     3 -> 
      Dynamic@NotebookOpen[
        FileNameJoin[{NotebookDirectory[], 
          TextString[nb1lst[[var]]]}]],
     4 -> 
      Dynamic@NotebookOpen[
        FileNameJoin[{NotebookDirectory[], 
          TextString[nb1lst[[var]]]}]]},
    Dynamic[var]]}]
 ]

Well, can you help me?

POSTED BY: W Mora
2 Replies

You can do this more simply with:

    ActionMenu["Choose a File...", {
    "nb1.nb" :> NotebookOpen[FileNameJoin[{NotebookDirectory[], "nb1.nb"}]], 
    "nb2.nb" :> NotebookOpen[FileNameJoin[{NotebookDirectory[], "nb2.nb"}]], 
    "nb3.nb" :> NotebookOpen[FileNameJoin[{NotebookDirectory[], "nb3.nb"}]]}]

or if you want to dynamically create the actions:

Module[{nblist = {"nb1.nb", "nb2.nb", "nb3.nb"}}, 
 ActionMenu["Choose a File...", 
  MapThread[
   RuleDelayed, {nblist, 
    Unevaluated[
       NotebookOpen[FileNameJoin[{NotebookDirectory[], #}]]] & /@ 
     nblist}] ]]

The Action Menu list is created by joining the file path to each filename in the list, nblist. The NotebookOpen command must be delayed (with Unevaluated) or it tries to act immediately. The MapThread[RuleDelayed... creates the list of rules so it looks like the first version.

Some other interface wizards on this forum may be able to make this even simpler, but that is my first take...

Regards

POSTED BY: Neil Singer
Posted 7 years ago

Thanks, that is that I was looking for.

POSTED BY: W Mora
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract