Skip to content

Commit f200f41

Browse files
author
Friedrich W. H. Kossebau
committed
Have Operations no longer emit document signals themselves, but collect them
1 parent b98fee4 commit f200f41

31 files changed

Lines changed: 204 additions & 134 deletions

webodf/lib/gui/SessionView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ gui.SessionViewOptions = function () {
410410
var annotationViewManager = odfCanvas.getAnnotationViewManager();
411411
if (annotationViewManager) {
412412
annotationViewManager.rehighlightAnnotations();
413-
odtDocument.fixCursorPositions();
413+
odtDocument.fixCursorPositions(); // TODO: remove this, this should not be needed. for now add return value if moved, and assert here that not.
414414
}
415415
}
416416

webodf/lib/ops/OdtDocument.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
742742

743743
if (cursorMoved) {
744744
cursor.setSelectedRange(selectedRange, cursor.hasForwardSelection());
745-
self.emit(ops.Document.signalCursorMoved, cursor);
745+
eventNotifier.emit(ops.Document.signalCursorMoved, cursor);
746746
}
747747
});
748748
};
@@ -881,7 +881,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
881881
if (cursor) {
882882
cursor.removeFromDocument();
883883
delete cursors[memberid];
884-
self.emit(ops.Document.signalCursorRemoved, memberid);
885884
return true;
886885
}
887886
return false;
@@ -916,12 +915,13 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
916915
};
917916

918917
/**
919-
* @param {!string} eventid
920-
* @param {*} args
918+
* @param {!Array.<!ops.Operation.Event>} events
921919
* @return {undefined}
922920
*/
923-
this.emit = function (eventid, args) {
924-
eventNotifier.emit(eventid, args);
921+
this.emitEvents = function (events) {
922+
events.forEach(function(event) {
923+
eventNotifier.emit(event.eventid, event.args);
924+
});
925925
};
926926

927927
/**
@@ -976,7 +976,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
976976
this.handleStepsInserted = function(args) {
977977
stepsTranslator.handleStepsInserted(args);
978978
// signal not used in webodf, but 3rd-party (NVivo)
979-
self.emit(ops.OdtDocument.signalStepsInserted, args);
979+
eventNotifier.emit(ops.OdtDocument.signalStepsInserted, args);
980980
};
981981

982982
/**
@@ -988,7 +988,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
988988
this.handleStepsRemoved = function(args) {
989989
stepsTranslator.handleStepsRemoved(args);
990990
// signal not used in webodf, but 3rd-party (NVivo)
991-
self.emit(ops.OdtDocument.signalStepsRemoved, args);
991+
eventNotifier.emit(ops.OdtDocument.signalStepsRemoved, args);
992992
};
993993

994994
/**

webodf/lib/ops/OpAddAnnotation.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ ops.OpAddAnnotation = function OpAddAnnotation() {
137137

138138
/**
139139
* @param {!ops.Document} document
140+
* @return {?Array.<!ops.Operation.Event>}
140141
*/
141142
this.execute = function (document) {
142143
var odtDocument = /**@type{ops.OdtDocument}*/(document),
143144
annotation, annotationEnd,
144145
cursor = odtDocument.getCursor(memberid),
145146
selectedRange,
146-
paragraphElement;
147+
paragraphElement,
148+
events = [];
147149

148150
doc = odtDocument.getDOMDocument();
149151

@@ -168,14 +170,14 @@ ops.OpAddAnnotation = function OpAddAnnotation() {
168170
selectedRange.selectNodeContents(paragraphElement);
169171
cursor.setSelectedRange(selectedRange, false);
170172
cursor.setSelectionType(ops.OdtCursor.RangeSelection);
171-
odtDocument.emit(ops.Document.signalCursorMoved, cursor);
173+
events.push({eventid: ops.Document.signalCursorMoved, args: cursor});
172174
}
173175
// Track this annotation
174176
odtDocument.getOdfCanvas().addAnnotation(annotation);
175177
odtDocument.fixCursorPositions();
176-
odtDocument.emit(ops.OdtDocument.signalAnnotationAdded, { memberId: memberid, annotation: annotation });
178+
events.push({eventid: ops.OdtDocument.signalAnnotationAdded, args: { memberId: memberid, annotation: annotation }});
177179

178-
return true;
180+
return events;
179181
};
180182

181183
/**

webodf/lib/ops/OpAddCursor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,21 @@ ops.OpAddCursor = function OpAddCursor() {
4646

4747
/**
4848
* @param {!ops.Document} document
49+
* @return {?Array.<!ops.Operation.Event>}
4950
*/
5051
this.execute = function (document) {
5152
var odtDocument = /**@type{ops.OdtDocument}*/(document),
5253
cursor = odtDocument.getCursor(memberid);
5354

5455
// there should be none
5556
if (cursor) {
56-
return false;
57+
return null;
5758
}
5859

5960
cursor = new ops.OdtCursor(memberid, odtDocument);
6061
odtDocument.addCursor(cursor);
61-
odtDocument.emit(ops.Document.signalCursorAdded, cursor);
62-
return true;
62+
63+
return [{eventid: ops.Document.signalCursorAdded, args: cursor}];
6364
};
6465

6566
/**

webodf/lib/ops/OpAddMember.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ ops.OpAddMember = function OpAddMember() {
5252

5353
/**
5454
* @param {!ops.Document} document
55+
* @return {?Array.<!ops.Operation.Event>}
5556
*/
5657
this.execute = function (document) {
5758
var odtDocument = /**@type{ops.OdtDocument}*/(document),
5859
member;
5960
if (odtDocument.getMember(memberid)) {
60-
return false;
61+
return null;
6162
}
6263

6364
member = new ops.Member(memberid, setProperties);
6465
odtDocument.addMember(member);
65-
odtDocument.emit(ops.Document.signalMemberAdded, member);
6666

67-
return true;
67+
return [{eventid: ops.Document.signalMemberAdded, args: member}];
6868
};
6969

7070
/**

webodf/lib/ops/OpAddStyle.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ops.OpAddStyle = function OpAddStyle() {
5656

5757
/**
5858
* @param {!ops.Document} document
59+
* @return {?Array.<!ops.Operation.Event>}
5960
*/
6061
this.execute = function (document) {
6162
var odtDocument = /**@type{ops.OdtDocument}*/(document),
@@ -65,7 +66,7 @@ ops.OpAddStyle = function OpAddStyle() {
6566
styleNode = dom.createElementNS(stylens, 'style:style');
6667

6768
if (!styleNode) {
68-
return false;
69+
return null;
6970
}
7071

7172
if (setProperties) {
@@ -83,9 +84,9 @@ ops.OpAddStyle = function OpAddStyle() {
8384

8485
odtDocument.getOdfCanvas().refreshCSS();
8586
if (!isAutomaticStyle) {
86-
odtDocument.emit(ops.OdtDocument.signalCommonStyleCreated, {name: styleName, family: styleFamily});
87+
return [{eventid: ops.OdtDocument.signalCommonStyleCreated, args: {name: styleName, family: styleFamily}}];
8788
}
88-
return true;
89+
return [];
8990
};
9091

9192
/**

webodf/lib/ops/OpApplyDirectStyling.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() {
8080

8181
/**
8282
* @param {!ops.Document} document
83+
* @return {?Array.<!ops.Operation.Event>}
8384
*/
8485
this.execute = function (document) {
8586
var odtDocument = /**@type{ops.OdtDocument}*/(document),
8687
range = odtDocument.convertCursorToDomRange(position, length),
87-
impactedParagraphs = odfUtils.getParagraphElements(range);
88+
impactedParagraphs = odfUtils.getParagraphElements(range),
89+
events = [];
8890

8991
applyStyle(odtDocument, range, setProperties);
9092

@@ -93,15 +95,18 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() {
9395
odtDocument.fixCursorPositions(); // The container splits may leave the cursor in an invalid spot
9496

9597
impactedParagraphs.forEach(function (n) {
96-
odtDocument.emit(ops.OdtDocument.signalParagraphChanged, {
97-
paragraphElement: n,
98-
memberId: memberid,
99-
timeStamp: timestamp
98+
events.push({
99+
eventid: ops.OdtDocument.signalParagraphChanged,
100+
args: {
101+
paragraphElement: n,
102+
memberId: memberid,
103+
timeStamp: timestamp
104+
}
100105
});
101106
});
102107

103108
odtDocument.getOdfCanvas().rerenderAnnotations();
104-
return true;
109+
return events;
105110
};
106111

107112
/**

webodf/lib/ops/OpApplyHyperlink.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() {
7878
/**
7979
* TODO: support adding image link
8080
* @param {!ops.Document} document
81+
* @return {?Array.<!ops.Operation.Event>}
8182
*/
8283
this.execute = function (document) {
8384
var odtDocument = /**@type{ops.OdtDocument}*/(document),
@@ -86,10 +87,11 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() {
8687
boundaryNodes = domUtils.splitBoundaries(range),
8788
/**@type{!Array.<!Element>}*/
8889
modifiedParagraphs = [],
89-
textNodes = odfUtils.getTextNodes(range, false);
90+
textNodes = odfUtils.getTextNodes(range, false),
91+
events = [];
9092

9193
if (textNodes.length === 0) {
92-
return false;
94+
return null;
9395
}
9496

9597
textNodes.forEach(function (node) {
@@ -114,14 +116,17 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() {
114116
odtDocument.getOdfCanvas().refreshSize();
115117
odtDocument.getOdfCanvas().rerenderAnnotations();
116118
modifiedParagraphs.forEach(function (paragraph) {
117-
odtDocument.emit(ops.OdtDocument.signalParagraphChanged, {
118-
paragraphElement: paragraph,
119-
memberId: memberid,
120-
timeStamp: timestamp
119+
events.push({
120+
eventid: ops.OdtDocument.signalParagraphChanged,
121+
args: {
122+
paragraphElement: paragraph,
123+
memberId: memberid,
124+
timeStamp: timestamp
125+
}
121126
});
122127
});
123128

124-
return true;
129+
return events;
125130
};
126131

127132
/**

webodf/lib/ops/OpInsertImage.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ops.OpInsertImage = function OpInsertImage() {
8080

8181
/**
8282
* @param {!ops.Document} document
83+
* @return {?Array.<!ops.Operation.Event>}
8384
*/
8485
this.execute = function (document) {
8586
var odtDocument = /**@type{ops.OdtDocument}*/(document),
@@ -88,7 +89,7 @@ ops.OpInsertImage = function OpInsertImage() {
8889
textNode, refNode, paragraphElement, frameElement;
8990

9091
if (!domPosition) {
91-
return false;
92+
return null;
9293
}
9394

9495
textNode = domPosition.textNode;
@@ -106,13 +107,16 @@ ops.OpInsertImage = function OpInsertImage() {
106107

107108
odfCanvas.addCssForFrameWithImage(frameElement);
108109
odfCanvas.refreshCSS();
109-
odtDocument.emit(ops.OdtDocument.signalParagraphChanged, {
110-
paragraphElement: paragraphElement,
111-
memberId: memberid,
112-
timeStamp: timestamp
113-
});
114110
odfCanvas.rerenderAnnotations();
115-
return true;
111+
112+
return [{
113+
eventid: ops.OdtDocument.signalParagraphChanged,
114+
args: {
115+
paragraphElement: paragraphElement,
116+
memberId: memberid,
117+
timeStamp: timestamp
118+
}
119+
}];
116120
};
117121

118122
/**

webodf/lib/ops/OpInsertTable.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ ops.OpInsertTable = function OpInsertTable() {
142142

143143
/**
144144
* @param {!ops.Document} document
145+
* @return {?Array.<!ops.Operation.Event>}
145146
*/
146147
this.execute = function (document) {
147148
var odtDocument = /**@type{ops.OdtDocument}*/(document),
@@ -160,16 +161,17 @@ ops.OpInsertTable = function OpInsertTable() {
160161
odtDocument.handleStepsInserted({position: position});
161162

162163
odtDocument.getOdfCanvas().refreshSize();
163-
odtDocument.emit(ops.OdtDocument.signalTableAdded, {
164-
tableElement: tableNode,
165-
memberId: memberid,
166-
timeStamp: timestamp
167-
});
168-
169164
odtDocument.getOdfCanvas().rerenderAnnotations();
170-
return true;
165+
return [{
166+
eventid: ops.OdtDocument.signalTableAdded,
167+
args: {
168+
tableElement: tableNode,
169+
memberId: memberid,
170+
timeStamp: timestamp
171+
}
172+
}];
171173
}
172-
return false;
174+
return null;
173175
};
174176

175177
/**

0 commit comments

Comments
 (0)