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

Mihai Varga mihai.varga at collabora.com
Fri Jul 10 08:08:34 PDT 2015


 loleaflet/build/deps.js                               |   26 ++++-
 loleaflet/debug/document/document_simple_example.html |   16 ++-
 loleaflet/src/control/Buttons.js                      |    8 +
 loleaflet/src/control/Control.Buttons.js              |   15 ---
 loleaflet/src/control/Control.EditView.js             |   65 -------------
 loleaflet/src/control/Control.Parts.js                |   29 +----
 loleaflet/src/control/Control.Permission.js           |   49 +++++++++
 loleaflet/src/control/Control.Search.js               |   47 ---------
 loleaflet/src/control/Control.StatusIndicator.js      |   22 +---
 loleaflet/src/control/Control.Zoom.js                 |   11 --
 loleaflet/src/control/Parts.js                        |   28 +++++
 loleaflet/src/control/Permission.js                   |   23 ++++
 loleaflet/src/control/Search.js                       |   34 ++++++
 loleaflet/src/layer/tile/TileLayer.js                 |   90 +++++-------------
 14 files changed, 218 insertions(+), 245 deletions(-)

New commits:
commit c881fd2f8f50201274195f4ca07c550acb152eb4
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 10 18:01:19 2015 +0300

    loleaflet: manually add controls in the html file

diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html
index 772caf3..bb00203 100644
--- a/loleaflet/debug/document/document_simple_example.html
+++ b/loleaflet/debug/document/document_simple_example.html
@@ -67,6 +67,14 @@
             doubleClickZoom: false
             });
 
+    ////// Controls /////
+    map.addControl(L.control.buttons());
+    map.addControl(L.control.search());
+    map.addControl(L.control.permissionSwitch());
+    map.addControl(L.control.zoom());
+    map.addControl(L.control.parts());
+    map.addControl(L.control.statusIndicator());
+
     ////// Document layer ////
     var docLayer = new L.TileLayer('', {
         doc: filePath,
@@ -76,10 +84,6 @@
     });
     map.addLayer(docLayer);
 
-    ////// Zoom Control /////
-    var zoomControl = L.control.zoom();
-    map.addControl(zoomControl);
-
     ////// Scrollbar /////
     (function($){
         $(window).load(function(){
diff --git a/loleaflet/src/control/Control.Buttons.js b/loleaflet/src/control/Control.Buttons.js
index 96977af..d4a08c2 100644
--- a/loleaflet/src/control/Control.Buttons.js
+++ b/loleaflet/src/control/Control.Buttons.js
@@ -79,15 +79,6 @@ L.Control.Buttons = L.Control.extend({
 	}
 });
 
-L.Map.mergeOptions({
-	buttonsControl: true
-});
-
-L.Map.addInitHook(function () {
-	this.buttonsControl = new L.Control.Buttons();
-	this.addControl(this.buttonsControl);
-});
-
 L.control.buttons = function (options) {
 	return new L.Control.Buttons(options);
 };
diff --git a/loleaflet/src/control/Control.Parts.js b/loleaflet/src/control/Control.Parts.js
index 528fcbe..07f67f1 100644
--- a/loleaflet/src/control/Control.Parts.js
+++ b/loleaflet/src/control/Control.Parts.js
@@ -63,16 +63,6 @@ L.Control.Parts = L.Control.extend({
 	}
 });
 
-L.Map.mergeOptions({
-	partsControl: true
-});
-
-L.Map.addInitHook(function () {
-	this.partsControl = new L.Control.Parts();
-	this.addControl(this.partsControl);
-});
-
-
 L.control.parts = function (options) {
 	return new L.Control.Parts(options);
 };
diff --git a/loleaflet/src/control/Control.Permission.js b/loleaflet/src/control/Control.Permission.js
index dee99e9..240d1bb 100644
--- a/loleaflet/src/control/Control.Permission.js
+++ b/loleaflet/src/control/Control.Permission.js
@@ -44,17 +44,6 @@ L.Control.PermissionSwitch = L.Control.extend({
 	}
 });
 
-L.Map.mergeOptions({
-	permissionSwitchControl: true
-});
-
-L.Map.addInitHook(function () {
-	if (this.options.permissionSwitchControl) {
-		this.permissionSwitchControl = new L.Control.PermissionSwitch();
-		this.addControl(this.permissionSwitchControl);
-	}
-});
-
 L.control.permissionSwitch = function (options) {
 	return new L.Control.PermissionSwitch(options);
 };
diff --git a/loleaflet/src/control/Control.Search.js b/loleaflet/src/control/Control.Search.js
index 0973607..91e3638 100644
--- a/loleaflet/src/control/Control.Search.js
+++ b/loleaflet/src/control/Control.Search.js
@@ -115,15 +115,6 @@ L.Control.Search = L.Control.extend({
 	}
 });
 
-L.Map.mergeOptions({
-	searchControl: true
-});
-
-L.Map.addInitHook(function () {
-	this.searchControl = new L.Control.Search();
-	this.addControl(this.searchControl);
-});
-
 L.control.search = function (options) {
 	return new L.Control.Search(options);
 };
diff --git a/loleaflet/src/control/Control.StatusIndicator.js b/loleaflet/src/control/Control.StatusIndicator.js
index fffc625..4603ff9 100644
--- a/loleaflet/src/control/Control.StatusIndicator.js
+++ b/loleaflet/src/control/Control.StatusIndicator.js
@@ -29,17 +29,6 @@ L.Control.StatusIndicator = L.Control.extend({
 	}
 });
 
-L.Map.mergeOptions({
-	statusIndicatorControl: true
-});
-
-L.Map.addInitHook(function () {
-	if (this.options.statusIndicatorControl) {
-		this.statusIndicatorControl = new L.Control.StatusIndicator();
-		this.addControl(this.statusIndicatorControl);
-	}
-});
-
 L.control.statusIndicator = function (options) {
 	return new L.Control.StatusIndicator(options);
 };
diff --git a/loleaflet/src/control/Control.Zoom.js b/loleaflet/src/control/Control.Zoom.js
index 5917258..2d550a9 100644
--- a/loleaflet/src/control/Control.Zoom.js
+++ b/loleaflet/src/control/Control.Zoom.js
@@ -86,17 +86,6 @@ L.Control.Zoom = L.Control.extend({
 	}
 });
 
-L.Map.mergeOptions({
-	zoomControl: false
-});
-
-L.Map.addInitHook(function () {
-	if (this.options.zoomControl) {
-		this.zoomControl = new L.Control.Zoom();
-		this.addControl(this.zoomControl);
-	}
-});
-
 L.control.zoom = function (options) {
 	return new L.Control.Zoom(options);
 };
commit f24ea56603d9ce0eba384787848f90b3f527afb1
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 10 16:51:50 2015 +0300

    loleaflet: updated the status indicator event

diff --git a/loleaflet/src/control/Control.StatusIndicator.js b/loleaflet/src/control/Control.StatusIndicator.js
index 78c24fd..fffc625 100644
--- a/loleaflet/src/control/Control.StatusIndicator.js
+++ b/loleaflet/src/control/Control.StatusIndicator.js
@@ -11,20 +11,19 @@ L.Control.StatusIndicator = L.Control.extend({
 		var partName = 'leaflet-control-statusindicator';
 		this._container = L.DomUtil.create('div', partName + ' leaflet-bar');
 
-		map.on('statusindicator:start statusindicator:setvalue statusindicator:finish',
-			this._updateStatus, this);
+		map.on('statusindicator', this._updateStatus, this);
 		return this._container;
 	},
 
 	_updateStatus: function (e) {
-		if (e.type === 'statusindicator:start') {
+		if (e.statusType === 'start') {
 			L.DomUtil.setStyle(this._container, 'display', '');
 			this._container.innerText = '0 %';
 		}
-		else if (e.type === 'statusindicator:setvalue') {
-			this._container.innerText = e.statusIndicator + '% ';
+		else if (e.statusType === 'setvalue') {
+			this._container.innerText = e.value + '% ';
 		}
-		else if (e.type === 'statusindicator:finish') {
+		else if (e.statusType === 'finish') {
 			L.DomUtil.setStyle(this._container, 'display', 'none');
 		}
 	}
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 8d07715..b028e12 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -404,14 +404,14 @@ L.TileLayer = L.GridLayer.extend({
 			}
 		}
 		else if (textMsg.startsWith('statusindicatorstart:')) {
-			this._map.fire('statusindicator:start');
+			this._map.fire('statusindicator', {statusType : 'start'});
 		}
 		else if (textMsg.startsWith('statusindicatorsetvalue:')) {
-			var statusIndicator = textMsg.match(/\d+/g)[0];
-			this._map.fire('statusindicator:setvalue', {statusIndicator:statusIndicator});
+			var value = textMsg.match(/\d+/g)[0];
+			this._map.fire('statusindicator', {statusType : 'setvalue', value : value});
 		}
 		else if (textMsg.startsWith('statusindicatorfinish:')) {
-			this._map.fire('statusindicator:finish');
+			this._map.fire('statusindicator', {statusType : 'finish'});
 		}
 		else if (textMsg.startsWith('tile:')) {
 			command = this._parseServerCmd(textMsg);
commit cd9433e19270eb9a2dd550926a4c826e28db1632
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 10 16:32:19 2015 +0300

    loleaflet: setPart API for switching parts
    
    Also added the 'updateparts' event which has the members:
    currentPart and parts, indicating the current visible part
    and the number of parts

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index c27f450..d656c7a 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -275,6 +275,11 @@ var deps = {
 		desc: 'Toolbar buttons handler.'
 	},
 
+	Parts: {
+		src: ['control/Parts.js'],
+		desc: 'Parts change handler.'
+	},
+
 	AnimationPan: {
 		src: [
 			'dom/DomEvent.js',
diff --git a/loleaflet/src/control/Control.Parts.js b/loleaflet/src/control/Control.Parts.js
index 7d6d2a7..528fcbe 100644
--- a/loleaflet/src/control/Control.Parts.js
+++ b/loleaflet/src/control/Control.Parts.js
@@ -21,28 +21,16 @@ L.Control.Parts = L.Control.extend({
 		this._nextPartButton = this._createButton(options.nextPartText, options.nextPartTitle,
 		        partName + '-next', container, this._nextPart);
 
-		this._parts = options.parts;
-		this._currentPart = options.currentPart;
-		this._updateDisabled();
-		map.on('setpart', this._updateDisabled, this);
-
+		map.on('updateparts', this._updateDisabled, this);
 		return container;
 	},
 
 	_prevPart: function () {
-		this._map.fire('prevpart');
-		if (this._currentPart > 0) {
-			this._currentPart -= 1;
-		}
-		this._updateDisabled();
+		this._map.setPart('previous');
 	},
 
 	_nextPart: function () {
-		this._map.fire('nextpart');
-		if (this._currentPart < this._parts - 1) {
-			this._currentPart += 1;
-		}
-		this._updateDisabled();
+		this._map.setPart('next');
 	},
 
 	_createButton: function (html, title, className, container, fn) {
@@ -61,16 +49,13 @@ L.Control.Parts = L.Control.extend({
 	},
 
 	_updateDisabled: function (e) {
-		if (e) {
-			this._currentPart = e.currentPart;
-		}
 		var className = 'leaflet-disabled';
-		if (this._currentPart === 0) {
+		if (e.currentPart === 0) {
 			L.DomUtil.addClass(this._prevPartButton, className);
 		} else {
 			L.DomUtil.removeClass(this._prevPartButton, className);
 		}
-		if (this._currentPart === this._parts - 1) {
+		if (e.currentPart === e.parts - 1) {
 			L.DomUtil.addClass(this._nextPartButton, className);
 		} else {
 			L.DomUtil.removeClass(this._nextPartButton, className);
@@ -79,9 +64,15 @@ L.Control.Parts = L.Control.extend({
 });
 
 L.Map.mergeOptions({
-	partsControl: false
+	partsControl: true
 });
 
+L.Map.addInitHook(function () {
+	this.partsControl = new L.Control.Parts();
+	this.addControl(this.partsControl);
+});
+
+
 L.control.parts = function (options) {
 	return new L.Control.Parts(options);
 };
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
new file mode 100644
index 0000000..69d9e83
--- /dev/null
+++ b/loleaflet/src/control/Parts.js
@@ -0,0 +1,28 @@
+/*
+ * Document parts switching handler
+ */
+L.Map.include({
+	setPart: function (part) {
+		var docLayer = this._docLayer
+		if (part === 'previous') {
+			if (docLayer._currentPart > 0) {
+				docLayer._currentPart -= 1;
+			}
+		}
+		else if (part === 'next') {
+			if (docLayer._currentPart < docLayer._parts - 1) {
+				docLayer._currentPart += 1;
+			}
+		}
+		else if (typeof(part) === 'number' && part >= 0 && part < docLayer._parts) {
+			docLayer._currentPart = part;
+		}
+		else {
+			return;
+		}
+		this.fire('updateparts', {currentPart : docLayer._currentPart, parts : docLayer._parts});
+		docLayer._update();
+		docLayer._pruneTiles();
+		docLayer._clearSelections();
+	}
+});
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index cefbdf7..8d07715 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -193,7 +193,6 @@ L.TileLayer = L.GridLayer.extend({
 		this._map.on('zoomend resize', this._updateScrollOffset, this);
 		this._map.on('zoomstart zoomend', this._onZoom, this);
 		this._map.on('clearselection', this._clearSelections, this);
-		this._map.on('prevpart nextpart', this._onSwitchPart, this);
 		this._map.on('drag', this._updateScrollOffset, this);
 		this._map.on('copy', this._onCopy, this);
 		this._map.on('mousedown mouseup mouseover mouseout mousemove dblclick',
@@ -395,13 +394,9 @@ L.TileLayer = L.GridLayer.extend({
 				this._docHeightTwips = command.height;
 				this._updateMaxBounds(true);
 				this._documentInfo = textMsg;
-				if (this._parts === undefined && command.parts > 1) {
-					this._map.addControl(L.control.parts({
-						'parts': command.parts,
-						'currentPart': command.currentPart}));
-				}
 				this._parts = command.parts;
 				this._currentPart = command.currentPart;
+				this._map.fire('updateparts', {currentPart : this._currentPart, parts: this._parts});
 				this._update();
 				if (!this._tilesPreFetcher) {
 					this._tilesPreFetcher = setInterval(L.bind(this._preFetchTiles, this), 2000);
@@ -848,22 +843,6 @@ L.TileLayer = L.GridLayer.extend({
 		this._mouseEventsQueue = [];
 	},
 
-	_onSwitchPart: function (e) {
-		if (e.type === 'prevpart') {
-			if (this._currentPart > 0) {
-				this._currentPart -= 1;
-			}
-		}
-		else if (e.type === 'nextpart') {
-			if (this._currentPart < this._parts - 1) {
-				this._currentPart += 1;
-			}
-		}
-		this._update();
-		this._pruneTiles();
-		this._clearSelections();
-	},
-
 	// Convert javascript key codes to UNO key codes.
 	_toUNOKeyCode: function (keyCode) {
 		return this.keymap[keyCode] || keyCode;
commit 761a1b320d9e3e8013610a538fb2dd34a9c17576
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 10 15:27:30 2015 +0300

    loleaflet: toggleState API for bold, italic, etc
    
    Also added the event 'statechanged' with members
    unoCmd and state

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 8cfae97..c27f450 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -270,6 +270,11 @@ var deps = {
 		desc: 'Permission change handler (edit, view, readonly).'
 	},
 
+	Buttons: {
+		src: ['control/Buttons.js'],
+		desc: 'Toolbar buttons handler.'
+	},
+
 	AnimationPan: {
 		src: [
 			'dom/DomEvent.js',
diff --git a/loleaflet/src/control/Buttons.js b/loleaflet/src/control/Buttons.js
new file mode 100644
index 0000000..2d7e806
--- /dev/null
+++ b/loleaflet/src/control/Buttons.js
@@ -0,0 +1,8 @@
+/*
+ * Toolbar buttons handler
+ */
+L.Map.include({
+	toggleState: function (unoState) {
+		this.socket.send('uno .uno:' + unoState);
+	}
+});
diff --git a/loleaflet/src/control/Control.Buttons.js b/loleaflet/src/control/Control.Buttons.js
index c54c291..96977af 100644
--- a/loleaflet/src/control/Control.Buttons.js
+++ b/loleaflet/src/control/Control.Buttons.js
@@ -59,12 +59,12 @@ L.Control.Buttons = L.Control.extend({
 			L.DomUtil.addClass(e.target, 'leaflet-control-buttons-active');
 			button.active = true;
 		}
-		this._map.socket.send('uno .uno:' + button.uno);
+		this._map.toggleState(button.uno);
 	},
 
 	_onStateChange: function (e) {
-		var unoCmd = e.state.match('.uno:(.*)=')[1];
-		var state = e.state.match('.*=(.*)')[1];
+		var unoCmd = e.unoCmd;
+		var state = e.state;
 		for (var key in this._buttons) {
 			var button = this._buttons[key];
 			if (button.uno === unoCmd) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 67a1579..cefbdf7 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -381,8 +381,12 @@ L.TileLayer = L.GridLayer.extend({
 			}
 		}
 		else if (textMsg.startsWith('statechanged:')) {
-			var state = textMsg.substr(14);
-			map.fire('statechanged', {state : state});
+			var unoMsg = textMsg.substr(14);
+			var unoCmd = unoMsg.match('.uno:(.*)=')[1];
+			var state = unoMsg.match('.*=(.*)')[1];
+			if (unoCmd && state) {
+				map.fire('statechanged', {unoCmd : unoCmd, state : state});
+			}
 		}
 		else if (textMsg.startsWith('status:')) {
 			command = this._parseServerCmd(textMsg);
commit 9eea9a63c7c12f0fcdd1ecff0b46121209a49ae9
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 10 12:20:46 2015 +0300

    loleaflet: exposed the setPermission API: map.setPermission(perm)
    
    Where perm can be: edit, view or readonly
    This also replaces the editMode and readOnly flags

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 349642c..8cfae97 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -221,11 +221,11 @@ var deps = {
 		desc: 'Parts control with two buttons (previous / next).'
 	},
 
-	ControlEditViewSwitch: {
+	ControlPermissionSwitch: {
 		src: ['control/Control.js',
-		      'control/Control.EditView.js'],
+		      'control/Control.Permission.js'],
 		heading: 'Controls',
-		desc: 'Switches from viewing to editing mode and backwards'
+		desc: 'Switches edit, view and readOnly modes'
 	},
 
 	ControlButtons: {
@@ -265,6 +265,11 @@ var deps = {
 		desc: 'Search command handler.'
 	},
 
+	Permission: {
+		src: ['control/Permission.js'],
+		desc: 'Permission change handler (edit, view, readonly).'
+	},
+
 	AnimationPan: {
 		src: [
 			'dom/DomEvent.js',
diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html
index 27edf71..772caf3 100644
--- a/loleaflet/debug/document/document_simple_example.html
+++ b/loleaflet/debug/document/document_simple_example.html
@@ -50,7 +50,7 @@
 
     var filePath = getParameterByName('file_path');
     var host = getParameterByName('host');
-    var editMode = getParameterByName('edit') === 'true';
+    var edit = getParameterByName('edit') === 'true';
     if (filePath === '') {
         alert('Wrong file_path, usage: file_path=/path/to/doc/');
     }
@@ -71,7 +71,7 @@
     var docLayer = new L.TileLayer('', {
         doc: filePath,
         useSocket : true,
-        editMode: editMode,
+        edit: edit,
         readOnly: false
     });
     map.addLayer(docLayer);
diff --git a/loleaflet/src/control/Control.EditView.js b/loleaflet/src/control/Control.EditView.js
deleted file mode 100644
index 748d312..0000000
--- a/loleaflet/src/control/Control.EditView.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * L.Control.EditView is used for switching between viewing and editing mode
- */
-
-L.Control.EditViewSwitch = L.Control.extend({
-	options: {
-		position: 'topleft'
-	},
-
-	onAdd: function (map) {
-		var partName = 'leaflet-control-editviewswitch',
-			container = L.DomUtil.create('label', partName + ' leaflet-bar');
-
-		this._checkBox = L.DomUtil.create('input', 'editview-cb', container);
-		this._checkBox.type = 'checkbox';
-		L.DomEvent.on(this._checkBox, 'change', this._onChange, this);
-		map.on('updatemode:view updatemode:edit updatemode:readonly', this._onUpdateMode, this);
-		container.appendChild(document.createTextNode('Enable editing'));
-		return container;
-	},
-
-	_onChange: function () {
-		var className = 'leaflet-editmode';
-		if (this._checkBox.checked) {
-			this._map.fire('editmode');
-			L.DomUtil.addClass(this._map._container, className);
-		}
-		else {
-			this._map.fire('viewmode');
-			L.DomUtil.removeClass(this._map._container, className);
-		}
-	},
-
-	_onUpdateMode: function (e) {
-		var className = 'leaflet-editmode';
-		if (e.type === 'updatemode:edit') {
-			this._map.fire('editmode');
-			L.DomUtil.addClass(this._map._container, className);
-			this._checkBox.checked = true;
-		}
-		else if (e.type === 'updatemode:view') {
-			this._map.fire('viewmode');
-			L.DomUtil.removeClass(this._map._container, className);
-			this._checkBox.checked = false;
-		}
-		else if (e.type === 'updatemode:readonly') {
-			this._checkBox.disabled = true;
-		}
-	}
-});
-
-L.Map.mergeOptions({
-	editViewSwitchControl: true
-});
-
-L.Map.addInitHook(function () {
-	if (this.options.editViewSwitchControl) {
-		this.editViewSwitchControl = new L.Control.EditViewSwitch();
-		this.addControl(this.editViewSwitchControl);
-	}
-});
-
-L.control.editViewSwitch = function (options) {
-	return new L.Control.EditViewSwitch(options);
-};
diff --git a/loleaflet/src/control/Control.Permission.js b/loleaflet/src/control/Control.Permission.js
new file mode 100644
index 0000000..dee99e9
--- /dev/null
+++ b/loleaflet/src/control/Control.Permission.js
@@ -0,0 +1,60 @@
+/*
+ * L.Control.EditView is used for switching between viewing and editing mode
+ */
+
+L.Control.PermissionSwitch = L.Control.extend({
+	options: {
+		position: 'topleft'
+	},
+
+	onAdd: function (map) {
+		var partName = 'leaflet-control-editviewswitch',
+			container = L.DomUtil.create('label', partName + ' leaflet-bar');
+
+		this._checkBox = L.DomUtil.create('input', 'editview-cb', container);
+		this._checkBox.type = 'checkbox';
+		L.DomEvent.on(this._checkBox, 'change', this._onChange, this);
+		map.on('updatepermission', this._onUpdatePermission, this);
+		container.appendChild(document.createTextNode('Enable editing'));
+		return container;
+	},
+
+	_onChange: function () {
+		if (this._checkBox.checked) {
+			this._map.setPermission('edit');
+		}
+		else {
+			this._map.setPermission('view');
+		}
+	},
+
+	_onUpdatePermission: function (e) {
+		if (e.perm === 'edit') {
+			this._checkBox.checked = true;
+			this._checkBox.disabled = false;
+		}
+		else if (e.perm === 'view') {
+			this._checkBox.checked = false;
+			this._checkBox.disabled = false;
+		}
+		else if (e.perm === 'readonly') {
+			this._checkBox.checked = false;
+			this._checkBox.disabled = true;
+		}
+	}
+});
+
+L.Map.mergeOptions({
+	permissionSwitchControl: true
+});
+
+L.Map.addInitHook(function () {
+	if (this.options.permissionSwitchControl) {
+		this.permissionSwitchControl = new L.Control.PermissionSwitch();
+		this.addControl(this.permissionSwitchControl);
+	}
+});
+
+L.control.permissionSwitch = function (options) {
+	return new L.Control.PermissionSwitch(options);
+};
diff --git a/loleaflet/src/control/Permission.js b/loleaflet/src/control/Permission.js
new file mode 100644
index 0000000..6933f64
--- /dev/null
+++ b/loleaflet/src/control/Permission.js
@@ -0,0 +1,23 @@
+/*
+ * Document permission handler
+ */
+L.Map.include({
+	setPermission: function (perm) {
+		this._docLayer._permission = perm;
+		var className = 'leaflet-editmode';
+		if (perm === 'edit') {
+			this.dragging.disable();
+			L.DomUtil.addClass(this._container, className);
+		}
+		else if (perm === 'view' || perm === 'readonly') {
+			this.dragging.enable();
+			// disable all user interaction, will need to add keyboard too
+			this._docLayer._onUpdateCursor();
+			this._docLayer._clearSelections();
+			this._docLayer._onUpdateTextSelection();
+			L.DomUtil.removeClass(this._container, className);
+		}
+		this.fire('updatepermission', {perm : perm});
+	}
+});
+
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 7599cf5..67a1579 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -138,7 +138,7 @@ L.TileLayer = L.GridLayer.extend({
 		}
 		this._documentInfo = '';
 		// View or edit mode.
-		this._editMode = false;
+		this._permission = 'view';
 		// Position and size of the visible cursor.
 		this._visibleCursor = new L.LatLngBounds(new L.LatLng(0, 0), new L.LatLng(0, 0));
 		// Cursor overlay is visible or hidden (for blinking).
@@ -194,19 +194,17 @@ L.TileLayer = L.GridLayer.extend({
 		this._map.on('zoomstart zoomend', this._onZoom, this);
 		this._map.on('clearselection', this._clearSelections, this);
 		this._map.on('prevpart nextpart', this._onSwitchPart, this);
-		this._map.on('viewmode editmode', this._updateEditViewMode, this);
 		this._map.on('drag', this._updateScrollOffset, this);
 		this._map.on('copy', this._onCopy, this);
 		this._map.on('mousedown mouseup mouseover mouseout mousemove dblclick',
 				this._onMouseEvent, this);
 		this._startMarker.on('drag dragend', this._onSelectionHandleDrag, this);
 		this._endMarker.on('drag dragend', this._onSelectionHandleDrag, this);
-		if (this.options.editMode && !this.options.readOnly) {
-			this._map.fire('updatemode:edit');
+		if (this.options.edit && !this.options.readOnly) {
+			this._map.setPermission('edit');
 		}
 		if (this.options.readOnly) {
-			this._map.fire('updatemode:readonly');
-			this._readOnlyMode = true;
+			this._map.setPermission('readonly');
 		}
 	},
 
@@ -741,7 +739,7 @@ L.TileLayer = L.GridLayer.extend({
 			return;
 		}
 
-		if (this._readOnlyMode) {
+		if (this._permission === 'readonly') {
 			return;
 		}
 
@@ -757,7 +755,7 @@ L.TileLayer = L.GridLayer.extend({
 		}
 		else if (e.type === 'mouseup') {
 			this._mouseDown = false;
-			if (!this._editMode) {
+			if (this._permission !== 'edit') {
 				if (this._mouseEventsQueue.length === 0) {
 					// mouse up after panning
 					return;
@@ -776,9 +774,8 @@ L.TileLayer = L.GridLayer.extend({
 					// it's a click, fire mousedown
 					this._mouseEventsQueue[0]();
 					this._clickTime = Date.now();
-					if (!this._editMode) {
-						this._editMode = true;
-						this._map.fire('updatemode:edit');
+					if (this._permission !== 'edit') {
+						this._map.setPermission('edit');
 					}
 				}
 				this._mouseEventsQueue = [];
@@ -798,7 +795,7 @@ L.TileLayer = L.GridLayer.extend({
 			if (this._holdMouseEvent) {
 				clearTimeout(this._holdMouseEvent);
 				this._holdMouseEvent = null;
-				if (!this._editMode) {
+				if (this._permission !== 'edit') {
 					// The user just panned the document
 					this._mouseEventsQueue = [];
 					return;
@@ -810,7 +807,7 @@ L.TileLayer = L.GridLayer.extend({
 				}
 				this._mouseEventsQueue = [];
 			}
-			if (this._editMode) {
+			if (this._permission === 'edit') {
 				mousePos = this._latLngToTwips(e.latlng);
 				this._postMouseEvent('move', mousePos.x, mousePos.y, 1);
 				if (this._startMarker._icon) {
@@ -832,15 +829,14 @@ L.TileLayer = L.GridLayer.extend({
 
 	_executeMouseEvents: function () {
 		this._holdMouseEvent = null;
-		if (this._mouseEventsQueue.length === 1 && !this._editMode) {
+		if (this._mouseEventsQueue.length === 1 && this._permission !== 'edit') {
 			// long mouse down or a mouseup after panning
 			this._mouseEventsQueue = [];
 			return;
 		}
-		else if (!this._editMode) {
+		else if (this._permission !== 'edit') {
 			// this time we have a mousedown and mouseup
-			this._editMode = true;
-			this._map.fire('updatemode:edit');
+			this._map.setPermission('edit');
 		}
 		for (var i = 0; i < this._mouseEventsQueue.length; i++) {
 			this._mouseEventsQueue[i]();
@@ -864,22 +860,6 @@ L.TileLayer = L.GridLayer.extend({
 		this._clearSelections();
 	},
 
-	_updateEditViewMode: function (e) {
-		if (e.type === 'viewmode') {
-			this._map.dragging.enable();
-			// disable all user interaction, will need to add keyboard too
-			this._editMode = false;
-			this._onUpdateCursor();
-			this._clearSelections();
-			this._onUpdateTextSelection();
-		}
-		else if (e.type === 'editmode') {
-			this._editMode = true;
-			this._map.dragging.disable();
-			this._map._container.focus();
-		}
-	},
-
 	// Convert javascript key codes to UNO key codes.
 	_toUNOKeyCode: function (keyCode) {
 		return this.keymap[keyCode] || keyCode;
@@ -887,7 +867,7 @@ L.TileLayer = L.GridLayer.extend({
 
 	// Receives a key press or release event.
 	_signalKey: function (e) {
-		if (!this._editMode) {
+		if (this._permission !== 'edit') {
 			return;
 		}
 
@@ -929,7 +909,8 @@ L.TileLayer = L.GridLayer.extend({
 
 	// Update cursor layer (blinking cursor).
 	_onUpdateCursor: function () {
-		if (this._editMode && this._isCursorVisible && this._isCursorOverlayVisible && !this._isEmptyRectangle(this._visibleCursor)) {
+		if (this._permission === 'edit' && this._isCursorVisible && this._isCursorOverlayVisible
+				&& !this._isEmptyRectangle(this._visibleCursor)) {
 			if (this._cursorMarker) {
 				this._map.removeLayer(this._cursorMarker);
 			}
commit 146afb7921a19b092166b4003881736bef6dab71
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 10 11:00:53 2015 +0300

    loleaflet: exposed the 'search' API: map.search()

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index ec2dbe3..349642c 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -260,6 +260,11 @@ var deps = {
 		desc: 'Layer Switcher control.'
 	},
 
+	Search: {
+		src: ['control/Search.js'],
+		desc: 'Search command handler.'
+	},
+
 	AnimationPan: {
 		src: [
 			'dom/DomEvent.js',
diff --git a/loleaflet/src/control/Control.Search.js b/loleaflet/src/control/Control.Search.js
index 39e7cb7..0973607 100644
--- a/loleaflet/src/control/Control.Search.js
+++ b/loleaflet/src/control/Control.Search.js
@@ -27,16 +27,6 @@ L.Control.Search = L.Control.extend({
 				searchName + '-next', container, this._searchNext);
 		this._cancelButton = this._createButton(options.cancelText, options.cancelTitle,
 				searchName + '-cancel', container, this._cancel);
-		this._searchCmd = {
-			'SearchItem.SearchString': {
-				'type': 'string',
-				'value': ''
-			},
-			'SearchItem.Backward': {
-				'type': 'boolean',
-				'value': false
-			}
-		};
 
 		this._disabled = true;
 		this._updateDisabled();
@@ -50,28 +40,10 @@ L.Control.Search = L.Control.extend({
 	},
 
 	_searchStart: function (e) {
-		this._map.fire('clearselection');
-		var viewTopLeftpx = this._map.project(this._map.getBounds().getNorthWest());
-		var docBoundsTopLeft = this._map.project(this._map.options.maxBounds.getNorthWest());
-		var topLeft = this._map.unproject(new L.Point(
-				Math.max(viewTopLeftpx.x, docBoundsTopLeft.x),
-				Math.max(viewTopLeftpx.y, docBoundsTopLeft.y)));
-		var topLeftTwips = this._map._docLayer._latLngToTwips(topLeft);
-
 		if (e.keyCode === 13 && this._searchBar.value !== '') {
+			this._map.search(this._searchBar.value);
 			this._disabled = false;
 			this._updateDisabled();
-			this._searchCmd['SearchItem.SearchString'].value = this._searchBar.value;
-			this._searchCmd['SearchItem.Backward'].value = false;
-			this._searchCmd['SearchItem.SearchStartPointX'] = {};
-			this._searchCmd['SearchItem.SearchStartPointX'].type = 'long';
-			this._searchCmd['SearchItem.SearchStartPointX'].value = topLeftTwips.x;
-			this._searchCmd['SearchItem.SearchStartPointY'] = {};
-			this._searchCmd['SearchItem.SearchStartPointY'].type = 'long';
-			this._searchCmd['SearchItem.SearchStartPointY'].value = topLeftTwips.y;
-			this._map.socket.send('uno .uno:ExecuteSearch ' + JSON.stringify(this._searchCmd));
-			delete this._searchCmd['SearchItem.SearchStartPointX'];
-			delete this._searchCmd['SearchItem.SearchStartPointY'];
 			this._refocusOnMap();
 		}
 	},
@@ -87,16 +59,12 @@ L.Control.Search = L.Control.extend({
 	},
 
 	_searchPrev: function () {
-		this._searchCmd['SearchItem.Backward'].value = true;
-		this._searchCmd['SearchItem.SearchString'].value = this._searchBar.value;
-		this._map.socket.send('uno .uno:ExecuteSearch ' + JSON.stringify(this._searchCmd));
+		this._map.search(this._searchBar.value, true);
 		this._refocusOnMap();
 	},
 
 	_searchNext: function () {
-		this._searchCmd['SearchItem.Backward'].value = false;
-		this._searchCmd['SearchItem.SearchString'].value = this._searchBar.value;
-		this._map.socket.send('uno .uno:ExecuteSearch ' + JSON.stringify(this._searchCmd));
+		this._map.search(this._searchBar.value);
 		this._refocusOnMap();
 	},
 
diff --git a/loleaflet/src/control/Search.js b/loleaflet/src/control/Search.js
new file mode 100644
index 0000000..a60d9da
--- /dev/null
+++ b/loleaflet/src/control/Search.js
@@ -0,0 +1,34 @@
+L.Map.include({
+	search: function (text, backward) {
+		if (backward === undefined) {
+			backward = false;
+		}
+
+		var searchCmd = {
+			'SearchItem.SearchString': {
+				'type': 'string'
+			},
+			'SearchItem.Backward': {
+				'type': 'boolean'
+			}
+		};
+
+		this.fire('clearselection');
+		var viewTopLeftpx = this.project(this.getBounds().getNorthWest());
+		var docBoundsTopLeft = this.project(this.options.maxBounds.getNorthWest());
+		var topLeft = this.unproject(new L.Point(
+				Math.max(viewTopLeftpx.x, docBoundsTopLeft.x),
+				Math.max(viewTopLeftpx.y, docBoundsTopLeft.y)));
+		var topLeftTwips = this._docLayer._latLngToTwips(topLeft);
+
+		searchCmd['SearchItem.SearchString'].value = text;
+		searchCmd['SearchItem.Backward'].value = backward;
+		searchCmd['SearchItem.SearchStartPointX'] = {};
+		searchCmd['SearchItem.SearchStartPointX'].type = 'long';
+		searchCmd['SearchItem.SearchStartPointX'].value = topLeftTwips.x;
+		searchCmd['SearchItem.SearchStartPointY'] = {};
+		searchCmd['SearchItem.SearchStartPointY'].type = 'long';
+		searchCmd['SearchItem.SearchStartPointY'].value = topLeftTwips.y;
+		this.socket.send('uno .uno:ExecuteSearch ' + JSON.stringify(searchCmd));
+	}
+});


More information about the Libreoffice-commits mailing list