Re: Disabling Groups of Cells
- To: mathgroup at smc.vnet.net
- Subject: [mg44844] Re: Disabling Groups of Cells
- From: juliuscarver at hotmail.com (Julius Carver)
- Date: Wed, 3 Dec 2003 04:24:38 -0500 (EST)
- References: <bovf8u$l2c$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ok man, i read your post and found it interesting. Here is my
solution:
Let's assume I've selected interactively the section that I want to
disable. Then I move the selection to the last cell of the section
with
SelectionMove[nb, After, Cell]; SelectionMove[nb, Previous, Cell]
where nb denotes the notebook where the section is placed.
After that I apply this recursive process
While[Not[MatchQ[NotebookRead[nb], Cell[__, "Section", ___]]],
If[MatchQ[NotebookRead[nb], Cell[__, "Input", ___]],
SetOptions[NotebookSelection[nb], Evaluatable -> False]];
SelectionMove[nb, Previous, Cell]]
With this cycle i look for input cells in the section from bottom to
top, and tell Mathematica to change the option Evaluatable of these
cells to False. As you can see, While does not stop until it finds a
cell of style "Section".
Finally, as you want enable and disable only sections, I define the
next command to make sure that the process will only be applied when
you have selected an entire section
MatchQ[NotebookRead[nb], Cell[CellGroupData[{Cell[_, "Section"], __},
_]]]
This gives True if a section is selected and false otherwise. Putting
the pieces together we obtain
If[MatchQ[NotebookRead[nb], Cell[CellGroupData[{Cell[_, "Section"],
__}, _]]],
SelectionMove[nb, After, Cell];
SelectionMove[nb, Previous, Cell];
While[Not[MatchQ[NotebookRead[nb], Cell[__, "Section", ___]]],
If[MatchQ[NotebookRead[nb], Cell[__, "Input", ___]],
SetOptions[NotebookSelection[nb], Evaluatable -> False]];
SelectionMove[nb, Previous, Cell]]]
Of course, the most simple way of using this code is to feed a button
with it, so i put it in this palette
Cell[BoxData[
GridBox[{{ButtonBox["Disable",
ButtonFunction :>
Module[{nb}, nb = SelectedNotebook[];
If[MatchQ[NotebookRead[nb],
Cell[CellGroupData[{Cell[_, "Section"], __},
_]]],
SelectionMove[nb, After, Cell];
SelectionMove[nb, Previous, Cell];
While[\[InvisibleSpace]! (MatchQ[NotebookRead[nb],
Cell[__, "Section", ___]]),
If[MatchQ[NotebookRead[nb], Cell[__, "Input",
___]],
SetOptions[NotebookSelection[nb],
Evaluatable -> False]];
SelectionMove[nb, Previous, Cell]]]],
ButtonEvaluator -> Automatic, Active -> True]},
{ButtonBox[
"Enable",
ButtonFunction :>
Module[{nb}, nb = SelectedNotebook[];
If[MatchQ[NotebookRead[nb],
Cell[CellGroupData[{Cell[_, "Section"], __},
_]]],
SelectionMove[nb, After, Cell];
SelectionMove[nb, Previous, Cell];
While[\[InvisibleSpace]! (MatchQ[NotebookRead[nb],
Cell[__, "Section", ___]]),
If[MatchQ[NotebookRead[nb], Cell[__, "Input",
___]],
SetOptions[NotebookSelection[nb],
Evaluatable -> True]];
SelectionMove[nb, Previous, Cell]]]],
ButtonEvaluator -> Automatic, Active -> True]}}]]] //
CellPrint
Hope this helps
Julius