# How to make AutoAction take effect only one time?

WARNING: better don't try this when you have any relevant notebooks open, the generated palette will edit your currently selected notebook in ways which are not easily noticed or undone!

AutoAction will repeatedly take effect when cursor over the button of pallete.

Cell[BoxData[$$\(CreatePalette[\({\(Button[\("Create Inline Cell", \(\(FrontEndExecute[\(FrontEndToken["CreateInlineCell"]$$]\)[$$NotebookRead[\(InputNotebook[]$$]\)]\), $$AutoAction -> True$$\)]\)}\)]\) ;\)], "Input"]


Here is one pallete to create inline cells, I wish it would perform only once when the selected content is the same.

How to make AutoAction Take effect only for different selected contents

Welcome to add an button to revert the value, ie convert new generated inline cell back to the prevous state(maybe plaintext).

What is the same content: In one Text Cell, content is who are you. when selected content is who, just convert who into one inline cell, if second time, i select who are they are not the same contents.

-
What does "content is the same" mean? The same as what? – Kuba May 29 '13 at 4:12
@Kuba In one Text Cell, content is who are you. when selected content is who, just convert who into one inline cell, if second time, i select wha are they are not the same contents. – HyperGroups May 29 '13 at 4:17

I actually think that what you provide is really dangerous: it does edits in the currently selected notebooks when moving the mouse over it which can't be seen nor undone and can't even easily be noticed and might corrupt that notebook. I'd like to warn anyone who is playing with this: better close all important notebooks you happen to have opened before even generating that palette. Anyway: here is what I think does what you want (it's not taking care about anything that might go wrong and is just almost as dangerous as your original code, though...):

CreatePalette[{
DynamicModule[{lastselection = ""},
Button["Create Inline Cell",
FrontEndExecute[FrontEndToken["CreateInlineCell"]][
],
AutoAction -> True
]
]
}]


Edit: Here is another version which adds CellTags which might help with finding these changes and probably undo them:

CreatePalette[{DynamicModule[{lastselection = ""},
Button["Create Inline Cell",
FrontEndExecute[FrontEndToken["CreateInlineCell"]][
SetOptions[
Cells[NotebookSelection[InputNotebook[]]][[1]],
CellTags -> {"AutoGeneratedInlineCell"}
];
]
]]}]


Unfortunately, the standard way to find cells by celltag (something like NotebookFind[ InputNotebook[], "AutoGeneratedInlineCell", All, CellTags]) seems to not work for inline cells. There might be possibilities to circumvent that, but these would needs some efforts and workarounds...

-
en,en,...much better than my original code. can you add an button for revertting the value? that would be safer. many thanks~~, – HyperGroups May 29 '13 at 15:50
@HyperGroups: a button to revert which value? – Albert Retey May 29 '13 at 17:03
I mean clear the inline cell back to plaintext. – HyperGroups May 30 '13 at 0:22
@HyperGroups: What I'd probably do is to provide a specific tag for those cells (search for the CellTags option of cells) for those generated cells so that you can later find and manipulate them. You could then search for that tag and then highlight these inline cells or replace them with their content. You could either do that one by one or for all in a notebook at once. I have no time to implement this, but I think it should be relatively straightforward with some FrontEnd-programming (and a good exercise ;-)... – Albert Retey May 30 '13 at 9:52
ok, I'll try that later, yeah, every time when change one text to inline cell than add an tag, a good way. – HyperGroups May 30 '13 at 9:57