Skip to content

Commit

Permalink
WIP #444 Naming support for SerializeEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Jul 11, 2016
1 parent ba210e4 commit 2541454
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/visualizers/panels/SerializeEditor/SerializeEditorControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define([
SerializeEditorControl = function (options) {
options.attributeName = 'serialize';
TextEditorControl.call(this, options);
this._widget.setName = this.setName.bind(this);
};

_.extend(
Expand All @@ -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;
});
32 changes: 26 additions & 6 deletions src/visualizers/widgets/SerializeEditor/SerializeEditorWidget.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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:',
Expand All @@ -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;
Expand Down

0 comments on commit 2541454

Please sign in to comment.