Add deleteCurrentLayer() to Drawing
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1953 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
cd00087f2a
commit
d85a7bc8a2
|
@ -276,6 +276,24 @@ svgedit.draw.Drawing.prototype.setCurrentLayer = function(name) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Function: svgedit.draw.Drawing.deleteCurrentLayer
|
||||||
|
// Deletes the current layer from the drawing and then clears the selection. This function
|
||||||
|
// then calls the 'changed' handler. This is an undoable action.
|
||||||
|
// Returns:
|
||||||
|
// The SVGGElement of the layer removed or null.
|
||||||
|
svgedit.draw.Drawing.prototype.deleteCurrentLayer = function() {
|
||||||
|
if (this.current_layer && this.getNumLayers() > 1) {
|
||||||
|
// actually delete from the DOM and return it
|
||||||
|
var parent = this.current_layer.parentNode;
|
||||||
|
var nextSibling = this.current_layer.nextSibling;
|
||||||
|
var oldLayerGroup = parent.removeChild(this.current_layer);
|
||||||
|
this.identifyLayers();
|
||||||
|
return oldLayerGroup;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
// Function: svgedit.draw.Drawing.identifyLayers
|
// Function: svgedit.draw.Drawing.identifyLayers
|
||||||
// Updates layer system and sets the current layer to the
|
// Updates layer system and sets the current layer to the
|
||||||
// top-most layer (last <g> child of this drawing).
|
// top-most layer (last <g> child of this drawing).
|
||||||
|
|
|
@ -66,13 +66,29 @@ function embedded_svg_edit(frame){
|
||||||
//Run in firebug on http://svg-edit.googlecode.com/svn/trunk/docs/files/svgcanvas-js.html
|
//Run in firebug on http://svg-edit.googlecode.com/svn/trunk/docs/files/svgcanvas-js.html
|
||||||
|
|
||||||
//for(var i=0,q=[],f = document.querySelectorAll("div.CFunction h3.CTitle a");i<f.length;i++){q.push(f[i].name)};q
|
//for(var i=0,q=[],f = document.querySelectorAll("div.CFunction h3.CTitle a");i<f.length;i++){q.push(f[i].name)};q
|
||||||
//var functions = ["clearSelection", "addToSelection", "removeFromSelection", "open", "save", "getSvgString", "setSvgString", "createLayer", "deleteCurrentLayer", "getCurrentLayerName", "setCurrentLayer", "renameCurrentLayer", "setCurrentLayerPosition", "setLayerVisibility", "moveSelectedToLayer", "clear"];
|
//var functions = ["clearSelection", "addToSelection", "removeFromSelection", "open", "save", "getSvgString", "setSvgString",
|
||||||
|
//"createLayer", "deleteCurrentLayer", "setCurrentLayer", "renameCurrentLayer", "setCurrentLayerPosition", "setLayerVisibility",
|
||||||
|
//"moveSelectedToLayer", "clear"];
|
||||||
|
|
||||||
|
|
||||||
//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
|
//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)}};
|
//var l=[];for(var i in svgCanvas){if(typeof svgCanvas[i] == "function"){l.push(i)}};
|
||||||
//run in svgedit itself
|
//run in svgedit itself
|
||||||
var functions = ["updateElementFromJson", "embedImage", "fixOperaXML", "clearSelection", "addToSelection", "removeFromSelection", "addNodeToSelection", "open", "save", "getSvgString", "setSvgString", "createLayer", "deleteCurrentLayer", "getCurrentLayerName", "setCurrentLayer", "renameCurrentLayer", "setCurrentLayerPosition", "setLayerVisibility", "moveSelectedToLayer", "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", "getCurrentDrawing", "setCurrentLayer", "renameCurrentLayer", "setCurrentLayerPosition",
|
||||||
|
"setLayerVisibility", "moveSelectedToLayer", "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.
|
//TODO: rewrite the following, it's pretty scary.
|
||||||
for(var i = 0; i < functions.length; i++){
|
for(var i = 0; i < functions.length; i++){
|
||||||
|
|
|
@ -831,7 +831,7 @@
|
||||||
var link_str = '';
|
var link_str = '';
|
||||||
if(context) {
|
if(context) {
|
||||||
var str = '';
|
var str = '';
|
||||||
link_str = '<a href="#" data-root="y">' + svgCanvas.getCurrentLayerName() + '</a>';
|
link_str = '<a href="#" data-root="y">' + svgCanvas.getCurrentDrawing().getCurrentLayerName() + '</a>';
|
||||||
|
|
||||||
$(context).parentsUntil('#svgcontent > g').andSelf().each(function() {
|
$(context).parentsUntil('#svgcontent > g').andSelf().each(function() {
|
||||||
if(this.id) {
|
if(this.id) {
|
||||||
|
@ -1478,7 +1478,7 @@
|
||||||
var elem = selectedElement;
|
var elem = selectedElement;
|
||||||
// If element has just been deleted, consider it null
|
// If element has just been deleted, consider it null
|
||||||
if(elem != null && !elem.parentNode) elem = null;
|
if(elem != null && !elem.parentNode) elem = null;
|
||||||
var currentLayerName = svgCanvas.getCurrentLayerName();
|
var currentLayerName = svgCanvas.getCurrentDrawing().getCurrentLayerName();
|
||||||
var currentMode = svgCanvas.getMode();
|
var currentMode = svgCanvas.getMode();
|
||||||
var unit = curConfig.baseUnit !== 'px' ? curConfig.baseUnit : null;
|
var unit = curConfig.baseUnit !== 'px' ? curConfig.baseUnit : null;
|
||||||
|
|
||||||
|
@ -3599,7 +3599,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloneLayer() {
|
function cloneLayer() {
|
||||||
var name = svgCanvas.getCurrentLayerName() + ' copy';
|
var name = svgCanvas.getCurrentDrawing().getCurrentLayerName() + ' copy';
|
||||||
|
|
||||||
$.prompt(uiStrings.notification.enterUniqueLayerName, name, function(newName) {
|
$.prompt(uiStrings.notification.enterUniqueLayerName, name, function(newName) {
|
||||||
if (!newName) return;
|
if (!newName) return;
|
||||||
|
@ -3748,7 +3748,7 @@
|
||||||
var selLayerNames = $('#selLayerNames');
|
var selLayerNames = $('#selLayerNames');
|
||||||
layerlist.empty();
|
layerlist.empty();
|
||||||
selLayerNames.empty();
|
selLayerNames.empty();
|
||||||
var currentLayerName = svgCanvas.getCurrentLayerName();
|
var currentLayerName = svgCanvas.getCurrentDrawing().getCurrentLayerName();
|
||||||
var layer = svgCanvas.getCurrentDrawing().getNumLayers();
|
var layer = svgCanvas.getCurrentDrawing().getNumLayers();
|
||||||
var icon = $.getSvgIcon('eye');
|
var icon = $.getSvgIcon('eye');
|
||||||
// we get the layers in the reverse z-order (the layer rendered on top is listed first)
|
// we get the layers in the reverse z-order (the layer rendered on top is listed first)
|
||||||
|
|
|
@ -7020,33 +7020,22 @@ this.cloneLayer = function(name) {
|
||||||
// Deletes the current layer from the drawing and then clears the selection. This function
|
// Deletes the current layer from the drawing and then clears the selection. This function
|
||||||
// then calls the 'changed' handler. This is an undoable action.
|
// then calls the 'changed' handler. This is an undoable action.
|
||||||
this.deleteCurrentLayer = function() {
|
this.deleteCurrentLayer = function() {
|
||||||
if (current_drawing.current_layer && current_drawing.getNumLayers() > 1) {
|
var current_layer = current_drawing.getCurrentLayer();
|
||||||
|
var nextSibling = current_layer.nextSibling;
|
||||||
|
var parent = current_layer.parentNode;
|
||||||
|
current_layer = current_drawing.deleteCurrentLayer();
|
||||||
|
if (current_layer) {
|
||||||
var batchCmd = new BatchCommand("Delete Layer");
|
var batchCmd = new BatchCommand("Delete Layer");
|
||||||
// actually delete from the DOM and store in our Undo History
|
// store in our Undo History
|
||||||
var parent = current_drawing.current_layer.parentNode;
|
batchCmd.addSubCommand(new RemoveElementCommand(current_layer, nextSibling, parent));
|
||||||
var nextSibling = current_drawing.current_layer.nextSibling;
|
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(current_drawing.current_layer, nextSibling, parent));
|
|
||||||
parent.removeChild(current_drawing.current_layer);
|
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
clearSelection();
|
clearSelection();
|
||||||
identifyLayers();
|
call("changed", [parent]);
|
||||||
canvas.setCurrentLayer(current_drawing.getLayerName(current_drawing.getNumLayers()));
|
|
||||||
call("changed", [svgcontent]);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: getCurrentLayerName
|
|
||||||
// Returns the name of the currently selected layer in the current drawing. If an error occurs, an empty string
|
|
||||||
// is returned.
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// The name of the currently active layer in the current drawing.
|
|
||||||
this.getCurrentLayerName = function() {
|
|
||||||
return getCurrentDrawing().getCurrentLayerName();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Function: setCurrentLayer
|
// Function: setCurrentLayer
|
||||||
// Sets the current layer. If the name is not a valid layer name, then this function returns
|
// 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.
|
// false. Otherwise it returns true. This is not an undo-able action.
|
||||||
|
@ -7417,7 +7406,7 @@ this.setConfig = function(opts) {
|
||||||
$.extend(curConfig, opts);
|
$.extend(curConfig, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function: getDocumentTitle
|
// Function: getTitle
|
||||||
// Returns the current group/SVG's title contents
|
// Returns the current group/SVG's title contents
|
||||||
this.getTitle = function(elem) {
|
this.getTitle = function(elem) {
|
||||||
elem = elem || selectedElements[0];
|
elem = elem || selectedElements[0];
|
||||||
|
|
|
@ -330,8 +330,8 @@
|
||||||
|
|
||||||
var drawing = new svgedit.draw.Drawing(svg);
|
var drawing = new svgedit.draw.Drawing(svg);
|
||||||
setupSvgWith3Layers(svg);
|
setupSvgWith3Layers(svg);
|
||||||
|
|
||||||
drawing.identifyLayers();
|
drawing.identifyLayers();
|
||||||
|
|
||||||
ok(drawing.getCurrentLayer);
|
ok(drawing.getCurrentLayer);
|
||||||
equals(typeof drawing.getCurrentLayer, typeof function(){});
|
equals(typeof drawing.getCurrentLayer, typeof function(){});
|
||||||
ok(drawing.getCurrentLayer());
|
ok(drawing.getCurrentLayer());
|
||||||
|
@ -343,8 +343,8 @@
|
||||||
|
|
||||||
var drawing = new svgedit.draw.Drawing(svg);
|
var drawing = new svgedit.draw.Drawing(svg);
|
||||||
setupSvgWith3Layers(svg);
|
setupSvgWith3Layers(svg);
|
||||||
|
|
||||||
drawing.identifyLayers();
|
drawing.identifyLayers();
|
||||||
|
|
||||||
ok(drawing.setCurrentLayer);
|
ok(drawing.setCurrentLayer);
|
||||||
equals(typeof drawing.setCurrentLayer, typeof function(){});
|
equals(typeof drawing.setCurrentLayer, typeof function(){});
|
||||||
|
|
||||||
|
@ -391,6 +391,8 @@
|
||||||
ok(drawing.getLayerVisibility(LAYER1));
|
ok(drawing.getLayerVisibility(LAYER1));
|
||||||
ok(drawing.getLayerVisibility(LAYER2));
|
ok(drawing.getLayerVisibility(LAYER2));
|
||||||
ok(drawing.getLayerVisibility(LAYER3));
|
ok(drawing.getLayerVisibility(LAYER3));
|
||||||
|
|
||||||
|
cleanupSvg(svg);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test setLayerVisibility()', function() {
|
test('Test setLayerVisibility()', function() {
|
||||||
|
@ -413,6 +415,8 @@
|
||||||
|
|
||||||
drawing.setLayerVisibility(LAYER3, 'test-string');
|
drawing.setLayerVisibility(LAYER3, 'test-string');
|
||||||
ok(!drawing.getLayerVisibility(LAYER3));
|
ok(!drawing.getLayerVisibility(LAYER3));
|
||||||
|
|
||||||
|
cleanupSvg(svg);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test getLayerOpacity()', function() {
|
test('Test getLayerOpacity()', function() {
|
||||||
|
@ -427,6 +431,8 @@
|
||||||
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
|
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
|
||||||
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
|
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
|
||||||
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
|
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
|
||||||
|
|
||||||
|
cleanupSvg(svg);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test setLayerOpacity()', function() {
|
test('Test setLayerOpacity()', function() {
|
||||||
|
@ -450,6 +456,28 @@
|
||||||
|
|
||||||
drawing.setLayerOpacity(LAYER3, 100);
|
drawing.setLayerOpacity(LAYER3, 100);
|
||||||
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
|
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
|
||||||
|
|
||||||
|
cleanupSvg(svg);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Test deleteCurrentLayer()', function() {
|
||||||
|
expect(6);
|
||||||
|
|
||||||
|
var drawing = new svgedit.draw.Drawing(svg);
|
||||||
|
setupSvgWith3Layers(svg);
|
||||||
|
drawing.identifyLayers();
|
||||||
|
|
||||||
|
drawing.setCurrentLayer(LAYER2);
|
||||||
|
|
||||||
|
var curLayer = drawing.getCurrentLayer();
|
||||||
|
equals(curLayer, drawing.all_layers[1][1]);
|
||||||
|
var deletedLayer = drawing.deleteCurrentLayer();
|
||||||
|
|
||||||
|
equals(curLayer, deletedLayer);
|
||||||
|
equals(2, drawing.getNumLayers());
|
||||||
|
equals(LAYER1, drawing.all_layers[0][0]);
|
||||||
|
equals(LAYER3, drawing.all_layers[1][0]);
|
||||||
|
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue