Changes between Version 6 and Version 7 of GROUP_SCRIPTING_R0
- Timestamp:
- 07/07/09 16:49:21 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GROUP_SCRIPTING_R0
v6 v7 40 40 41 41 == How to demo == 42 * C reate a new script.42 * Click Insert -> Script. A new window should be opened. 43 43 * Write a JavaScript code that outputs "Hello world". 44 44 * Click the Run button. … … 46 46 = Design = 47 47 * Create a Sophie module {{{org.sophie2.extra.func.scripting}}}. 48 * Create subpackages model, view and controller.48 * Create subpackages model, view and logic. 49 49 50 50 * model: … … 59 59 * schema "storage|file|js" 60 60 * the script is persisted as a plain text file with ".js" extension 61 * register the persisters as extensions 61 62 62 63 * view: 63 * menuitems InsertScriptItem and InsertScriptFileItem in Insert menu 64 * menu items InsertScriptItem and InsertScriptFileItem in Insert menu 65 * enum EventIds that contains the identifiers of all events that can be fired by any UI component in this package 66 * INSERT_SCRIPT 67 * INSERT_SCRIPT_FILE 68 * RUN_SCRIPT 69 * EDIT_SCRIPT 64 70 * document window for resource viewing, editing and running: 65 71 * class {{{ScriptDocumentWindow}}} extends {{{DefaultDocumentWindow}}} implements {{{DocumentView}}} 66 72 * RwProp<ResourceRef> model - the script resource that is displayed 67 * resource property {{{swingFrameSync}}} that adds a text area and "Run" button to {{{swingComponent}}} 73 * resource property {{{swingFrameSync}}} that adds the following components to {{{swingComponent}}}: 74 * a text area that fires EDIT_SCRIPT 75 * and "Run" {{{LogicR3Button}}} that fires RUN_SCRIPT 76 * resource preview of scripts (in Resource Preview Palette): 77 * class {{{ScriptResourcePreviewProvider}}} implements {{{ResourcePreviewProvider}}} 78 * {{{getResourceKind()}}} should return the kind in {{{ScriptResource}}} 79 * {{{filterKind()}}} should return "Script" 80 * nested private static class {{{ScriptResourcePreview}}} 81 * constructor with argument of type {{{ScriptResource}}} 82 * in {{{swingComponent}}} create a new JPanel, analogic to the panel in {{{ScriptDocumentWindow}}} 83 * components should fire the same events as in {{{ScriptDocumentWindow}}} 84 * {{{getVisualElement(Resource element)}}} should return a new instance of {{{ScriptResourcePreview}}} 85 * register the class as an extension 68 86 69 87 * logic: 70 * enum ScriptingLogic: 88 * enum ScriptingLogic that implements OperationDef: 89 * all of the following items should listen for an event with the same id 71 90 * INSERT_SCRIPT 72 91 * listens for the event in {{{InsertScriptItem}}} 73 * creates a new empty {{{ScriptResource}}} in current book 92 * creates a new empty {{{ScriptResource}}} in current book (use {{{CurrentBookUtil.getCurrentBook}}}) 74 93 * adds it to {{{App.documents}}} (see below for details) 75 94 * INSERT_SCRIPT_FILE … … 79 98 * adds it to {{{App.documents}}} (see below for details) 80 99 * RUN_SCRIPT 81 * listens for the event in the "Run" button82 100 * write the following temporary solution: 83 101 * create a new context using {{{Context cx = Context.enter();}}} 84 102 * initialize the standard objects (Object, Function, etc.) using {{{Scriptable scope = cx.initStandardObjects();}}} 85 103 * 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}}}104 * if there's a result, open a message box to display the result by creating a new {{{MessageDialogInput}}} and invoking {{{DialogManager#showDialog}}} 87 105 * exit from the context with {{{Context.exit();}}}. Call this from a finally block. 106 * EDIT_SCRIPT 107 * the following solution can be optimized: 108 * create a new AutoChange that changes the text in the resource with that from the text area. Register the change to current book. 109 * register the enum as an extension 88 110 89 111 * Refactor {{{App}}} and {{{AppDocumentsDesktop}}}: