我修改了我的笔记本的样式表,以包含一个StyleData["Todo"]继承自的样式表StyleData["Item"].它将单元格dingbat更改为复选框.在样式表编辑器中:
Cell[StyleData["ToDo", StyleDefinitions -> StyleData["Item"]],
CellDingbat->DynamicModuleBox[{$CellContext`color$$},
CheckboxBox[
Dynamic[$CellContext`color$$], {RGBColor[1, 0.5, 0],RGBColor[0,Rational[2, 3], 0]},
Background -> Dynamic[$CellContext`color$$]],
DynamicModuleValues :> {}
],
]
Run Code Online (Sandbox Code Playgroud)
问题是,当在笔记本中使用时,复选框的状态不会保存在Mathematica会话之间.我以为DynamicModule[]会做到这一点.如何让复选框记住其状态?
编辑
Simon的解决方案确实保存了复选框的状态,但是当用作CellDingbat(MacOS X)时,复选框会被剪切.将Simon的代码放在CellFrameLabels选项中可以解决问题,并保留默认的"Item"CellDingbat.这就是我的用处:
Cell[StyleData["ToDo", StyleDefinitions -> StyleData["Item"]],
CellFrameLabels->{{
ButtonBox[
CheckboxBox[False], ButtonFunction :> (SelectionMove[
ButtonNotebook[], All, ButtonCell];
With[{$CellContext`new = ReplaceAll[
Options[
NotebookSelection[
ButtonNotebook[]], CellFrameLabels], CheckboxBox[
Pattern[$CellContext`x,
Alternatives[True, False]]] :> CheckboxBox[
Not[$CellContext`x]]]},
SetOptions[
NotebookSelection[
ButtonNotebook[]], $CellContext`new]]; SelectionMove[
ButtonNotebook[], After, CellContents]), Appearance -> None,
Method -> "Preemptive", Evaluator -> Automatic], None}, {
None, None}},
MenuSortingValue->1621]
Run Code Online (Sandbox Code Playgroud)