1
$\begingroup$

I have created palette with 3 buttons next to each other that allow me to change the justification the current cell in the notebooks to: Left, Center, and Right.

I want the buttons to dynamically highlight (in red) whether the cell is currently left, center or right justified. It was able to get the code below to work in a docked cell perfectly, but not in a palette. I'm not sure why.

CreatePalette[
  Grid[{{Tooltip[
      Row[
       Flatten[{
         Button[

            Grid[{{"---"}, {"--"}, {"---"}, {"-"}}, 
             BaseStyle -> {9, "Label", Bold},

             ItemStyle -> 
              If[Dynamic[
                TrueQ[CurrentValue[NotebookSelection[], 
                   TextAlignment] == #]], Red],
             Alignment -> {"Columns" -> {{#}}},
             Spacings -> {"Columns" -> {{0}}, "Rows" -> {{-.8}}}
             ], {SelectionMove[InputNotebook[], All, Cell], 
             SetOptions[NotebookSelection[InputNotebook[]], 
              TextAlignment -> #]}, Appearance -> "Palette",
            ImageSize -> 24] & /@ {Left, Center, Right}}], 
       ImageSize -> {4, 1}*24, BaselinePosition -> Axis], "Alignment", 
      TooltipDelay -> 0]}}]];

It does change the justification of the cell but does not dynamically highlight whether the cell is currently left, center or right justified. Any ideas?

$\endgroup$

1 Answer 1

1
$\begingroup$

You need to target correct notebook, otherwise it tracks a palette's selection.

CurrentValue[NotebookSelection[InputNotebook[]], TextAlignment]

should do.

$\endgroup$
2
  • $\begingroup$ That did it. hmmm... Why is it that a docked cell does not require this? Is it because the docked cell is part of the notebook itself? $\endgroup$
    – B flat
    Commented Nov 18, 2016 at 10:48
  • 1
    $\begingroup$ @MichaelMcCain Yes $\endgroup$
    – Kuba
    Commented Nov 18, 2016 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.