undoredostate.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2008 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Code for an UndoRedoState interface representing an undo and
  16. * redo action for a particular state change. To be used by
  17. * {@link goog.editor.plugins.UndoRedoManager}.
  18. *
  19. */
  20. goog.provide('goog.editor.plugins.UndoRedoState');
  21. goog.require('goog.events.EventTarget');
  22. /**
  23. * Represents an undo and redo action for a particular state transition.
  24. *
  25. * @param {boolean} asynchronous Whether the undo or redo actions for this
  26. * state complete asynchronously. If true, then this state must fire
  27. * an ACTION_COMPLETED event when undo or redo is complete.
  28. * @constructor
  29. * @extends {goog.events.EventTarget}
  30. */
  31. goog.editor.plugins.UndoRedoState = function(asynchronous) {
  32. goog.editor.plugins.UndoRedoState.base(this, 'constructor');
  33. /**
  34. * Indicates if the undo or redo actions for this state complete
  35. * asynchronously.
  36. * @type {boolean}
  37. * @private
  38. */
  39. this.asynchronous_ = asynchronous;
  40. };
  41. goog.inherits(goog.editor.plugins.UndoRedoState, goog.events.EventTarget);
  42. /**
  43. * Event type for events indicating that this state has completed an undo or
  44. * redo operation.
  45. */
  46. goog.editor.plugins.UndoRedoState.ACTION_COMPLETED = 'action_completed';
  47. /**
  48. * @return {boolean} Whether or not the undo and redo actions of this state
  49. * complete asynchronously. If true, the state will fire an ACTION_COMPLETED
  50. * event when an undo or redo action is complete.
  51. */
  52. goog.editor.plugins.UndoRedoState.prototype.isAsynchronous = function() {
  53. return this.asynchronous_;
  54. };
  55. /**
  56. * Undoes the action represented by this state.
  57. */
  58. goog.editor.plugins.UndoRedoState.prototype.undo = goog.abstractMethod;
  59. /**
  60. * Redoes the action represented by this state.
  61. */
  62. goog.editor.plugins.UndoRedoState.prototype.redo = goog.abstractMethod;
  63. /**
  64. * Checks if two undo-redo states are the same.
  65. * @param {goog.editor.plugins.UndoRedoState} state The state to compare.
  66. * @return {boolean} Wether the two states are equal.
  67. */
  68. goog.editor.plugins.UndoRedoState.prototype.equals = goog.abstractMethod;