2
$\begingroup$

I have been searching the forum for an answer to this question and although people seem to have asked this exact same question, it is in the context of specific function in their DialogInput window or else I just don't understand the answer.

I am trying to use a CancelButton in a DialogInput window to cause all evaluations in my notebook to abort. Alternatively the kernel could quit. Either would be fine for my purpose. However, nothing I can do works. In the code I enter below, when the user hits the cancel button, the notebook just hangs.

I'm looking for a very general answer to how to just cause the kernel to quit when the user hits cancel in any DialogInput window. Any help is greatly appreciated.

DialogInput[
  Column[{"Select folder.", 
     FileNameSetter[Dynamic[d], "Directory"],
     Row[{
       DefaultButton[DialogReturn[SetDirectory[d]]], 
       CancelButton[DialogReturn[Abort[]]]
     }]
  }]
];
$\endgroup$
2
$\begingroup$

You have problems because Abort[] in Button's action will abort evaluation of that action.

A standard approach is to return $Canceled/$Failed from the InputDialog, catch it afterwards and react accordingly. But you can use tokens too, this should do:

CancelButton[DialogReturn[]; FrontEndTokenExecute["EvaluatorAbort"]]

At the end it may not always work because there is no (I don't know any) tool to abort a sequence of inputs from the same cell:

https://mathematica.stackexchange.com/a/99582/5478

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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