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

Henry Castro hcastro at collabora.com
Sun Oct 1 15:00:04 UTC 2017


 loleaflet/src/control/Control.Menubar.js      |   40 ++++++++++++++++++++++----
 loleaflet/src/layer/tile/TileLayer.js         |   19 ++++++++++--
 loleaflet/src/map/handler/Map.StateChanges.js |    4 +-
 3 files changed, 53 insertions(+), 10 deletions(-)

New commits:
commit 22b7bee742b3455c86fe816efa1e5f281af19636
Author: Henry Castro <hcastro at collabora.com>
Date:   Sun Oct 1 10:58:11 2017 -0400

    loleaflet: add tools -> language menu items
    
    Change-Id: Ie79a03b53bdbb248788e444115cf7d7e159bb964

diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index e37ad5a1..fbd818a9 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -10,7 +10,8 @@ L.Control.Menubar = L.Control.extend({
 			{name: _('File'), disabled: true},
 			{name: _('Edit'), disabled: true},
 			{name: _('View'), disabled: true},
-			{name: _('Insert'), disabled: true}
+			{name: _('Insert'), disabled: true},
+			{name: _('Tools'), disabled: true},
 		],
 		text:  [
 			{name: _('File'), id: 'file', type: 'menu', menu: [
@@ -172,7 +173,9 @@ L.Control.Menubar = L.Control.extend({
 					{name: _('Merge cells'), type: 'unocommand', uno: '.uno:MergeCells'}]
 			},
 			{name: _('Tools'), id: 'tools', type: 'menu', menu: [
-				{name: _('Automatic Spell Checking'), type: 'unocommand', uno: '.uno:SpellOnline'}
+				{name: _('Automatic Spell Checking'), type: 'unocommand', uno: '.uno:SpellOnline'},
+				{name: _('Language'), type: 'menu', menu: [
+					{name: _('Reset to Default Language'), id: 'resetlanguage', type: 'unocommand', uno:'.uno:LanguageStatus?Language:string=Default_RESET_LANGUAGES'}]}
 			]},
 			{name: _('Help'), id: 'help', type: 'menu', menu: [
 				{name: _('Keyboard shortcuts'), id: 'keyboard-shortcuts', type: 'action'},
@@ -317,9 +320,10 @@ L.Control.Menubar = L.Control.extend({
 
 		map.on('doclayerinit', this._onDocLayerInit, this);
 		map.on('addmenu', this._addMenu, this);
+		map.on('commandinitialized', this._onInitMenu, this);
 	},
 
-	_addMenu: function(e) {
+	_addMenu: function (e) {
 		var alreadyExists = L.DomUtil.get('menu-' + e.id);
 		if (alreadyExists)
 			return;
@@ -337,6 +341,21 @@ L.Control.Menubar = L.Control.extend({
 		this._menubarCont.insertBefore(liItem, this._menubarCont.firstChild);
 	},
 
+	_onInitMenu: function (e) {
+		if (e.commandName === '.uno:LanguageStatus') {
+			var liItem, aItem;
+			$menuParent = $('#menu-resetlanguage').parent();
+			for (var lang in e.data) {
+				liItem = L.DomUtil.create('li', '');
+				aItem = L.DomUtil.create('a', '', liItem);
+				$(aItem).text(e.data[lang]);
+				$(aItem).data('type', 'unocommand');
+				$(aItem).data('uno', '.uno:LanguageStatus?Language:string=' + encodeURIComponent('Default_' + e.data[lang]));
+				$menuParent.append(liItem);
+			}
+		}
+	},
+
 	_onDocLayerInit: function() {
 		// clear initial menu
 		while (this._menubarCont.hasChildNodes()) {
@@ -417,13 +436,22 @@ L.Control.Menubar = L.Control.extend({
 			if (map._permission === 'edit') {
 				if (type === 'unocommand') { // enable all depending on stored commandStates
 					var unoCommand = $(aItem).data('uno');
-					if (map['stateChangeHandler'].getItemValue(unoCommand) === 'disabled') {
+					var itemState = map['stateChangeHandler'].getItemValue(unoCommand);
+					if (itemState === 'disabled') {
 						$(aItem).addClass('disabled');
 					} else {
 						$(aItem).removeClass('disabled');
 					}
-
-					if (map['stateChangeHandler'].getItemValue(unoCommand) === 'true') {
+					if (unoCommand.indexOf('.uno:LanguageStatus') !== -1) {
+						var lang = map['stateChangeHandler'].getItemValue('.uno:LanguageStatus');
+						var label = $(aItem).html();
+						if (label === lang) {
+							$(aItem).addClass('lo-menu-item-checked');
+						} else {
+							$(aItem).removeClass('lo-menu-item-checked');
+						}
+					}
+					else if (itemState === 'true') {
 						$(aItem).addClass('lo-menu-item-checked');
 					} else {
 						$(aItem).removeClass('lo-menu-item-checked');
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index d5ffef57..c18c4004 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1045,10 +1045,23 @@ L.TileLayer = L.GridLayer.extend({
 	_onStateChangedMsg: function (textMsg) {
 		textMsg = textMsg.substr(14);
 		var index = textMsg.indexOf('=');
-		var commandName = index !== -1 ? textMsg.substr(0, index) : '';
-		var state = index !== -1 ? textMsg.substr(index + 1) : '';
+		var commandName, state;
+		if (index !== -1)
+		{
+			commandName = textMsg.substr(0, index);
+			state = textMsg.substr(index + 1);
+			this._map.fire('commandstatechanged', {commandName : commandName, state : state});
+			return;
+		}
 
-		this._map.fire('commandstatechanged', {commandName : commandName, state : state});
+		index = textMsg.indexOf('?');
+		if (index !== -1)
+		{
+			commandName = textMsg.substr(0, index);
+			textMsg = textMsg.substr(index + 1);
+			state = JSON.parse(textMsg);
+			this._map.fire('commandinitialized', {commandName: commandName, data: state});
+		}
 	},
 
 	_onUnoCommandResultMsg: function (textMsg) {
diff --git a/loleaflet/src/map/handler/Map.StateChanges.js b/loleaflet/src/map/handler/Map.StateChanges.js
index 6c31981e..b0abcb11 100644
--- a/loleaflet/src/map/handler/Map.StateChanges.js
+++ b/loleaflet/src/map/handler/Map.StateChanges.js
@@ -25,7 +25,9 @@ L.Map.StateChangeHandler = L.Handler.extend({
 	},
 
 	_onStateChanged: function(e) {
-		this._items[e.commandName] = e.state;
+		if (e.commandName.indexOf('?') === -1) {
+			this._items[e.commandName] = e.state;
+		}
 	},
 
 	getItems: function() {


More information about the Libreoffice-commits mailing list