Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added primitive renaming support (by editing comment). Fixes #444 #480

Merged
merged 1 commit into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define([
// input/output updates are actually activeNode updates
ClassCodeEditorControl.prototype._onUpdate = function (id) {
if (id === this._currentNodeId) {
TextEditorControl.prototype._onUpdate.call(this, this._currentNodeId);
TextEditorControl.prototype._onUpdate.call(this, id);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/*jshint browser: true*/

define([
'panels/TextEditor/TextEditorControl',
'panels/SerializeEditor/SerializeEditorControl',
'underscore'
], function (
TextEditorControl,
SerializeEditorControl,
_
) {

Expand All @@ -15,20 +15,13 @@ define([

DeserializeEditorControl = function (options) {
options.attributeName = 'deserialize';
TextEditorControl.call(this, options);
SerializeEditorControl.call(this, options);
};

_.extend(
DeserializeEditorControl.prototype,
TextEditorControl.prototype
SerializeEditorControl.prototype
);

// input/output updates are actually activeNode updates
DeserializeEditorControl.prototype._onUpdate = function (id) {
if (id === this._currentNodeId) {
TextEditorControl.prototype._onUpdate.call(this, this._currentNodeId);
}
};

return DeserializeEditorControl;
});
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
14 changes: 11 additions & 3 deletions src/visualizers/panels/TextEditor/TextEditorControl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*globals define, WebGMEGlobal*/
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Wed May 18 2016 08:58:20 GMT-0500 (CDT).
*/

define([
'js/Constants',
Expand Down Expand Up @@ -47,12 +44,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