Fix collapse using keybard.

This commit is contained in:
Paulo Gustavo Veiga 2012-07-02 22:54:59 -03:00
parent 1df9afda1b
commit 31c86d053d
8 changed files with 71 additions and 50 deletions

View File

@ -351,6 +351,27 @@ mindplot.Designer = new Class({
return this._model; return this._model;
}, },
shrinkSelectedBranch:function () {
var nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0) {
// If there are more than one node selected,
$notify($msg('ONE_TOPIC_MUST_BE_SELECTED'));
return;
}
if (nodes.length != 1) {
// If there are more than one node selected,
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED'));
return;
}
// Execute event ...
var topic = nodes[0];
this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken());
},
createChildForSelectedNode:function () { createChildForSelectedNode:function () {
var nodes = this.getModel().filterSelectedTopics(); var nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0) { if (nodes.length <= 0) {

View File

@ -19,140 +19,134 @@
mindplot.DesignerKeyboard = new Class({ mindplot.DesignerKeyboard = new Class({
Extends:Keyboard, Extends:Keyboard,
Static:{ Static:{
register: function(designer) { register:function (designer) {
this._instance = new mindplot.DesignerKeyboard(designer); this._instance = new mindplot.DesignerKeyboard(designer);
this._instance.activate(); this._instance.activate();
}, },
getInstance: function() { getInstance:function () {
return this._instance; return this._instance;
} }
}, },
initialize : function(designer) { initialize:function (designer) {
$assert(designer, "designer can not be null"); $assert(designer, "designer can not be null");
this.parent({defaultEventType: 'keydown'}); this.parent({defaultEventType:'keydown'});
this._registerEvents(designer); this._registerEvents(designer);
}, },
_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 = {
'backspace':function(event) { 'backspace':function (event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.deleteCurrentNode(); designer.deleteCurrentNode();
}.bind(this), }.bind(this),
'space' : function() { 'space':function () {
var node = model.selectedTopic(); designer.shrinkSelectedBranch();
if (node) {
var model = topic.getModel();
var isShrink = !model.areChildrenShrunken();
topic.setChildrenShrunken(isShrink);
}
}.bind(this), }.bind(this),
'f2' : function() { 'f2':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
node.showTextEditor(); node.showTextEditor();
} }
}.bind(this), }.bind(this),
'delete' : function() { 'delete':function () {
designer.deleteCurrentNode(); designer.deleteCurrentNode();
}.bind(this), }.bind(this),
'enter' : 'enter':function () {
function() {
designer.createSiblingForSelectedNode(); designer.createSiblingForSelectedNode();
}.bind(this), }.bind(this),
'insert' : function() { 'insert':function () {
designer.createChildForSelectedNode(); designer.createChildForSelectedNode();
}.bind(this), }.bind(this),
'meta+enter' : function() { 'meta+enter':function () {
designer.createChildForSelectedNode(); designer.createChildForSelectedNode();
}.bind(this), }.bind(this),
'ctrl+z' : function() { 'ctrl+z':function () {
designer.undo(); designer.undo();
}.bind(this), }.bind(this),
'meta+z' : function() { 'meta+z':function () {
designer.undo(); designer.undo();
}.bind(this), }.bind(this),
'ctrl+z+shift' :function() { 'ctrl+z+shift':function () {
designer.redo(); designer.redo();
}.bind(this), }.bind(this),
'meta+z+shift' : function() { 'meta+z+shift':function () {
designer.redo(); designer.redo();
}.bind(this), }.bind(this),
'ctrl+y' :function() { 'ctrl+y':function () {
designer.redo(); designer.redo();
}.bind(this), }.bind(this),
'meta+y' : function() { 'meta+y':function () {
designer.redo(); designer.redo();
}.bind(this), }.bind(this),
'ctrl+a' : function(event) { 'ctrl+a':function (event) {
designer.selectAll(); designer.selectAll();
event.preventDefault(); event.preventDefault();
}, },
'ctrl+b' : function() { 'ctrl+b':function () {
designer.changeFontWeight(); designer.changeFontWeight();
}, },
'meta+b' : function() { 'meta+b':function () {
designer.changeFontWeight(); designer.changeFontWeight();
}, },
'ctrl+s' : function(event) { 'ctrl+s':function (event) {
event.preventDefault(); event.preventDefault();
$('save').fireEvent('click'); $('save').fireEvent('click');
}, },
'meta+s' : function(event) { 'meta+s':function (event) {
event.preventDefault(); event.preventDefault();
$('save').fireEvent('click'); $('save').fireEvent('click');
}, },
'ctrl+i' : function() { 'ctrl+i':function () {
designer.changeFontStyle(); designer.changeFontStyle();
}, },
'meta+i' : function() { 'meta+i':function () {
designer.changeFontStyle(); designer.changeFontStyle();
}, },
'meta+shift+a' : function(event) { 'meta+shift+a':function (event) {
designer.deselectAll(); designer.deselectAll();
event.preventDefault(); event.preventDefault();
}, },
'ctrl+shift+a' : function(event) { 'ctrl+shift+a':function (event) {
designer.deselectAll(); designer.deselectAll();
event.preventDefault(); event.preventDefault();
}, },
'meta+a' : function(event) { 'meta+a':function (event) {
designer.selectAll(); designer.selectAll();
event.preventDefault(); event.preventDefault();
}, },
'right' : function() { 'right':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
@ -172,7 +166,7 @@ mindplot.DesignerKeyboard = new Class({
} }
}.bind(this), }.bind(this),
'left' : function() { 'left':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
@ -192,7 +186,7 @@ mindplot.DesignerKeyboard = new Class({
} }
}.bind(this), }.bind(this),
'up' : function() { 'up':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
@ -204,7 +198,7 @@ mindplot.DesignerKeyboard = new Class({
} }
}.bind(this), }.bind(this),
'down' : function() { 'down':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
@ -220,13 +214,13 @@ mindplot.DesignerKeyboard = new Class({
var regex = /^(?:shift|control|ctrl|alt|meta)$/; var regex = /^(?:shift|control|ctrl|alt|meta)$/;
var modifiers = ['shift', 'control', 'alt', 'meta']; var modifiers = ['shift', 'control', 'alt', 'meta'];
var excludes = ['esc','capslock','tab','f1','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12','backspace','down','up','left','right','control']; var excludes = ['esc', 'capslock', 'tab', 'f1', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'backspace', 'down', 'up', 'left', 'right', 'control'];
$(document).addEvent('keydown', function(event) { $(document).addEvent('keydown', function (event) {
// Convert key to mootools keyboard event format... // Convert key to mootools keyboard event format...
var keys = []; var keys = [];
modifiers.each(function(mod) { modifiers.each(function (mod) {
if (event[mod]) keys.push(mod); if (event[mod]) keys.push(mod);
}); });
if (!regex.test(event.key)) if (!regex.test(event.key))
@ -261,7 +255,7 @@ mindplot.DesignerKeyboard = new Class({
}, },
_goToBrother : function(designer, node, direction) { _goToBrother:function (designer, node, direction) {
var brothers = node._parent.getChildren(); var brothers = node._parent.getChildren();
var target = node; var target = node;
var y = node.getPosition().y; var y = node.getPosition().y;
@ -298,7 +292,7 @@ mindplot.DesignerKeyboard = new Class({
}, },
_goToSideChild : function(designer, node, side) { _goToSideChild:function (designer, node, side) {
var children = node.getChildren(); var children = node.getChildren();
if (children.length > 0) { if (children.length > 0) {
var target = children[0]; var target = children[0];
@ -324,12 +318,12 @@ mindplot.DesignerKeyboard = new Class({
} }
}, },
_goToParent : function(designer, node) { _goToParent:function (designer, node) {
var parent = node._parent; var parent = node._parent;
this._goToNode(designer, parent); this._goToNode(designer, parent);
}, },
_goToChild : function(designer, node) { _goToChild:function (designer, node) {
var children = node.getChildren(); var children = node.getChildren();
if (children.length > 0) { if (children.length > 0) {
var target = children[0]; var target = children[0];
@ -345,7 +339,7 @@ mindplot.DesignerKeyboard = new Class({
} }
}, },
_goToNode : function(designer, node) { _goToNode:function (designer, node) {
// First deselect all the nodes ... // First deselect all the nodes ...
designer.deselectAll(); designer.deselectAll();

View File

@ -624,7 +624,6 @@ mindplot.Topic = new Class({
model.setChildrenShrunken(value); model.setChildrenShrunken(value);
// Change render base on the state. // Change render base on the state.
var shrinkConnector = this.getShrinkConnector(); var shrinkConnector = this.getShrinkConnector();
if ($defined(shrinkConnector)) { if ($defined(shrinkConnector)) {
shrinkConnector.changeRender(value); shrinkConnector.changeRender(value);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -202,4 +202,5 @@ SAVE_CHANGES=Save Chages
CHANGE_TEXT_ITALIC=Change Text Italic CHANGE_TEXT_ITALIC=Change Text Italic
DESELECT_ALL_TOPIC=Deselect All Topic DESELECT_ALL_TOPIC=Deselect All Topic
SHORTCUTS=Shortcuts SHORTCUTS=Shortcuts
COLLAPSE_CHILDREN=Collapse Children

View File

@ -203,4 +203,5 @@ SAVE_CHANGES=Guardar los Cambios
CHANGE_TEXT_ITALIC=Cambiar Texto a Italica CHANGE_TEXT_ITALIC=Cambiar Texto a Italica
DESELECT_ALL_TOPIC=Revertir Selecci\u00f3n de T\u00f3picos DESELECT_ALL_TOPIC=Revertir Selecci\u00f3n de T\u00f3picos
SHORTCUTS=Shortcuts SHORTCUTS=Shortcuts
COLLAPSE_CHILDREN=Colapsar Hijos

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -63,6 +63,11 @@
<td><spring:message code="JUST_START_TYPING"/> | F2</td> <td><spring:message code="JUST_START_TYPING"/> | F2</td>
<td><spring:message code="JUST_START_TYPING"/> | F2</td> <td><spring:message code="JUST_START_TYPING"/> | F2</td>
</tr> </tr>
<tr>
<td><spring:message code="COLLAPSE_CHILDREN"/></td>
<td>Space bar</td>
<td>Space bar</td>
</tr>
<tr> <tr>
<td><spring:message code="TOPIC_NAVIGATION"/></td> <td><spring:message code="TOPIC_NAVIGATION"/></td>
<td><spring:message code="ARROW_KEYS"/></td> <td><spring:message code="ARROW_KEYS"/></td>