Move hasLayer() into svgedit.draw.Drawing
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1926 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
0db154bff4
commit
6f9f943093
|
@ -132,15 +132,16 @@ svgedit.draw.Drawing.prototype.getNextId = function() {
|
|||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Releases the object Id, letting it be used as the next id in getNextId().
|
||||
* This method DOES NOT remove any elements from the DOM, it is expected
|
||||
* that client code will do this.
|
||||
*
|
||||
* @param {String} The id to release.
|
||||
* @return {boolean} Returns true if the id was valid to be released,
|
||||
* false otherwise.
|
||||
*/
|
||||
// Function: svgedit.draw.Drawing.releaseId
|
||||
// Releases the object Id, letting it be used as the next id in getNextId().
|
||||
// This method DOES NOT remove any elements from the DOM, it is expected
|
||||
// that client code will do this.
|
||||
//
|
||||
// Parameters:
|
||||
// id - The id to release.
|
||||
//
|
||||
// Returns:
|
||||
// True if the id was valid to be released, false otherwise.
|
||||
svgedit.draw.Drawing.prototype.releaseId = function(id) {
|
||||
// confirm if this is a valid id for this Document, else return false
|
||||
var front = this.idPrefix + (this.nonce_ ? this.nonce_ +'_' : '');
|
||||
|
@ -162,7 +163,7 @@ svgedit.draw.Drawing.prototype.releaseId = function(id) {
|
|||
return true;
|
||||
};
|
||||
|
||||
// Function: getNumLayers
|
||||
// Function: svgedit.draw.Drawing.getNumLayers
|
||||
// Returns the number of layers in the current drawing.
|
||||
//
|
||||
// Returns:
|
||||
|
@ -171,4 +172,14 @@ svgedit.draw.Drawing.prototype.getNumLayers = function() {
|
|||
return this.all_layers.length;
|
||||
};
|
||||
|
||||
// Function: svgedit.draw.Drawing.hasLayer
|
||||
// Check if layer with given name already exists
|
||||
svgedit.draw.Drawing.prototype.hasLayer = function(name) {
|
||||
for(var i = 0; i < this.getNumLayers(); i++) {
|
||||
if(this.all_layers[i][0] == name) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
})();
|
||||
|
|
|
@ -72,7 +72,7 @@ function embedded_svg_edit(frame){
|
|||
//Newer, well, it extracts things that aren't documented as well. All functions accessible through the normal thingy can now be accessed though the API
|
||||
//var l=[];for(var i in svgCanvas){if(typeof svgCanvas[i] == "function"){l.push(i)}};
|
||||
//run in svgedit itself
|
||||
var functions = ["updateElementFromJson", "embedImage", "fixOperaXML", "clearSelection", "addToSelection", "removeFromSelection", "addNodeToSelection", "open", "save", "getSvgString", "setSvgString", "createLayer", "deleteCurrentLayer", "getNumLayers", "getLayer", "getCurrentLayer", "setCurrentLayer", "renameCurrentLayer", "setCurrentLayerPosition", "getLayerVisibility", "setLayerVisibility", "moveSelectedToLayer", "getLayerOpacity", "setLayerOpacity", "clear", "clearPath", "getNodePoint", "clonePathNode", "deletePathNode", "getResolution", "getImageTitle", "setImageTitle", "setResolution", "setBBoxZoom", "setZoom", "getMode", "setMode", "getStrokeColor", "setStrokeColor", "getFillColor", "setFillColor", "setStrokePaint", "setFillPaint", "getStrokeWidth", "setStrokeWidth", "getStrokeStyle", "setStrokeStyle", "getOpacity", "setOpacity", "getFillOpacity", "setFillOpacity", "getStrokeOpacity", "setStrokeOpacity", "getTransformList", "getBBox", "getRotationAngle", "setRotationAngle", "each", "bind", "setIdPrefix", "getBold", "setBold", "getItalic", "setItalic", "getFontFamily", "setFontFamily", "getFontSize", "setFontSize", "getText", "setTextContent", "setImageURL", "setRectRadius", "setSegType", "quickClone", "changeSelectedAttributeNoUndo", "changeSelectedAttribute", "deleteSelectedElements", "groupSelectedElements", "ungroupSelectedElement", "moveToTopSelectedElement", "moveToBottomSelectedElement", "moveSelectedElements", "getStrokedBBox", "getVisibleElements", "cycleElement", "getUndoStackSize", "getRedoStackSize", "getNextUndoCommandText", "getNextRedoCommandText", "undo", "redo", "cloneSelectedElements", "alignSelectedElements", "getZoom", "getVersion", "setIconSize", "setLang", "setCustomHandlers"]
|
||||
var functions = ["updateElementFromJson", "embedImage", "fixOperaXML", "clearSelection", "addToSelection", "removeFromSelection", "addNodeToSelection", "open", "save", "getSvgString", "setSvgString", "createLayer", "deleteCurrentLayer", "getLayer", "getCurrentLayer", "setCurrentLayer", "renameCurrentLayer", "setCurrentLayerPosition", "getLayerVisibility", "setLayerVisibility", "moveSelectedToLayer", "getLayerOpacity", "setLayerOpacity", "clear", "clearPath", "getNodePoint", "clonePathNode", "deletePathNode", "getResolution", "getImageTitle", "setImageTitle", "setResolution", "setBBoxZoom", "setZoom", "getMode", "setMode", "getStrokeColor", "setStrokeColor", "getFillColor", "setFillColor", "setStrokePaint", "setFillPaint", "getStrokeWidth", "setStrokeWidth", "getStrokeStyle", "setStrokeStyle", "getOpacity", "setOpacity", "getFillOpacity", "setFillOpacity", "getStrokeOpacity", "setStrokeOpacity", "getTransformList", "getBBox", "getRotationAngle", "setRotationAngle", "each", "bind", "setIdPrefix", "getBold", "setBold", "getItalic", "setItalic", "getFontFamily", "setFontFamily", "getFontSize", "setFontSize", "getText", "setTextContent", "setImageURL", "setRectRadius", "setSegType", "quickClone", "changeSelectedAttributeNoUndo", "changeSelectedAttribute", "deleteSelectedElements", "groupSelectedElements", "ungroupSelectedElement", "moveToTopSelectedElement", "moveToBottomSelectedElement", "moveSelectedElements", "getStrokedBBox", "getVisibleElements", "cycleElement", "getUndoStackSize", "getRedoStackSize", "getNextUndoCommandText", "getNextRedoCommandText", "undo", "redo", "cloneSelectedElements", "alignSelectedElements", "getZoom", "getVersion", "setIconSize", "setLang", "setCustomHandlers"]
|
||||
|
||||
//TODO: rewrite the following, it's pretty scary.
|
||||
for(var i = 0; i < functions.length; i++){
|
||||
|
|
|
@ -3541,11 +3541,11 @@
|
|||
var i = svgCanvas.getCurrentDrawing().getNumLayers();
|
||||
do {
|
||||
var uniqName = uiStrings.layers.layer + " " + ++i;
|
||||
} while(svgCanvas.hasLayer(uniqName));
|
||||
} while(svgCanvas.getCurrentDrawing().hasLayer(uniqName));
|
||||
|
||||
$.prompt(uiStrings.notification.enterUniqueLayerName,uniqName, function(newName) {
|
||||
if (!newName) return;
|
||||
if (svgCanvas.hasLayer(newName)) {
|
||||
if (svgCanvas.getCurrentDrawing().hasLayer(newName)) {
|
||||
$.alert(uiStrings.notification.dupeLayerName);
|
||||
return;
|
||||
}
|
||||
|
@ -3572,7 +3572,7 @@
|
|||
|
||||
$.prompt(uiStrings.notification.enterUniqueLayerName, name, function(newName) {
|
||||
if (!newName) return;
|
||||
if (svgCanvas.hasLayer(newName)) {
|
||||
if (svgCanvas.getCurrentDrawing().hasLayer(newName)) {
|
||||
$.alert(uiStrings.notification.dupeLayerName);
|
||||
return;
|
||||
}
|
||||
|
@ -3614,7 +3614,7 @@
|
|||
var oldName = $('#layerlist tr.layersel td.layername').text();
|
||||
$.prompt(uiStrings.notification.enterNewLayerName,"", function(newName) {
|
||||
if (!newName) return;
|
||||
if (oldName == newName || svgCanvas.hasLayer(newName)) {
|
||||
if (oldName == newName || svgCanvas.getCurrentDrawing().hasLayer(newName)) {
|
||||
$.alert(uiStrings.notification.layerHasThatName);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -7086,17 +7086,6 @@ this.deleteCurrentLayer = function() {
|
|||
return false;
|
||||
};
|
||||
|
||||
// Function: hasLayer
|
||||
// Check if layer with given name already exists
|
||||
this.hasLayer = function(name) {
|
||||
for(var i = 0; i < current_drawing.all_layers.length; i++) {
|
||||
if(current_drawing.all_layers[i][0] == name) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.getNumLayers = function() { return current_drawing.getNumLayers(); };
|
||||
|
||||
// Function: getLayer
|
||||
// Returns the name of the ith layer. If the index is out of range, an empty string is returned.
|
||||
//
|
||||
|
|
|
@ -177,6 +177,15 @@
|
|||
var doc = new svgedit.draw.Drawing(svg);
|
||||
equals(typeof doc.getNumLayers, typeof function() {});
|
||||
equals(doc.getNumLayers(), 0);
|
||||
// TODO(codedread): More here once identifyLayers works.
|
||||
});
|
||||
|
||||
test('Test hasLayer', function() {
|
||||
expect(2);
|
||||
var doc = new svgedit.draw.Drawing(svg);
|
||||
equals(typeof doc.hasLayer, typeof function() {});
|
||||
ok(!doc.hasLayer('invalid-layer'));
|
||||
// TODO(codedread): More here once identifyLayers works.
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue