Re: Disabling Groups of Cells
- To: mathgroup at smc.vnet.net
- Subject: [mg44867] Re: Disabling Groups of Cells
- From: AES/newspost <siegman at stanford.edu>
- Date: Thu, 4 Dec 2003 03:04:28 -0500 (EST)
- References: <bovf8u$l2c$1@smc.vnet.net> <bqkbhi$hn6$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <bqkbhi$hn6$1 at smc.vnet.net>, juliuscarver at hotmail.com (Julius Carver) wrote: > Ok man, i read your post and found it interesting. Here is my > solution: Thanks much, that's very much the kind of thing I wanted to do, and I'll try your approach as soon as I get a chance (I was a little intimidated by the idea of trying this sort of recursive approach myself). Actually, when I think more about what I want to do, it's most likely to be disabling an entire notebook containing a lot of sections, then enabling only the small subset of sections that I want to execute. So, I could reasily disable all the Input cells using Option-Select and the menu Disable command, then use your button approach to Enable those few sections I wanted to run. Thanks again. > > 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 >