Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SetOptions[EvaluationNotebook[], DockedCells -> Cell[#, "Output", CellMargins -> 0]] &@
- BoxData@ToBoxes@
- With[{GetTOC =
- Cases[NotebookGet@SelectedNotebook[],
- Cell[name_, style : "Section" | "Subsection" | "Subsubsection", ___] :> {style, name},
- Infinity] /. {"Subsubsection", x_} :> x[] //.
- {x___, {"Subsection", y_}, z : Except[_List] ...,
- w : PatternSequence[{_, _}, ___] | PatternSequence[]} :> {x, y[z], w} //.
- {x___, {"Section", y_}, z : Except[_List] ...,
- w : PatternSequence[{_, _}, ___] | PatternSequence[]} :> {x, y[z], w} &},
- DynamicModule[{TOC = GetTOC[]}, Row@
- {Button["Update", TOC = GetTOC[]],
- Dynamic@Refresh[" " <> StringJoin @@ (ToString[#] <> "." & /@ #) <>
- " " <> If[Length[#] == 0, "",
- Head@Catch@Fold[If[Length[#] >= #2, #[[#2]], Throw[#]] &, TOC, #]] &[
- CurrentValue[NotebookSelection[], {"CounterValue", #}] & /@
- {"Section", "Subsection", "Subsubsection"} /. {x___, 0 ...} :> {x}],
- UpdateInterval -> 1]}]]
- Button["press", Print @ FrontEndExecute @ FrontEnd`CellInformation[NotebookSelection[]]]
- current = First @ Cells[ExpressionUUID -> "a4103240-2c81-4d64-90fc-deb0941ca4a0"]
- PreviousCell[current, CellStyle->"Section"]
- Dynamic[FrontEndExecute @ FrontEnd`CellInformation[NotebookSelection[]]]
- Dynamic[{
- CurrentValue[NotebookSelection[], CellStyle],
- FrontEndExecute @ FrontEnd`CellInformation[NotebookSelection[]]
- }]
- SetOptions[
- EvaluationNotebook[],
- StyleDefinitions -> Notebook[
- {
- Cell[StyleData[StyleDefinitions->"Default.nb"]],
- Cell[StyleData["Notebook"],
- DockedCells->Cell[BoxData @ ToBoxes @ Dynamic[
- Row@{
- CurrentValue[NotebookSelection[],{"CounterValue","Section"}],
- Replace[CurrentValue[NotebookSelection[],{"CounterValue","Subsection"}],{0->Sequence[],n_->Sequence[".",n]}],
- ": ",
- Replace[Cell[a_,__]:>RawBoxes@Cell[a]] @ With[
- {cell=First[Cells[ExpressionUUID->OptionValue[FrontEndExecute@FrontEnd`CellInformation[FrontEnd`SelectionObject],ExpressionUUID]],{}]},
- Which[
- cell==={},
- "",
- MemberQ[CurrentValue[cell,CellStyle],"Section"|"Subsection"],
- NotebookRead[cell],
- True,
- NotebookRead[PreviousCell[cell,CellStyle->{"Section","Subsection"}]]
- ]
- ]
- }
- ],
- TextAlignment->Center
- ]
- ]
- },
- StyleDefinitions->"PrivateStylesheetFormatting.nb"
- ]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement