-
Notifications
You must be signed in to change notification settings - Fork 0
Widget Palette
This wiki page describes how some things work in the Widget Palette.
The widget palette initializes the first time the visual editor initializes. The key files are:
- davinci/ve/palette/Palette.js
- davinci/ve/palette/PaletteItem.js
At application startup time, a good part of the initialization of the visual parts of the Widget Palette stems from a call within davinci/ve/palette/Palette.js, to:
- _addProviders()
- new davinci.ve.palette.PaletteDescriptorProvider()
Note that in Palette.js, there are two class variables, "providers" and "_providers":
// "providers" is a comma-separated string that contains a list of custom "providers", // which appears to be locations for custom widget libraries. However, the custom // provider feature isn't really working now. // FIXME: Need to either get rid of "providers" or fix it to make it work. // // "_providers" is an array of objects that includes information about the default provider // and any custom providers. In the current code, there is only the default provider, // which points to davinci/libs/dojo_1_4.
The list of "descriptors" (dijit,dojox,html,OpenAjax) is initialized within:
- davinci/ve/HtmlWidgets.js
new davinci.ve.palette.Palette()</code>and then does an assignment to the "descriptors" property on the palette's instance object as follows:
this.palette.descriptors = "dijit,dojox,html,OpenAjax";
The HTML user interface for the list of widgets is added to the Widget Palette each time a new document is added to the visual editor. The code path is:
davinci/ve/palette/Palette.js: _createPalette() forEach() // loop through array of objects (each with own category) in current *.json file davinci/ve/palette/Palette.js: addDescriptor() forEach() // loop through Palette.js's list of descriptors: dijit,dojox,html,OpenAjax davinci/ve/palette/Palette.js: setContext() davinci/ve/HtmlWidgets.js: setContext() (dojo) constructor() (dojo) _construct() (dojo) _makeCtor() davinci/ve/HTMLVisualEditor.js: constructor() (dojo) _construct() (dojo) _makeCtor() davinci/ui/EditorContainer.js: setEditor() davinci/Workbench.js: createEditor davinci/Workbench.js: openEditor() davinci/resource.js: createFile()
_createPalette()
ends up being called in a double-loop:
- Outer loop: foreach on descriptors (dijit,dojox,html,OpenAjax), pull in *.json file for descriptor
- Inner loop: foreach object in the current *.json file (each with own palette category: Form, Layout, Dijit, HTML, Dojox, OpenAjax)
- davinci/ve/palette/Palette.js: _createItem()
- new davinci.ve.palette.PaletteItem(opt); (foundin davinci/ve/palette/PaletteItem.js)
buildRendering()
and postCreate()
methods, which actually set up the HTML snippet and set up event listeners (via this.connect(), which is a dijit wrapper function on dojo.connect()).
There are actually two ways to place a widget onto the canvas, described in sections below:
- The key event setup logic is found in davinci/ve/palette/Palette.js. The _createItem() method in davinci/ve/palette/Palette.js sets up drag/drop behavior for each given widget via the following logic:
_createItem: function(opt){ var node = new davinci.ve.palette.PaletteItem(opt); this.addChild(node); var ds = new davinci.edit.dnd.DragSource(node.domNode, "component", node); ... this.connect(ds, "onDragStart", "onDragStart"); // move start this.connect(ds, "onDragEnd", "onDragEnd"); // move end ... }
- The event handler for the drag-start event is
onDragstart()
in Palette.js, which callsCreateTool(data.data)
to set up the drag and create a "tool" object, and thenthis._context.setActiveTool(tool)
. - For the drag-end event, the first mouseup handler is in Context.js, which then invokes the mouseup handler for the current "tool", which ultimately calls
createWidget()
within widget.js. The call stack for thecreateWidget()
call is as follows:
davinci/ve/widget.js: createWidget() (?)() withDoc() davinci/ve/tools/CreateTool.js: _create() davinci/ve/tools/CreateTool.js: create() davinci/ve/tools/CreateTool.js: onMouseUp() davinci/edit/Context.js: onMouseUp() // calls onMouseUp function for the "active tool"
Click on a widget from Widget Palette to select it and then click on canvas to add that widget to the current document
- The key event setup logic is found in davinci/ve/palette/PaletteItem.js, with its
itemMouseDownHandler()
anditemMouseUpHandler()
routines. One of the key things done initemMouseUpHandler()
is this call, which establishes the currently selected widget as the "active tool" such that if you click on the canvas, you get an instance of that widget:
this.palette._context.setActiveTool(tool);
- The mouseup handler logic for this case is the same as for the drag case.