11
$\begingroup$

Old versions of Mathematica had a help browser that was more click through and structured. How can I reimplement something like that for the new (since v6) docs?

$\endgroup$
13
$\begingroup$

Update

This code is no longer the most up-to-date. The properly up-to-date code is in the package on GitHub.

For a run-down of the changes between this and that see the discussion between b3m2a1 and Nasser that starts here


Update 2

This package has now been merged with the documentation search package, allowing one to perform searches and open them in an old-style browser. For example, one can search like so:

HelpPagesSearch[{
  "status" -> "ObsoleteFlag",
  "type" -> "Tutorial",
  "context" -> "System`"
  }, True]

search results

And then these links will open in the old-style help browser:

open img


Original

We'll build off of my answer here.

The basic idea will just be to make a DockedCell click through interface that will load the new pages in the notebook.

First we'll need to load and organize the data in a tree structure:

helpBrowserCoreDS :=
  helpBrowserCoreDS =
   GroupBy[
    $helpSearcherDocMetadataDS,
    Key["type"] -> KeyDrop["type"],
    GroupBy[Key["context"] -> KeyDrop["context"]]
    ];

Then we can make a little click through Dataset where we can open the doc notebooks, rather than load them in notebook:

helpBrowserDSButton[entry_, onClick_] :=
  Column[{
    Button[#,
       onClick["paclet:" <> #2, #],
       BaseStyle -> "Hyperlink",
       Appearance -> None,
       Method -> "Queued"
       ] & @@ Lookup[entry, {"title", "uri"}],
    If[StringQ@#,
       Pane[#, {400, UpTo[250]}, ImageSizeAction -> "Scrollable"],
       #
       ] &@Lookup[entry, "summary", Nothing]
    }];
helpBrowserDS[
  formatFunction_: helpBrowserDSButton,
  onClick_: Documentation`HelpLookup
  ] :=
 Map[
   Association@*
    Map[
     Lookup[#, "title"] ->
       formatFunction[#, onClick]
      &
     ]
   ] /@ helpBrowserCoreDS

This is nice for quick stuff.

Or we can build out a proper click through interface with ListPicker:

helpBrowserDockedCell[path : _List : {}] :=
  DynamicModule[
   {
    panePath = path,
    panePicker,
    coreDS,
    setNB,
    showBrowser = True
    },
   coreDS = 
    Normal@helpBrowserDS["paclet:" <> Lookup[#, {"uri"}, ""] &, 
      Null];
   panePicker =
    Function@
     With[{
       choices = #, idx = #2
       },
      ListPicker[
       Dynamic[
        If[Length@panePath >= idx, panePath[[{idx}]]],
        Function@
         Set[
          panePath,
          ReplacePart[
           If[Length@panePath >= idx,
            Take[panePath, idx],
            PadRight[panePath, idx, ""]
            ], idx -> First@#]
          ]
        ],
       choices,
       ImageSize -> {150, 150},
       Background -> {{GrayLevel[.95], White}}
       ]
      ];
   setNB =
    Function[
     CheckAll[
      FrontEndExecute@
       FrontEnd`NotebookSuspendScreenUpdates[EvaluationNotebook[]];
      SelectionMove[EvaluationNotebook[], All, Notebook];
      SetOptions[NotebookSelection[EvaluationNotebook[]], 
       Deletable -> True];
      NotebookDelete[EvaluationNotebook[]];
      With[{
        nb =
         DeleteCases[
           WindowSize | WindowMargins | DockedCells | 
             StyleDefinitions -> _]@
          Replace[Documentation`ResolveLink[#], {
            f_String?FileExistsQ :> Import[f],
            _ -> Notebook[{}]
            }]
        },
       NotebookWrite[
        EvaluationNotebook[],
        First@nb
        ];
       SetOptions[EvaluationNotebook[],
        Join[
         {
          StyleDefinitions ->

           FrontEnd`FileName[{"Wolfram"}, "Reference.nb", 
            CharacterEncoding -> "UTF-8"]
          },
         List @@ Rest@nb
         ]
        ]
       ];
      SelectionMove[EvaluationNotebook[], Before, Notebook];
      FrontEndExecute@
       FrontEnd`NotebookResumeScreenUpdates[EvaluationNotebook[]],
      FrontEndExecute@
       FrontEnd`NotebookResumeScreenUpdates[EvaluationNotebook[]]
      ];
     Nothing
     ];
   Dynamic@
    If[showBrowser,
     Column[{
       Button["Hide Browser",
        showBrowser = False,
        Appearance -> None,
        BaseStyle -> "Hyperlink"
        ],
       Row@
        Prepend[
         MapIndexed[
          Replace[
            coreDS @@ Take[panePath, #2[[1]]], {
             a_Association :> panePicker[a // Keys, #2[[1]] + 1],
             e_ :> setNB[e]
             }] &,
          panePath
          ],
         panePicker[Keys[coreDS], 1]
         ]
       }],
     Button["Show Browser",
      showBrowser = True,
      Appearance -> None,
      BaseStyle -> "Hyperlink"
      ]
     ]
   ];

helpBrowserNotebook[path : _List : {}] :=
  Notebook[{},
   DockedCells ->
    Cell[BoxData@ToBoxes@helpBrowserDockedCell[path],
     CellFrame -> {{0, 0}, {1, 0}},
     CellMargins -> None,
     CellFrameMargins -> None
     ],
   System`ClosingSaveDialog -> False,
   Saveable -> False,
   WindowTitle -> "Help Browser"
   ];

And finally a top-level function to implement this:

OpenHelpBrowser[path : _List : {}] :=

 If[MatchQ[$helpBrowser, _NotebookObject?(NotebookRead[#] =!= $Failed \
&)],
  SetOptions[$helpBrowser, {
    WindowFloating -> True,
    Visible -> True
    }];
  SetOptions[$helpBrowser, WindowFloating -> False],
  $helpBrowser = CreateDocument@helpBrowserNotebook[]
  ]

And when we run this:

OpenHelpBrowser[]

NotebookObject[FrontEndObject[LinkObject["w7er3_shm", 3, 1]], 59]

interface

Finally I packaged this all up here so you can use it like:

Get["https://raw.githubusercontent.com/b3m2a1/mathematica-tools/master/OldHelpBrowser.wl"];
OpenHelpBrowser[]

Note it'll be very slow the first time while it builds the index, but then it caches it every usage after that will be fast.

$\endgroup$

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.