currentStyle.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 */
  25. define("webodf/editor/widgets/toolbarWidgets/currentStyle",
  26. ["webodf/editor/EditorSession"],
  27. function (EditorSession) {
  28. "use strict";
  29. return function CurrentStyle(callback) {
  30. var self = this,
  31. editorSession,
  32. paragraphStyles;
  33. function selectParagraphStyle(info) {
  34. if (paragraphStyles) {
  35. if (info.type === 'style') {
  36. paragraphStyles.setValue(info.styleName);
  37. }
  38. }
  39. }
  40. function setParagraphStyle() {
  41. if (editorSession) {
  42. editorSession.setCurrentParagraphStyle(paragraphStyles.value());
  43. }
  44. self.onToolDone();
  45. }
  46. function makeWidget(callback) {
  47. require(["webodf/editor/widgets/paragraphStyles"], function (ParagraphStyles) {
  48. var p;
  49. p = new ParagraphStyles(function (pStyles) {
  50. paragraphStyles = pStyles;
  51. paragraphStyles.widget().onChange = setParagraphStyle;
  52. paragraphStyles.setEditorSession(editorSession);
  53. return callback(paragraphStyles.widget());
  54. });
  55. });
  56. }
  57. this.setEditorSession = function(session) {
  58. if (editorSession) {
  59. editorSession.unsubscribe(EditorSession.signalParagraphChanged, selectParagraphStyle);
  60. }
  61. editorSession = session;
  62. if (paragraphStyles) {
  63. paragraphStyles.setEditorSession(editorSession);
  64. }
  65. if (editorSession) {
  66. editorSession.subscribe(EditorSession.signalParagraphChanged, selectParagraphStyle);
  67. // TODO: selectParagraphStyle(editorSession.getCurrentParagraphStyle());
  68. }
  69. };
  70. this.onToolDone = function () {};
  71. makeWidget(function (widget) {
  72. return callback(widget);
  73. });
  74. };
  75. });