adding clearState function for tools and using clearState if no selection exists

Originally committed in SVN as r114418 by Christian, missed the git
conversion

Change-Id: I56e91c170670519fa2b482a4b7f30cdcbc8ff163
This commit is contained in:
Catrope 2012-03-22 13:53:26 -07:00
parent 7b20509b78
commit 826437950c
2 changed files with 29 additions and 21 deletions

View file

@ -22,3 +22,7 @@ ve.ui.Tool.tools = {};
ve.ui.Tool.prototype.updateState = function() {
throw 'Tool.updateState not implemented in this subclass:' + this.constructor;
};
ve.ui.Tool.prototype.clearState = function() {
this.$.removeClass( 'es-toolbarButtonTool-down' );
}

View file

@ -17,31 +17,35 @@ ve.ui.Toolbar = function( $container, surfaceView, config ) {
this.tools = [];
this.surfaceView.surfaceObserver.on( 'select', function ( selection ) {
var annotations = _this.surfaceView.getAnnotations(),
nodes = [],
model = _this.surfaceView.documentView.model;
if ( selection.from === selection.to ) {
nodes.push( model.getNodeFromOffset( selection.from ) );
} else {
var startNode = model.getNodeFromOffset( selection.start ),
endNode = model.getNodeFromOffset( selection.end );
if ( startNode === endNode ) {
nodes.push( startNode );
} else {
model.traverseLeafNodes( function( node ) {
nodes.push( node );
if( node === endNode ) {
return false;
}
}, startNode );
}
}
if ( selection !== null ) {
var annotations = _this.surfaceView.getAnnotations(),
nodes = [],
model = _this.surfaceView.documentView.model;
if ( selection.from === selection.to ) {
nodes.push( model.getNodeFromOffset( selection.from ) );
} else {
var startNode = model.getNodeFromOffset( selection.start ),
endNode = model.getNodeFromOffset( selection.end );
if ( startNode === endNode ) {
nodes.push( startNode );
} else {
model.traverseLeafNodes( function( node ) {
nodes.push( node );
if( node === endNode ) {
return false;
}
}, startNode );
}
}
for( var i = 0; i < _this.tools.length; i++ ) {
_this.tools[i].updateState( annotations, nodes );
}
} else {
for( var i = 0; i < _this.tools.length; i++ ) {
_this.tools[i].clearState();
}
}
});