There is a "OpenCloseGroup"
in FrontEndTokenExecute
. It act like toggle. If the selected cell group is open, FrontEndTokenExecute["OpenCloseGroup"]
will close cell group. If the selected cell group is closed, FrontEndTokenExecute["OpenCloseGroup"]
will open cell group.
But I want a way to explicitly open or close cell group. It is not like FrontEndTokenExecute["SelectionOpenAllGroups"]
or
FrontEndTokenExecute["SelectionCloseAllGroups"]
which will open or close all sub cell groups in any level. I want open and close one level like the FrontEndTokenExecute["OpenCloseGroup"]
does.
Update
The problem is actually equivalent to seeking an efficient way to get the open status of a cell group, then we can use FrontEndTokenExecute["OpenCloseGroup"]
.
Thanks to Alexey Popkov for many information. I found currently the most reliable way is to NotebookRead
cell data to check if it is closed or not. Here is a way
ClearAll[openSelectedCellGroup];
openSelectedCellGroup[nb_NotebookObject]:=Module[{},
If[MatchQ[NotebookRead[nb],Cell[CellGroupData[_,Closed]]],
FrontEndTokenExecute[nb,"OpenCloseGroup"]];
Though NotebookRead
seems to be inefficient if the cell group contains large data. However, my experience is that it is still workable. But again, there should better be a more efficient way to check the open-close state of cell group. Hope anyone knows.
Update 2
Alexey Popkov found a way using CurrentValue[cellObj, "CellGroupOpen"]
. Now we finally have an efficient tool for explicitly open and close cell groups! Like this function:
ClearAll[openSelectedCellGroup];
openSelectedCellGroup[nb_NotebookObject]:=Module[{},
If[CurrentValue[First@Cells[NotebookSelection[nb]],"CellGroupOpen"]===Closed,
FrontEndTokenExecute[nb,"OpenCloseGroup"]];
See my real applications here
"SelectionOpenAllGroups"
and"SelectionCloseAllGroups"
? $\endgroup$CellGroup
is open or not. Here is one way that doesn't take into account that the second argument ofCellGroupData
can be aDynamic
expression. $\endgroup$Developer`CellInformation
provides information about every cell in the selectedCellGroup
, but no information on whether the group is open or closed. $\endgroup$NotebookLocate
, it is great. But it is also bugged. It only works in the same notebook. I found if I useNotebookLocate
to locate inner folding cells in another notebook, it can not automatically open cell group $\endgroup$