Fix Issue 144: Undo/redo poly editing
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@500 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -561,6 +561,7 @@ function SvgCanvas(c)
|
|||||||
var current_poly = null;
|
var current_poly = null;
|
||||||
var current_poly_pts = [];
|
var current_poly_pts = [];
|
||||||
var current_poly_pt_drag = -1;
|
var current_poly_pt_drag = -1;
|
||||||
|
var current_poly_oldd = null;
|
||||||
// this will hold all the currently selected elements
|
// this will hold all the currently selected elements
|
||||||
// default size of 1 until it needs to grow bigger
|
// default size of 1 until it needs to grow bigger
|
||||||
var selectedElements = new Array(1);
|
var selectedElements = new Array(1);
|
||||||
@@ -1362,6 +1363,7 @@ function SvgCanvas(c)
|
|||||||
break;
|
break;
|
||||||
case "polyedit":
|
case "polyedit":
|
||||||
started = true;
|
started = true;
|
||||||
|
current_poly_oldd = current_poly.getAttribute("d");
|
||||||
var id = evt.target.id;
|
var id = evt.target.id;
|
||||||
if (id.substr(0,14) == "polypointgrip_") {
|
if (id.substr(0,14) == "polypointgrip_") {
|
||||||
current_poly_pt_drag = parseInt(id.substr(14));
|
current_poly_pt_drag = parseInt(id.substr(14));
|
||||||
@@ -2057,6 +2059,11 @@ function SvgCanvas(c)
|
|||||||
if (current_poly_pt_drag != -1) {
|
if (current_poly_pt_drag != -1) {
|
||||||
current_poly_pt_drag = -1;
|
current_poly_pt_drag = -1;
|
||||||
|
|
||||||
|
var batchCmd = new BatchCommand("Edit Poly");
|
||||||
|
// the attribute changes we want to undo
|
||||||
|
var oldvalues = {};
|
||||||
|
oldvalues["d"] = current_poly_oldd;
|
||||||
|
|
||||||
// If the poly was rotated, we must now pay the piper:
|
// If the poly was rotated, we must now pay the piper:
|
||||||
// Every poly point must be rotated into the rotated coordinate system of
|
// Every poly point must be rotated into the rotated coordinate system of
|
||||||
// its old center, then determine the new center, then rotate it back
|
// its old center, then determine the new center, then rotate it back
|
||||||
@@ -2132,6 +2139,7 @@ function SvgCanvas(c)
|
|||||||
|
|
||||||
// now we must set the new transform to be rotated around the new center
|
// now we must set the new transform to be rotated around the new center
|
||||||
var rotate = "rotate(" + (angle * 180.0 / Math.PI) + " " + newcx + "," + newcy + ")";
|
var rotate = "rotate(" + (angle * 180.0 / Math.PI) + " " + newcx + "," + newcy + ")";
|
||||||
|
oldvalues["transform"] = current_poly.getAttribute("rotate");
|
||||||
current_poly.setAttribute("transform", rotate);
|
current_poly.setAttribute("transform", rotate);
|
||||||
|
|
||||||
var pointGripContainer = document.getElementById("polypointgrip_container");
|
var pointGripContainer = document.getElementById("polypointgrip_container");
|
||||||
@@ -2139,6 +2147,12 @@ function SvgCanvas(c)
|
|||||||
pointGripContainer.setAttribute("transform", rotate);
|
pointGripContainer.setAttribute("transform", rotate);
|
||||||
}
|
}
|
||||||
} // if rotated
|
} // if rotated
|
||||||
|
|
||||||
|
batchCmd.addSubCommand(new ChangeElementCommand(current_poly, oldvalues, "poly points"));
|
||||||
|
addCommandToHistory(batchCmd);
|
||||||
|
call("changed", [current_poly]);
|
||||||
|
|
||||||
|
// make these changes undo-able
|
||||||
} // if (current_poly_pt_drag != -1)
|
} // if (current_poly_pt_drag != -1)
|
||||||
// else, move back to select mode
|
// else, move back to select mode
|
||||||
else {
|
else {
|
||||||
@@ -2859,6 +2873,7 @@ function SvgCanvas(c)
|
|||||||
this.undo = function() {
|
this.undo = function() {
|
||||||
if (undoStackPointer > 0) {
|
if (undoStackPointer > 0) {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
removeAllPointGripsFromPoly();
|
||||||
var cmd = undoStack[--undoStackPointer];
|
var cmd = undoStack[--undoStackPointer];
|
||||||
cmd.unapply();
|
cmd.unapply();
|
||||||
call("changed", cmd.elements());
|
call("changed", cmd.elements());
|
||||||
|
|||||||
Reference in New Issue
Block a user