From cfa488a502064ab9a73ef12df5d930ce70b9e297 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Fri, 26 Jun 2009 14:31:03 +0000 Subject: [PATCH] Make changing resolution undo/redo-able git-svn-id: http://svg-edit.googlecode.com/svn/trunk@202 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 18 ++++++++++++++---- editor/svgcanvas.js | 6 ++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index fcff9d80..cd835d68 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -37,6 +37,12 @@ function svg_edit_setup() { // called when any element has changed var elementChanged = function(window,elem) { + // if the element changed was the svg, then it must be a resolution change + if (elem && elem.tagName == "svg") { + changeResolution(parseInt(elem.getAttribute("width")), + parseInt(elem.getAttribute("height"))); + } + // we update the contextual panel with potentially new // positional/sizing information (we DON'T want to update the // toolbar here as that creates an infinite loop) @@ -518,16 +524,20 @@ function svg_edit_setup() { $('#tools_ellipse').show(); }); - $('#resolution').change(function(){ - var res = this.value.split('x'); - var x = parseInt(res[0]), y = parseInt(res[1]); - svgCanvas.setResolution(x,y); + function changeResolution(x,y) { + $('#resolution').val(x+'x'+y); $('#svgroot').css( { 'width': x, 'height': y } ); $('#svgcanvas').css( { 'width': x, 'height': y } ); $('div#palette_holder').css('width', x); $('#context_tools').css('width', x + 65); $('#tools').css('height', y + 24); $('#footer').css('width', x + 65); + } + + $('#resolution').change(function(){ + var res = this.value.split('x'); + var x = parseInt(res[0]), y = parseInt(res[1]); + svgCanvas.setResolution(x,y); }); return svgCanvas; diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 8dedc9c5..8dde8448 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1,5 +1,3 @@ -var svgcanvas = null; - if(!window.console) { window.console = new function() { this.log = function(str) {}; @@ -905,8 +903,12 @@ function SvgCanvas(c) } this.setResolution = function(x, y) { + var w = svgroot.getAttribute("width"), + h = svgroot.getAttribute("height"); svgroot.setAttribute("width", x); svgroot.setAttribute("height", y); + addCommandToHistory(new ChangeElementCommand(svgroot, {"width":w,"height":h}, "resolution")); + call("changed", svgroot); } this.getMode = function() {