Undo.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.drawing.manager.Undo"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.manager.Undo"] = true;
  8. dojo.provide("dojox.drawing.manager.Undo");
  9. dojox.drawing.manager.Undo = dojox.drawing.util.oo.declare(
  10. // summary
  11. // Handles the Undo in drawing.
  12. // NOTE: Only partially implemented!!! There is very
  13. // little actual undo functionality!
  14. //
  15. function(options){
  16. this.keys = options.keys;
  17. this.undostack = [];
  18. this.redostack = [];
  19. dojo.connect(this.keys, "onKeyDown", this, "onKeyDown");
  20. },
  21. {
  22. onKeyDown: function(evt){
  23. if(!evt.cmmd){ return; }
  24. if(evt.keyCode==90 && !evt.shift){
  25. this.undo();
  26. }else if((evt.keyCode == 90 && evt.shift) || evt.keyCode==89){
  27. this.redo();
  28. }
  29. },
  30. add: function(stack){
  31. //console.log("undo add", stack)
  32. stack.args = dojo.mixin({}, stack.args);
  33. this.undostack.push(stack);
  34. },
  35. apply: function(scope, method, args){
  36. dojo.hitch(scope, method)(args);
  37. },
  38. undo: function(){
  39. var o = this.undostack.pop();
  40. console.log("undo!", o);
  41. if(!o){ return; }
  42. o.before();
  43. this.redostack.push(o);
  44. },
  45. redo: function(){
  46. console.log("redo!");
  47. var o = this.redostack.pop();
  48. if(!o){ return; }
  49. if(o.after){
  50. o.after();
  51. }else{
  52. o.before(); ///??????
  53. }
  54. this.undostack.push(o);
  55. }
  56. }
  57. );
  58. }