Assume the following very complex palette:
CreatePalette[
PasteButton[FontColor -> RGBColor[1, 0, 0]]
];
Its purpose is to insert a FontColor rule. It works like expected in a notebook but I plan to use it inside raw cell expressions. Please try the following two examples. Paste the following code into a notebook
NotebookWrite[
SelectedNotebook[],
Cell[Cell["abc", "Text"]]
]
You get a text cell saying "abc". Now go with the cursor anywhere between the "abc" and press Ctrl+Shift+E (this is Cell->Show Expression) to see the underlying cell data. Go directly in front of the last closing bracket, make a comma and press the palette-button. You should get
Cell[BoxData[
FormBox["abc", Text]],FontColor->RGBColor[1,0,0]]
Pressing Ctrl+Shift+E again and the text is red. Works like a charm. Now try the following cell with the same approach:
NotebookWrite[
SelectedNotebook[],
Cell[StyleData["StandardForm"]]
]
Here I get (Linux 64, Mma 8.0.4)
Cell[StyleData["StandardForm"],
RowBox[{"FontColor", "->", RowBox[{"RGBColor", "[",
RowBox[{"1", ",", "0", ",", "0"}], "]"}]}]
]
which is not what I expected and which does not work.
Question: Can anyone explain me what's going on here? Is the PasteButton aware of the context?
Background: The background is, that I have created a palette which I want to use to adjust style-sheet definitions. That was, when I stumbled over this behaviour.
Fix: One possible way to fix this is to use NotebookWrite directly instead of the PasteButton. Disadvantage of this approach is, that the expression can no longer be inserted into a normal notebook, because there you have to insert cell-expression.

BaseStyle->"Paste"and a normalButtonand you get the same weird behavior. The doc of "Paste" says "effectively use NotebookApply upon the current selection using the button label as the applied data". – halirutan May 30 '12 at 1:28Button["paste FontColor", Paste[Defer[FontColor -> RGBColor[1, 0, 0]]]]. – Heike May 30 '12 at 7:51Defer) the translation from->to\[Rule]happens? It seems that wrappingInputFormaround it always keeps the->form. – halirutan May 30 '12 at 12:21