Skip to content

Commit 0cc0032

Browse files
author
Friedrich W. H. Kossebau
committed
Call OdtDocument op exec wrapper methods directly from session, not by signal
1 parent 4ac191b commit 0cc0032

5 files changed

Lines changed: 26 additions & 10 deletions

File tree

webodf/lib/ops/OdtDocument.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,24 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
434434
return {textNode: lastTextNode, offset: nodeOffset };
435435
}
436436

437+
/**
438+
* @param {!ops.Operation} op
439+
* @return {undefined}
440+
*/
441+
this.prepareOperationExecution = function(op) {
442+
eventNotifier.emit(ops.OdtDocument.signalOperationStart, op);
443+
};
444+
437445
/**
438446
* Called after an operation is executed, this
439447
* function will check if the operation is an
440448
* 'edit', and in that case will update the
441449
* document's metadata, such as dc:creator,
442450
* meta:editing-cycles, and dc:creator.
443451
* @param {!ops.Operation} op
452+
* @return {undefined}
444453
*/
445-
function handleOperationExecuted(op) {
454+
this.finishOperationExecution = function (op) {
446455
var opspec = op.spec(),
447456
memberId = opspec.memberid,
448457
date = new Date(opspec.timestamp).toISOString(),
@@ -484,9 +493,14 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
484493
}
485494

486495
lastEditingOp = op;
487-
self.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata);
488496
}
489-
}
497+
498+
eventNotifier.emit(ops.OdtDocument.signalOperationEnd, op);
499+
500+
if (op.isEdit) {
501+
eventNotifier.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata);
502+
}
503+
};
490504

491505
/**
492506
* Upgrades literal whitespaces (' ') to <text:s> </text:s>,
@@ -976,7 +990,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
976990
filter = new ops.TextPositionFilter();
977991
stepUtils = new odf.StepUtils();
978992
stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500);
979-
eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted);
980993
eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks);
981994
}
982995
init();

webodf/lib/ops/Session.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ ops.Session = function Session(odfCanvas) {
8181
operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchStart, forwardBatchStart);
8282
operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchEnd, forwardBatchEnd);
8383
opRouter.setPlaybackFunction(function (op) {
84-
odtDocument.emit(ops.OdtDocument.signalOperationStart, op);
84+
odtDocument.prepareOperationExecution(op);
8585
if (op.execute(odtDocument)) {
86-
odtDocument.emit(ops.OdtDocument.signalOperationEnd, op);
86+
odtDocument.finishOperationExecution(op);
8787
return true;
8888
}
8989
return false;

webodf/tests/gui/MetadataControllerTests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ gui.MetadataControllerTests = function MetadataControllerTests(runner) {
8484

8585
// need to set the timestamp, otherwise things fail in odtDocument
8686
opspec.timestamp = Date.now();
87-
timedOp = operationFactory.create(opspec);
87+
timedOp = /**@type {!ops.Operation}*/(operationFactory.create(opspec));
88+
odtDocument.prepareOperationExecution(timedOp);
8889
if (timedOp.execute(odtDocument)) {
89-
odtDocument.emit(ops.OdtDocument.signalOperationEnd, timedOp);
90+
odtDocument.finishOperationExecution(timedOp);
9091
}
9192
});
9293
};

webodf/tests/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
"ops.Document",
230230
"ops.Member",
231231
"ops.OdtDocument",
232+
"ops.Operation",
232233
"ops.OperationFactory",
233234
"ops.OperationTestHelper",
234235
"xmldom.LSSerializer"

webodf/tests/ops/OperationTests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,11 @@ ops.OperationTests = function OperationTests(runner) {
288288

289289
// execute test ops
290290
for (i = 0; i < test.ops.length; i += 1) {
291-
op = factory.create(test.ops[i]);
291+
op = /**@type {!ops.Operation}*/(factory.create(test.ops[i]));
292+
t.odtDocument.prepareOperationExecution(op);
292293
op.execute(t.odtDocument);
293294
if (metabefore) {
294-
t.odtDocument.emit(ops.OdtDocument.signalOperationEnd, op);
295+
t.odtDocument.finishOperationExecution(op);
295296
}
296297
checkForEmptyTextNodes(t.odtDocument.getCanvas().getElement());
297298
}

0 commit comments

Comments
 (0)