5 return function(sandbox) {
 
   7     var view = $(sandbox.getTemplate('main')()),
 
   8         documentIsDirty = true,
 
   9         documentEditedHere = false,
 
  12     view.onShow = function() {
 
  14             editor.setValue(wlxmlDocument.toXML());
 
  16             documentEditedHere = false;
 
  18             sandbox.publish('documentSet');
 
  19             documentIsDirty = false;
 
  23     view.onHide = function() {
 
  24         if(documentEditedHere) {
 
  25             documentEditedHere = false;
 
  26             wlxmlDocument.loadXML(editor.getValue());
 
  30     var editor = ace.edit(view.find('#rng-sourceEditor-editor')[0]),
 
  31         session = editor.getSession();
 
  32     editor.setTheme("ace/theme/chrome");
 
  33     session.setMode("ace/mode/xml")
 
  34     session.setUseWrapMode(true);
 
  36     $('textarea', view).on('keyup', function() {
 
  37         documentEditedHere = true;
 
  40     editor.getSession().on('change', function() {
 
  41         documentEditedHere = true;
 
  45             sandbox.publish('ready');
 
  50         setDocument: function(document) {
 
  51             wlxmlDocument = document;
 
  52             wlxmlDocument.on('change', function() {
 
  53                 documentIsDirty = true;
 
  56         getDocument: function() {
 
  57             return editor.getValue();