Severa lfixed.

This commit is contained in:
Paulo Veiga 2011-09-04 21:32:29 -03:00
parent dbb2b2d0c9
commit 0e21aad802
13 changed files with 85 additions and 65 deletions

View File

@ -16,12 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
core.Utils = core.Utils = {
{
escapeInvalidTags: function (text) {
//todo:Pablo. scape invalid tags in a text
return text;
}
}; };
/** /**

View File

@ -27,7 +27,6 @@ mindplot.DesignerKeyboard = new Class({
_registerEvents : function(designer) { _registerEvents : function(designer) {
// Try with the keyboard .. // Try with the keyboard ..
var model = designer.getModel(); var model = designer.getModel();
var keyboardEvents = { var keyboardEvents = {
@ -220,10 +219,17 @@ mindplot.DesignerKeyboard = new Class({
} }
// If it's not registered, let's // If it's not registered, let's
if (!isRegistered && !excludes.contains(key) && !modifiers.contains(key) && !key.contains('meta') && !key.contains('ctrl') && !key.contains('control')) { if (!isRegistered && !excludes.contains(key) && 'meta+[' != key) {
var nodes = designer.getModel().filterSelectedTopics(); var nodes = designer.getModel().filterSelectedTopics();
if (nodes.length > 0) { if (nodes.length > 0) {
nodes[0].showTextEditor(event.key);
// If a modifier is press, the key selected must be ignored.
var pressKey = event.key;
if (modifiers.contains(key)) {
pressKey = "";
}
nodes[0].showTextEditor(pressKey);
event.stopPropagation(); event.stopPropagation();
} }
} }
@ -322,6 +328,7 @@ mindplot.DesignerKeyboard = new Class({
// Give focus to the selected node.... // Give focus to the selected node....
node.setOnFocus(true); node.setOnFocus(true);
} }
}); });
mindplot.DesignerKeyboard.register = function(designer) { mindplot.DesignerKeyboard.register = function(designer) {

View File

@ -139,7 +139,7 @@ mindplot.MainTopic = new Class({
_updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) {
if (updatePosition == false && this.getModel().getFinalPosition()) { if (!updatePosition && this.getModel().getFinalPosition()) {
this.setPosition(this.getModel().getFinalPosition(), false); this.setPosition(this.getModel().getFinalPosition(), false);
} }
else { else {

View File

@ -17,6 +17,7 @@
*/ */
mindplot.MultilineTextEditor = new Class({ mindplot.MultilineTextEditor = new Class({
Extends: Events,
initialize:function(topic) { initialize:function(topic) {
this._topic = topic; this._topic = topic;
}, },
@ -41,7 +42,7 @@ mindplot.MultilineTextEditor = new Class({
); );
textareaElem.setStyles({ textareaElem.setStyles({
border: "0 none", border: "1px gray dashed",
background:"transparent", background:"transparent",
outline: '0 none', outline: '0 none',
resize: 'none', resize: 'none',
@ -70,13 +71,22 @@ mindplot.MultilineTextEditor = new Class({
} }
break; break;
} }
this._adjustEditorSize();
event.stopPropagation(); event.stopPropagation();
}.bind(this)); }.bind(this));
textareaElem.addEvent('keypress', function(event) {
event.stopPropagation();
});
textareaElem.addEvent('keyup', function(event) {
var text = this._getTextareaElem().value;
this.fireEvent('input', [event, text]);
this._adjustEditorSize();
}.bind(this));
textareaElem.addEvent('blur', function() { textareaElem.addEvent('blur', function() {
this.close(true); // @Todo: Issues if this is enables and esc is pressed.
// this.close.bind(this).attempt(true);
}.bind(this)); }.bind(this));
// If the user clicks on the input, all event must be ignored ... // If the user clicks on the input, all event must be ignored ...
@ -93,21 +103,24 @@ mindplot.MultilineTextEditor = new Class({
_adjustEditorSize : function() { _adjustEditorSize : function() {
var textElem = this._getTextareaElem(); if (this.isVisible()) {
var lines = textElem.value.split('\n'); var textElem = this._getTextareaElem();
var maxLineLength = 5;
lines.forEach(function(line) {
if (maxLineLength < line.length)
maxLineLength = line.length;
});
textElem.setAttribute('cols', maxLineLength + 3); var lines = textElem.value.split('\n');
textElem.setAttribute('rows', lines.length); var maxLineLength = 1;
lines.forEach(function(line) {
if (maxLineLength < line.length)
maxLineLength = line.length;
});
this._containerElem.setStyles({ textElem.setAttribute('cols', maxLineLength);
width: maxLineLength + 'em', textElem.setAttribute('rows', lines.length);
height: textElem.getSize().height
}); this._containerElem.setStyles({
width: (maxLineLength + 3) + 'em',
height: textElem.getSize().height
});
}
}, },
isVisible : function () { isVisible : function () {
@ -152,10 +165,6 @@ mindplot.MultilineTextEditor = new Class({
font.color = nodeText.getColor(); font.color = nodeText.getColor();
this._setStyle(font); this._setStyle(font);
// Set editor's initial text
var text = $defined(defaultText) ? defaultText : topic.getText();
this._setText(text);
// Set editor's initial size // Set editor's initial size
var displayFunc = function() { var displayFunc = function() {
// Position the editor and set the size... // Position the editor and set the size...
@ -166,6 +175,11 @@ mindplot.MultilineTextEditor = new Class({
}); });
this._containerElem.setStyle('display', 'block'); this._containerElem.setStyle('display', 'block');
// Set editor's initial text ...
var text = $defined(defaultText) ? defaultText : topic.getText();
this._setText(text);
// Set the element focus and select the current text ...
var inputElem = this._getTextareaElem(); var inputElem = this._getTextareaElem();
inputElem.focus(); inputElem.focus();
this._changeCursor(inputElem, $defined(defaultText)); this._changeCursor(inputElem, $defined(defaultText));
@ -214,12 +228,12 @@ mindplot.MultilineTextEditor = new Class({
return this._containerElem.getElement('textarea'); return this._containerElem.getElement('textarea');
}, },
_changeCursor : function(inputElem, selectText) { _changeCursor : function(textareaElem, selectText) {
// Select text if it's required ... // Select text if it's required ...
if (inputElem.createTextRange) //ie if (textareaElem.createTextRange) //ie
{ {
var range = inputElem.createTextRange(); var range = textareaElem.createTextRange();
var pos = inputElem.value.length; var pos = textareaElem.value.length;
if (!selectText) { if (!selectText) {
range.select(); range.select();
range.move("character", pos); range.move("character", pos);
@ -230,7 +244,7 @@ mindplot.MultilineTextEditor = new Class({
} }
} }
else if (!selectText) { else if (!selectText) {
inputElem.setSelectionRange(0, inputElem.value.length); textareaElem.setSelectionRange(0, textareaElem.value.length);
} }
}, },

View File

@ -39,7 +39,7 @@ mindplot.Note = new Class({
}, },
getText: function() { getText: function() {
return this._text; return this._textShape;
}, },
getModel : function() { getModel : function() {

View File

@ -101,9 +101,9 @@ mindplot.RichTextEditor = mindplot.TextEditor.extend({
//becarefull this._editor is not mootools!! //becarefull this._editor is not mootools!!
this._editor.addEvent('blur',function(event){ this._editor.addEvent('blur',function(event){
this._myOverlay.setStyle('display','none'); this._myOverlay.setStyle('display','none');
var text = this._text; var text = this._textShape;
this._text = this._editor.instanceById("inputText2").getContent(); this._textShape = this._editor.instanceById("inputText2").getContent();
if(text!=this._text){ if(text!=this._textShape){
this._applyChanges = true; this._applyChanges = true;
} }
console.log('bye'); console.log('bye');
@ -118,7 +118,7 @@ mindplot.RichTextEditor = mindplot.TextEditor.extend({
$(this.inputText).focus(); $(this.inputText).focus();
}, },
getText:function(){ getText:function(){
return this._text; return this._textShape;
}, },
lostFocusListener:function(){ lostFocusListener:function(){
this._hideNode(); this._hideNode();

View File

@ -53,6 +53,16 @@ mindplot.Topic = new Class({
this._textEditor.show(); this._textEditor.show();
event.stopPropagation(true); event.stopPropagation(true);
}.bind(this)); }.bind(this));
this._textEditor.addEvent('input', function(event, text) {
var textShape = this.getTextShape();
// var oldText = textShape.getText();
// this._setText(text, false);
// @Todo: I must resize, no change the position ...
// textShape.setText(oldText);
}.bind(this));
}, },
setShapeType : function(type) { setShapeType : function(type) {
@ -78,8 +88,6 @@ mindplot.Topic = new Class({
// Create a new one ... // Create a new one ...
var innerShape = this.getInnerShape(); var innerShape = this.getInnerShape();
// @Todo: Fix...
//innerShape.cloneEvents(oldInnerShape);
// Update figure size ... // Update figure size ...
var size = model.getSize(); var size = model.getSize();
@ -228,14 +236,14 @@ mindplot.Topic = new Class({
}, },
getTextShape : function() { getTextShape : function() {
if (!$defined(this._text)) { if (!$defined(this._textShape)) {
this._text = this._buildTextShape(false); this._textShape = this._buildTextShape(false);
// Set Text ... // Set Text ...
var text = this.getText(); var text = this.getText();
this._setText(text, false); this._setText(text, false);
} }
return this._text; return this._textShape;
}, },
getOrBuildIconGroup : function() { getOrBuildIconGroup : function() {
@ -518,12 +526,12 @@ mindplot.Topic = new Class({
_setText : function(text, updateModel) { _setText : function(text, updateModel) {
var textShape = this.getTextShape(); var textShape = this.getTextShape();
textShape.setText(text); textShape.setText(text);
this._adjustShapes(updateModel);
if ($defined(updateModel) && updateModel) { if ($defined(updateModel) && updateModel) {
var model = this.getModel(); var model = this.getModel();
model.setText(text); model.setText(text);
} }
this._adjustShapes(updateModel);
}, },
setText : function(text) { setText : function(text) {
@ -1152,7 +1160,6 @@ mindplot.Topic = new Class({
iconGroup.setPosition(topicPadding, topicPadding); iconGroup.setPosition(topicPadding, topicPadding);
iconGroup.seIconSize(fontHeight, fontHeight); iconGroup.seIconSize(fontHeight, fontHeight);
// Add a extra padding between the text and the icons // Add a extra padding between the text and the icons
var iconsWidth = iconGroup.getSize().width; var iconsWidth = iconGroup.getSize().width;
if (iconsWidth != 0) { if (iconsWidth != 0) {
@ -1169,6 +1176,7 @@ mindplot.Topic = new Class({
// Position node ... // Position node ...
textShape.setPosition(topicPadding + iconsWidth, topicPadding); textShape.setPosition(topicPadding + iconsWidth, topicPadding);
console.log(textShape.getText() + ":works ?");
}).delay(0, this); }).delay(0, this);
}, },

View File

@ -98,7 +98,7 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
result._position = this._position; result._position = this._position;
result._id = this._id; result._id = this._id;
result._mindmap = this._mindmap; result._mindmap = this._mindmap;
result._text = this._text; result._textShape = this._textShape;
result._shapeType = this._shapeType; result._shapeType = this._shapeType;
result._fontFamily = this._fontFamily; result._fontFamily = this._fontFamily;
result._fontSize = this._fontSize; result._fontSize = this._fontSize;
@ -143,7 +143,7 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
}, },
getText : function() { getText : function() {
return this._text; return this._textShape;
}, },
isNodeModel : function() { isNodeModel : function() {

View File

@ -21,13 +21,13 @@ mindplot.commands.AddNoteToTopicCommand = new Class({
initialize: function(topicId, text) { initialize: function(topicId, text) {
$assert(topicId, 'topicId can not be null'); $assert(topicId, 'topicId can not be null');
this._topicsIds = topicId; this._topicsIds = topicId;
this._text = text; this._textShape = text;
this._id = mindplot.Command._nextUUID(); this._id = mindplot.Command._nextUUID();
}, },
execute: function(commandContext) { execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0]; var topic = commandContext.findTopics(this._topicsIds)[0];
var updated = function() { var updated = function() {
topic.addNote(this._text); topic.addNote(this._textShape);
topic._adjustShapes(); topic._adjustShapes();
}.bind(this); }.bind(this);
updated.delay(0); updated.delay(0);

View File

@ -26,7 +26,7 @@ mindplot.commands.RemoveNoteFromTopicCommand = new Class({
execute: function(commandContext) execute: function(commandContext)
{ {
var topic = commandContext.findTopics(this._topicsIds)[0]; var topic = commandContext.findTopics(this._topicsIds)[0];
this._text = topic._note.getText(); this._textShape = topic._note.getText();
var updated = function() { var updated = function() {
topic.removeNote(); topic.removeNote();
}.bind(this); }.bind(this);
@ -36,7 +36,7 @@ mindplot.commands.RemoveNoteFromTopicCommand = new Class({
{ {
var topic = commandContext.findTopics(this._topicsIds)[0]; var topic = commandContext.findTopics(this._topicsIds)[0];
var updated = function() { var updated = function() {
topic.addNote(this._text,commandContext._designer); topic.addNote(this._textShape,commandContext._designer);
topic._adjustShapes(); topic._adjustShapes();
}.bind(this); }.bind(this);
updated.delay(0); updated.delay(0);

View File

@ -38,7 +38,7 @@ mindplot.model.NodeModel = new Class({
this._id = mindplot.model.NodeModel._nextUUID(); this._id = mindplot.model.NodeModel._nextUUID();
} }
this._mindmap = mindmap; this._mindmap = mindmap;
this._text = null; this._textShape = null;
this._shapeType = null; this._shapeType = null;
this._fontFamily = null; this._fontFamily = null;
this._fontSize = null; this._fontSize = null;
@ -68,7 +68,7 @@ mindplot.model.NodeModel = new Class({
result._position = this._position; result._position = this._position;
result._id = this._id; result._id = this._id;
result._mindmap = this._mindmap; result._mindmap = this._mindmap;
result._text = this._text; result._textShape = this._textShape;
result._shapeType = this._shapeType; result._shapeType = this._shapeType;
result._fontFamily = this._fontFamily; result._fontFamily = this._fontFamily;
result._fontSize = this._fontSize; result._fontSize = this._fontSize;
@ -106,11 +106,11 @@ mindplot.model.NodeModel = new Class({
}, },
setText : function(text) { setText : function(text) {
this._text = text; this._textShape = text;
}, },
getText : function() { getText : function() {
return this._text; return this._textShape;
}, },
isNodeModel : function() { isNodeModel : function() {

View File

@ -20,16 +20,16 @@ mindplot.model.NoteModel = new Class({
initialize : function(text, topic) { initialize : function(text, topic) {
$assert(text != null, 'note text can not be null'); $assert(text != null, 'note text can not be null');
$assert(topic, 'mindmap can not be null'); $assert(topic, 'mindmap can not be null');
this._text = text; this._textShape = text;
this._topic = topic; this._topic = topic;
}, },
getText:function() { getText:function() {
return this._text; return this._textShape;
}, },
setText : function(text) { setText : function(text) {
this._text = text; this._textShape = text;
}, },
getTopic : function() { getTopic : function() {

View File

@ -39,14 +39,12 @@ web2d.peer.svg.TextPeer = new Class({
}, },
setText : function(text) { setText : function(text) {
text = core.Utils.escapeInvalidTags(text);
var childs = this._native.getChildren(); var childs = this._native.getChildren();
childs.forEach(function(child) { childs.forEach(function(child) {
child.dispose(); child.dispose();
}); });
this._text = text; this._text = text;
this.setVisibility(false);
var lines = text.split('\n'); var lines = text.split('\n');
var tspans = []; var tspans = [];
@ -61,9 +59,6 @@ web2d.peer.svg.TextPeer = new Class({
this._native.appendChild(tspan); this._native.appendChild(tspan);
}.bind(this)); }.bind(this));
this.setVisibility(true);
}, },
getText : function() { getText : function() {