Change style of cell if group collapses?
I haven't figured out how to do this with styles yet but I feel as though I have made significant progress and I want to share it. Please try:
t1 = True;
Notebook[{Cell[
CellGroupData[{
Cell["Parent", "Section",
Background -> Dynamic[If[t1, LightRed, LightBlue]]],
Cell["Fee", "Subsection"],
Cell["Fi", "Subsection"],
Cell["Fo", "Subsection"],
Cell["Fum", "Subsection"]
}, Dynamic[t1]]
]}] // NotebookPut
Here is a style sheet solution:
Notebook[
{
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Section"],
ShowGroupOpener->True,
CellContext->Cell,
CellDynamicExpression :> With[{cell = NotebookRead[EvaluationCell[]]},
NotebookWrite[EvaluationCell[], Cell[""], All];
NotebookWrite[
EvaluationNotebook[],
Cell @ CellGroupData[
{
Replace[cell,
Cell[b_, "Section", ___] :>
Cell[b, "Section",
CellDynamicExpression:>None,
Background->Dynamic[If[open, White, LightBlue]]
]
]
},
Dynamic[open]
]
];
FrontEndTokenExecute["MovePrevious"]
]
]
},
Saveable->False,WindowSize->{808,689},WindowMargins->{{Automatic,143},{40,Automatic}},
FrontEndVersion->"10.3 for Mac OS X x86 (32-bit, 64-bit Kernel) (December 10, 2015)",
StyleDefinitions->"PrivateStylesheetFormatting.nb"
];
NotebookPut @ %;
The first NotebookWrite
is a hack so that the second NotebookWrite
actually does what I want, which is to create a CellGroupData
object with a Dynamic
in it's second argument.