Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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,

enter image description here

such that when you press the File Button and select "C:\\Users\\path\\testing.txt" it autofill with the textual arguments.

enter image description here

I'm quit interested to see what the Mathematica community thinks is the best technique for specifying which arguments should be File Buttons 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"]
 ]
share|improve this question
    
there is some code here mathematica.stackexchange.com/questions/5846/… in which you press a button and the button is replaced by text. You may be able to hack that around to do what you want for this task. –  Mike Honeychurch Jul 18 '13 at 3:56
    
I copied your code into the question. It's not excessively long, and I think it is better to have it here than linked exclusively. –  Mr.Wizard Aug 17 '13 at 16:54

1 Answer 1

up vote 1 down vote accepted

I'd start with something like this:

file = Button["File", file = SystemDialogInput["FileOpen"]];
CellPrint@ExpressionCell[test[Dynamic@file, Placeholder[text]], "Input"]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.