| 62 | * view: |
| 63 | * menuitems InsertScriptItem and InsertScriptFileItem in Insert menu |
| 64 | * document window for resource viewing, editing and running: |
| 65 | * class {{{ScriptDocumentWindow}}} extends {{{DefaultDocumentWindow}}} implements {{{DocumentView}}} |
| 66 | * RwProp<ResourceRef> model - the script resource that is displayed |
| 67 | * resource property {{{swingFrameSync}}} that adds a text area and "Run" button to {{{swingComponent}}} |
| 68 | |
| 69 | * logic: |
| 70 | * enum ScriptingLogic: |
| 71 | * INSERT_SCRIPT |
| 72 | * listens for the event in {{{InsertScriptItem}}} |
| 73 | * creates a new empty {{{ScriptResource}}} in current book |
| 74 | * adds it to {{{App.documents}}} (see below for details) |
| 75 | * INSERT_SCRIPT_FILE |
| 76 | * listens for the event in {{{InsertScriptFileItem}}} |
| 77 | * displays a file dialog for "JavaScript files (*.js)" with "Insert" button |
| 78 | * using the persisters, creates a new {{{ScriptResource}}} in current book |
| 79 | * adds it to {{{App.documents}}} (see below for details) |
| 80 | * RUN_SCRIPT |
| 81 | * listens for the event in the "Run" button |
| 82 | * write the following temporary solution: |
| 83 | * create a new context using {{{Context cx = Context.enter();}}} |
| 84 | * initialize the standard objects (Object, Function, etc.) using {{{Scriptable scope = cx.initStandardObjects();}}} |
| 85 | * evaluate the resource's text: {{{Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);}}} |
| 86 | * open a message box to display the result by creating a new {{{MessageDialogInput}}} and invoking {{{DialogManager#showDialog}}} |
| 87 | * exit from the context with {{{Context.exit();}}}. Call this from a finally block. |
| 88 | |
| 89 | * Refactor {{{App}}} and {{{AppDocumentsDesktop}}}: |
| 90 | |