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.

How can I prevent the DialogInput from failing (or returning early) as soon as I close the "Close this" dialog?

DialogInput@Button["Click this", CreateDialog["Close this" ]]
share|improve this question
add comment

4 Answers

Would that help?

DialogInput@
 Column[{Button["Click this", 
    CreateDialog["Close this",NotebookEventActions -> {}]],
   Button["Done", DialogReturn["done"]]
   }]

I think the outer dialog won't return as long as the inner dialog doesn't call DialogReturn (it could do something else, though). DialogReturn[$Failed] is somehow automatigally inserted for some event actions when calling CreateDialog, although Options[CreateDialog,NotebookEventActions] returns {NotebookEventActions -> None}. The inserted event actions can be seen e.g. with this:

CreateDialog[
 Dynamic@Column@
   CurrentValue[EvaluationNotebook[], NotebookEventActions]]
share|improve this answer
    
+1 Yeah, it helped, thanks! Now I scrapped a solution that haven't tested intensely but I'm posting it as a self answer –  Rojo Jun 23 '12 at 4:13
add comment
nestedDialog[] := Module[{tag = True},
   Unprotect[DialogReturn];
   DialogReturn[i_] /; tag := 
    Internal`InheritedBlock[{System`FEDump`$DialogDone},
         Unprotect[DialogReturn];
         DialogReturn[j_] /; tag =.;
         System`FEDump`$DialogDone /: 
      HoldPattern[System`FEDump`$DialogDone = True] = True;
         DialogReturn[i];
         Protect[DialogReturn];
         System`FEDump`$DialogDone /: 
      HoldPattern[System`FEDump`$DialogDone = True] =.;
     ];
   Protect[DialogReturn];
   ];

Use: just call nestedDialog[] before creating new nested dialogs. It makes sense to make the nested dialogs modal because the DialogInput won't return until as many DialogReturnshave been run as nestedDialog[]s have been run (plus one)

DialogInput@{Button["Click this", nestedDialog[]; 
   CreateDialog["Close this", Modal -> True]], 
  DefaultButton[DialogReturn["alskjl"]]}

I tested this in Mathematica 8.0.4, W7x64. Quoted from @AlbertRetey's comment. "I have now tested your code with Mathematica 6.0.2,7.0.1 and 8.0.4 on both Windows 7 and Linux (CentOS) and at least the simple example seems to work alright with any of them"

share|improve this answer
    
+1, unlike my suggestion this really makes possible to use nested modal dialogs, which I couldn't get to work up to now. As you are using nondocumented internal functions, I'd suggest to add a note with which version you have tested this... –  Albert Retey Jun 24 '12 at 17:15
    
I have now tested your code with Mathematica 6.0.2,7.0.1 and 8.0.4 on both Windows 7 and Linux (CentOS) and at least the simple example seems to work alright with any of them. I would conclude what you are using seems to be fairly stable amongs the various versions. Maybe you want to add that to your answer. –  Albert Retey Jun 25 '12 at 19:20
add comment

You could do something like this

DialogInput[Button["Click this",
  CreateDialog["Close this", NotebookEventActions -> {"WindowClose" :> DialogReturn[]}]]]
share|improve this answer
    
That doesn't seem to work... I'm on 8.0.0 right now, and that prevents the failed return but doesn't prevent the early return. Changes $Failed to Null –  Rojo Jun 21 '12 at 16:34
    
@Rojo I missed the bit where you wanted to keep the underlying window. –  Heike Jun 21 '12 at 16:59
add comment

Try putting a semi-colon after CreateDialog

DialogInput@Button["Click this", CreateDialog["Close this" ];]
share|improve this answer
    
What did that change? –  Rojo Jun 21 '12 at 16:35
    
Sorry, it doesn't do what you want. What it changed is that Click this button persists. I "failed" to notice that it still "$Failed" –  Robert Miller Jun 21 '12 at 16:40
    
@Rojo Sorry, it doesn't do what you want. What it changed is that Click this button persists. I "failed" to notice that it still "$Failed". Does adding the semi-colon to Heike's solution do what you want? It appears to. –  Robert Miller Jun 21 '12 at 16:47
add comment

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.