Switch order of layers (top-most layer is the one that is rendered on top now)

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@689 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-09-23 03:05:27 +00:00
parent 6b0bec3a0d
commit 2033115a3e
2 changed files with 17 additions and 11 deletions

View File

@ -1100,7 +1100,7 @@ function svg_edit_setup() {
updateContextPanel();
populateLayers();
$('#layerlist option').removeAttr("selected");
$('#layerlist option:last').attr("selected", "selected");
$('#layerlist option:first').attr("selected", "selected");
});
$('#layer_delete').click(function() {
@ -1110,7 +1110,7 @@ function svg_edit_setup() {
// This matches what SvgCanvas does
// TODO: make this behavior less brittle (svg-editor should get which
// layer is selected from the canvas and then select that one in the UI)
$('#layerlist option:last').attr("selected", "selected");
$('#layerlist option:first').attr("selected", "selected");
}
});
@ -1118,8 +1118,9 @@ function svg_edit_setup() {
// find index position of selected option
var curIndex = $('#layerlist option:selected').prevAll().length;
if (curIndex > 0) {
var total = $('#layerlist option').length;
curIndex--;
svgCanvas.setCurrentLayerPosition(curIndex);
svgCanvas.setCurrentLayerPosition(total-curIndex-1);
populateLayers();
$('#layerlist option').removeAttr("selected");
$('#layerlist option:eq('+curIndex+')').attr("selected", "selected");
@ -1132,7 +1133,7 @@ function svg_edit_setup() {
var total = $('#layerlist option').length;
if (curIndex < total-1) {
curIndex++;
svgCanvas.setCurrentLayerPosition(curIndex);
svgCanvas.setCurrentLayerPosition(total-curIndex-1);
populateLayers();
$('#layerlist option').removeAttr("selected");
$('#layerlist option:eq('+curIndex+')').attr("selected", "selected");
@ -1140,6 +1141,7 @@ function svg_edit_setup() {
});
$('#layer_rename').click(function() {
var curIndex = $('#layerlist option:selected').prevAll().length;
var oldName = $('#layerlist option:selected').attr("value");
var newName = prompt("Please enter the new layer name","");
if (!newName) return;
@ -1155,14 +1157,17 @@ function svg_edit_setup() {
return;
}
svgCanvas.renameLayer(oldName, newName);
svgCanvas.renameCurrentLayer(newName);
populateLayers();
$('#layerlist option').removeAttr("selected");
$('#layerlist option:eq('+curIndex+')').attr("selected", "selected");
});
var populateLayers = function(){
var layerlen = svgCanvas.getNumLayers();
$('#layerlist').empty();
for (var layer = 0; layer < layerlen; ++layer) {
var layer = svgCanvas.getNumLayers();
// we get the layers in the reverse z-order (the layer rendered on top is listed first)
while (layer--) {
var name = svgCanvas.getLayer(layer);
$('#layerlist').append("<option value=\"" + name + "\">" + name + "</option>");
}

View File

@ -1,7 +1,6 @@
/*
Issue 73 (Layers) TODO:
- reverse order of layer list (top-most list should be on top of the image)
- Fit To Content must look at all layers
- convert select/options to tables, handle 'selection' of rows
- add visibility icon to table as a column
@ -623,6 +622,7 @@ function BatchCommand(text) {
var comment = svgdoc.createComment(" created with SVG-edit - http://svg-edit.googlecode.com/ ");
svgzoom.appendChild(comment);
// z-ordered array of tuples containing layer names and <g> elements
// the first layer is the one at the bottom of the rendering
var all_layers = [];
// pointer to the current layer <g>
var current_layer = null;
@ -2719,9 +2719,8 @@ function BatchCommand(text) {
return false;
};
this.renameLayer = function(oldname, newname) {
var rememberCurrentLayer = current_layer;
if (canvas.setCurrentLayer(oldname)) {
this.renameCurrentLayer = function(newname) {
if (current_layer) {
var oldLayer = current_layer;
// setCurrentLayer will return false if the name doesn't already exists
if (!canvas.setCurrentLayer(newname)) {
@ -2730,6 +2729,7 @@ function BatchCommand(text) {
for (var i = 0; i < all_layers.length; ++i) {
if (all_layers[i][1] == oldLayer) break;
}
var oldname = all_layers[i][0];
all_layers[i][0] = newname;
// now change the underlying title element contents
@ -2749,6 +2749,7 @@ function BatchCommand(text) {
}
}
}
current_layer = oldLayer;
}
return false;
};