Move setCurrentLayer() into Drawing. Rename getCurrentLayer() to getCurrentLayerName() and move into Drawing. Tests.

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1937 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Jeff Schiller
2011-01-26 03:18:59 +00:00
parent 493ac8ae41
commit ec56e8b2c3
5 changed files with 122 additions and 73 deletions

View File

@@ -90,6 +90,7 @@ svgedit.draw.Drawing = function(svgElem, opt_idPrefix) {
/**
* The current layer being used.
* TODO: Make this a {Layer}.
* @type {SVGGElement}
*/
this.current_layer = null;
@@ -115,10 +116,6 @@ svgedit.draw.Drawing.prototype.getSvgElem = function() {
return this.svgElem_;
};
svgedit.draw.Drawing.prototype.getCurrentLayer = function() {
return this.current_layer;
};
svgedit.draw.Drawing.prototype.getNonce = function() {
return this.nonce_;
};
@@ -218,6 +215,67 @@ svgedit.draw.Drawing.prototype.hasLayer = function(name) {
return false;
};
// Function: svgedit.draw.Drawing.getLayerName
// Returns the name of the ith layer. If the index is out of range, an empty string is returned.
//
// Parameters:
// i - the zero-based index of the layer you are querying.
//
// Returns:
// The name of the ith layer
svgedit.draw.Drawing.prototype.getLayerName = function(i) {
if (i >= 0 && i < this.getNumLayers()) {
return this.all_layers[i][0];
}
return "";
};
// Function: svgedit.draw.Drawing.getCurrentLayer
// Returns:
// The SVGGElement representing the current layer.
svgedit.draw.Drawing.prototype.getCurrentLayer = function() {
return this.current_layer;
};
// Function: getCurrentLayerName
// Returns the name of the currently selected layer. If an error occurs, an empty string
// is returned.
//
// Returns:
// The name of the currently active layer.
svgedit.draw.Drawing.prototype.getCurrentLayerName = function() {
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.all_layers[i][1] == this.current_layer) {
return this.getLayerName(i);
}
}
return "";
};
// Function: setCurrentLayer
// Sets the current layer. If the name is not a valid layer name, then this function returns
// false. Otherwise it returns true. This is not an undo-able action.
//
// Parameters:
// name - the name of the layer you want to switch to.
//
// Returns:
// true if the current layer was switched, otherwise false
svgedit.draw.Drawing.prototype.setCurrentLayer = function(name) {
for (var i = 0; i < this.getNumLayers(); ++i) {
if (name == this.getLayerName(i)) {
if (this.current_layer != this.all_layers[i][1]) {
this.current_layer.setAttribute("style", "pointer-events:none");
this.current_layer = this.all_layers[i][1];
this.current_layer.setAttribute("style", "pointer-events:all");
}
return true;
}
}
return false;
};
// Function: svgedit.draw.Drawing.identifyLayers
// Updates layer system
svgedit.draw.Drawing.prototype.identifyLayers = function() {
@@ -284,20 +342,4 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
};
// Function: svgedit.draw.Drawing.getLayer
// Returns the name of the ith layer. If the index is out of range, an empty string is returned.
//
// Parameters:
// i - the zero-based index of the layer you are querying.
//
// Returns:
// The name of the ith layer
svgedit.draw.Drawing.prototype.getLayer = function(i) {
if (i >= 0 && i < this.getNumLayers()) {
return this.all_layers[i][0];
}
return "";
};
})();