undoRedoMenu.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Copyright (C) 2012-2013 KO GmbH <copyright@kogmbh.com>
  3. *
  4. * @licstart
  5. * This file is part of WebODF.
  6. *
  7. * WebODF is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU Affero General Public License (GNU AGPL)
  9. * as published by the Free Software Foundation, either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * WebODF is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with WebODF. If not, see <http://www.gnu.org/licenses/>.
  19. * @licend
  20. *
  21. * @source: http://www.webodf.org/
  22. * @source: https://github.com/kogmbh/WebODF/
  23. */
  24. /*global define, require, runtime*/
  25. define("webodf/editor/widgets/undoRedoMenu",
  26. ["webodf/editor/EditorSession", "dijit/form/Button"],
  27. function (EditorSession, Button) {
  28. "use strict";
  29. return function UndoRedoMenu(callback) {
  30. var self = this,
  31. editorSession,
  32. undoButton,
  33. redoButton,
  34. widget = {};
  35. undoButton = new Button({
  36. label: runtime.tr('Undo'),
  37. showLabel: false,
  38. disabled: true, // TODO: get current session state
  39. iconClass: "dijitEditorIcon dijitEditorIconUndo",
  40. onClick: function () {
  41. if (editorSession) {
  42. editorSession.undo();
  43. self.onToolDone();
  44. }
  45. }
  46. });
  47. redoButton = new Button({
  48. label: runtime.tr('Redo'),
  49. showLabel: false,
  50. disabled: true, // TODO: get current session state
  51. iconClass: "dijitEditorIcon dijitEditorIconRedo",
  52. onClick: function () {
  53. if (editorSession) {
  54. editorSession.redo();
  55. self.onToolDone();
  56. }
  57. }
  58. });
  59. widget.children = [undoButton, redoButton];
  60. widget.startup = function () {
  61. widget.children.forEach(function (element) {
  62. element.startup();
  63. });
  64. };
  65. widget.placeAt = function (container) {
  66. widget.children.forEach(function (element) {
  67. element.placeAt(container);
  68. });
  69. return widget;
  70. };
  71. function checkUndoButtons(e) {
  72. if (undoButton) {
  73. undoButton.set('disabled', e.undoAvailable === false);
  74. }
  75. if (redoButton) {
  76. redoButton.set('disabled', e.redoAvailable === false);
  77. }
  78. }
  79. this.setEditorSession = function (session) {
  80. if (editorSession) {
  81. editorSession.unsubscribe(EditorSession.signalUndoStackChanged, checkUndoButtons);
  82. }
  83. editorSession = session;
  84. if (editorSession) {
  85. editorSession.subscribe(EditorSession.signalUndoStackChanged, checkUndoButtons);
  86. // TODO: checkUndoButtons(editorSession.getundoredoavailablalalo());
  87. } else {
  88. widget.children.forEach(function (element) {
  89. element.setAttribute('disabled', true);
  90. });
  91. }
  92. };
  93. /*jslint emptyblock: true*/
  94. this.onToolDone = function () {};
  95. /*jslint emptyblock: false*/
  96. // init
  97. callback(widget);
  98. };
  99. });