EditorSession.js 26 KB

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