[Libreoffice-commits] online.git: loleaflet/src

Henry Castro hcastro at collabora.com
Sun Mar 5 20:27:58 UTC 2017


 loleaflet/src/control/Control.Menubar.js     |    1 
 loleaflet/src/layer/AnnotationManager.js     |    9 ++++++--
 loleaflet/src/layer/tile/ImpressTileLayer.js |   28 +++++++++++++++++++++++++++
 loleaflet/src/layer/tile/WriterTileLayer.js  |    6 +++--
 4 files changed, 40 insertions(+), 4 deletions(-)

New commits:
commit 42823172a27db2e40d050eda6d5f44795d6ffd21
Author: Henry Castro <hcastro at collabora.com>
Date:   Sun Mar 5 16:25:26 2017 -0400

    loleaflet: insert Impress annotations
    
    Impress does not send anchor position property of the annotation object, so tweak the code
    to set the cursor position
    
    Change-Id: I12e365ed600a53b5a2c1bcb0ef52dec078a258f2

diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index d066e66..da2fbee 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -200,6 +200,7 @@ L.Control.Menubar = L.Control.extend({
 			},
 			{name: _('Insert'), type: 'menu', menu: [
 				{name: _('Image'), id: 'insertgraphic', type: 'action'},
+				{name: _('Comment...'), id: 'insertcomment', type: 'action'},
 				{type: 'separator'},
 				{name: _('Special character...'), id: 'specialcharacter', type: 'action'}]
 			},
diff --git a/loleaflet/src/layer/AnnotationManager.js b/loleaflet/src/layer/AnnotationManager.js
index 3f4f431..c816700 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -53,6 +53,9 @@ L.AnnotationManager = L.Class.extend({
 		this.clear();
 		for (var index in comments) {
 			comment = comments[index];
+			if (!comment.anchorPos) {
+				continue;
+			}
 			comment.anchorPos = L.LOUtil.stringToPoint(comment.anchorPos);
 			this._items.push(L.annotation(this._map.options.maxBounds.getSouthEast(), comment).addTo(this._map));
 		}
@@ -194,10 +197,11 @@ L.AnnotationManager = L.Class.extend({
 		var obj = JSON.parse(textMsg.substring('comment:'.length + 1));
 
 		if (obj.comment.action === 'Add') {
-			obj.comment.anchorPos = L.LOUtil.stringToPoint(obj.comment.anchorPos);
 			var added = this.getItem('new');
 			if (added) {
 				delete obj.comment.action;
+				obj.comment.anchorPos = obj.comment.anchorPos ? L.LOUtil.stringToPoint(obj.comment.anchorPos) :
+					added._data.anchorPos;
 				added._data = obj.comment;
 				this._items.sort(function(a, b) {
 					return Math.abs(a._data.anchorPos.y) - Math.abs(b._data.anchorPos.y) ||
@@ -215,9 +219,10 @@ L.AnnotationManager = L.Class.extend({
 				this.remove(obj.comment.id);
 			}
 		} else if (obj.comment.action === 'Modify') {
-			obj.comment.anchorPos = L.LOUtil.stringToPoint(obj.comment.anchorPos);
 			var modified = this.getItem(obj.comment.id);
 			if (modified) {
+				obj.comment.anchorPos = obj.comment.anchorPos ? L.LOUtil.stringToPoint(obj.comment.anchorPos) :
+					modified._data.anchorPos;
 				modified._data = obj.comment;
 				modified.update();
 				this.update();
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js b/loleaflet/src/layer/tile/ImpressTileLayer.js
index e384d5f..0c1b267 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -6,10 +6,38 @@
 L.ImpressTileLayer = L.TileLayer.extend({
 
 	newAnnotation: function (comment) {
+		if (!comment.anchorPos && this._isCursorVisible) {
+			comment.anchorPos = this._latLngToTwips(this._visibleCursor.getNorthWest());
+		}
+		if (comment.anchorPos) {
+			this._annotations.add(comment, true);
+		}
 	},
 
 	onAdd: function (map) {
 		L.TileLayer.prototype.onAdd.call(this, map);
+		this._annotations = L.annotationManager(map);
+	},
+
+	_onCommandValuesMsg: function (textMsg) {
+		var values = JSON.parse(textMsg.substring(textMsg.indexOf('{')));
+		if (!values) {
+			return;
+		}
+
+		if (values.comments) {
+			this._annotations.fill(values.comments);
+		} else {
+			L.TileLayer.prototype._onCommandValuesMsg.call(this, textMsg);
+		}
+	},
+
+	_onMessage: function (textMsg, img) {
+		if (textMsg.startsWith('comment:')) {
+			this._annotations.onACKComment(textMsg);
+		} else {
+			L.TileLayer.prototype._onMessage.call(this, textMsg, img);
+		}
 	},
 
 	_onInvalidateTilesMsg: function (textMsg) {
diff --git a/loleaflet/src/layer/tile/WriterTileLayer.js b/loleaflet/src/layer/tile/WriterTileLayer.js
index 114ee76..4e78168 100644
--- a/loleaflet/src/layer/tile/WriterTileLayer.js
+++ b/loleaflet/src/layer/tile/WriterTileLayer.js
@@ -6,10 +6,12 @@
 L.WriterTileLayer = L.TileLayer.extend({
 
 	newAnnotation: function (comment) {
-		if (!comment.anchorPos) {
+		if (!comment.anchorPos && this._isCursorVisible) {
 			comment.anchorPos = this._latLngToTwips(this._visibleCursor.getNorthWest());
 		}
-		this._annotations.add(comment, true);
+		if (comment.anchorPos) {
+			this._annotations.add(comment, true);
+		}
 	},
 
 	onAdd: function (map) {


More information about the Libreoffice-commits mailing list