Changes between Version 6 and Version 7 of GROUP_SCRIPTING_R0


Ignore:
Timestamp:
07/07/09 16:49:21 (16 years ago)
Author:
mitex
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GROUP_SCRIPTING_R0

    v6 v7  
    4040 
    4141== How to demo == 
    42  * Create a new script. 
     42 * Click Insert -> Script. A new window should be opened. 
    4343 * Write a JavaScript code that outputs "Hello world". 
    4444 * Click the Run button. 
     
    4646= Design = 
    4747 * Create a Sophie module {{{org.sophie2.extra.func.scripting}}}. 
    48  * Create subpackages model, view and controller. 
     48 * Create subpackages model, view and logic. 
    4949 
    5050 * model: 
     
    5959    * schema "storage|file|js" 
    6060    * the script is persisted as a plain text file with ".js" extension 
     61   * register the persisters as extensions 
    6162 
    6263 * 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 
    6470  * document window for resource viewing, editing and running: 
    6571   * class {{{ScriptDocumentWindow}}} extends {{{DefaultDocumentWindow}}} implements {{{DocumentView}}} 
    6672   * 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 
    6886 
    6987 * 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 
    7190   * INSERT_SCRIPT 
    7291    * 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}}}) 
    7493    * adds it to {{{App.documents}}} (see below for details) 
    7594   * INSERT_SCRIPT_FILE 
     
    7998    * adds it to {{{App.documents}}} (see below for details) 
    8099   * RUN_SCRIPT 
    81     * listens for the event in the "Run" button 
    82100    * write the following temporary solution: 
    83101     * create a new context using {{{Context cx = Context.enter();}}} 
    84102     * initialize the standard objects (Object, Function, etc.) using {{{Scriptable scope = cx.initStandardObjects();}}} 
    85103     * 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}}} 
    87105     * 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 
    88110 
    89111 * Refactor {{{App}}} and {{{AppDocumentsDesktop}}}: