diff --git a/src/util/PaperScript.js b/src/util/PaperScript.js index 1f921988..03d50d3f 100644 --- a/src/util/PaperScript.js +++ b/src/util/PaperScript.js @@ -119,7 +119,19 @@ var PaperScript = new function() { // Use paper.extend() to create a paper scope within which the code is // evaluated. with (paper.extend()) { - return eval(compile(code)); + // TODO: Only create tool if code contains reference to tool scripts! + var tool = new Tool(); + var res = eval(compile(code)); + // TODO: Again, only do this if we actually detected a tool script: + Base.each(['onEditOptions', 'onOptions', 'onSelect', 'onDeselect', + 'onReselect', 'onMouseDown', 'onMouseUp', 'onMouseDrag', + 'onMouseMove'], function(key) { + try { + tool[key] = eval(key); + } catch (e) { + } + }); + return res; } }