Re: hyperlink back button
- To: mathgroup at smc.vnet.net
- Subject: [mg105840] Re: [mg105676] hyperlink back button
- From: Dan Dubin <ddubin at ucsd.edu>
- Date: Mon, 21 Dec 2009 03:31:56 -0500 (EST)
OK, here I am back again, with a partial answer to my own question about hyperlinks and a better back button. I have designed such a back button and present it below for the group's amusement. It works, but my new hyperlink and backbutton require a running kernel, unlike regular hyperlinks . Any ideas on how to make this work better, say, using only the Front End? Anyway, I first had to change the hyperlink button function from a simple NotebookLocate call to a user-defined function backbutton`g. Here is the new version of the hyperlink style, called Hyperlink1. This should be evaluated and the result pasted into the notebook's style sheet CellPrint[Cell[StyleData["Hyperlink1", StyleDefinitions -> StyleData["Link"]], FontColor->RGBColor[0, 0.8, 0.6], ButtonBoxOptions->{ButtonFunction:>Function[x, backbutton`g[x]], Method->"Queued"}]] The function backbutton`g remembers the CellTag of the cell in which the hyperlink sits; and if there is no such CellTag, adds one (using the MousePosition as the tag.) It places the celltag of the hyperlink into a variable backbutton`alist. Only then does it call NotebookLocate to jump to the new location. backbutton`g[x_] := Module[{a, b, a2, a21}, (b = ButtonNotebook[]; SelectionMove[b, All, ButtonCell]; SelectionMove[b, All, Cell]; a2 = CellTags /. Options[NotebookSelection[b], "CellTags"]; If[ListQ[a2], If[Length[a2] == 0, a = MousePosition["DocumentAbsolute"]; a21 = ToString[a]; SetOptions[NotebookSelection[b], CellTags -> a21]; backbutton`alist = {"CellTags", a21}, backbutton`alist = {"CellTags", a2[[1]]}], backbutton`alist = {"CellTags", a2}]; NotebookLocate[x])] This function has to be pre-defined for the hyperlink to work, maybe in an initialization cell. The backbutton is created via SetOptions[EvaluationNotebook[], DockedCells -> {Cell[ BoxData[ButtonBox["back", Evaluator -> Automatic, ButtonFunction :> (If[Length[backbutton`alist] == 2, NotebookLocate[backbutton`alist[[2]]]] &) ]], "Text", Background -> LightGray]}] Finally, here is a hyperlink connected to a cell with a tag, for test purposes: CellPrint[Cell["cell with tag", "Text", CellTags->"tag"]] CellPrint[ Cell[BoxData[ ButtonBox["hyperlink", ButtonData -> "tag", Evaluator -> Automatic, BaseStyle -> "Hyperlink1"]]]] As I said, this all works, but needs a running kernel. Also, the backbutton`g function needs to be pre-defined. Again, none of this would be necessary if the current back button worked properly, the way mine does. Any ideas for improvement would be appreciated. Happy holidays! --Dan Dubin >Happy holidays, folks. I have a question about hyperlinks and the >back button. The following command creates a docked cell with a back >button: > >SetOptions[EvaluationNotebook[], > DockedCells -> {Cell[ > BoxData[ToBoxes[ > Button["back", > FrontEnd`FrontEndExecute[ > FrontEnd`FrontEndToken[ButtonNotebook[], "HyperlinkGoBack"]], > Evaluator -> None]]], "DockedCell"]}] > > >However, this button does not work quite the way I would like it to >(nor does Mathematica's back button in the toolbar). After I click >on a hyperlink that takes me somewhere in a document, I want my back >button to take me back to where I was before I clicked the link. This >only happens if a list of previously-used hyperlinks is empty; >otherwise the back button takes one to the last-used hyperlink, not >back to the previous location. The history list is apparently in >FEPrivate`HistoryList["Back"], but I cannot clear that list, or even >see what is in it. > >Does anyone know how to get at/modify this list, or barring that, >create a back button that functions as I described? > > --cheers -- Dan Dubin >-- -- Professor Dan Dubin Dept. of Physics, UCSD La Jolla CA 92093-0319 ddubin at ucsd.edu (858)-534-4174 fax: (858)-534-0173