# Unexpected behavior of PasteButton

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.

-
It's very weird. Bug? It doesn't like StyleData cells it tries to paste it as a box expressions – Rojo May 30 '12 at 1:16
Maybe the magic word is "effectively" here: You could use the option BaseStyle->"Paste" and a normal Button and 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:28
@halirutan You could try Button["paste FontColor", Paste[Defer[FontColor -> RGBColor[1, 0, 0]]]]. – Heike May 30 '12 at 7:51
@Heike This seems to work like I had hoped. Do you have an idea, why and when (even with the Defer) the translation from -> to \[Rule] happens? It seems that wrapping InputForm around it always keeps the -> form. – halirutan May 30 '12 at 12:21
Bug. Report it to tech support. – John Fultz Jun 2 '12 at 20:21

 CreatePalette[