From 59f94c677e12c8a269bdff2e1d0601d1828eb404 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Thu, 18 Sep 2014 21:35:23 +1000 Subject: [PATCH 01/12] Change step insertion/removal signaling to differ from normal signals These events feed straight into the steps cache, and must be processed by the cache before any external consumers receive the event. --- webodf/lib/ops/OdtDocument.js | 31 +++++++++++++++++++++------- webodf/lib/ops/OpAddAnnotation.js | 2 +- webodf/lib/ops/OpInsertImage.js | 2 +- webodf/lib/ops/OpInsertTable.js | 2 +- webodf/lib/ops/OpInsertText.js | 2 +- webodf/lib/ops/OpMergeParagraph.js | 2 +- webodf/lib/ops/OpRemoveAnnotation.js | 2 +- webodf/lib/ops/OpRemoveText.js | 2 +- webodf/lib/ops/OpSplitParagraph.js | 2 +- 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index af2b42628..e1747ad9c 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -165,9 +165,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { var odfContainer = odfCanvas.odfContainer(), rootNode; - eventNotifier.unsubscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted); - eventNotifier.unsubscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved); - // TODO Replace with a neater hack for reloading the Odt tree // Once this is fixed, SelectionView.addOverlays can be removed odfContainer.setRootElement(documentElement); @@ -175,8 +172,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { odfCanvas.refreshCSS(); rootNode = getRootNode(); stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500); - eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted); - eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved); }; /** @@ -942,6 +937,30 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { callback(); }; + /** + * Process steps being inserted into the document. Will emit a steps inserted signal on + * behalf of the caller + * @param {!{position: !number}} args + * @return {undefined} + */ + this.handleStepsInserted = function(args) { + stepsTranslator.handleStepsInserted(args); + // signal not used in webodf, but 3rd-party (NVivo) + self.emit(ops.OdtDocument.signalStepsInserted, args); + }; + + /** + * Process steps being removed from the document. Will emit a steps removed signal on + * behalf of the caller + * @param {!{position: !number}} args + * @return {undefined} + */ + this.handleStepsRemoved = function(args) { + stepsTranslator.handleStepsRemoved(args); + // signal not used in webodf, but 3rd-party (NVivo) + self.emit(ops.OdtDocument.signalStepsRemoved, args); + }; + /** * @return {undefined} */ @@ -951,8 +970,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { filter = new ops.TextPositionFilter(); stepUtils = new odf.StepUtils(); stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500); - eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted); - eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved); eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted); eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks); } diff --git a/webodf/lib/ops/OpAddAnnotation.js b/webodf/lib/ops/OpAddAnnotation.js index 9feff3b62..bb88adacb 100644 --- a/webodf/lib/ops/OpAddAnnotation.js +++ b/webodf/lib/ops/OpAddAnnotation.js @@ -158,7 +158,7 @@ ops.OpAddAnnotation = function OpAddAnnotation() { insertNodeAtPosition(odtDocument, annotationEnd, position + length); } insertNodeAtPosition(odtDocument, annotation, position); - odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position}); + odtDocument.handleStepsInserted({position: position}); // Move the cursor inside the new annotation, // by selecting the paragraph's range. diff --git a/webodf/lib/ops/OpInsertImage.js b/webodf/lib/ops/OpInsertImage.js index 190f433b9..3c38ed9af 100644 --- a/webodf/lib/ops/OpInsertImage.js +++ b/webodf/lib/ops/OpInsertImage.js @@ -97,7 +97,7 @@ ops.OpInsertImage = function OpInsertImage() { textNode.splitText(domPosition.offset) : textNode.nextSibling; frameElement = createFrameElement(odtDocument.getDOMDocument()); textNode.parentNode.insertBefore(frameElement, refNode); - odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position}); + odtDocument.handleStepsInserted({position: position}); // clean up any empty text node which was created by odtDocument.getTextNodeAtStep if (textNode.length === 0) { diff --git a/webodf/lib/ops/OpInsertTable.js b/webodf/lib/ops/OpInsertTable.js index a60d8b042..02075274d 100644 --- a/webodf/lib/ops/OpInsertTable.js +++ b/webodf/lib/ops/OpInsertTable.js @@ -157,7 +157,7 @@ ops.OpInsertTable = function OpInsertTable() { previousSibling = odfUtils.getParagraphElement(domPosition.textNode); rootNode.insertBefore(tableNode, previousSibling.nextSibling); // The parent table counts for 1 position, and 1 paragraph is added per cell - odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position}); + odtDocument.handleStepsInserted({position: position}); odtDocument.getOdfCanvas().refreshSize(); odtDocument.emit(ops.OdtDocument.signalTableAdded, { diff --git a/webodf/lib/ops/OpInsertText.js b/webodf/lib/ops/OpInsertText.js index 14185dfc6..835bc0d1c 100644 --- a/webodf/lib/ops/OpInsertText.js +++ b/webodf/lib/ops/OpInsertText.js @@ -186,7 +186,7 @@ ops.OpInsertText = function OpInsertText() { previousNode.parentNode.removeChild(previousNode); } - odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position}); + odtDocument.handleStepsInserted({position: position}); if (cursor && moveCursor) { // Explicitly place the cursor in the desired position after insertion diff --git a/webodf/lib/ops/OpMergeParagraph.js b/webodf/lib/ops/OpMergeParagraph.js index 90fb2468b..155b70567 100644 --- a/webodf/lib/ops/OpMergeParagraph.js +++ b/webodf/lib/ops/OpMergeParagraph.js @@ -244,7 +244,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() { collapseRules.mergeChildrenIntoParent(sourceParagraph); // Merging removes a single step between the boundary of the two paragraphs - odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: sourceStartPosition - 1}); + odtDocument.handleStepsRemoved({position: sourceStartPosition - 1}); // Downgrade trailing spaces at the end of the destination paragraph, and the beginning of the source paragraph. // These are the only two places that might need downgrading as a result of the merge. diff --git a/webodf/lib/ops/OpRemoveAnnotation.js b/webodf/lib/ops/OpRemoveAnnotation.js index 3a3031663..300859c37 100644 --- a/webodf/lib/ops/OpRemoveAnnotation.js +++ b/webodf/lib/ops/OpRemoveAnnotation.js @@ -90,7 +90,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { annotationEnd.parentNode.removeChild(annotationEnd); } // The specified position is the first walkable step in the annotation. The position is always just before the first point of change - odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: position > 0 ? position - 1 : position}); + odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position}); odtDocument.getOdfCanvas().rerenderAnnotations(); odtDocument.fixCursorPositions(); diff --git a/webodf/lib/ops/OpRemoveText.js b/webodf/lib/ops/OpRemoveText.js index 0a09e22d5..2da4d4738 100644 --- a/webodf/lib/ops/OpRemoveText.js +++ b/webodf/lib/ops/OpRemoveText.js @@ -91,7 +91,7 @@ ops.OpRemoveText = function OpRemoveText() { } }); - odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: position}); + odtDocument.handleStepsRemoved({position: position}); odtDocument.downgradeWhitespacesAtPosition(position); odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); diff --git a/webodf/lib/ops/OpSplitParagraph.js b/webodf/lib/ops/OpSplitParagraph.js index d84f6167a..e25109f7c 100644 --- a/webodf/lib/ops/OpSplitParagraph.js +++ b/webodf/lib/ops/OpSplitParagraph.js @@ -168,7 +168,7 @@ ops.OpSplitParagraph = function OpSplitParagraph() { if (domPosition.textNode.length === 0) { domPosition.textNode.parentNode.removeChild(domPosition.textNode); } - odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position}); + odtDocument.handleStepsInserted({position: position}); if (cursor && moveCursor) { odtDocument.moveCursor(memberid, position + 1, 0); From 5fea1bacce80533c3ec4ba1b65366670a66dc8d0 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 9 Oct 2014 16:41:50 +0200 Subject: [PATCH 02/12] Let SessionController emit signalCursorMoved only via explicit helper method --- webodf/lib/gui/SessionController.js | 4 ++-- webodf/lib/ops/OdtDocument.js | 9 +++++++++ webodf/tests/gui/DirectFormattingControllerTests.js | 2 +- webodf/tests/manifest.json | 1 - 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/webodf/lib/gui/SessionController.js b/webodf/lib/gui/SessionController.js index 278875607..57f6f45a0 100644 --- a/webodf/lib/gui/SessionController.js +++ b/webodf/lib/gui/SessionController.js @@ -374,7 +374,7 @@ gui.SessionControllerOptions = function () { newSelectionRange.setEnd(shadowCursorIterator.container(), shadowCursorIterator.unfilteredDomOffset()); } shadowCursor.setSelectedRange(newSelectionRange, handleEnd === 'right'); - odtDocument.emit(ops.Document.signalCursorMoved, shadowCursor); + odtDocument.emitSignalCursorMoved(shadowCursor); } } } @@ -400,7 +400,7 @@ gui.SessionControllerOptions = function () { selectionController.expandToParagraphBoundaries(selectionRange.range); } shadowCursor.setSelectedRange(selectionRange.range, selectionRange.hasForwardSelection); - odtDocument.emit(ops.Document.signalCursorMoved, shadowCursor); + odtDocument.emitSignalCursorMoved(shadowCursor); } } } diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index e1747ad9c..cc0b35adb 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -961,6 +961,15 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { self.emit(ops.OdtDocument.signalStepsRemoved, args); }; + /** + * Emit the signal that the passed cursor moved. + * @param {!ops.OdtCursor} cursor + * @return {undefined} + */ + this.emitSignalCursorMoved = function(cursor) { + eventNotifier.emit(ops.Document.signalCursorMoved, cursor); + }; + /** * @return {undefined} */ diff --git a/webodf/tests/gui/DirectFormattingControllerTests.js b/webodf/tests/gui/DirectFormattingControllerTests.js index be6e8c805..797d1cc29 100644 --- a/webodf/tests/gui/DirectFormattingControllerTests.js +++ b/webodf/tests/gui/DirectFormattingControllerTests.js @@ -140,7 +140,7 @@ gui.DirectFormattingControllerTests = function DirectFormattingControllerTests(r domUtils.getElementsByTagNameNS(node, testns, '*').forEach(function(node) { node.parentNode.removeChild(node); }); - t.odtDocument.emit(ops.Document.signalCursorMoved, t.cursor); + t.odtDocument.emitSignalCursorMoved(t.cursor); } return node; } diff --git a/webodf/tests/manifest.json b/webodf/tests/manifest.json index cac860cd1..4884079fe 100644 --- a/webodf/tests/manifest.json +++ b/webodf/tests/manifest.json @@ -49,7 +49,6 @@ "odf.ObjectNameGenerator", "odf.OdfCanvas", "odf.OdfContainer", - "ops.Document", "ops.OdtCursor", "ops.OdtDocument", "ops.Session" From d6381261208aa388ce2e6ebdc891ee5b057f23f4 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 9 Oct 2014 19:45:48 +0200 Subject: [PATCH 03/12] Call OdtDocument op exec wrapper methods directly from session, not by signal --- webodf/lib/ops/OdtDocument.js | 21 +++++++++++++++++---- webodf/lib/ops/Session.js | 4 ++-- webodf/tests/gui/MetadataControllerTests.js | 5 +++-- webodf/tests/manifest.json | 1 + webodf/tests/ops/OperationTests.js | 5 +++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index cc0b35adb..c808e7d19 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -437,6 +437,14 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { return {textNode: lastTextNode, offset: nodeOffset }; } + /** + * @param {!ops.Operation} op + * @return {undefined} + */ + this.prepareOperationExecution = function(op) { + eventNotifier.emit(ops.OdtDocument.signalOperationStart, op); + }; + /** * Called after an operation is executed, this * function will check if the operation is an @@ -444,8 +452,9 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { * document's metadata, such as dc:creator, * meta:editing-cycles, and dc:creator. * @param {!ops.Operation} op + * @return {undefined} */ - function handleOperationExecuted(op) { + this.finishOperationExecution = function (op) { var opspec = op.spec(), memberId = opspec.memberid, date = new Date(opspec.timestamp).toISOString(), @@ -487,9 +496,14 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { } lastEditingOp = op; - self.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata); } - } + + eventNotifier.emit(ops.OdtDocument.signalOperationEnd, op); + + if (op.isEdit) { + eventNotifier.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata); + } + }; /** * Upgrades literal whitespaces (' ') to , @@ -979,7 +993,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { filter = new ops.TextPositionFilter(); stepUtils = new odf.StepUtils(); stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500); - eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted); eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks); } init(); diff --git a/webodf/lib/ops/Session.js b/webodf/lib/ops/Session.js index 1685afffe..b5603bbef 100644 --- a/webodf/lib/ops/Session.js +++ b/webodf/lib/ops/Session.js @@ -81,9 +81,9 @@ ops.Session = function Session(odfCanvas) { operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchStart, forwardBatchStart); operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchEnd, forwardBatchEnd); opRouter.setPlaybackFunction(function (op) { - odtDocument.emit(ops.OdtDocument.signalOperationStart, op); + odtDocument.prepareOperationExecution(op); if (op.execute(odtDocument)) { - odtDocument.emit(ops.OdtDocument.signalOperationEnd, op); + odtDocument.finishOperationExecution(op); return true; } return false; diff --git a/webodf/tests/gui/MetadataControllerTests.js b/webodf/tests/gui/MetadataControllerTests.js index dce0b07f6..c0570172b 100644 --- a/webodf/tests/gui/MetadataControllerTests.js +++ b/webodf/tests/gui/MetadataControllerTests.js @@ -84,9 +84,10 @@ gui.MetadataControllerTests = function MetadataControllerTests(runner) { // need to set the timestamp, otherwise things fail in odtDocument opspec.timestamp = Date.now(); - timedOp = operationFactory.create(opspec); + timedOp = /**@type {!ops.Operation}*/(operationFactory.create(opspec)); + odtDocument.prepareOperationExecution(timedOp); if (timedOp.execute(odtDocument)) { - odtDocument.emit(ops.OdtDocument.signalOperationEnd, timedOp); + odtDocument.finishOperationExecution(timedOp); } }); }; diff --git a/webodf/tests/manifest.json b/webodf/tests/manifest.json index 4884079fe..de0b3babb 100644 --- a/webodf/tests/manifest.json +++ b/webodf/tests/manifest.json @@ -229,6 +229,7 @@ "ops.Document", "ops.Member", "ops.OdtDocument", + "ops.Operation", "ops.OperationFactory", "ops.OperationTestHelper", "xmldom.LSSerializer" diff --git a/webodf/tests/ops/OperationTests.js b/webodf/tests/ops/OperationTests.js index 3ec12fe1b..b12493cc8 100644 --- a/webodf/tests/ops/OperationTests.js +++ b/webodf/tests/ops/OperationTests.js @@ -288,10 +288,11 @@ ops.OperationTests = function OperationTests(runner) { // execute test ops for (i = 0; i < test.ops.length; i += 1) { - op = factory.create(test.ops[i]); + op = /**@type {!ops.Operation}*/(factory.create(test.ops[i])); + t.odtDocument.prepareOperationExecution(op); op.execute(t.odtDocument); if (metabefore) { - t.odtDocument.emit(ops.OdtDocument.signalOperationEnd, op); + t.odtDocument.finishOperationExecution(op); } checkForEmptyTextNodes(t.odtDocument.getCanvas().getElement()); } From 0ef8f1256af2772e1fee5911c31d7c0172c2cf34 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 9 Oct 2014 23:06:48 +0200 Subject: [PATCH 04/12] Let SessionController emit signalUndoStackChanged only via explicit helper method --- webodf/lib/gui/SessionController.js | 2 +- webodf/lib/ops/OdtDocument.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/webodf/lib/gui/SessionController.js b/webodf/lib/gui/SessionController.js index 57f6f45a0..3cd0ab7d1 100644 --- a/webodf/lib/gui/SessionController.js +++ b/webodf/lib/gui/SessionController.js @@ -304,7 +304,7 @@ gui.SessionControllerOptions = function () { * @return {undefined} */ function forwardUndoStackChange(e) { - odtDocument.emit(ops.OdtDocument.signalUndoStackChanged, e); + odtDocument.emitSignalUndoStackChanged(e); } /** diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index c808e7d19..6394034ea 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -984,6 +984,15 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { eventNotifier.emit(ops.Document.signalCursorMoved, cursor); }; + /** + * Emit the signal that the passed cursor moved. + * @param {?Event} e + * @return {undefined} + */ + this.emitSignalUndoStackChanged = function(e) { + eventNotifier.emit(ops.OdtDocument.signalUndoStackChanged, e); + }; + /** * @return {undefined} */ From 40acf3adf9dd11655f932336e838316dbc3337ce Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 9 Oct 2014 23:33:08 +0200 Subject: [PATCH 05/12] Let Session emit ProcessingBatchStart/End signals only via explicit helper method --- webodf/lib/ops/OdtDocument.js | 16 ++++++++++++++++ webodf/lib/ops/Session.js | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index 6394034ea..8b28a36f1 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -505,6 +505,22 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { } }; + /** + * @param {*} args + * @return {undefined} + */ + this.prepareBatchProcessing = function(args) { + eventNotifier.emit(ops.OdtDocument.signalProcessingBatchStart, args); + }; + + /** + * @param {*} args + * @return {undefined} + */ + this.finishBatchProcessing = function (args) { + eventNotifier.emit(ops.OdtDocument.signalProcessingBatchEnd, args); + }; + /** * Upgrades literal whitespaces (' ') to , * when given a textNode containing the whitespace and an offset diff --git a/webodf/lib/ops/Session.js b/webodf/lib/ops/Session.js index b5603bbef..01ac67b3a 100644 --- a/webodf/lib/ops/Session.js +++ b/webodf/lib/ops/Session.js @@ -46,7 +46,7 @@ ops.Session = function Session(odfCanvas) { * @return {undefined} */ function forwardBatchStart(args) { - odtDocument.emit(ops.OdtDocument.signalProcessingBatchStart, args); + odtDocument.prepareBatchProcessing(args); } /** @@ -55,7 +55,7 @@ ops.Session = function Session(odfCanvas) { * @return {undefined} */ function forwardBatchEnd(args) { - odtDocument.emit(ops.OdtDocument.signalProcessingBatchEnd, args); + odtDocument.finishBatchProcessing(args); } /** From b98fee49c0e0c2a9f0a662b688f89e789790e0ae Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Mon, 19 Jan 2015 19:52:31 +0100 Subject: [PATCH 06/12] Fix collecting removed properties in tests' MetadataChangeListener --- webodf/tests/gui/MetadataControllerTests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webodf/tests/gui/MetadataControllerTests.js b/webodf/tests/gui/MetadataControllerTests.js index c0570172b..408857b2c 100644 --- a/webodf/tests/gui/MetadataControllerTests.js +++ b/webodf/tests/gui/MetadataControllerTests.js @@ -124,7 +124,7 @@ gui.MetadataControllerTests = function MetadataControllerTests(runner) { }); changes.removedProperties.forEach(function (key) { delete changedMetadata.setProperties[key]; - if (changedMetadata.removedProperties.indexOf(key) !== -1) { + if (changedMetadata.removedProperties.indexOf(key) === -1) { changedMetadata.removedProperties.push(key); } }); From f200f4102ae7035d16f75fb1024e56d88162d31c Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Fri, 10 Oct 2014 14:13:00 +0200 Subject: [PATCH 07/12] Have Operations no longer emit document signals themselves, but collect them --- webodf/lib/gui/SessionView.js | 2 +- webodf/lib/ops/OdtDocument.js | 16 +++++----- webodf/lib/ops/OpAddAnnotation.js | 10 +++--- webodf/lib/ops/OpAddCursor.js | 7 +++-- webodf/lib/ops/OpAddMember.js | 6 ++-- webodf/lib/ops/OpAddStyle.js | 7 +++-- webodf/lib/ops/OpApplyDirectStyling.js | 17 +++++++---- webodf/lib/ops/OpApplyHyperlink.js | 19 +++++++----- webodf/lib/ops/OpInsertImage.js | 18 ++++++----- webodf/lib/ops/OpInsertTable.js | 18 ++++++----- webodf/lib/ops/OpInsertText.js | 21 ++++++++----- webodf/lib/ops/OpMergeParagraph.js | 20 +++++++----- webodf/lib/ops/OpMoveCursor.js | 7 +++-- webodf/lib/ops/OpRemoveAnnotation.js | 6 ++-- webodf/lib/ops/OpRemoveBlob.js | 3 +- webodf/lib/ops/OpRemoveCursor.js | 5 +-- webodf/lib/ops/OpRemoveHyperlink.js | 15 +++++---- webodf/lib/ops/OpRemoveMember.js | 7 ++--- webodf/lib/ops/OpRemoveStyle.js | 7 +++-- webodf/lib/ops/OpRemoveText.js | 19 +++++++----- webodf/lib/ops/OpSetBlob.js | 3 +- webodf/lib/ops/OpSetParagraphStyle.js | 19 +++++++----- webodf/lib/ops/OpSplitParagraph.js | 34 +++++++++++++-------- webodf/lib/ops/OpUpdateMember.js | 6 ++-- webodf/lib/ops/OpUpdateMetadata.js | 14 +++++---- webodf/lib/ops/OpUpdateParagraphStyle.js | 6 ++-- webodf/lib/ops/Operation.js | 8 ++++- webodf/lib/ops/Session.js | 5 ++- webodf/tests/gui/MetadataControllerTests.js | 5 ++- webodf/tests/ops/OperationTests.js | 4 ++- webodf/tests/ops/TransformationTests.js | 4 +-- 31 files changed, 204 insertions(+), 134 deletions(-) diff --git a/webodf/lib/gui/SessionView.js b/webodf/lib/gui/SessionView.js index d2b5dd484..257fbc40a 100644 --- a/webodf/lib/gui/SessionView.js +++ b/webodf/lib/gui/SessionView.js @@ -410,7 +410,7 @@ gui.SessionViewOptions = function () { var annotationViewManager = odfCanvas.getAnnotationViewManager(); if (annotationViewManager) { annotationViewManager.rehighlightAnnotations(); - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(); // TODO: remove this, this should not be needed. for now add return value if moved, and assert here that not. } } diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index 8b28a36f1..7b60fda31 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -742,7 +742,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { if (cursorMoved) { cursor.setSelectedRange(selectedRange, cursor.hasForwardSelection()); - self.emit(ops.Document.signalCursorMoved, cursor); + eventNotifier.emit(ops.Document.signalCursorMoved, cursor); } }); }; @@ -881,7 +881,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { if (cursor) { cursor.removeFromDocument(); delete cursors[memberid]; - self.emit(ops.Document.signalCursorRemoved, memberid); return true; } return false; @@ -916,12 +915,13 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { }; /** - * @param {!string} eventid - * @param {*} args + * @param {!Array.} events * @return {undefined} */ - this.emit = function (eventid, args) { - eventNotifier.emit(eventid, args); + this.emitEvents = function (events) { + events.forEach(function(event) { + eventNotifier.emit(event.eventid, event.args); + }); }; /** @@ -976,7 +976,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { this.handleStepsInserted = function(args) { stepsTranslator.handleStepsInserted(args); // signal not used in webodf, but 3rd-party (NVivo) - self.emit(ops.OdtDocument.signalStepsInserted, args); + eventNotifier.emit(ops.OdtDocument.signalStepsInserted, args); }; /** @@ -988,7 +988,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { this.handleStepsRemoved = function(args) { stepsTranslator.handleStepsRemoved(args); // signal not used in webodf, but 3rd-party (NVivo) - self.emit(ops.OdtDocument.signalStepsRemoved, args); + eventNotifier.emit(ops.OdtDocument.signalStepsRemoved, args); }; /** diff --git a/webodf/lib/ops/OpAddAnnotation.js b/webodf/lib/ops/OpAddAnnotation.js index bb88adacb..df0fa3bbd 100644 --- a/webodf/lib/ops/OpAddAnnotation.js +++ b/webodf/lib/ops/OpAddAnnotation.js @@ -137,13 +137,15 @@ ops.OpAddAnnotation = function OpAddAnnotation() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), annotation, annotationEnd, cursor = odtDocument.getCursor(memberid), selectedRange, - paragraphElement; + paragraphElement, + events = []; doc = odtDocument.getDOMDocument(); @@ -168,14 +170,14 @@ ops.OpAddAnnotation = function OpAddAnnotation() { selectedRange.selectNodeContents(paragraphElement); cursor.setSelectedRange(selectedRange, false); cursor.setSelectionType(ops.OdtCursor.RangeSelection); - odtDocument.emit(ops.Document.signalCursorMoved, cursor); + events.push({eventid: ops.Document.signalCursorMoved, args: cursor}); } // Track this annotation odtDocument.getOdfCanvas().addAnnotation(annotation); odtDocument.fixCursorPositions(); - odtDocument.emit(ops.OdtDocument.signalAnnotationAdded, { memberId: memberid, annotation: annotation }); + events.push({eventid: ops.OdtDocument.signalAnnotationAdded, args: { memberId: memberid, annotation: annotation }}); - return true; + return events; }; /** diff --git a/webodf/lib/ops/OpAddCursor.js b/webodf/lib/ops/OpAddCursor.js index a3ade9ea0..d909938b9 100644 --- a/webodf/lib/ops/OpAddCursor.js +++ b/webodf/lib/ops/OpAddCursor.js @@ -46,6 +46,7 @@ ops.OpAddCursor = function OpAddCursor() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -53,13 +54,13 @@ ops.OpAddCursor = function OpAddCursor() { // there should be none if (cursor) { - return false; + return null; } cursor = new ops.OdtCursor(memberid, odtDocument); odtDocument.addCursor(cursor); - odtDocument.emit(ops.Document.signalCursorAdded, cursor); - return true; + + return [{eventid: ops.Document.signalCursorAdded, args: cursor}]; }; /** diff --git a/webodf/lib/ops/OpAddMember.js b/webodf/lib/ops/OpAddMember.js index 5afce4329..6c4e84228 100644 --- a/webodf/lib/ops/OpAddMember.js +++ b/webodf/lib/ops/OpAddMember.js @@ -52,19 +52,19 @@ ops.OpAddMember = function OpAddMember() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), member; if (odtDocument.getMember(memberid)) { - return false; + return null; } member = new ops.Member(memberid, setProperties); odtDocument.addMember(member); - odtDocument.emit(ops.Document.signalMemberAdded, member); - return true; + return [{eventid: ops.Document.signalMemberAdded, args: member}]; }; /** diff --git a/webodf/lib/ops/OpAddStyle.js b/webodf/lib/ops/OpAddStyle.js index 0a2d83fed..3a37e68aa 100644 --- a/webodf/lib/ops/OpAddStyle.js +++ b/webodf/lib/ops/OpAddStyle.js @@ -56,6 +56,7 @@ ops.OpAddStyle = function OpAddStyle() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -65,7 +66,7 @@ ops.OpAddStyle = function OpAddStyle() { styleNode = dom.createElementNS(stylens, 'style:style'); if (!styleNode) { - return false; + return null; } if (setProperties) { @@ -83,9 +84,9 @@ ops.OpAddStyle = function OpAddStyle() { odtDocument.getOdfCanvas().refreshCSS(); if (!isAutomaticStyle) { - odtDocument.emit(ops.OdtDocument.signalCommonStyleCreated, {name: styleName, family: styleFamily}); + return [{eventid: ops.OdtDocument.signalCommonStyleCreated, args: {name: styleName, family: styleFamily}}]; } - return true; + return []; }; /** diff --git a/webodf/lib/ops/OpApplyDirectStyling.js b/webodf/lib/ops/OpApplyDirectStyling.js index 515b6427f..dccfe7c5c 100644 --- a/webodf/lib/ops/OpApplyDirectStyling.js +++ b/webodf/lib/ops/OpApplyDirectStyling.js @@ -80,11 +80,13 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), range = odtDocument.convertCursorToDomRange(position, length), - impactedParagraphs = odfUtils.getParagraphElements(range); + impactedParagraphs = odfUtils.getParagraphElements(range), + events = []; applyStyle(odtDocument, range, setProperties); @@ -93,15 +95,18 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() { odtDocument.fixCursorPositions(); // The container splits may leave the cursor in an invalid spot impactedParagraphs.forEach(function (n) { - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: n, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: n, + memberId: memberid, + timeStamp: timestamp + } }); }); odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return events; }; /** diff --git a/webodf/lib/ops/OpApplyHyperlink.js b/webodf/lib/ops/OpApplyHyperlink.js index 584c860ed..a0f100e0c 100644 --- a/webodf/lib/ops/OpApplyHyperlink.js +++ b/webodf/lib/ops/OpApplyHyperlink.js @@ -78,6 +78,7 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() { /** * TODO: support adding image link * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -86,10 +87,11 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() { boundaryNodes = domUtils.splitBoundaries(range), /**@type{!Array.}*/ modifiedParagraphs = [], - textNodes = odfUtils.getTextNodes(range, false); + textNodes = odfUtils.getTextNodes(range, false), + events = []; if (textNodes.length === 0) { - return false; + return null; } textNodes.forEach(function (node) { @@ -114,14 +116,17 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() { odtDocument.getOdfCanvas().refreshSize(); odtDocument.getOdfCanvas().rerenderAnnotations(); modifiedParagraphs.forEach(function (paragraph) { - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: paragraph, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: paragraph, + memberId: memberid, + timeStamp: timestamp + } }); }); - return true; + return events; }; /** diff --git a/webodf/lib/ops/OpInsertImage.js b/webodf/lib/ops/OpInsertImage.js index 3c38ed9af..ba27ef357 100644 --- a/webodf/lib/ops/OpInsertImage.js +++ b/webodf/lib/ops/OpInsertImage.js @@ -80,6 +80,7 @@ ops.OpInsertImage = function OpInsertImage() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -88,7 +89,7 @@ ops.OpInsertImage = function OpInsertImage() { textNode, refNode, paragraphElement, frameElement; if (!domPosition) { - return false; + return null; } textNode = domPosition.textNode; @@ -106,13 +107,16 @@ ops.OpInsertImage = function OpInsertImage() { odfCanvas.addCssForFrameWithImage(frameElement); odfCanvas.refreshCSS(); - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: paragraphElement, - memberId: memberid, - timeStamp: timestamp - }); odfCanvas.rerenderAnnotations(); - return true; + + return [{ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: paragraphElement, + memberId: memberid, + timeStamp: timestamp + } + }]; }; /** diff --git a/webodf/lib/ops/OpInsertTable.js b/webodf/lib/ops/OpInsertTable.js index 02075274d..50ab41d40 100644 --- a/webodf/lib/ops/OpInsertTable.js +++ b/webodf/lib/ops/OpInsertTable.js @@ -142,6 +142,7 @@ ops.OpInsertTable = function OpInsertTable() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -160,16 +161,17 @@ ops.OpInsertTable = function OpInsertTable() { odtDocument.handleStepsInserted({position: position}); odtDocument.getOdfCanvas().refreshSize(); - odtDocument.emit(ops.OdtDocument.signalTableAdded, { - tableElement: tableNode, - memberId: memberid, - timeStamp: timestamp - }); - odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return [{ + eventid: ops.OdtDocument.signalTableAdded, + args: { + tableElement: tableNode, + memberId: memberid, + timeStamp: timestamp + } + }]; } - return false; + return null; }; /** diff --git a/webodf/lib/ops/OpInsertText.js b/webodf/lib/ops/OpInsertText.js index 835bc0d1c..2f7810c4a 100644 --- a/webodf/lib/ops/OpInsertText.js +++ b/webodf/lib/ops/OpInsertText.js @@ -101,6 +101,7 @@ ops.OpInsertText = function OpInsertText() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -115,7 +116,8 @@ ops.OpInsertText = function OpInsertText() { toInsertIndex = 0, spaceElement, cursor = odtDocument.getCursor(memberid), - i; + i, + events = []; /** * @param {string} toInsertText @@ -196,23 +198,26 @@ ops.OpInsertText = function OpInsertText() { // the textnode + cursor reordering logic from OdtDocument's // getTextNodeAtStep. odtDocument.moveCursor(memberid, position + text.length, 0); - odtDocument.emit(ops.Document.signalCursorMoved, cursor); + events.push({eventid: ops.Document.signalCursorMoved, args: cursor}); } odtDocument.downgradeWhitespacesAtPosition(position); odtDocument.downgradeWhitespacesAtPosition(position + text.length); odtDocument.getOdfCanvas().refreshSize(); - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: paragraphElement, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: paragraphElement, + memberId: memberid, + timeStamp: timestamp + } }); odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return events; } - return false; + return null; }; /** diff --git a/webodf/lib/ops/OpMergeParagraph.js b/webodf/lib/ops/OpMergeParagraph.js index 155b70567..f821c3df3 100644 --- a/webodf/lib/ops/OpMergeParagraph.js +++ b/webodf/lib/ops/OpMergeParagraph.js @@ -206,7 +206,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() { /** * @param {!ops.Document} document - * @return {!boolean} + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{!ops.OdtDocument}*/(document), @@ -216,7 +216,8 @@ ops.OpMergeParagraph = function OpMergeParagraph() { rootNode = odtDocument.getRootNode(), collapseRules = new odf.CollapsingRules(rootNode), stepIterator = odtDocument.createStepIterator(rootNode, 0, [odtDocument.getPositionFilter()], rootNode), - downgradeOffset; + downgradeOffset, + events = []; // Asserting a specific order for destination + source makes it easier to decide which ends to upgrade runtime.assert(destinationStartPosition < sourceStartPosition, @@ -267,20 +268,23 @@ ops.OpMergeParagraph = function OpMergeParagraph() { if (cursor && moveCursor) { odtDocument.moveCursor(memberid, sourceStartPosition - 1, 0); - odtDocument.emit(ops.Document.signalCursorMoved, cursor); + events.push({eventid: ops.Document.signalCursorMoved, args:cursor}); } odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); // TODO: signal also the deleted paragraphs, so e.g. SessionView can clean up the EditInfo - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: destinationParagraph, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: destinationParagraph, + memberId: memberid, + timeStamp: timestamp + } }); odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return events; }; /** diff --git a/webodf/lib/ops/OpMoveCursor.js b/webodf/lib/ops/OpMoveCursor.js index 5bf2eb6ef..c4acc2c4b 100644 --- a/webodf/lib/ops/OpMoveCursor.js +++ b/webodf/lib/ops/OpMoveCursor.js @@ -49,6 +49,7 @@ ops.OpMoveCursor = function OpMoveCursor() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -56,14 +57,14 @@ ops.OpMoveCursor = function OpMoveCursor() { selectedRange; if (!cursor) { - return false; + return null; } selectedRange = odtDocument.convertCursorToDomRange(position, length); cursor.setSelectedRange(selectedRange, length >= 0); cursor.setSelectionType(selectionType); - odtDocument.emit(ops.Document.signalCursorMoved, cursor); - return true; + + return [{eventid: ops.Document.signalCursorMoved, args: cursor}]; }; /** diff --git a/webodf/lib/ops/OpRemoveAnnotation.js b/webodf/lib/ops/OpRemoveAnnotation.js index 300859c37..580cc5e51 100644 --- a/webodf/lib/ops/OpRemoveAnnotation.js +++ b/webodf/lib/ops/OpRemoveAnnotation.js @@ -52,6 +52,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -65,7 +66,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { container = container.parentNode; } if (container === null) { - return false; + return null; } annotationNode = /**@type{!odf.AnnotationElement}*/(container); @@ -94,7 +95,8 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { odtDocument.getOdfCanvas().rerenderAnnotations(); odtDocument.fixCursorPositions(); - return true; + + return []; }; /** diff --git a/webodf/lib/ops/OpRemoveBlob.js b/webodf/lib/ops/OpRemoveBlob.js index 487e7ff1c..9be150fc4 100644 --- a/webodf/lib/ops/OpRemoveBlob.js +++ b/webodf/lib/ops/OpRemoveBlob.js @@ -47,11 +47,12 @@ ops.OpRemoveBlob = function OpRemoveBlob() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document); odtDocument.getOdfCanvas().odfContainer().removeBlob(filename); - return true; + return []; }; /** diff --git a/webodf/lib/ops/OpRemoveCursor.js b/webodf/lib/ops/OpRemoveCursor.js index 60eef7138..58e762742 100644 --- a/webodf/lib/ops/OpRemoveCursor.js +++ b/webodf/lib/ops/OpRemoveCursor.js @@ -46,14 +46,15 @@ ops.OpRemoveCursor = function OpRemoveCursor() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document); if (!odtDocument.removeCursor(memberid)) { - return false; + return null; } - return true; + return [{eventid:ops.Document.signalCursorRemoved, args: memberid}]; }; /** diff --git a/webodf/lib/ops/OpRemoveHyperlink.js b/webodf/lib/ops/OpRemoveHyperlink.js index 8106d7d24..fdd05a95c 100644 --- a/webodf/lib/ops/OpRemoveHyperlink.js +++ b/webodf/lib/ops/OpRemoveHyperlink.js @@ -50,6 +50,7 @@ ops.OpRemoveHyperlink = function OpRemoveHyperlink() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -64,12 +65,14 @@ ops.OpRemoveHyperlink = function OpRemoveHyperlink() { odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); odtDocument.getOdfCanvas().rerenderAnnotations(); - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: odfUtils.getParagraphElement(node), - memberId: memberid, - timeStamp: timestamp - }); - return true; + return [{ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: odfUtils.getParagraphElement(node), + memberId: memberid, + timeStamp: timestamp + } + }]; }; /** diff --git a/webodf/lib/ops/OpRemoveMember.js b/webodf/lib/ops/OpRemoveMember.js index e7b08aff1..b8be17c25 100644 --- a/webodf/lib/ops/OpRemoveMember.js +++ b/webodf/lib/ops/OpRemoveMember.js @@ -46,17 +46,16 @@ ops.OpRemoveMember = function OpRemoveMember() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document); if (!odtDocument.getMember(memberid)) { - return false; + return null; } odtDocument.removeMember(memberid); - odtDocument.emit(ops.Document.signalMemberRemoved, memberid); - - return true; + return [{ eventid: ops.Document.signalMemberRemoved, args: memberid}]; }; /** diff --git a/webodf/lib/ops/OpRemoveStyle.js b/webodf/lib/ops/OpRemoveStyle.js index e6dedade8..9cc23b890 100644 --- a/webodf/lib/ops/OpRemoveStyle.js +++ b/webodf/lib/ops/OpRemoveStyle.js @@ -48,20 +48,21 @@ ops.OpRemoveStyle = function OpRemoveStyle() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), styleNode = odtDocument.getFormatting().getStyleElement(styleName, styleFamily); if (!styleNode) { - return false; + return null; } styleNode.parentNode.removeChild(styleNode); odtDocument.getOdfCanvas().refreshCSS(); - odtDocument.emit(ops.OdtDocument.signalCommonStyleDeleted, {name: styleName, family: styleFamily}); - return true; + + return [{eventid: ops.OdtDocument.signalCommonStyleDeleted, args: {name: styleName, family: styleFamily}}]; }; /** diff --git a/webodf/lib/ops/OpRemoveText.js b/webodf/lib/ops/OpRemoveText.js index 2da4d4738..b92410423 100644 --- a/webodf/lib/ops/OpRemoveText.js +++ b/webodf/lib/ops/OpRemoveText.js @@ -55,6 +55,7 @@ ops.OpRemoveText = function OpRemoveText() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -62,7 +63,8 @@ ops.OpRemoveText = function OpRemoveText() { textNodes, paragraph, cursor = odtDocument.getCursor(memberid), - collapseRules = new odf.CollapsingRules(odtDocument.getRootNode()); + collapseRules = new odf.CollapsingRules(odtDocument.getRootNode()), + events = []; odtDocument.upgradeWhitespacesAtPosition(position); odtDocument.upgradeWhitespacesAtPosition(position + length); @@ -95,19 +97,22 @@ ops.OpRemoveText = function OpRemoveText() { odtDocument.downgradeWhitespacesAtPosition(position); odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: paragraph, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: paragraph, + memberId: memberid, + timeStamp: timestamp + } }); if (cursor) { cursor.resetSelectionType(); - odtDocument.emit(ops.Document.signalCursorMoved, cursor); + events.push({eventid: ops.Document.signalCursorMoved, args: cursor}); } odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return events; }; /** diff --git a/webodf/lib/ops/OpSetBlob.js b/webodf/lib/ops/OpSetBlob.js index 8978bd0fe..858c6ab59 100644 --- a/webodf/lib/ops/OpSetBlob.js +++ b/webodf/lib/ops/OpSetBlob.js @@ -49,11 +49,12 @@ ops.OpSetBlob = function OpSetBlob() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document); odtDocument.getOdfCanvas().odfContainer().setBlob(filename, mimetype, content); - return true; + return []; }; /** diff --git a/webodf/lib/ops/OpSetParagraphStyle.js b/webodf/lib/ops/OpSetParagraphStyle.js index 0c33350c0..d6947f0cc 100644 --- a/webodf/lib/ops/OpSetParagraphStyle.js +++ b/webodf/lib/ops/OpSetParagraphStyle.js @@ -71,6 +71,7 @@ ops.OpSetParagraphStyle = function OpSetParagraphStyle() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -89,16 +90,18 @@ ops.OpSetParagraphStyle = function OpSetParagraphStyle() { } odtDocument.getOdfCanvas().refreshSize(); - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: paragraphNode, - timeStamp: timestamp, - memberId: memberid - }); - odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + + return [{ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: paragraphNode, + timeStamp: timestamp, + memberId: memberid + } + }]; } - return false; + return null; }; /** diff --git a/webodf/lib/ops/OpSplitParagraph.js b/webodf/lib/ops/OpSplitParagraph.js index e25109f7c..d42f36ce1 100644 --- a/webodf/lib/ops/OpSplitParagraph.js +++ b/webodf/lib/ops/OpSplitParagraph.js @@ -71,22 +71,24 @@ ops.OpSplitParagraph = function OpSplitParagraph() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{!ops.OdtDocument}*/(document), domPosition, paragraphNode, targetNode, node, splitNode, splitChildNode, keptChildNode, - cursor = odtDocument.getCursor(memberid); + cursor = odtDocument.getCursor(memberid), + events = []; odtDocument.upgradeWhitespacesAtPosition(position); domPosition = odtDocument.getTextNodeAtStep(position); if (!domPosition) { - return false; + return null; } paragraphNode = odfUtils.getParagraphElement(domPosition.textNode); if (!paragraphNode) { - return false; + return null; } if (odfUtils.isListItem(paragraphNode.parentNode)) { @@ -172,25 +174,31 @@ ops.OpSplitParagraph = function OpSplitParagraph() { if (cursor && moveCursor) { odtDocument.moveCursor(memberid, position + 1, 0); - odtDocument.emit(ops.Document.signalCursorMoved, cursor); + events.push({eventid: ops.Document.signalCursorMoved, args: cursor}); } odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); // mark both paragraphs as edited - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: paragraphNode, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: paragraphNode, + memberId: memberid, + timeStamp: timestamp + } }); - odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { - paragraphElement: splitChildNode, - memberId: memberid, - timeStamp: timestamp + events.push({ + eventid: ops.OdtDocument.signalParagraphChanged, + args: { + paragraphElement: splitChildNode, + memberId: memberid, + timeStamp: timestamp + } }); odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return events; }; /** diff --git a/webodf/lib/ops/OpUpdateMember.js b/webodf/lib/ops/OpUpdateMember.js index ce8f72597..b8c328ff8 100644 --- a/webodf/lib/ops/OpUpdateMember.js +++ b/webodf/lib/ops/OpUpdateMember.js @@ -77,12 +77,13 @@ ops.OpUpdateMember = function OpUpdateMember() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), member = odtDocument.getMember(memberid); if (!member) { - return false; + return null; } if (removedProperties) { @@ -95,8 +96,7 @@ ops.OpUpdateMember = function OpUpdateMember() { } } - odtDocument.emit(ops.Document.signalMemberUpdated, member); - return true; + return [{eventid: ops.Document.signalMemberUpdated, args: member}]; }; /** diff --git a/webodf/lib/ops/OpUpdateMetadata.js b/webodf/lib/ops/OpUpdateMetadata.js index aeb2f80c5..edfbc4a6f 100644 --- a/webodf/lib/ops/OpUpdateMetadata.js +++ b/webodf/lib/ops/OpUpdateMetadata.js @@ -56,6 +56,7 @@ ops.OpUpdateMetadata = function OpUpdateMetadata() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -68,12 +69,13 @@ ops.OpUpdateMetadata = function OpUpdateMetadata() { odfContainer.setMetadata(setProperties, removedPropertiesArray); - odtDocument.emit(ops.OdtDocument.signalMetadataUpdated, { - setProperties: setProperties !== null ? setProperties : {}, - removedProperties: removedPropertiesArray !== null ? removedPropertiesArray : [] - }); - - return true; + return [{ + eventid: ops.OdtDocument.signalMetadataUpdated, + args: { + setProperties: setProperties !== null ? setProperties : {}, + removedProperties: removedPropertiesArray !== null ? removedPropertiesArray : [] + } + }]; }; /** diff --git a/webodf/lib/ops/OpUpdateParagraphStyle.js b/webodf/lib/ops/OpUpdateParagraphStyle.js index 0345cb301..e82d86e49 100644 --- a/webodf/lib/ops/OpUpdateParagraphStyle.js +++ b/webodf/lib/ops/OpUpdateParagraphStyle.js @@ -76,6 +76,7 @@ ops.OpUpdateParagraphStyle = function OpUpdateParagraphStyle() { /** * @param {!ops.Document} document + * @return {?Array.} */ this.execute = function (document) { var odtDocument = /**@type{ops.OdtDocument}*/(document), @@ -122,11 +123,10 @@ ops.OpUpdateParagraphStyle = function OpUpdateParagraphStyle() { } odtDocument.getOdfCanvas().refreshCSS(); - odtDocument.emit(ops.OdtDocument.signalParagraphStyleModified, styleName); odtDocument.getOdfCanvas().rerenderAnnotations(); - return true; + return [{eventid:ops.OdtDocument.signalParagraphStyleModified, args: styleName}]; } - return false; + return null; }; /** diff --git a/webodf/lib/ops/Operation.js b/webodf/lib/ops/Operation.js index 3a682d212..450831bbb 100644 --- a/webodf/lib/ops/Operation.js +++ b/webodf/lib/ops/Operation.js @@ -33,6 +33,12 @@ ops.Operation = function Operation() { "use strict"; }; +/**@typedef{{ + eventid:!string, + args:* +}}*/ +ops.Operation.Event; + /** * @param {?} data * @return {undefined} @@ -55,7 +61,7 @@ ops.Operation.prototype.group; /** * @param {!ops.Document} document - * @return {!boolean} true if the operation was executed + * @return {?Array.} a list of events if the operation was executed, otherwise null */ ops.Operation.prototype.execute = function (document) {"use strict"; }; diff --git a/webodf/lib/ops/Session.js b/webodf/lib/ops/Session.js index 01ac67b3a..8b00cd43d 100644 --- a/webodf/lib/ops/Session.js +++ b/webodf/lib/ops/Session.js @@ -81,9 +81,12 @@ ops.Session = function Session(odfCanvas) { operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchStart, forwardBatchStart); operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchEnd, forwardBatchEnd); opRouter.setPlaybackFunction(function (op) { + var events; odtDocument.prepareOperationExecution(op); - if (op.execute(odtDocument)) { + events = op.execute(odtDocument); + if (events !== null) { odtDocument.finishOperationExecution(op); + odtDocument.emitEvents(events); return true; } return false; diff --git a/webodf/tests/gui/MetadataControllerTests.js b/webodf/tests/gui/MetadataControllerTests.js index 408857b2c..256547596 100644 --- a/webodf/tests/gui/MetadataControllerTests.js +++ b/webodf/tests/gui/MetadataControllerTests.js @@ -80,14 +80,17 @@ gui.MetadataControllerTests = function MetadataControllerTests(runner) { operations.forEach(function(op) { var /**@type{?ops.Operation}*/ timedOp, + events, opspec = op.spec(); // need to set the timestamp, otherwise things fail in odtDocument opspec.timestamp = Date.now(); timedOp = /**@type {!ops.Operation}*/(operationFactory.create(opspec)); odtDocument.prepareOperationExecution(timedOp); - if (timedOp.execute(odtDocument)) { + events = timedOp.execute(odtDocument); + if (events !== null) { odtDocument.finishOperationExecution(timedOp); + odtDocument.emitEvents(events); } }); }; diff --git a/webodf/tests/ops/OperationTests.js b/webodf/tests/ops/OperationTests.js index b12493cc8..5d72e4a34 100644 --- a/webodf/tests/ops/OperationTests.js +++ b/webodf/tests/ops/OperationTests.js @@ -259,6 +259,7 @@ ops.OperationTests = function OperationTests(runner) { factory = new ops.OperationFactory(), i, op, + events, textbefore = getOfficeTextElement(test.before), textafter = getOfficeTextElement(test.after), styles = t.odfContainer.rootElement.styles, @@ -290,10 +291,11 @@ ops.OperationTests = function OperationTests(runner) { for (i = 0; i < test.ops.length; i += 1) { op = /**@type {!ops.Operation}*/(factory.create(test.ops[i])); t.odtDocument.prepareOperationExecution(op); - op.execute(t.odtDocument); + events = op.execute(t.odtDocument); if (metabefore) { t.odtDocument.finishOperationExecution(op); } + t.odtDocument.emitEvents(events); checkForEmptyTextNodes(t.odtDocument.getCanvas().getElement()); } diff --git a/webodf/tests/ops/TransformationTests.js b/webodf/tests/ops/TransformationTests.js index 6fdb1fa93..b1aac0591 100644 --- a/webodf/tests/ops/TransformationTests.js +++ b/webodf/tests/ops/TransformationTests.js @@ -458,13 +458,13 @@ ops.TransformationTests = function TransformationTests(runner) { // runtime.log("Going to apply:"+runtime.toJson(opspecs[i])); op = t.operationFactory.create(opspecs[i]); t.opResult = op.execute(odtDocument); - r.shouldBe(t, "t.opResult", "true"); + r.shouldBeNonNull(t, "t.opResult"); } // execute transformedOps for (i = 0; i < transformedOps.length; i += 1) { // runtime.log("Going to apply:"+runtime.toJson(transformedOps[i].spec())); t.opResult = transformedOps[i].execute(odtDocument); - r.shouldBe(t, "t.opResult", "true"); + r.shouldBeNonNull(t, "t.opResult"); } // check result From 5da7c3c8d173e467d9c375afe605bb593ef8abdb Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 19 Feb 2015 01:26:43 +0100 Subject: [PATCH 08/12] Add ops.OdtDocument.executeOperation() to concentrate/simpifly code --- webodf/lib/ops/OdtDocument.js | 43 ++++++++++++++------ webodf/lib/ops/Session.js | 10 +---- webodf/tests/gui/MetadataControllerTests.js | 8 +--- webodf/tests/ops/OperationTests.js | 44 ++++++++++++--------- 4 files changed, 57 insertions(+), 48 deletions(-) diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index 7b60fda31..d33209cab 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -441,9 +441,9 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { * @param {!ops.Operation} op * @return {undefined} */ - this.prepareOperationExecution = function(op) { + function prepareOperationExecution(op) { eventNotifier.emit(ops.OdtDocument.signalOperationStart, op); - }; + } /** * Called after an operation is executed, this @@ -454,7 +454,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { * @param {!ops.Operation} op * @return {undefined} */ - this.finishOperationExecution = function (op) { + function finishOperationExecution(op) { var opspec = op.spec(), memberId = opspec.memberid, date = new Date(opspec.timestamp).toISOString(), @@ -503,6 +503,33 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { if (op.isEdit) { eventNotifier.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata); } + } + + /** + * @param {!Array.} events + * @return {undefined} + */ + function emitEvents(events) { + events.forEach(function(event) { + eventNotifier.emit(event.eventid, event.args); + }); + } + + /** + * @param {!ops.Operation} op + * @return {!boolean} + */ + this.executeOperation = function(op) { + var events; + + prepareOperationExecution(op); + events = op.execute(self); + if (events !== null) { + finishOperationExecution(op); + emitEvents(events); + return true; + } + return false; }; /** @@ -914,16 +941,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { return odfCanvas.getFormatting(); }; - /** - * @param {!Array.} events - * @return {undefined} - */ - this.emitEvents = function (events) { - events.forEach(function(event) { - eventNotifier.emit(event.eventid, event.args); - }); - }; - /** * @param {!string} eventid * @param {!Function} cb diff --git a/webodf/lib/ops/Session.js b/webodf/lib/ops/Session.js index 8b00cd43d..2fd5bb5e1 100644 --- a/webodf/lib/ops/Session.js +++ b/webodf/lib/ops/Session.js @@ -81,15 +81,7 @@ ops.Session = function Session(odfCanvas) { operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchStart, forwardBatchStart); operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchEnd, forwardBatchEnd); opRouter.setPlaybackFunction(function (op) { - var events; - odtDocument.prepareOperationExecution(op); - events = op.execute(odtDocument); - if (events !== null) { - odtDocument.finishOperationExecution(op); - odtDocument.emitEvents(events); - return true; - } - return false; + return odtDocument.executeOperation(op); }); opRouter.setOperationFactory(operationFactory); }; diff --git a/webodf/tests/gui/MetadataControllerTests.js b/webodf/tests/gui/MetadataControllerTests.js index 256547596..dd97f1bbd 100644 --- a/webodf/tests/gui/MetadataControllerTests.js +++ b/webodf/tests/gui/MetadataControllerTests.js @@ -80,18 +80,12 @@ gui.MetadataControllerTests = function MetadataControllerTests(runner) { operations.forEach(function(op) { var /**@type{?ops.Operation}*/ timedOp, - events, opspec = op.spec(); // need to set the timestamp, otherwise things fail in odtDocument opspec.timestamp = Date.now(); timedOp = /**@type {!ops.Operation}*/(operationFactory.create(opspec)); - odtDocument.prepareOperationExecution(timedOp); - events = timedOp.execute(odtDocument); - if (events !== null) { - odtDocument.finishOperationExecution(timedOp); - odtDocument.emitEvents(events); - } + odtDocument.executeOperation(timedOp); }); }; diff --git a/webodf/tests/ops/OperationTests.js b/webodf/tests/ops/OperationTests.js index 5d72e4a34..b8d00e594 100644 --- a/webodf/tests/ops/OperationTests.js +++ b/webodf/tests/ops/OperationTests.js @@ -177,7 +177,8 @@ ops.OperationTests = function OperationTests(runner) { opsElement = before.nextElementSibling, after = opsElement.nextElementSibling, ops = [], - op, + opElement, opspec, + now = Date.now(), setup; runtime.assert(before.localName === "before", "Expected in " + name + "."); runtime.assert(checkWhitespace(before, "s", " "), "Unexpanded text:s element or text:c attribute found in " + name + "."); @@ -187,11 +188,20 @@ ops.OperationTests = function OperationTests(runner) { runtime.assert(checkWhitespace(after, "s", " "), "Unexpanded text:s element or text:c attribute found in " + name + "."); runtime.assert(checkWhitespace(after, "tab", "\t"), "Unexpanded text:tab element found in " + name + "."); opsTestHelper.removeInsignificantTextNodes(node); - op = opsElement.firstElementChild; - while (op) { - runtime.assert(op.localName === "op", "Expected in " + name + "."); - ops.push(parseOperation(op)); - op = op.nextElementSibling; + opElement = opsElement.firstElementChild; + while (opElement) { + runtime.assert(opElement.localName === "op", "Expected in " + name + "."); + opspec = parseOperation(opElement); + // default to Alice + if (!opspec.memberid) { + opspec.memberid = 'Alice'; + } + // default to now + if (!opspec.timestamp) { + opspec.timestamp = now; + } + ops.push(opspec); + opElement = opElement.nextElementSibling; } setup = self.setUps.hasOwnProperty(name) ? self.setUps[name]() : null; if (hasSetup) { @@ -259,7 +269,6 @@ ops.OperationTests = function OperationTests(runner) { factory = new ops.OperationFactory(), i, op, - events, textbefore = getOfficeTextElement(test.before), textafter = getOfficeTextElement(test.after), styles = t.odfContainer.rootElement.styles, @@ -290,12 +299,7 @@ ops.OperationTests = function OperationTests(runner) { // execute test ops for (i = 0; i < test.ops.length; i += 1) { op = /**@type {!ops.Operation}*/(factory.create(test.ops[i])); - t.odtDocument.prepareOperationExecution(op); - events = op.execute(t.odtDocument); - if (metabefore) { - t.odtDocument.finishOperationExecution(op); - } - t.odtDocument.emitEvents(events); + t.odtDocument.executeOperation(op); checkForEmptyTextNodes(t.odtDocument.getCanvas().getElement()); } @@ -406,18 +410,20 @@ ops.OperationTests = function OperationTests(runner) { } this.setUp = function () { - var testarea, properties; + var testarea; t = {}; testarea = core.UnitTest.provideTestAreaDiv(); t.odfcanvas = new odf.OdfCanvas(testarea); t.odfContainer = new odf.OdfContainer(odf.OdfContainer.DocumentType.TEXT, null); t.odfcanvas.setOdfContainer(t.odfContainer); t.odtDocument = new ops.OdtDocument(t.odfcanvas); - properties = new ops.MemberProperties(); - properties.color = "black"; - properties.fullName = "Alice"; - properties.imageUrl = ""; - t.odtDocument.addMember(new ops.Member('Alice', properties)); + ["Alice", "Bob", "Eve", "Joe"].forEach(function(name) { + var properties = new ops.MemberProperties(); + properties.color = "black"; + properties.fullName = name; + properties.imageUrl = ""; + t.odtDocument.addMember(new ops.Member(name, properties)); + }); }; this.tearDown = function () { t.odfcanvas.destroy(function () { return; }); From 5bde046640e5dd5c7f7b7806fa02a351b5771600 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 19 Feb 2015 02:07:59 +0100 Subject: [PATCH 09/12] Merge methods only used by ops.ODtDocument.executeOperation Also merge creator metadata update signal into any existing metadata update signal --- webodf/lib/ops/OdtDocument.js | 67 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index d33209cab..65e365554 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -437,14 +437,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { return {textNode: lastTextNode, offset: nodeOffset }; } - /** - * @param {!ops.Operation} op - * @return {undefined} - */ - function prepareOperationExecution(op) { - eventNotifier.emit(ops.OdtDocument.signalOperationStart, op); - } - /** * Called after an operation is executed, this * function will check if the operation is an @@ -452,16 +444,20 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { * document's metadata, such as dc:creator, * meta:editing-cycles, and dc:creator. * @param {!ops.Operation} op + * @param {!Array.} events * @return {undefined} */ - function finishOperationExecution(op) { + function finishOperationExecution(op, events) { var opspec = op.spec(), memberId = opspec.memberid, date = new Date(opspec.timestamp).toISOString(), odfContainer = odfCanvas.odfContainer(), - /**@type{!{setProperties: !Object, removedProperties: ?Array.}}*/ + /**@type{!ops.Operation.Event}*/ + changedMetadataEvent, + /**@type{!{setProperties: !Object, removedProperties: !Array.}}*/ changedMetadata, - fullName; + fullName, + i; // If the operation is an edit (that changes the // ODF that will be saved), then update metadata. @@ -472,13 +468,25 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { "dc:date": date }, null); - changedMetadata = { - setProperties: { - "dc:creator": fullName, - "dc:date": date - }, - removedProperties: [] - }; + // find any existing metadataupdated event or create one + for (i = 0; i < events.length; i += 1) { + if (events[i].eventid === ops.OdtDocument.signalMetadataUpdated) { + changedMetadataEvent = events[i]; + changedMetadata = /**@type{!{setProperties: !Object, removedProperties: !Array.}}*/(changedMetadataEvent.args); + break; + } + } + if (!changedMetadataEvent) { + changedMetadata = { setProperties: {}, removedProperties: [] }; + changedMetadataEvent = { + eventid: ops.OdtDocument.signalMetadataUpdated, + args: changedMetadata + }; + events.push(changedMetadataEvent); + } + + changedMetadata.setProperties["dc:creator"] = fullName; + changedMetadata.setProperties["dc:date"] = date; // If no previous op was found in this session, // then increment meta:editing-cycles by 1. @@ -500,16 +508,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { eventNotifier.emit(ops.OdtDocument.signalOperationEnd, op); - if (op.isEdit) { - eventNotifier.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata); - } - } - - /** - * @param {!Array.} events - * @return {undefined} - */ - function emitEvents(events) { events.forEach(function(event) { eventNotifier.emit(event.eventid, event.args); }); @@ -522,14 +520,15 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { this.executeOperation = function(op) { var events; - prepareOperationExecution(op); + eventNotifier.emit(ops.OdtDocument.signalOperationStart, op); + events = op.execute(self); - if (events !== null) { - finishOperationExecution(op); - emitEvents(events); - return true; + if (events === null) { + return false; } - return false; + + finishOperationExecution(op, events); + return true; }; /** From 0730180f28f98a08e0e966d84706823a599bc9d7 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Fri, 5 Jun 2015 14:31:44 +0200 Subject: [PATCH 10/12] Let events about added/removed steps part be part of operation event stack --- webodf/lib/ops/OdtDocument.js | 20 ++++++++++++++------ webodf/lib/ops/OpAddAnnotation.js | 2 +- webodf/lib/ops/OpInsertImage.js | 11 +++++++---- webodf/lib/ops/OpInsertTable.js | 11 +++++++---- webodf/lib/ops/OpInsertText.js | 2 +- webodf/lib/ops/OpMergeParagraph.js | 2 +- webodf/lib/ops/OpRemoveAnnotation.js | 7 ++++--- webodf/lib/ops/OpRemoveText.js | 2 +- webodf/lib/ops/OpSplitParagraph.js | 2 +- 9 files changed, 37 insertions(+), 22 deletions(-) diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index 65e365554..a081c15fe 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -984,27 +984,35 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { }; /** - * Process steps being inserted into the document. Will emit a steps inserted signal on - * behalf of the caller + * Process steps being inserted into the document. Will add a steps inserted signal + * to the passed events list * @param {!{position: !number}} args + * @param {!Array.} events * @return {undefined} */ - this.handleStepsInserted = function(args) { + this.handleStepsInserted = function(args, events) { stepsTranslator.handleStepsInserted(args); // signal not used in webodf, but 3rd-party (NVivo) - eventNotifier.emit(ops.OdtDocument.signalStepsInserted, args); + events.push({ + eventid: ops.OdtDocument.signalStepsInserted, + args: args + }); }; /** * Process steps being removed from the document. Will emit a steps removed signal on * behalf of the caller * @param {!{position: !number}} args + * @param {!Array.} events * @return {undefined} */ - this.handleStepsRemoved = function(args) { + this.handleStepsRemoved = function(args, events) { stepsTranslator.handleStepsRemoved(args); // signal not used in webodf, but 3rd-party (NVivo) - eventNotifier.emit(ops.OdtDocument.signalStepsRemoved, args); + events.push({ + eventid: ops.OdtDocument.signalStepsRemoved, + args: args + }); }; /** diff --git a/webodf/lib/ops/OpAddAnnotation.js b/webodf/lib/ops/OpAddAnnotation.js index df0fa3bbd..8d962c7d4 100644 --- a/webodf/lib/ops/OpAddAnnotation.js +++ b/webodf/lib/ops/OpAddAnnotation.js @@ -160,7 +160,7 @@ ops.OpAddAnnotation = function OpAddAnnotation() { insertNodeAtPosition(odtDocument, annotationEnd, position + length); } insertNodeAtPosition(odtDocument, annotation, position); - odtDocument.handleStepsInserted({position: position}); + odtDocument.handleStepsInserted({position: position}, events); // Move the cursor inside the new annotation, // by selecting the paragraph's range. diff --git a/webodf/lib/ops/OpInsertImage.js b/webodf/lib/ops/OpInsertImage.js index ba27ef357..8d6ca7ce1 100644 --- a/webodf/lib/ops/OpInsertImage.js +++ b/webodf/lib/ops/OpInsertImage.js @@ -86,7 +86,8 @@ ops.OpInsertImage = function OpInsertImage() { var odtDocument = /**@type{ops.OdtDocument}*/(document), odfCanvas = odtDocument.getOdfCanvas(), domPosition = odtDocument.getTextNodeAtStep(position, memberid), - textNode, refNode, paragraphElement, frameElement; + textNode, refNode, paragraphElement, frameElement, + events = []; if (!domPosition) { return null; @@ -98,7 +99,7 @@ ops.OpInsertImage = function OpInsertImage() { textNode.splitText(domPosition.offset) : textNode.nextSibling; frameElement = createFrameElement(odtDocument.getDOMDocument()); textNode.parentNode.insertBefore(frameElement, refNode); - odtDocument.handleStepsInserted({position: position}); + odtDocument.handleStepsInserted({position: position}, events); // clean up any empty text node which was created by odtDocument.getTextNodeAtStep if (textNode.length === 0) { @@ -109,14 +110,16 @@ ops.OpInsertImage = function OpInsertImage() { odfCanvas.refreshCSS(); odfCanvas.rerenderAnnotations(); - return [{ + events.push({ eventid: ops.OdtDocument.signalParagraphChanged, args: { paragraphElement: paragraphElement, memberId: memberid, timeStamp: timestamp } - }]; + }); + + return events; }; /** diff --git a/webodf/lib/ops/OpInsertTable.js b/webodf/lib/ops/OpInsertTable.js index 50ab41d40..c9a91115f 100644 --- a/webodf/lib/ops/OpInsertTable.js +++ b/webodf/lib/ops/OpInsertTable.js @@ -149,7 +149,8 @@ ops.OpInsertTable = function OpInsertTable() { domPosition = odtDocument.getTextNodeAtStep(position), rootNode = odtDocument.getRootNode(), previousSibling, - tableNode; + tableNode, + events = []; if (domPosition) { tableNode = createTableNode(odtDocument.getDOMDocument()); @@ -158,18 +159,20 @@ ops.OpInsertTable = function OpInsertTable() { previousSibling = odfUtils.getParagraphElement(domPosition.textNode); rootNode.insertBefore(tableNode, previousSibling.nextSibling); // The parent table counts for 1 position, and 1 paragraph is added per cell - odtDocument.handleStepsInserted({position: position}); + odtDocument.handleStepsInserted({position: position}, events); odtDocument.getOdfCanvas().refreshSize(); odtDocument.getOdfCanvas().rerenderAnnotations(); - return [{ + events.push({ eventid: ops.OdtDocument.signalTableAdded, args: { tableElement: tableNode, memberId: memberid, timeStamp: timestamp } - }]; + }); + + return events; } return null; }; diff --git a/webodf/lib/ops/OpInsertText.js b/webodf/lib/ops/OpInsertText.js index 2f7810c4a..cd37ecbed 100644 --- a/webodf/lib/ops/OpInsertText.js +++ b/webodf/lib/ops/OpInsertText.js @@ -188,7 +188,7 @@ ops.OpInsertText = function OpInsertText() { previousNode.parentNode.removeChild(previousNode); } - odtDocument.handleStepsInserted({position: position}); + odtDocument.handleStepsInserted({position: position}, events); if (cursor && moveCursor) { // Explicitly place the cursor in the desired position after insertion diff --git a/webodf/lib/ops/OpMergeParagraph.js b/webodf/lib/ops/OpMergeParagraph.js index f821c3df3..1d9ee7d3b 100644 --- a/webodf/lib/ops/OpMergeParagraph.js +++ b/webodf/lib/ops/OpMergeParagraph.js @@ -245,7 +245,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() { collapseRules.mergeChildrenIntoParent(sourceParagraph); // Merging removes a single step between the boundary of the two paragraphs - odtDocument.handleStepsRemoved({position: sourceStartPosition - 1}); + odtDocument.handleStepsRemoved({position: sourceStartPosition - 1}, events); // Downgrade trailing spaces at the end of the destination paragraph, and the beginning of the source paragraph. // These are the only two places that might need downgrading as a result of the merge. diff --git a/webodf/lib/ops/OpRemoveAnnotation.js b/webodf/lib/ops/OpRemoveAnnotation.js index 580cc5e51..5e815b40d 100644 --- a/webodf/lib/ops/OpRemoveAnnotation.js +++ b/webodf/lib/ops/OpRemoveAnnotation.js @@ -59,7 +59,8 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { iterator = odtDocument.getIteratorAtPosition(position), container = iterator.container(), annotationNode, - annotationEnd; + annotationEnd, + events = []; while (!(container.namespaceURI === odf.Namespaces.officens && container.localName === 'annotation')) { @@ -91,12 +92,12 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { annotationEnd.parentNode.removeChild(annotationEnd); } // The specified position is the first walkable step in the annotation. The position is always just before the first point of change - odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position}); + odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position}, events); odtDocument.getOdfCanvas().rerenderAnnotations(); odtDocument.fixCursorPositions(); - return []; + return events; }; /** diff --git a/webodf/lib/ops/OpRemoveText.js b/webodf/lib/ops/OpRemoveText.js index b92410423..71e4e57e4 100644 --- a/webodf/lib/ops/OpRemoveText.js +++ b/webodf/lib/ops/OpRemoveText.js @@ -93,7 +93,7 @@ ops.OpRemoveText = function OpRemoveText() { } }); - odtDocument.handleStepsRemoved({position: position}); + odtDocument.handleStepsRemoved({position: position}, events); odtDocument.downgradeWhitespacesAtPosition(position); odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); diff --git a/webodf/lib/ops/OpSplitParagraph.js b/webodf/lib/ops/OpSplitParagraph.js index d42f36ce1..36a95bfc6 100644 --- a/webodf/lib/ops/OpSplitParagraph.js +++ b/webodf/lib/ops/OpSplitParagraph.js @@ -170,7 +170,7 @@ ops.OpSplitParagraph = function OpSplitParagraph() { if (domPosition.textNode.length === 0) { domPosition.textNode.parentNode.removeChild(domPosition.textNode); } - odtDocument.handleStepsInserted({position: position}); + odtDocument.handleStepsInserted({position: position}, events); if (cursor && moveCursor) { odtDocument.moveCursor(memberid, position + 1, 0); From 9534f818880d2fbafe98f1c2ca8677d4981f3563 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Fri, 5 Jun 2015 15:26:27 +0200 Subject: [PATCH 11/12] Let events about fixed up cursor positions be part of operation event stack --- webodf/lib/gui/SessionView.js | 2 +- webodf/lib/ops/OdtDocument.js | 22 +++++++++++++++++++--- webodf/lib/ops/OpAddAnnotation.js | 2 +- webodf/lib/ops/OpApplyDirectStyling.js | 2 +- webodf/lib/ops/OpApplyHyperlink.js | 2 +- webodf/lib/ops/OpMergeParagraph.js | 2 +- webodf/lib/ops/OpRemoveAnnotation.js | 2 +- webodf/lib/ops/OpRemoveHyperlink.js | 10 ++++++---- webodf/lib/ops/OpRemoveText.js | 2 +- webodf/lib/ops/OpSplitParagraph.js | 2 +- webodf/tests/ops/OdtDocumentTests.js | 16 ++++++++-------- 11 files changed, 41 insertions(+), 23 deletions(-) diff --git a/webodf/lib/gui/SessionView.js b/webodf/lib/gui/SessionView.js index 257fbc40a..dd72894be 100644 --- a/webodf/lib/gui/SessionView.js +++ b/webodf/lib/gui/SessionView.js @@ -410,7 +410,7 @@ gui.SessionViewOptions = function () { var annotationViewManager = odfCanvas.getAnnotationViewManager(); if (annotationViewManager) { annotationViewManager.rehighlightAnnotations(); - odtDocument.fixCursorPositions(); // TODO: remove this, this should not be needed. for now add return value if moved, and assert here that not. + odtDocument.fixCursorPositions(false); // TODO: workaround, ideally this would not be needed } } diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index a081c15fe..0d1b8ef4d 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -154,7 +154,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { initialDoc = rootElement.cloneNode(true); odfCanvas.refreshAnnotations(); // workaround AnnotationViewManager not fixing up cursor positions after creating the highlighting - self.fixCursorPositions(); + self.fixCursorPositions(false); return initialDoc; }; @@ -724,8 +724,14 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { * walkable positions; if not, move the cursor 1 filtered step backward * which guarantees walkable state for all cursors, * while keeping them inside the same root. An event will be raised for this cursor if it is moved + * @param {!Array.|!boolean} events array to add events for moved cursors, needs to be otherwise explicitely set to false + * @return {undefined} */ - this.fixCursorPositions = function () { + this.fixCursorPositions = function (events) { + var /** @type{!Array.}*/ movedCursors = []; + + runtime.assert(Array.isArray(events) || (typeof events === "boolean" && events === false), "second parameter to fixCursorPositions needs to be set to false or an event"); + Object.keys(cursors).forEach(function (memberId) { var cursor = cursors[memberId], root = getRoot(cursor.getNode()), @@ -768,9 +774,19 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { if (cursorMoved) { cursor.setSelectedRange(selectedRange, cursor.hasForwardSelection()); - eventNotifier.emit(ops.Document.signalCursorMoved, cursor); + movedCursors.push(cursor); } }); + + if (events) { + movedCursors.forEach(function(cursor) { + events.push({ eventid: ops.Document.signalCursorMoved, args: cursor }); + }); + } else { + movedCursors.forEach(function(cursor) { + eventNotifier.emit(ops.Document.signalCursorMoved, cursor); + }); + } }; /** diff --git a/webodf/lib/ops/OpAddAnnotation.js b/webodf/lib/ops/OpAddAnnotation.js index 8d962c7d4..8665a28b0 100644 --- a/webodf/lib/ops/OpAddAnnotation.js +++ b/webodf/lib/ops/OpAddAnnotation.js @@ -174,7 +174,7 @@ ops.OpAddAnnotation = function OpAddAnnotation() { } // Track this annotation odtDocument.getOdfCanvas().addAnnotation(annotation); - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); events.push({eventid: ops.OdtDocument.signalAnnotationAdded, args: { memberId: memberid, annotation: annotation }}); return events; diff --git a/webodf/lib/ops/OpApplyDirectStyling.js b/webodf/lib/ops/OpApplyDirectStyling.js index dccfe7c5c..5e5b5de6e 100644 --- a/webodf/lib/ops/OpApplyDirectStyling.js +++ b/webodf/lib/ops/OpApplyDirectStyling.js @@ -92,7 +92,7 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() { range.detach(); odtDocument.getOdfCanvas().refreshCSS(); - odtDocument.fixCursorPositions(); // The container splits may leave the cursor in an invalid spot + odtDocument.fixCursorPositions(events); // The container splits may leave the cursor in an invalid spot impactedParagraphs.forEach(function (n) { events.push({ diff --git a/webodf/lib/ops/OpApplyHyperlink.js b/webodf/lib/ops/OpApplyHyperlink.js index a0f100e0c..24aa11737 100644 --- a/webodf/lib/ops/OpApplyHyperlink.js +++ b/webodf/lib/ops/OpApplyHyperlink.js @@ -112,7 +112,7 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() { boundaryNodes.forEach(domUtils.normalizeTextNodes); range.detach(); - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); odtDocument.getOdfCanvas().refreshSize(); odtDocument.getOdfCanvas().rerenderAnnotations(); modifiedParagraphs.forEach(function (paragraph) { diff --git a/webodf/lib/ops/OpMergeParagraph.js b/webodf/lib/ops/OpMergeParagraph.js index 1d9ee7d3b..ac1cb5e7d 100644 --- a/webodf/lib/ops/OpMergeParagraph.js +++ b/webodf/lib/ops/OpMergeParagraph.js @@ -271,7 +271,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() { events.push({eventid: ops.Document.signalCursorMoved, args:cursor}); } - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); odtDocument.getOdfCanvas().refreshSize(); // TODO: signal also the deleted paragraphs, so e.g. SessionView can clean up the EditInfo events.push({ diff --git a/webodf/lib/ops/OpRemoveAnnotation.js b/webodf/lib/ops/OpRemoveAnnotation.js index 5e815b40d..780d985b1 100644 --- a/webodf/lib/ops/OpRemoveAnnotation.js +++ b/webodf/lib/ops/OpRemoveAnnotation.js @@ -95,7 +95,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() { odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position}, events); odtDocument.getOdfCanvas().rerenderAnnotations(); - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); return events; }; diff --git a/webodf/lib/ops/OpRemoveHyperlink.js b/webodf/lib/ops/OpRemoveHyperlink.js index fdd05a95c..efcbb2a98 100644 --- a/webodf/lib/ops/OpRemoveHyperlink.js +++ b/webodf/lib/ops/OpRemoveHyperlink.js @@ -56,23 +56,25 @@ ops.OpRemoveHyperlink = function OpRemoveHyperlink() { var odtDocument = /**@type{ops.OdtDocument}*/(document), range = odtDocument.convertCursorToDomRange(position, length), links = odfUtils.getHyperlinkElements(range), - node; + node, + events = []; runtime.assert(links.length === 1, "The given range should only contain a single link."); node = domUtils.mergeIntoParent(/**@type{!Node}*/(links[0])); range.detach(); - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); odtDocument.getOdfCanvas().refreshSize(); odtDocument.getOdfCanvas().rerenderAnnotations(); - return [{ + events.push({ eventid: ops.OdtDocument.signalParagraphChanged, args: { paragraphElement: odfUtils.getParagraphElement(node), memberId: memberid, timeStamp: timestamp } - }]; + }); + return events; }; /** diff --git a/webodf/lib/ops/OpRemoveText.js b/webodf/lib/ops/OpRemoveText.js index 71e4e57e4..f6314121a 100644 --- a/webodf/lib/ops/OpRemoveText.js +++ b/webodf/lib/ops/OpRemoveText.js @@ -95,7 +95,7 @@ ops.OpRemoveText = function OpRemoveText() { odtDocument.handleStepsRemoved({position: position}, events); odtDocument.downgradeWhitespacesAtPosition(position); - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); odtDocument.getOdfCanvas().refreshSize(); events.push({ eventid: ops.OdtDocument.signalParagraphChanged, diff --git a/webodf/lib/ops/OpSplitParagraph.js b/webodf/lib/ops/OpSplitParagraph.js index 36a95bfc6..1538e125d 100644 --- a/webodf/lib/ops/OpSplitParagraph.js +++ b/webodf/lib/ops/OpSplitParagraph.js @@ -177,7 +177,7 @@ ops.OpSplitParagraph = function OpSplitParagraph() { events.push({eventid: ops.Document.signalCursorMoved, args: cursor}); } - odtDocument.fixCursorPositions(); + odtDocument.fixCursorPositions(events); odtDocument.getOdfCanvas().refreshSize(); // mark both paragraphs as edited events.push({ diff --git a/webodf/tests/ops/OdtDocumentTests.js b/webodf/tests/ops/OdtDocumentTests.js index 5182b2189..3851ace4b 100644 --- a/webodf/tests/ops/OdtDocumentTests.js +++ b/webodf/tests/ops/OdtDocumentTests.js @@ -216,7 +216,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { setCursorPosition(1, 2); wrapInDiv(t.cursor.getAnchorNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -234,7 +234,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { setCursorPosition(1, 2); wrapInDiv(t.cursor.getNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -253,7 +253,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { wrapInDiv(t.cursor.getNode()); wrapInDiv(t.cursor.getAnchorNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -272,7 +272,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { wrapInDiv(t.cursor.getNode()); wrapInDiv(t.cursor.getAnchorNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -291,7 +291,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { wrapInDiv(t.cursor.getNode()); wrapInDiv(t.cursor.getAnchorNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -312,7 +312,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { wrapInDiv(t.cursor.getNode()); wrapInDiv(t.cursor.getAnchorNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -333,7 +333,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { wrapInDiv(t.cursor.getNode()); wrapInDiv(t.cursor.getAnchorNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; @@ -353,7 +353,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { setCursorPosition(1); wrapInDiv(t.cursor.getNode()); - t.odtDocument.fixCursorPositions(); + t.odtDocument.fixCursorPositions(false); t.isWalkable = isCursorSelectionInWalkablePositions(); t.anchorInDiv = t.cursor.getAnchorNode().parentNode.localName === "div"; From 55f987ad89b82c11a62e8b61924be4d7ebabbbf2 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Fri, 5 Jun 2015 19:43:48 +0200 Subject: [PATCH 12/12] Mark methods which should not be used by others with DONOTUSE_ prefix --- webodf/lib/gui/SessionController.js | 6 +++--- webodf/lib/ops/OdtDocument.js | 8 ++++++-- webodf/tests/gui/DirectFormattingControllerTests.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/webodf/lib/gui/SessionController.js b/webodf/lib/gui/SessionController.js index 3cd0ab7d1..1e1236659 100644 --- a/webodf/lib/gui/SessionController.js +++ b/webodf/lib/gui/SessionController.js @@ -304,7 +304,7 @@ gui.SessionControllerOptions = function () { * @return {undefined} */ function forwardUndoStackChange(e) { - odtDocument.emitSignalUndoStackChanged(e); + odtDocument.DONOTUSE_emitSignalUndoStackChanged(e); } /** @@ -374,7 +374,7 @@ gui.SessionControllerOptions = function () { newSelectionRange.setEnd(shadowCursorIterator.container(), shadowCursorIterator.unfilteredDomOffset()); } shadowCursor.setSelectedRange(newSelectionRange, handleEnd === 'right'); - odtDocument.emitSignalCursorMoved(shadowCursor); + odtDocument.DONOTUSE_emitSignalCursorMoved(shadowCursor); } } } @@ -400,7 +400,7 @@ gui.SessionControllerOptions = function () { selectionController.expandToParagraphBoundaries(selectionRange.range); } shadowCursor.setSelectedRange(selectionRange.range, selectionRange.hasForwardSelection); - odtDocument.emitSignalCursorMoved(shadowCursor); + odtDocument.DONOTUSE_emitSignalCursorMoved(shadowCursor); } } } diff --git a/webodf/lib/ops/OdtDocument.js b/webodf/lib/ops/OdtDocument.js index 0d1b8ef4d..ccb32cc7c 100644 --- a/webodf/lib/ops/OdtDocument.js +++ b/webodf/lib/ops/OdtDocument.js @@ -1033,19 +1033,23 @@ ops.OdtDocument = function OdtDocument(odfCanvas) { /** * Emit the signal that the passed cursor moved. + * TODO: get rid of this method, noone should be able to emit signals by direct calls, only by op execution + * @internal * @param {!ops.OdtCursor} cursor * @return {undefined} */ - this.emitSignalCursorMoved = function(cursor) { + this.DONOTUSE_emitSignalCursorMoved = function(cursor) { eventNotifier.emit(ops.Document.signalCursorMoved, cursor); }; /** * Emit the signal that the passed cursor moved. + * TODO: get rid of this method, noone should be able to emit signals by direct calls, only by op execution + * @internal * @param {?Event} e * @return {undefined} */ - this.emitSignalUndoStackChanged = function(e) { + this.DONOTUSE_emitSignalUndoStackChanged = function(e) { eventNotifier.emit(ops.OdtDocument.signalUndoStackChanged, e); }; diff --git a/webodf/tests/gui/DirectFormattingControllerTests.js b/webodf/tests/gui/DirectFormattingControllerTests.js index 797d1cc29..1a22b334c 100644 --- a/webodf/tests/gui/DirectFormattingControllerTests.js +++ b/webodf/tests/gui/DirectFormattingControllerTests.js @@ -140,7 +140,7 @@ gui.DirectFormattingControllerTests = function DirectFormattingControllerTests(r domUtils.getElementsByTagNameNS(node, testns, '*').forEach(function(node) { node.parentNode.removeChild(node); }); - t.odtDocument.emitSignalCursorMoved(t.cursor); + t.odtDocument.DONOTUSE_emitSignalCursorMoved(t.cursor); } return node; }