[[BackLinksMenu]] [[TicketQuery(summary=GROUP_SCRIPTING_R0, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|)]] = Analysis = == Overview == General Scripting overview: The users should be able to type and execute custom scripts. * A script is a resource. * Execute button should be present inside the resource pallete. * Scripts could be edited inside a document window. Again execute button should be available. While editing the resource is saved automatically. * Scripts could also be executed via links. * The resource preview for scripts should allow editing. * There should be ability to import/export script files. * The user could create/edit/delete scripts. == Task requirements == Create prototype for scripting that includes the following functionality: * Ability to add/edit/delete script files. * Add 'Insert Script File' button inside 'Insert' menu * Create 'Insert Script' button inside 'Insert' menu that creates new resource. * Provide document window that allows editing for scripts as well as executing them. * Add 'Execute' button inside resource details pallete, that is visible only when script resource is selected. * Create 'Hello world' example via scripting in Sophie. * OPTIONAL: Provide functionality that allows scripts to be evoked from links. * Provide functionality that allows for script resource to be exported to files. Again in the resource pallete. Also while editing it from the file menu save and save as should be functional. (NOTE: Saving the resource should be automatically, but exporting it to file is not). == Task result == * The result should be code. == Implementation idea == * Use the Rhino library: [http://www.mozilla.org/rhino/]. * The output for the script could be Eclipse console or popup window. == Related == ^(Add links to related tasks that could be useful or helpful.)^ == How to demo == * Create a new script. * Write a JavaScript code that outputs "Hello world". * Click the Run button. = Design = * Create a Sophie module {{{org.sophie2.extra.func.scripting}}}. * Create subpackages model, view and controller. * model: * class ScriptResource that extends Resource. * kind is "script" * RwProp scriptText - the javascript source code text * subpackage {{{persistence}}} * class {{{ScriptPersister}}} extends {{{Persister}}} * schema "resource:script|storage|r3" * this persister is needed when the parent book is persisted. * class {{{ScriptFilePersister}}} extends {{{Persister}}} * schema "storage|file|js" * the script is persisted as a plain text file with ".js" extension * view: * menuitems InsertScriptItem and InsertScriptFileItem in Insert menu * document window for resource viewing, editing and running: * class {{{ScriptDocumentWindow}}} extends {{{DefaultDocumentWindow}}} implements {{{DocumentView}}} * RwProp model - the script resource that is displayed * resource property {{{swingFrameSync}}} that adds a text area and "Run" button to {{{swingComponent}}} * logic: * enum ScriptingLogic: * INSERT_SCRIPT * listens for the event in {{{InsertScriptItem}}} * creates a new empty {{{ScriptResource}}} in current book * adds it to {{{App.documents}}} (see below for details) * INSERT_SCRIPT_FILE * listens for the event in {{{InsertScriptFileItem}}} * displays a file dialog for "JavaScript files (*.js)" with "Insert" button * using the persisters, creates a new {{{ScriptResource}}} in current book * adds it to {{{App.documents}}} (see below for details) * RUN_SCRIPT * listens for the event in the "Run" button * write the following temporary solution: * create a new context using {{{Context cx = Context.enter();}}} * initialize the standard objects (Object, Function, etc.) using {{{Scriptable scope = cx.initStandardObjects();}}} * evaluate the resource's text: {{{Object result = cx.evaluateString(scope, s, "", 1, null);}}} * open a message box to display the result by creating a new {{{MessageDialogInput}}} and invoking {{{DialogManager#showDialog}}} * exit from the context with {{{Context.exit();}}}. Call this from a finally block. * Refactor {{{App}}} and {{{AppDocumentsDesktop}}}: * Source code: [source:/branches/private/deni/scripting/] = Implementation = ^(Describe and link the implementation results here (from the wiki or the repository).)^ = Testing = ^(Place the testing results here.)^ = Comments = * The goal of this task is mainly to provide interface for scripting