When manipulating a Notebook from the Kernel using such functions as NotebookLocate
, SelectionMove
, NotebookSelection
, NotebookDelete
etc. by default user-interaction with the Notebook is allowed and it is possible that the user will occasionally change the current selection which was programmatically set from the kernel leading to unexpected and potentially dangerous results. Consider the following example:
Do[Print[l], {l, {a, b, c}}];
SelectionMove[EvaluationNotebook[], After, EvaluationCell];
SelectionMove[EvaluationNotebook[], Next, Cell];
Pause[3]; (* <- some time-consuming evaluation here *)
If[CurrentValue[NotebookSelection[], CellTags] === {},
NotebookDelete[EvaluationNotebook[]]];
The above code prints three Cell
s, then selects the first printed Cell
, performs some other computations, checks whether this Cell
has CellTags
and then decides whether it is necessary to delete that Cell
. During these operations the user can for example touch the touchpad of his laptop and change the current selection what can result in deleting some important information and loosing the work.
Is it possible to disable user-interaction with the Notebook until evaluation will not finish? It would be perfect to allow the user to abort the evaluation despite he cannot interact with the Notebook.