Easy button or hot key to switch between `Working` and `SlideShow` Screen Environments to avoid trip to menu

You can use NotebookEventActions

SetOptions[EvaluationNotebook[], 
 NotebookEventActions :> {{"KeyDown", "s"} :> SetOptions[EvaluationNotebook[], 
     ScreenStyleEnvironment -> "SlideShow"], {"KeyDown", "w"} :> 
    SetOptions[EvaluationNotebook[], ScreenStyleEnvironment -> "Working"]}]

This is rudimentary so you can play around and choose your keys etc. but it seems to do what you want (it worked ok for me with 8.0.4 on OS X 10.6.8).

Note that NotebookEventActions can be set globally in the options inspector so you can paste:

{{"KeyDown", "s"} :> SetOptions[EvaluationNotebook[], 
         ScreenStyleEnvironment -> "SlideShow"], {"KeyDown", "w"} :> 
        SetOptions[EvaluationNotebook[], ScreenStyleEnvironment -> "Working"]}

into the options inspector. I just tried this and it works fine -- hopefully there are no unintended consequences so use at your own risk. :)

Edit

When I wrote this answer I chose "s" and "w" keys for "slideshow" and "working" just for example. Clearly it is not practical to tie up the "s" and "w" keys at the notebook level. However the next day I tried to make these event keys function keys and couldn't get it to work so contacted WRI tech support. They advise that there is no (documented) way to use the shift, option, control, and function keys with EventHandler. Further they said there is no way to use key combinations with EventHandler.

So therefore the stylesheet method that I posted the other day looks like the best way to (practically) achieve what you want.


Here is a docked cell solution that can be added to a stylesheet:

Firstly make the docked cell grid. I'm using PaneSelector rather than If to choose how to layout the docked cell. An alternative is to create two separate docked cells, one for working and one for slideshow. This seems easier.

grid = DynamicModule[{slideshow = False},

  PaneSelector[{

    True -> Grid[{
       {Button[Graphics[{GrayLevel[0.3], Disk[]}, ImageSize -> 30],
         (FEPrivate`NotebookToggleFullScreen[]; {}),
         Appearance -> None],

        Style[Row[{

           Button["\[FirstPage]", 
            FrontEndTokenExecute[ButtonNotebook[], "ScrollPageFirst"],
             Appearance -> "Palette"], 
           Button["\[LeftPointer]", 
            FrontEndTokenExecute[ButtonNotebook[], 
             "ScrollPagePrevious"], Appearance -> "Palette"],

           Button["\[RightPointer]", 
            FrontEndTokenExecute[ButtonNotebook[], "ScrollPageNext"], 
            Appearance -> "Palette"], 
           Button["\[LastPage]", 
            FrontEndTokenExecute[ButtonNotebook[], "ScrollPageLast"], 
            Appearance -> "Palette"]}],
         DefaultOptions -> {
           Button -> {
             BaseStyle -> {FontSize -> 25, GrayLevel[0.3]},
             FrameMargins -> 0,
             ImageMargins -> 0,
             ImageSize -> 20}
           }
         ],

        DynamicModule[{cells = {}, tagFind = False},

         EventHandler[
          Dynamic[
           PopupMenu[Dynamic[0, With[{nb = ButtonNotebook[]},

               SelectionMove[nb, Before, Notebook, 
                AutoScroll -> False];
               If[tagFind,

                Do[NotebookFind[nb, "SlideShowHeader", Next, CellTags,
                   AutoScroll -> False], {#}], 
                Do[NotebookFind[nb, "SlideShowNavigationBar", Next, 
                  CellStyle, AutoScroll -> False], {#}]
                ];
               SelectionMove[nb, After, Cell, AutoScroll -> False];

               NotebookWrite[nb, 
                Cell["", Deletable -> True, ShowCellBracket -> False],
                 All];
               NotebookDelete[nb];

               SelectionMove[nb, If[tagFind, Previous, Next], 
                Cell]] &
             ], cells,
            Style[Row[{

               Dynamic[
                CurrentValue[{"CounterValue", 
                  "SlideShowNavigationBar"}]], 

               Dynamic[
                FrontEndResource["SlideshowToolbarText", 
                 "SlideshowToolbarCounterText"]], 
               Dynamic[
                CurrentValue[{"MaxCounterValue", 
                  "SlideShowNavigationBar"}]]
               }], "ControlStyle"],
            Appearance -> None,
            ImageSize -> Automatic]
           ],
          {"MouseDown" :> Module[{cnt, nb = InputNotebook[]},
             cells = {};

             cnt = Apply[(NotebookFind[nb, #1, All, #2, 
                  AutoScroll -> False]; 
                 CurrentValue[
                  nb, {"CellCount", 
                   True}]) &, {{"SlideShowNavigationBar", 
                 CellStyle}, {"SlideShowHeader", CellTags}}, {1}];
             cnt = (If[tagFind = #1 == 0, #2, #1] &) @@ cnt;

             SelectionMove[nb, Before, Notebook, 
              AutoScroll -> False];

             If[tagFind, 
              cells = (#1 -> "Slide " <> ToString[#1] &) /@ 
                Range[cnt], 
              Do[NotebookFind[nb, "SlideShowNavigationBar", Next, 
                CellStyle, AutoScroll -> False]; 
               SelectionMove[nb, Next, Cell, AutoScroll -> False]; 

               AppendTo[cells, 
                NotebookRead[nb] /. 
                 s_Style :> 
                  With[{ss = 
                    Join[Take[s, 1], 
                    DeleteCases[Rest[s], _String | _[FontColor, _]]]},
                    ss /; True]], {cnt}]; 
              cells = 
               Replace[
                cells[[All, 1]], {BoxData[c_] :> c, 
                 TextData[c_] :> Row[If[ListQ[c], c, {c}]]}, 1]; 
              cells = Thread[Range[cnt] -> cells]]]},
          PassEventsDown -> True,
          EvaluationOrder -> Before,
          PassEventsUp -> True]
         ],
        EventHandler[
         Pane[
          Style[Dynamic@
            If[TrueQ[slideshow], "Switch to Working", 
             "Switch to Slideshow"], FontFamily -> "Arial", 14], {150,
            30}, Alignment -> {Center, Center}],
         {"MouseClicked" :> If[TrueQ[slideshow],

            SetOptions[InputNotebook[], 
             ScreenStyleEnvironment -> "Working"]; 
            slideshow = ! slideshow,

            SetOptions[InputNotebook[], 
             ScreenStyleEnvironment -> "SlideShow"]; 
            slideshow = ! slideshow]}]
        }},
      AutoDelete -> False,
      Alignment -> {{Left, Center, Right}, Center},
      ItemSize -> {Automatic, Fit, Automatic},
      Spacings -> 3],

    False -> Grid[{
       {Button[Graphics[{GrayLevel[0.3], Disk[]}, ImageSize -> 30],
         (FEPrivate`NotebookToggleFullScreen[]; {}),
         Appearance -> None],

        EventHandler[
         Pane[
          Style[Dynamic@
            If[TrueQ[slideshow], "Switch to Working", 
             "Switch to Slideshow"], FontFamily -> "Arial", 14], {150,
            30}, Alignment -> {Center, Center}],
         {"MouseClicked" :> If[TrueQ[slideshow],

            SetOptions[InputNotebook[], 
             ScreenStyleEnvironment -> "Working"]; 
            slideshow = ! slideshow,

            SetOptions[InputNotebook[], 
             ScreenStyleEnvironment -> "SlideShow"]; 
            slideshow = ! slideshow]}]
        }},
      AutoDelete -> False,
      Alignment -> {{Left, Center, Right}, Center},
      ItemSize -> {Automatic, Fit, Automatic},
      Spacings -> 3]
    },
   Dynamic[slideshow]]
  ]

To add this as a docked cell:

SetOptions[EvaluationNotebook[], DockedCells -> {First[ToBoxes[
     TextCell[grid, Background -> GrayLevel[0.8], CellMargins -> 0]
     ]]}]

To remove it:

SetOptions[EvaluationNotebook[], DockedCells -> {}]

Notes:

  1. This has been cobbled together after studying how other slideshow docked cells work. Note the red EvalutionOrder option to EventHandler.

  2. This places the option (button, i.e. the disk on the left)) to go full screen from the working environment.

  3. You can switch between slideshow and working via the docked cell by clicking on "Switch to Working" and "Switch to Slideshow".

To make the stylesheet:

CreateDocument@Notebook[{
   Cell[StyleData[StyleDefinitions -> "Default.nb"]],
   Cell[StyleData["Notebook"],
    DockedCells -> {First[ToBoxes[
        TextCell[grid, Background -> GrayLevel[0.8], 
         CellMargins -> 0]
        ]]}]}, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]

From there give it a name and install it.


You could edit the MenuSetup.tr file in the same manner as KeyEventTranslations.tr to include shortcut keys for each mode.


At present I cannot see a way to make this actually work. I am leaving the answer here for a while in case someone else can, and because I am curious to know what can be done with the "MenuListScreenStyleEnvironments" token.

Tags:

Front End