Skip to content

Commit d638126

Browse files
author
Friedrich W. H. Kossebau
committed
Call OdtDocument op exec wrapper methods directly from session, not by signal
1 parent 5fea1ba commit d638126

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
@@ -437,15 +437,24 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
437437
return {textNode: lastTextNode, offset: nodeOffset };
438438
}
439439

440+
/**
441+
* @param {!ops.Operation} op
442+
* @return {undefined}
443+
*/
444+
this.prepareOperationExecution = function(op) {
445+
eventNotifier.emit(ops.OdtDocument.signalOperationStart, op);
446+
};
447+
440448
/**
441449
* Called after an operation is executed, this
442450
* function will check if the operation is an
443451
* 'edit', and in that case will update the
444452
* document's metadata, such as dc:creator,
445453
* meta:editing-cycles, and dc:creator.
446454
* @param {!ops.Operation} op
455+
* @return {undefined}
447456
*/
448-
function handleOperationExecuted(op) {
457+
this.finishOperationExecution = function (op) {
449458
var opspec = op.spec(),
450459
memberId = opspec.memberid,
451460
date = new Date(opspec.timestamp).toISOString(),
@@ -487,9 +496,14 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
487496
}
488497

489498
lastEditingOp = op;
490-
self.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata);
491499
}
492-
}
500+
501+
eventNotifier.emit(ops.OdtDocument.signalOperationEnd, op);
502+
503+
if (op.isEdit) {
504+
eventNotifier.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata);
505+
}
506+
};
493507

494508
/**
495509
* Upgrades literal whitespaces (' ') to <text:s> </text:s>,
@@ -979,7 +993,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
979993
filter = new ops.TextPositionFilter();
980994
stepUtils = new odf.StepUtils();
981995
stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500);
982-
eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted);
983996
eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks);
984997
}
985998
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)