Skip to content

Commit

Permalink
Added primitive renaming support (by editing comment). Fixes #444
Browse files Browse the repository at this point in the history
WIP #444 Naming support for SerializeEditor

WIP #444 Added renaming functionality for the deserialize editor
  • Loading branch information
brollb committed Jul 11, 2016
1 parent d6c201c commit 8f8e54e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
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 Down
11 changes: 11 additions & 0 deletions src/visualizers/panels/TextEditor/TextEditorControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,23 @@ define([
`for ${id} - node doesn't have the given attribute!`);
}
};
this._widget.setName = this.setName.bind(this);
};

TextEditorControl.prototype.saveTextFor = function (id, text) {
this._client.setAttributes(id, this.ATTRIBUTE_NAME, text);
};

TextEditorControl.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();
};

TextEditorControl.prototype.TERRITORY_RULE = {children: 0};
TextEditorControl.prototype.selectedObjectChanged = function (nodeId) {
var self = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

define([
'widgets/TextEditor/TextEditorWidget',
'widgets/SerializeEditor/SerializeEditorWidget',
'underscore',
'css!./styles/DeserializeEditorWidget.css'
], function (
TextEditorWidget,
SerializeEditorWidget,
_
) {
'use strict';
Expand All @@ -19,10 +19,10 @@ define([
//WIDGET_CLASS = 'deserialize-editor';

DeserializeEditorWidget = function (logger, container) {
TextEditorWidget.call(this, logger, container);
SerializeEditorWidget.call(this, logger, container);
};

_.extend(DeserializeEditorWidget.prototype, TextEditorWidget.prototype);
_.extend(DeserializeEditorWidget.prototype, SerializeEditorWidget.prototype);

DeserializeEditorWidget.prototype.getHeader = function(desc) {
return [
Expand All @@ -34,8 +34,8 @@ define([
].join('\n');
};

DeserializeEditorWidget.prototype.updateNode = function() {
// nop
DeserializeEditorWidget.prototype.getNameRegex = function() {
return /The deserialization function for (.*)/;
};

return DeserializeEditorWidget;
Expand Down
38 changes: 32 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,36 @@ define([
].join('\n');
};

SerializeEditorWidget.prototype.updateNode = function() {
// nop
SerializeEditorWidget.prototype.getNameRegex = function () {
return /The serialization function for (.*)/;
};

SerializeEditorWidget.prototype.getName = function () {
var text = this.editor.getValue(),
r = this.getNameRegex(),
match = text.match(r);

return match && match[1].replace(/\s+$/, '');
};

SerializeEditorWidget.prototype.saveText = function () {
var name = this.getName();

if (this.readOnly) {
return;
}

if (name && 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 8f8e54e

Please sign in to comment.