When graphics are right-clicked in Mathematica you get a context menu (cut graphics, copy graphics, save graphics as,...), but for a LocatorPane Graphic this right click menu is disable. How can I call a context menu for a LocatorPane graphics with an EventHandler or a MouseAction command in Mathematica? What command creates this menu?
LocatorPane[{1, 1}/2, Graphics[{Gray, Disk[]}]]
I find this code to open "Save as" Window in mathematica.
FrontEndExecute[FrontEndToken["SelectionSaveSpecial"]]
I want when i right click a LocatorPane graphic the "Save As" window open.
You said:
I want to call "save graphic as" by right click on LocatorPane graphics.
I have not yet found a way to do that, but you may not know that you can:
select the LocatorPane
object by clicking in the white-space to the right of it and dragging left.
use menu File > Save Selection As...
to save a graphic in your desired format.
What I believe is the correct option does not appear to work:
SetOptions[EvaluationNotebook[],
ComponentwiseContextMenu -> {"GraphicsBox" ->
FEPrivate`FrontEndResource["ContextMenus", "GraphicsBox"],
"Graphics3DBox" ->
FEPrivate`FrontEndResource["ContextMenus", "Graphics3DBox"],
"LocatorPaneBox" ->
FEPrivate`FrontEndResource["ContextMenus", "GraphicsBox"],
"CellGroup" ->
FEPrivate`FrontEndResource["ContextMenus", "CellGroup"],
"CellBracket" ->
FEPrivate`FrontEndResource["ContextMenus", "CellBracket"],
"CellRange" ->
FEPrivate`FrontEndResource["ContextMenus", "CellRange"],
"CellInsertionPoint" ->
FEPrivate`FrontEndResource["ContextMenus", "CellInsertionPoint"]}
];
Specifically, the value for "LocatorPaneBox" ->
was changed to "GraphicsBox"
but it has no apparent effect.
On the other hand, changing the value for "GraphicsBox" ->
does have an effect.
I suspect that because LocatorPane
uses the mouse input, it captures the right-click attempt, and never passes it to the context menu mechanism. Perhaps disabling the mouse as an input device for LocatorPane
would correct this, but that does not seem practical.
Here is one way to implement your suggestion of using "SelectionSaveSpecial"
:
Dynamic[EventHandler[
LocatorPane[{1, 1}/2, Graphics[{Gray, Disk[]}]],
{"MouseClicked", 2} :>
FrontEndExecute[
SelectionMove[EvaluationNotebook[], All, GeneratedCell];
SelectionMove[EvaluationNotebook[], All, CellContents];
FrontEndToken["SelectionSaveSpecial"]
]
]]