Fix Issue 19: Undo/Redo in context panel and react as buttons

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@201 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-06-25 15:35:28 +00:00
parent 5c67d896ac
commit ecb0f0e74e
3 changed files with 35 additions and 12 deletions

View File

@ -38,8 +38,8 @@
<!-- History buttons -->
<div>
<img class="tool_sep" src="images/sep.png" alt="|"/>
<img class="tool_button" id="tool_undo" src="images/undo.png" title="Undo [Z]" alt="Undo" />
<img class="tool_button" id="tool_redo" src="images/redo.png" title="Redo [Shift+Z/Y]" alt="Redo"/>
<img class="tool_button tool_button_disabled" id="tool_undo" src="images/undo.png" title="Undo [Z]" alt="Undo" />
<img class="tool_button tool_button_disabled" id="tool_redo" src="images/redo.png" title="Redo [Shift+Z/Y]" alt="Redo"/>
</div>
<!-- Buttons when something is selected -->

View File

@ -37,15 +37,14 @@ function svg_edit_setup() {
// called when any element has changed
var elementChanged = function(window,elem) {
// if the element that changed was the selected element, we
// should update the contextual panel with potentially new
// 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)
if (elem == selectedElement) {
// we tell it to skip focusing the text control if the
// text element was previously in focus
updateContextPanel(false);
}
// also this updates the history buttons
// we tell it to skip focusing the text control if the
// text element was previously in focus
updateContextPanel(false);
}
// updates the toolbar (colors, opacity, etc) based on the selected element
@ -131,6 +130,20 @@ function svg_edit_setup() {
break;
}
}
// update history buttons
if (svgCanvas.getUndoStackSize() > 0) {
$('#tool_undo').removeClass( 'tool_button_disabled');
}
else {
$('#tool_undo').addClass( 'tool_button_disabled');
}
if (svgCanvas.getRedoStackSize() > 0) {
$('#tool_redo').removeClass( 'tool_button_disabled');
}
else {
$('#tool_redo').addClass( 'tool_button_disabled');
}
}
$('#text').focus( function(){ textBeingEntered = true; } );
@ -364,6 +377,12 @@ function svg_edit_setup() {
$('#tool_delete').mousedown(function(){$('#tool_delete').addClass('tool_button_current');});
$('#tool_delete').mouseup(function(){$('#tool_delete').removeClass('tool_button_current');});
$('#tool_delete').mouseout(function(){$('#tool_delete').removeClass('tool_button_current');});
$('#tool_undo').mousedown(function(){ if (!$('#tool_undo').hasClass('tool_button_disabled')) $('#tool_undo').addClass('tool_button_current');});
$('#tool_undo').mouseup(function(){$('#tool_undo').removeClass('tool_button_current');});
$('#tool_undo').mouseout(function(){$('#tool_undo').removeClass('tool_button_current');});
$('#tool_redo').mousedown(function(){ if (!$('#tool_redo').hasClass('tool_button_disabled')) $('#tool_redo').addClass('tool_button_current');});
$('#tool_redo').mouseup(function(){$('#tool_redo').removeClass('tool_button_current');});
$('#tool_redo').mouseout(function(){$('#tool_redo').removeClass('tool_button_current');});
$('#tool_move_top').mousedown(function(){$('#tool_move_top').addClass('tool_button_current');});
$('#tool_move_top').mouseup(function(){$('#tool_move_top').removeClass('tool_button_current');});
$('#tool_move_top').mouseout(function(){$('#tool_move_top').removeClass('tool_button_current');});

View File

@ -1119,13 +1119,15 @@ function SvgCanvas(c)
}
}
this.getUndoStackSize = function() { return undoStack.length; }
this.getUndoStackSize = function() { return undoStackPointer; }
this.getRedoStackSize = function() { return undoStack.length - undoStackPointer; }
this.undo = function() {
if (undoStackPointer > 0) {
this.selectNone();
undoStack[--undoStackPointer].unapply();
var cmd = undoStack[--undoStackPointer];
cmd.unapply();
call("changed", cmd.elem);
}
// console.log("after undo, stackPointer=" + undoStackPointer);
// console.log(undoStack);
@ -1133,7 +1135,9 @@ function SvgCanvas(c)
this.redo = function() {
if (undoStackPointer < undoStack.length && undoStack.length > 0) {
this.selectNone();
undoStack[undoStackPointer++].apply();
var cmd = undoStack[undoStackPointer++];
cmd.apply();
call("changed", cmd.elem);
}
// console.log("after redo, stackPointer=" + undoStackPointer);
// console.log(undoStack);