I have created a toolbar that, among other things, has an action menu button that gives me a table of contents list to navigate, see the picture bellow:
Now I'm trying to make this toolbar appear only in Working environment and disappear in printout environment. Since toolbar is a cell that has an evaluating command I wasn't able to put it directly in the stylesheet, so that I'm setting the toolbar with next command:
SetOptions[EvaluationNotebook[], DockedCells -> toolbarCell]
Usually when dealing with static DockedCells I would do this in the deffinitions of Working and Printout style cells like this:
Cell[StyleData["Notebook", "Working"], DockedCells->{toolbarCell}]
Cell[StyleData["Notebook", "Printout"], DockedCells->{}]
But, as said earlier, toolbarCell has code that searches whole notebook for section cells and makes a list from them in order to create ActionMenu buton. One option that I unsuccessfully tried was to put toolbarCell code in MiscExpressions.tr file in location C:\Program Files\Wolfram Research\Mathematica\11.0\SystemFiles\FrontEnd\TextResources and call it with command:
DockedCells -> {FEPrivate`FrontEndResource["FEExpressions","MasterToolbar"]}]
This is the way that presentation toolbar is called. But I can't seem to get it to work.
Another thing I tried was using Dynamic but still unsuccessful. Any help is more than welcome. I tried to present the problem conceptually since putting in all the code would be an overdue.
EDIT:
The main part of the code goes like this:
{Cell[
BoxData[
ToBoxes[
ActionMenu["Toc",
(*creating list of action menu item names and list of commands*)
Inner[
RuleDelayed,
(*1 create list of names*)
Composition[
Map[
(*1.3. Extract modified input text into list*)
First@FrontEndExecute@FrontEnd`ExportPacket[#, "InputText"] &],
(*1.2. read objects into an expression and replace CounterBox["typeOfCell"] with counter values*)
Map[(NotebookRead[#] /. CounterBox[style_] :>
ToBoxes@CurrentValue[#, {"CounterValue", style}]) &],
(*1.1. extract list of section cells objects to put in TOC*)
Cells[#,
CellStyle -> {"AbstractSection", "Section", "Subsection",
"Subsubsection", "ReferenceSection",
"EndnoteSection"}]&
]@EvaluationNotebook[],
(*2. create list of commands*)
Map[
Unevaluated@NotebookFind[EvaluationNotebook[], #, All, CellID] &,
CurrentValue[
Cells[CellStyle -> {"AbstractSection", "Section",
"Subsection", "Subsubsection", "ReferenceSection",
"EndnoteSection"}], CellID], 1], List]]]]]}
Now when I put the above written code as a docked cell in stylesheet I cannot close the cell when pressing ctr+shift+e and mathematica makes a beep sound while pressing the mentioned combination of keys.

ActionMenudynamic there should be no issue with it regenerating when notebooks are changed, I think. Alternatively make it dynamic, populating the actions from a symbol, then update that symbol on mouseover. No need to add it to a tr, really. If you want it as a tr make sure to useFrontEnd`FlushTextResourceCaches[]to get it to load. – b3m2a1 Jul 17 '17 at 01:51Mouseover[ActionMenu[...]]? – Milos Cipovic Jul 17 '17 at 18:38$inputNotebokTOCto whatever you like (e.g.TablesOfContents$NotebookTOCs[InputNotebook[]]). Should get the job done, clumsy though it is. The dynamic updating doesn't quite work as it should (theInputNotebookshould have caused an event to fire when editing), but that's fine. You can also wrap thatEventHandlerin aDynamicModuleto localize each$inputNotebookTOC` instance. – b3m2a1 Jul 17 '17 at 19:17SetOptions[EvaluationNotebook[], DockedCells -> Dynamic[If[CurrentValue[EvaluationNotebook[], ScreenStyleEnvironment] === "Working", toolbarCell, {}]]]works, while:SetOptions[EvaluationNotebook[], DockedCells -> Dynamic[If[CurrentValue[ScreenStyleEnvironment] === "Working", toolbarCell, {}]]]does not, and the later was the code that I used originally. – Milos Cipovic Jul 21 '17 at 21:56