diff --git a/src/visualizers/panels/SerializeEditor/SerializeEditorControl.js b/src/visualizers/panels/SerializeEditor/SerializeEditorControl.js index 5a9b77f9e..2f08b5ea3 100644 --- a/src/visualizers/panels/SerializeEditor/SerializeEditorControl.js +++ b/src/visualizers/panels/SerializeEditor/SerializeEditorControl.js @@ -16,6 +16,7 @@ define([ SerializeEditorControl = function (options) { options.attributeName = 'serialize'; TextEditorControl.call(this, options); + this._widget.setName = this.setName.bind(this); }; _.extend( @@ -30,5 +31,15 @@ define([ } }; + SerializeEditorControl.prototype.setName = function (name) { + var node = this._client.getNode(this._currentNodeId), + oldName = node.getAttribute('name'), + msg = `Renaming ${oldName} -> ${name}`; + + this._client.startTransaction(msg); + this._client.setAttributes(this._currentNodeId, 'name', name); + this._client.completeTransaction(); + }; + return SerializeEditorControl; }); diff --git a/src/visualizers/widgets/SerializeEditor/SerializeEditorWidget.js b/src/visualizers/widgets/SerializeEditor/SerializeEditorWidget.js index 510e8cc4a..92156fc2e 100644 --- a/src/visualizers/widgets/SerializeEditor/SerializeEditorWidget.js +++ b/src/visualizers/widgets/SerializeEditor/SerializeEditorWidget.js @@ -1,10 +1,6 @@ /*globals define */ /*jshint browser: true*/ -/** - * Generated by VisualizerGenerator 1.7.0 from webgme on Wed Jun 01 2016 14:44:21 GMT-0500 (CDT). - */ - define([ 'widgets/TextEditor/TextEditorWidget', 'underscore', @@ -20,11 +16,13 @@ define([ SerializeEditorWidget = function (logger, container) { TextEditorWidget.call(this, logger, container); + this._name = null; }; _.extend(SerializeEditorWidget.prototype, TextEditorWidget.prototype); SerializeEditorWidget.prototype.getHeader = function(desc) { + this._name = desc.name; return [ `-- The serialization function for ${desc.name}`, '-- Globals:', @@ -33,8 +31,30 @@ define([ ].join('\n'); }; - SerializeEditorWidget.prototype.updateNode = function() { - // nop + SerializeEditorWidget.prototype.saveText = function () { + var text = this.editor.getValue(), + r = /The serialization function for (.*)/, + match = text.match(r), + name; + + if (this.readOnly) { + return; + } + + if (match) { // Detect the name from the header + name = match[1].replace(/\s+$/, ''); + if (this._name !== name) { + this.setName(name); + } + } + TextEditorWidget.prototype.saveText.call(this); + }; + + SerializeEditorWidget.prototype.updateNode = function(desc) { + if (this._name !== desc.name) { + // Check if the name updated. If so, update the text + this.addNode(desc); + } }; return SerializeEditorWidget;