Undo.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // wrapped by build app
  2. define("dojox/drawing/manager/Undo", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.manager.Undo");
  4. dojox.drawing.manager.Undo = dojox.drawing.util.oo.declare(
  5. // summary
  6. // Handles the Undo in drawing.
  7. // NOTE: Only partially implemented!!! There is very
  8. // little actual undo functionality!
  9. //
  10. function(options){
  11. this.keys = options.keys;
  12. this.undostack = [];
  13. this.redostack = [];
  14. dojo.connect(this.keys, "onKeyDown", this, "onKeyDown");
  15. },
  16. {
  17. onKeyDown: function(evt){
  18. if(!evt.cmmd){ return; }
  19. if(evt.keyCode==90 && !evt.shift){
  20. this.undo();
  21. }else if((evt.keyCode == 90 && evt.shift) || evt.keyCode==89){
  22. this.redo();
  23. }
  24. },
  25. add: function(stack){
  26. //console.log("undo add", stack)
  27. stack.args = dojo.mixin({}, stack.args);
  28. this.undostack.push(stack);
  29. },
  30. apply: function(scope, method, args){
  31. dojo.hitch(scope, method)(args);
  32. },
  33. undo: function(){
  34. var o = this.undostack.pop();
  35. console.log("undo!", o);
  36. if(!o){ return; }
  37. o.before();
  38. this.redostack.push(o);
  39. },
  40. redo: function(){
  41. console.log("redo!");
  42. var o = this.redostack.pop();
  43. if(!o){ return; }
  44. if(o.after){
  45. o.after();
  46. }else{
  47. o.before(); ///??????
  48. }
  49. this.undostack.push(o);
  50. }
  51. }
  52. );
  53. });