Let's say I have a function of the form.
Test[File_,text_]
What would be the most automated way and flexible way to generate an input cell of the form,
such that when you press the File Button and select "C:\\Users\\path\\testing.txt"
it autofill with the textual arguments.
I'm quit interested to see what the Mathematica community thinks is the best technique for specifying which arguments should be File Button
s and if it might be possible to incorporate the File buttons with Template Completion. My current code is below, which isn't generalized to all function definitions, but I knew it would be best to attempt to create a partially working solution. I used the following question to help piece a together my partially working example.
MakeBoxes[replacementMarker[a_, tag_], StandardForm] ^:=
TagBox[MakeBoxes[a], tag];
replaceMark[rule_, nb_: EvaluationNotebook[], which_: All,
cell_: EvaluationCell] := (
SelectionMove[nb, which, cell];
NotebookWrite[EvaluationNotebook[],
NotebookRead[EvaluationNotebook[]] /. rule]
) ;
CellPrint[
Cell[
BoxData[RowBox[{"Test", "[",
RowBox[{
ToBoxes@replacementMarker[
Button["Browse",
replaceMark[
file = SystemDialogInput["FileOpen"];
TagBox[_, "replaceThis"] :> "\"" <>
StringReplace[file, "\\" -> "\\\\"]
<> "\""
]
], "replaceThis"]
, ",",
TagBox[
FrameBox["test"],
"Placeholder"]}], "]"}]]
, "Output"]
]