As of 11. something this is nice and easy, if you're on Mac. It seems this does not work for Windows.
We'll leverage FrontEnd`MoveCursorToInputField
and SetSelectedNotebook
to temporarily overcome the WindowClickSelect
issue.
paletteInputField[specs__] :=
With[{uuid = CreateUUID["input-field-"]},
EventHandler[
InputField[specs, BoxID -> uuid],
{
"MouseClicked" :>
If[EvaluationNotebook[] =!= SelectedNotebook[],
CurrentValue[
EvaluationNotebook[],
{TaggingRules, "OldSelection"}
] = SelectedNotebook[];
SetSelectedNotebook[EvaluationNotebook[]];
FrontEnd`MoveCursorToInputField[EvaluationNotebook[], uuid]],
"MouseExited" :>
(
SelectionMove[EvaluationCell[], All, Cell];
SetSelectedNotebook[
CurrentValue[
EvaluationNotebook[],
{TaggingRules, "OldSelection"}
]
]
),
PassEventsDown -> True
}
]
]
This then works (almost) exactly as expected:
CreatePalette[
paletteInputField["asdasd", String],
WindowMargins -> Automatic,
System`ClosingSaveDialog -> False,
WindowSize -> 300
]
Note the "MouseExited"
call there. This just passes focus back to the previously selected notebook so nothing wonky happens and moves the selection point for aesthetic reasons.
And we don't lose WindowFloating
either.
CreateDialog
can be used to address the OP's issue? It would make your answer more helpful and probably solicit some rep. $\endgroup$