EditorSession.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /**
  2. * Copyright (C) 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 runtime, define, document, core, odf, gui, ops*/
  25. define("webodf/editor/EditorSession", [
  26. "dojo/text!resources/fonts/fonts.css"
  27. ], function (fontsCSS) { // fontsCSS is retrieved as a string, using dojo's text retrieval AMD plugin
  28. "use strict";
  29. runtime.loadClass("core.Async");
  30. runtime.loadClass("core.DomUtils");
  31. runtime.loadClass("odf.OdfUtils");
  32. runtime.loadClass("ops.OdtDocument");
  33. runtime.loadClass("ops.OdtStepsTranslator");
  34. runtime.loadClass("ops.Session");
  35. runtime.loadClass("odf.Namespaces");
  36. runtime.loadClass("odf.OdfCanvas");
  37. runtime.loadClass("odf.OdfUtils");
  38. runtime.loadClass("gui.CaretManager");
  39. runtime.loadClass("gui.Caret");
  40. runtime.loadClass("gui.OdfFieldView");
  41. runtime.loadClass("gui.SessionController");
  42. runtime.loadClass("gui.SessionView");
  43. runtime.loadClass("gui.HyperlinkTooltipView");
  44. runtime.loadClass("gui.TrivialUndoManager");
  45. runtime.loadClass("gui.SvgSelectionView");
  46. runtime.loadClass("gui.SelectionViewManager");
  47. runtime.loadClass("core.EventNotifier");
  48. runtime.loadClass("gui.ShadowCursor");
  49. runtime.loadClass("gui.CommonConstraints");
  50. /**
  51. * Instantiate a new editor session attached to an existing operation session
  52. * @constructor
  53. * @implements {core.EventSource}
  54. * @param {!ops.Session} session
  55. * @param {!string} localMemberId
  56. * @param {{viewOptions:gui.SessionViewOptions,directParagraphStylingEnabled:boolean,annotationsEnabled:boolean}} config
  57. */
  58. var EditorSession = function EditorSession(session, localMemberId, config) {
  59. var self = this,
  60. currentParagraphNode = null,
  61. currentCommonStyleName = null,
  62. currentStyleName = null,
  63. caretManager,
  64. selectionViewManager,
  65. hyperlinkTooltipView,
  66. odtDocument = session.getOdtDocument(),
  67. textns = odf.Namespaces.textns,
  68. fontStyles = document.createElement('style'),
  69. formatting = odtDocument.getFormatting(),
  70. domUtils = core.DomUtils,
  71. odfUtils = odf.OdfUtils,
  72. odfFieldView,
  73. eventNotifier = new core.EventNotifier([
  74. EditorSession.signalMemberAdded,
  75. EditorSession.signalMemberUpdated,
  76. EditorSession.signalMemberRemoved,
  77. EditorSession.signalCursorAdded,
  78. EditorSession.signalCursorMoved,
  79. EditorSession.signalCursorRemoved,
  80. EditorSession.signalParagraphChanged,
  81. EditorSession.signalCommonStyleCreated,
  82. EditorSession.signalCommonStyleDeleted,
  83. EditorSession.signalParagraphStyleModified,
  84. EditorSession.signalUndoStackChanged]),
  85. shadowCursor = new gui.ShadowCursor(odtDocument),
  86. sessionConstraints,
  87. /**@const*/
  88. NEXT = core.StepDirection.NEXT;
  89. /**
  90. * @return {Array.<!string>}
  91. */
  92. function getAvailableFonts() {
  93. var availableFonts, regex, matches;
  94. availableFonts = {};
  95. /*jslint regexp: true*/
  96. regex = /font-family *: *(?:\'([^']*)\'|\"([^"]*)\")/gm;
  97. /*jslint regexp: false*/
  98. matches = regex.exec(fontsCSS);
  99. while (matches) {
  100. availableFonts[matches[1] || matches[2]] = 1;
  101. matches = regex.exec(fontsCSS);
  102. }
  103. availableFonts = Object.keys(availableFonts);
  104. return availableFonts;
  105. }
  106. function checkParagraphStyleName() {
  107. var newStyleName,
  108. newCommonStyleName;
  109. newStyleName = currentParagraphNode.getAttributeNS(textns, 'style-name');
  110. if (newStyleName !== currentStyleName) {
  111. currentStyleName = newStyleName;
  112. // check if common style is still the same
  113. newCommonStyleName = formatting.getFirstCommonParentStyleNameOrSelf(newStyleName);
  114. if (!newCommonStyleName) {
  115. // Default style, empty-string name
  116. currentCommonStyleName = newStyleName = currentStyleName = "";
  117. self.emit(EditorSession.signalParagraphChanged, {
  118. type: 'style',
  119. node: currentParagraphNode,
  120. styleName: currentCommonStyleName
  121. });
  122. return;
  123. }
  124. // a common style
  125. if (newCommonStyleName !== currentCommonStyleName) {
  126. currentCommonStyleName = newCommonStyleName;
  127. self.emit(EditorSession.signalParagraphChanged, {
  128. type: 'style',
  129. node: currentParagraphNode,
  130. styleName: currentCommonStyleName
  131. });
  132. }
  133. }
  134. }
  135. /**
  136. * Creates a NCName from the passed string
  137. * @param {!string} name
  138. * @return {!string}
  139. */
  140. function createNCName(name) {
  141. var letter,
  142. result = "",
  143. i;
  144. // encode
  145. for (i = 0; i < name.length; i += 1) {
  146. letter = name[i];
  147. // simple approach, can be improved to not skip other allowed chars
  148. if (letter.match(/[a-zA-Z0-9.-_]/) !== null) {
  149. result += letter;
  150. } else {
  151. result += "_" + letter.charCodeAt(0).toString(16) + "_";
  152. }
  153. }
  154. // ensure leading char is from proper range
  155. if (result.match(/^[a-zA-Z_]/) === null) {
  156. result = "_" + result;
  157. }
  158. return result;
  159. }
  160. function uniqueParagraphStyleNCName(name) {
  161. var result,
  162. i = 0,
  163. ncMemberId = createNCName(localMemberId),
  164. ncName = createNCName(name);
  165. // create default paragraph style
  166. // localMemberId is used to avoid id conflicts with ids created by other members
  167. result = ncName + "_" + ncMemberId;
  168. // then loop until result is really unique
  169. while (formatting.hasParagraphStyle(result)) {
  170. result = ncName + "_" + i + "_" + ncMemberId;
  171. i += 1;
  172. }
  173. return result;
  174. }
  175. function trackCursor(cursor) {
  176. var node;
  177. node = odfUtils.getParagraphElement(cursor.getNode());
  178. if (!node) {
  179. return;
  180. }
  181. currentParagraphNode = node;
  182. checkParagraphStyleName();
  183. }
  184. function trackCurrentParagraph(info) {
  185. var cursor = odtDocument.getCursor(localMemberId),
  186. range = cursor && cursor.getSelectedRange(),
  187. paragraphRange = odtDocument.getDOMDocument().createRange();
  188. paragraphRange.selectNode(info.paragraphElement);
  189. if ((range && domUtils.rangesIntersect(range, paragraphRange)) || info.paragraphElement === currentParagraphNode) {
  190. self.emit(EditorSession.signalParagraphChanged, info);
  191. checkParagraphStyleName();
  192. }
  193. paragraphRange.detach();
  194. }
  195. function onMemberAdded(member) {
  196. self.emit(EditorSession.signalMemberAdded, member.getMemberId());
  197. }
  198. function onMemberUpdated(member) {
  199. self.emit(EditorSession.signalMemberUpdated, member.getMemberId());
  200. }
  201. function onMemberRemoved(memberId) {
  202. self.emit(EditorSession.signalMemberRemoved, memberId);
  203. }
  204. function onCursorAdded(cursor) {
  205. self.emit(EditorSession.signalCursorAdded, cursor.getMemberId());
  206. trackCursor(cursor);
  207. }
  208. function onCursorRemoved(memberId) {
  209. self.emit(EditorSession.signalCursorRemoved, memberId);
  210. }
  211. function onCursorMoved(cursor) {
  212. // Emit 'cursorMoved' only when *I* am moving the cursor, not the other users
  213. if (cursor.getMemberId() === localMemberId) {
  214. self.emit(EditorSession.signalCursorMoved, cursor);
  215. trackCursor(cursor);
  216. }
  217. }
  218. function onStyleCreated(newStyleName) {
  219. self.emit(EditorSession.signalCommonStyleCreated, newStyleName);
  220. }
  221. function onStyleDeleted(styleName) {
  222. self.emit(EditorSession.signalCommonStyleDeleted, styleName);
  223. }
  224. function onParagraphStyleModified(styleName) {
  225. self.emit(EditorSession.signalParagraphStyleModified, styleName);
  226. }
  227. /**
  228. * Call all subscribers for the given event with the specified argument
  229. * @param {!string} eventid
  230. * @param {Object} args
  231. */
  232. this.emit = function (eventid, args) {
  233. eventNotifier.emit(eventid, args);
  234. };
  235. /**
  236. * Subscribe to a given event with a callback
  237. * @param {!string} eventid
  238. * @param {!Function} cb
  239. */
  240. this.subscribe = function (eventid, cb) {
  241. eventNotifier.subscribe(eventid, cb);
  242. };
  243. /**
  244. * @param {!string} eventid
  245. * @param {!Function} cb
  246. * @return {undefined}
  247. */
  248. this.unsubscribe = function (eventid, cb) {
  249. eventNotifier.unsubscribe(eventid, cb);
  250. };
  251. this.getCursorPosition = function () {
  252. return odtDocument.getCursorPosition(localMemberId);
  253. };
  254. this.getCursorSelection = function () {
  255. return odtDocument.getCursorSelection(localMemberId);
  256. };
  257. this.getOdfCanvas = function () {
  258. return odtDocument.getOdfCanvas();
  259. };
  260. this.getCurrentParagraph = function () {
  261. return currentParagraphNode;
  262. };
  263. this.getAvailableParagraphStyles = function () {
  264. return formatting.getAvailableParagraphStyles();
  265. };
  266. this.getCurrentParagraphStyle = function () {
  267. return currentCommonStyleName;
  268. };
  269. /**
  270. * Applies the paragraph style with the given
  271. * style name to all the paragraphs within
  272. * the cursor selection.
  273. * @param {!string} styleName
  274. * @return {undefined}
  275. */
  276. this.setCurrentParagraphStyle = function (styleName) {
  277. var range = odtDocument.getCursor(localMemberId).getSelectedRange(),
  278. paragraphs = odfUtils.getParagraphElements(range),
  279. opQueue = [];
  280. paragraphs.forEach(function (paragraph) {
  281. var paragraphStartPoint = odtDocument.convertDomPointToCursorStep(paragraph, 0, NEXT),
  282. paragraphStyleName = paragraph.getAttributeNS(odf.Namespaces.textns, "style-name"),
  283. opSetParagraphStyle;
  284. if (paragraphStyleName !== styleName) {
  285. opSetParagraphStyle = new ops.OpSetParagraphStyle();
  286. opSetParagraphStyle.init({
  287. memberid: localMemberId,
  288. styleName: styleName,
  289. position: paragraphStartPoint
  290. });
  291. opQueue.push(opSetParagraphStyle);
  292. }
  293. });
  294. if (opQueue.length > 0) {
  295. session.enqueue(opQueue);
  296. }
  297. };
  298. this.insertTable = function (initialRows, initialColumns, tableStyleName, tableColumnStyleName, tableCellStyleMatrix) {
  299. var op = new ops.OpInsertTable();
  300. op.init({
  301. memberid: localMemberId,
  302. position: self.getCursorPosition(),
  303. initialRows: initialRows,
  304. initialColumns: initialColumns,
  305. tableStyleName: tableStyleName,
  306. tableColumnStyleName: tableColumnStyleName,
  307. tableCellStyleMatrix: tableCellStyleMatrix
  308. });
  309. session.enqueue([op]);
  310. };
  311. /**
  312. * Takes a style name and returns the corresponding paragraph style
  313. * element. If the style name is an empty string, the default style
  314. * is returned.
  315. * @param {!string} styleName
  316. * @return {?Element}
  317. */
  318. function getParagraphStyleElement(styleName) {
  319. return (styleName === "")
  320. ? formatting.getDefaultStyleElement('paragraph')
  321. : formatting.getStyleElement(styleName, 'paragraph');
  322. }
  323. this.getParagraphStyleElement = getParagraphStyleElement;
  324. /**
  325. * Returns if the style is used anywhere in the document
  326. * @param {!Element} styleElement
  327. * @return {boolean}
  328. */
  329. this.isStyleUsed = function (styleElement) {
  330. return formatting.isStyleUsed(styleElement);
  331. };
  332. /**
  333. * Returns the attributes of a given paragraph style name
  334. * (with inheritance). If the name is an empty string,
  335. * the attributes of the default style are returned.
  336. * @param {!string} styleName
  337. * @return {?odf.Formatting.StyleData}
  338. */
  339. this.getParagraphStyleAttributes = function (styleName) {
  340. var styleNode = getParagraphStyleElement(styleName),
  341. includeSystemDefault = styleName === "";
  342. if (styleNode) {
  343. return formatting.getInheritedStyleAttributes(styleNode, includeSystemDefault);
  344. }
  345. return null;
  346. };
  347. /**
  348. * Creates and enqueues a paragraph-style cloning operation.
  349. * Returns the created id for the new style.
  350. * @param {!string} styleName id of the style to update
  351. * @param {!{paragraphProperties,textProperties}} setProperties properties which are set
  352. * @param {!{paragraphPropertyNames,textPropertyNames}=} removedProperties properties which are removed
  353. * @return {undefined}
  354. */
  355. this.updateParagraphStyle = function (styleName, setProperties, removedProperties) {
  356. var op;
  357. op = new ops.OpUpdateParagraphStyle();
  358. op.init({
  359. memberid: localMemberId,
  360. styleName: styleName,
  361. setProperties: setProperties,
  362. removedProperties: (!removedProperties) ? {} : removedProperties
  363. });
  364. session.enqueue([op]);
  365. };
  366. /**
  367. * Creates and enqueues a paragraph-style cloning operation.
  368. * Returns the created id for the new style.
  369. * @param {!string} styleName id of the style to clone
  370. * @param {!string} newStyleDisplayName display name of the new style
  371. * @return {!string}
  372. */
  373. this.cloneParagraphStyle = function (styleName, newStyleDisplayName) {
  374. var newStyleName = uniqueParagraphStyleNCName(newStyleDisplayName),
  375. styleNode = getParagraphStyleElement(styleName),
  376. op, setProperties, attributes, i;
  377. setProperties = formatting.getStyleAttributes(styleNode);
  378. // copy any attributes directly on the style
  379. attributes = styleNode.attributes;
  380. for (i = 0; i < attributes.length; i += 1) {
  381. // skip...
  382. // * style:display-name -> not copied, set to new string below
  383. // * style:name -> not copied, set from op by styleName property
  384. // * style:family -> "paragraph" always, set by op
  385. if (!/^(style:display-name|style:name|style:family)/.test(attributes[i].name)) {
  386. setProperties[attributes[i].name] = attributes[i].value;
  387. }
  388. }
  389. setProperties['style:display-name'] = newStyleDisplayName;
  390. op = new ops.OpAddStyle();
  391. op.init({
  392. memberid: localMemberId,
  393. styleName: newStyleName,
  394. styleFamily: 'paragraph',
  395. setProperties: setProperties
  396. });
  397. session.enqueue([op]);
  398. return newStyleName;
  399. };
  400. this.deleteStyle = function (styleName) {
  401. var op;
  402. op = new ops.OpRemoveStyle();
  403. op.init({
  404. memberid: localMemberId,
  405. styleName: styleName,
  406. styleFamily: 'paragraph'
  407. });
  408. session.enqueue([op]);
  409. };
  410. /**
  411. * Returns an array of the declared fonts in the ODF document,
  412. * with 'duplicates' like Arial1, Arial2, etc removed. The alphabetically
  413. * first font name for any given family is kept.
  414. * The elements of the array are objects containing the font's name and
  415. * the family.
  416. * @return {Array.<!Object>}
  417. */
  418. this.getDeclaredFonts = function () {
  419. var fontMap = formatting.getFontMap(),
  420. usedFamilies = [],
  421. array = [],
  422. sortedNames,
  423. key,
  424. value,
  425. i;
  426. // Sort all the keys in the font map alphabetically
  427. sortedNames = Object.keys(fontMap);
  428. sortedNames.sort();
  429. for (i = 0; i < sortedNames.length; i += 1) {
  430. key = sortedNames[i];
  431. value = fontMap[key];
  432. // Use the font declaration only if the family is not already used.
  433. // Therefore we are able to discard the alphabetic successors of the first
  434. // font name.
  435. if (usedFamilies.indexOf(value) === -1) {
  436. array.push({
  437. name: key,
  438. family: value
  439. });
  440. if (value) {
  441. usedFamilies.push(value);
  442. }
  443. }
  444. }
  445. return array;
  446. };
  447. this.getSelectedHyperlinks = function () {
  448. var cursor = odtDocument.getCursor(localMemberId);
  449. // no own cursor yet/currently added?
  450. if (!cursor) {
  451. return [];
  452. }
  453. return odfUtils.getHyperlinkElements(cursor.getSelectedRange());
  454. };
  455. this.getSelectedRange = function () {
  456. var cursor = odtDocument.getCursor(localMemberId);
  457. return cursor && cursor.getSelectedRange();
  458. };
  459. function undoStackModified(e) {
  460. self.emit(EditorSession.signalUndoStackChanged, e);
  461. }
  462. this.undo = function () {
  463. self.sessionController.undo();
  464. };
  465. this.redo = function () {
  466. self.sessionController.redo();
  467. };
  468. /**
  469. * @param {!string} memberId
  470. * @return {?ops.Member}
  471. */
  472. this.getMember = function (memberId) {
  473. return odtDocument.getMember(memberId);
  474. };
  475. /**
  476. * @param {!function(!Object=)} callback passing an error object in case of error
  477. * @return {undefined}
  478. */
  479. function destroy(callback) {
  480. var head = document.getElementsByTagName('head')[0],
  481. eventManager = self.sessionController.getEventManager();
  482. head.removeChild(fontStyles);
  483. odtDocument.unsubscribe(ops.Document.signalMemberAdded, onMemberAdded);
  484. odtDocument.unsubscribe(ops.Document.signalMemberUpdated, onMemberUpdated);
  485. odtDocument.unsubscribe(ops.Document.signalMemberRemoved, onMemberRemoved);
  486. odtDocument.unsubscribe(ops.Document.signalCursorAdded, onCursorAdded);
  487. odtDocument.unsubscribe(ops.Document.signalCursorRemoved, onCursorRemoved);
  488. odtDocument.unsubscribe(ops.Document.signalCursorMoved, onCursorMoved);
  489. odtDocument.unsubscribe(ops.OdtDocument.signalCommonStyleCreated, onStyleCreated);
  490. odtDocument.unsubscribe(ops.OdtDocument.signalCommonStyleDeleted, onStyleDeleted);
  491. odtDocument.unsubscribe(ops.OdtDocument.signalParagraphStyleModified, onParagraphStyleModified);
  492. odtDocument.unsubscribe(ops.OdtDocument.signalParagraphChanged, trackCurrentParagraph);
  493. odtDocument.unsubscribe(ops.OdtDocument.signalUndoStackChanged, undoStackModified);
  494. eventManager.unsubscribe("mousemove", hyperlinkTooltipView.showTooltip);
  495. eventManager.unsubscribe("mouseout", hyperlinkTooltipView.hideTooltip);
  496. delete self.sessionView;
  497. delete self.sessionController;
  498. callback();
  499. }
  500. /**
  501. * @param {!function(!Error=)} callback passing an error object in case of error
  502. * @return {undefined}
  503. */
  504. this.destroy = function(callback) {
  505. var cleanup = [
  506. self.sessionView.destroy,
  507. caretManager.destroy,
  508. selectionViewManager.destroy,
  509. self.sessionController.destroy,
  510. hyperlinkTooltipView.destroy,
  511. odfFieldView.destroy,
  512. destroy
  513. ];
  514. core.Async.destroyAll(cleanup, callback);
  515. };
  516. function init() {
  517. var head = document.getElementsByTagName('head')[0],
  518. odfCanvas = session.getOdtDocument().getOdfCanvas(),
  519. eventManager;
  520. // TODO: fonts.css should be rather done by odfCanvas, or?
  521. fontStyles.type = 'text/css';
  522. fontStyles.media = 'screen, print, handheld, projection';
  523. fontStyles.appendChild(document.createTextNode(fontsCSS));
  524. head.appendChild(fontStyles);
  525. odfFieldView = new gui.OdfFieldView(odfCanvas);
  526. odfFieldView.showFieldHighlight();
  527. self.sessionController = new gui.SessionController(session, localMemberId, shadowCursor, {
  528. annotationsEnabled: config.annotationsEnabled,
  529. directTextStylingEnabled: config.directTextStylingEnabled,
  530. directParagraphStylingEnabled: config.directParagraphStylingEnabled
  531. });
  532. sessionConstraints = self.sessionController.getSessionConstraints();
  533. eventManager = self.sessionController.getEventManager();
  534. hyperlinkTooltipView = new gui.HyperlinkTooltipView(odfCanvas,
  535. self.sessionController.getHyperlinkClickHandler().getModifier);
  536. eventManager.subscribe("mousemove", hyperlinkTooltipView.showTooltip);
  537. eventManager.subscribe("mouseout", hyperlinkTooltipView.hideTooltip);
  538. caretManager = new gui.CaretManager(self.sessionController, odfCanvas.getViewport());
  539. selectionViewManager = new gui.SelectionViewManager(gui.SvgSelectionView);
  540. self.sessionView = new gui.SessionView(config.viewOptions, localMemberId, session, sessionConstraints, caretManager, selectionViewManager);
  541. self.availableFonts = getAvailableFonts();
  542. selectionViewManager.registerCursor(shadowCursor, true);
  543. // Session Constraints can be applied once the controllers are instantiated.
  544. if (config.reviewModeEnabled) {
  545. // Disallow deleting other authors' annotations.
  546. sessionConstraints.setState(gui.CommonConstraints.EDIT.ANNOTATIONS.ONLY_DELETE_OWN, true);
  547. sessionConstraints.setState(gui.CommonConstraints.EDIT.REVIEW_MODE, true);
  548. }
  549. // Custom signals, that make sense in the Editor context. We do not want to expose webodf's ops signals to random bits of the editor UI.
  550. odtDocument.subscribe(ops.Document.signalMemberAdded, onMemberAdded);
  551. odtDocument.subscribe(ops.Document.signalMemberUpdated, onMemberUpdated);
  552. odtDocument.subscribe(ops.Document.signalMemberRemoved, onMemberRemoved);
  553. odtDocument.subscribe(ops.Document.signalCursorAdded, onCursorAdded);
  554. odtDocument.subscribe(ops.Document.signalCursorRemoved, onCursorRemoved);
  555. odtDocument.subscribe(ops.Document.signalCursorMoved, onCursorMoved);
  556. odtDocument.subscribe(ops.OdtDocument.signalCommonStyleCreated, onStyleCreated);
  557. odtDocument.subscribe(ops.OdtDocument.signalCommonStyleDeleted, onStyleDeleted);
  558. odtDocument.subscribe(ops.OdtDocument.signalParagraphStyleModified, onParagraphStyleModified);
  559. odtDocument.subscribe(ops.OdtDocument.signalParagraphChanged, trackCurrentParagraph);
  560. odtDocument.subscribe(ops.OdtDocument.signalUndoStackChanged, undoStackModified);
  561. }
  562. init();
  563. };
  564. /**@const*/EditorSession.signalMemberAdded = "memberAdded";
  565. /**@const*/EditorSession.signalMemberUpdated = "memberUpdated";
  566. /**@const*/EditorSession.signalMemberRemoved = "memberRemoved";
  567. /**@const*/EditorSession.signalCursorAdded = "cursorAdded";
  568. /**@const*/EditorSession.signalCursorRemoved = "cursorRemoved";
  569. /**@const*/EditorSession.signalCursorMoved = "cursorMoved";
  570. /**@const*/EditorSession.signalParagraphChanged = "paragraphChanged";
  571. /**@const*/EditorSession.signalCommonStyleCreated = "styleCreated";
  572. /**@const*/EditorSession.signalCommonStyleDeleted = "styleDeleted";
  573. /**@const*/EditorSession.signalParagraphStyleModified = "paragraphStyleModified";
  574. /**@const*/EditorSession.signalUndoStackChanged = "signalUndoStackChanged";
  575. return EditorSession;
  576. });