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

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 15 14:52:53 UTC 2020


 loleaflet/Makefile.am                      |    1 
 loleaflet/src/control/Control.SheetsBar.js |  123 +++++++++++++++++++++++++++++
 loleaflet/src/control/Control.Toolbar.js   |   74 -----------------
 loleaflet/src/layer/tile/CalcTileLayer.js  |   22 -----
 4 files changed, 127 insertions(+), 93 deletions(-)

New commits:
commit fe2743233fe644dfb7ea7e3e78f2ae4274b2ada7
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Wed Apr 15 14:15:22 2020 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Wed Apr 15 16:52:35 2020 +0200

    Move sheets bar to separate file
    
    Change-Id: Id2cdfdd50e178e4de54a41fa1926e94def9a43f5
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92271
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index c5693d351..2a6355431 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -268,6 +268,7 @@ LOLEAFLET_JS =\
 	src/control/Control.MobileBottomBar.js \
 	src/control/Control.UserList.js \
 	src/control/Control.FormulaBar.js \
+	src/control/Control.SheetsBar.js \
 	src/control/Control.Layers.js \
 	src/control/Search.js \
 	src/control/Permission.js \
diff --git a/loleaflet/src/control/Control.SheetsBar.js b/loleaflet/src/control/Control.SheetsBar.js
new file mode 100644
index 000000000..1a9696a09
--- /dev/null
+++ b/loleaflet/src/control/Control.SheetsBar.js
@@ -0,0 +1,123 @@
+/* -*- js-indent-level: 8 -*- */
+/*
+ * L.Control.SheetsBar
+ */
+
+/* global $ w2ui _ */
+L.Control.SheetsBar = L.Control.extend({
+	options: {
+		shownavigation: true
+	},
+
+	onAdd: function (map) {
+		this.map = map;
+		this.create();
+
+		map.on('doclayerinit', this.onDocLayerInit, this);
+		map.on('updatepermission', this.onUpdatePermission, this);
+	},
+
+	create: function() {
+		var that = this;
+		var toolbar = $('#spreadsheet-toolbar');
+		toolbar.w2toolbar({
+			name: 'spreadsheet-toolbar',
+			tooltip: 'bottom',
+			hidden: true,
+			items: [
+				{type: 'button',  hidden: !this.options.shownavigation, id: 'firstrecord',  img: 'firstrecord', hint: _('First sheet')},
+				{type: 'button',  hidden: !this.options.shownavigation, id: 'prevrecord',  img: 'prevrecord', hint: _('Previous sheet')},
+				{type: 'button',  hidden: !this.options.shownavigation, id: 'nextrecord',  img: 'nextrecord', hint: _('Next sheet')},
+				{type: 'button',  hidden: !this.options.shownavigation, id: 'lastrecord',  img: 'lastrecord', hint: _('Last sheet')},
+				{type: 'button',  id: 'insertsheet', img: 'insertsheet', hint: _('Insert sheet')}
+			],
+			onClick: function (e) {
+				that.onClick(e, e.target);
+				window.hideTooltip(this, e.target);
+			}
+		});
+		toolbar.bind('touchstart', function(e) {
+			w2ui['spreadsheet-toolbar'].touchStarted = true;
+			var touchEvent = e.originalEvent;
+			if (touchEvent && touchEvent.touches.length > 1) {
+				L.DomEvent.preventDefault(e);
+			}
+		});
+		toolbar.show();
+	},
+
+	onClick: function(e, id, item) {
+		if ('spreadsheet-toolbar' in w2ui && w2ui['spreadsheet-toolbar'].get(id) !== null) {
+			var toolbar = w2ui['spreadsheet-toolbar'];
+			item = toolbar.get(id);
+		}
+
+		// In the iOS app we don't want clicking on the toolbar to pop up the keyboard.
+		if (!window.ThisIsTheiOSApp && id !== 'zoomin' && id !== 'zoomout' && id !== 'mobile_wizard' && id !== 'insertion_mobile_wizard') {
+			this.map.focus(this.map.canAcceptKeyboardInput()); // Maintain same keyboard state.
+		}
+
+		if (item.disabled) {
+			return;
+		}
+
+		if (id === 'insertsheet') {
+			var nPos = $('#spreadsheet-tab-scroll')[0].childElementCount;
+			this.map.insertPage(nPos);
+			this.map.insertPage.scrollToEnd = true;
+		}
+		else if (id === 'firstrecord') {
+			$('#spreadsheet-tab-scroll').scrollLeft(0);
+		}
+		// TODO: We should get visible tab's width instead of 60px
+		else if (id === 'nextrecord') {
+			$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() + 60);
+		}
+		else if (id === 'prevrecord') {
+			$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() - 30);
+		}
+		else if (id === 'lastrecord') {
+			// Set a very high value, so that scroll is set to the maximum possible value internally.
+			// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
+			L.DomUtil.get('spreadsheet-tab-scroll').scrollLeft = 100000;
+		}
+	},
+
+	onDocLayerInit: function() {
+		var docType = this.map.getDocType();
+		if (docType == 'spreadsheet') {
+			if (!window.mode.isMobile()) {
+				$('#spreadsheet-toolbar').show();
+			}
+
+			var toolbar = w2ui['spreadsheet-toolbar'];
+			if (toolbar)
+				toolbar.resize();
+		}
+	},
+
+	onUpdatePermission: function(e) {
+		var spreadsheetButtons = ['insertsheet'];
+		var toolbar = w2ui.formulabar;
+
+		if (e.perm === 'edit') {
+			toolbar = w2ui['spreadsheet-toolbar'];
+			if (toolbar) {
+				spreadsheetButtons.forEach(function(id) {
+					toolbar.enable(id);
+				});
+			}
+		} else {
+			toolbar = w2ui['spreadsheet-toolbar'];
+			if (toolbar) {
+				spreadsheetButtons.forEach(function(id) {
+					toolbar.disable(id);
+				});
+			}
+		}
+	},
+});
+
+L.control.sheetsBar = function (options) {
+	return new L.Control.SheetsBar(options);
+};
diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index 3f38a5958..a8f7b2204 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -99,10 +99,6 @@ function onClick(e, id, item) {
 		toolbar = w2ui['actionbar'];
 		item = toolbar.get(id);
 	}
-	else if ('spreadsheet-toolbar' in w2ui && w2ui['spreadsheet-toolbar'].get(id) !== null) {
-		toolbar = w2ui['spreadsheet-toolbar'];
-		item = toolbar.get(id);
-	}
 	else if ('presentation-toolbar' in w2ui && w2ui['presentation-toolbar'].get(id) !== null) {
 		toolbar = w2ui['presentation-toolbar'];
 		item = toolbar.get(id);
@@ -178,26 +174,6 @@ function onClick(e, id, item) {
 			callback: onDelete
 		});
 	}
-	else if (id === 'insertsheet') {
-		var nPos = $('#spreadsheet-tab-scroll')[0].childElementCount;
-		map.insertPage(nPos);
-		map.insertPage.scrollToEnd = true;
-	}
-	else if (id === 'firstrecord') {
-		$('#spreadsheet-tab-scroll').scrollLeft(0);
-	}
-	// TODO: We should get visible tab's width instead of 60px
-	else if (id === 'nextrecord') {
-		$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() + 60);
-	}
-	else if (id === 'prevrecord') {
-		$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() - 30);
-	}
-	else if (id === 'lastrecord') {
-		// Set a very high value, so that scroll is set to the maximum possible value internally.
-		// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
-		L.DomUtil.get('spreadsheet-tab-scroll').scrollLeft = 100000;
-	}
 	else if (id === 'insertgraphic' || item.id === 'localgraphic') {
 		L.DomUtil.get('insertgraphic').click();
 	}
@@ -923,29 +899,6 @@ function createSigningBar() {
 	}
 }
 
-function createSpreadsheetToolbar() {
-	var toolbar = $('#spreadsheet-toolbar');
-	toolbar.w2toolbar({
-		name: 'spreadsheet-toolbar',
-		tooltip: 'bottom',
-		hidden: true,
-		items: [
-			{type: 'button',  id: 'firstrecord',  img: 'firstrecord', hint: _('First sheet')},
-			{type: 'button',  id: 'prevrecord',  img: 'prevrecord', hint: _('Previous sheet')},
-			{type: 'button',  id: 'nextrecord',  img: 'nextrecord', hint: _('Next sheet')},
-			{type: 'button',  id: 'lastrecord',  img: 'lastrecord', hint: _('Last sheet')},
-			{type: 'button',  id: 'insertsheet', img: 'insertsheet', hint: _('Insert sheet')}
-		],
-		onClick: function (e) {
-			onClick(e, e.target);
-			hideTooltip(this, e.target);
-		}
-	});
-	toolbar.bind('touchstart', function() {
-		w2ui['spreadsheet-toolbar'].touchStarted = true;
-	});
-}
-
 function createPresentationToolbar() {
 	var toolbar = $('#presentation-toolbar');
 	toolbar.w2toolbar({
@@ -975,7 +928,7 @@ function initNormalToolbar() {
 	createMainToolbar();
 	map.addControl(L.control.formulaBar({showfunctionwizard: true}));
 	createSigningBar();
-	createSpreadsheetToolbar();
+	map.addControl(L.control.sheetsBar({shownavigation: true}));
 	createPresentationToolbar();
 }
 
@@ -1247,10 +1200,6 @@ function onDocLayerInit() {
 			toolbarUp.remove('styles');
 		}
 
-		if (!window.mode.isMobile()) {
-			$('#spreadsheet-toolbar').show();
-		}
-
 		break;
 	case 'text':
 		if (toolbarUp)
@@ -1331,12 +1280,6 @@ function onDocLayerInit() {
 					     );
 	}
 
-	if (docType == 'spreadsheet') {
-		var el = w2ui['spreadsheet-toolbar'];
-		if (el)
-			el.resize();
-	}
-
 	data = [6, 7, 8, 9, 10, 10.5, 11, 12, 13, 14, 15, 16, 18, 20,
 		22, 24, 26, 28, 32, 36, 40, 44, 48, 54, 60, 66, 72, 80, 88, 96];
 	$('.fontsizes-select').select2({
@@ -1742,7 +1685,6 @@ function onUpdatePermission(e) {
 		}
 	}
 
-	var spreadsheetButtons = ['insertsheet'];
 	var presentationButtons = ['insertpage', 'duplicatepage', 'deletepage'];
 	if (e.perm === 'edit') {
 		// Enable list boxes
@@ -1750,13 +1692,6 @@ function onUpdatePermission(e) {
 		$('.fonts-select').prop('disabled', false);
 		$('.fontsizes-select').prop('disabled', false);
 
-		toolbar = w2ui['spreadsheet-toolbar'];
-		if (toolbar) {
-			spreadsheetButtons.forEach(function(id) {
-				toolbar.enable(id);
-			});
-		}
-
 		toolbar = w2ui['presentation-toolbar'];
 		if (toolbar) {
 			presentationButtons.forEach(function(id) {
@@ -1794,13 +1729,6 @@ function onUpdatePermission(e) {
 		$('.fonts-select').prop('disabled', true);
 		$('.fontsizes-select').prop('disabled', true);
 
-		toolbar = w2ui['spreadsheet-toolbar'];
-		if (toolbar) {
-			spreadsheetButtons.forEach(function(id) {
-				toolbar.disable(id);
-			});
-		}
-
 		toolbar = w2ui['presentation-toolbar'];
 		if (toolbar) {
 			presentationButtons.forEach(function(id) {
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index f4767648f..bc4a30f3d 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -3,7 +3,7 @@
  * Calc tile layer is used to display a spreadsheet document
  */
 
-/* global $ _ w2ui w2utils */
+/* global w2ui w2utils */
 L.CalcTileLayer = L.TileLayer.extend({
 	STD_EXTRA_WIDTH: 113, /* 2mm extra for optimal width,
 							  * 0.1986cm with TeX points,
@@ -75,25 +75,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 
 		map.addControl(L.control.formulaBar({showfunctionwizard: false}));
 
-		var toolbar = $('#spreadsheet-toolbar');
-		toolbar.w2toolbar({
-			name: 'spreadsheet-toolbar',
-			tooltip: 'bottom',
-			hidden: true,
-			items: [{type: 'button',  id: 'insertsheet', img: 'insertsheet', hint: _('Insert sheet')}],
-			onClick: function (e) {
-				window.onClick(e, e.target);
-				window.hideTooltip(this, e.target);
-			}
-		});
-		toolbar.bind('touchstart', function(e) {
-			w2ui['spreadsheet-toolbar'].touchStarted = true;
-			var touchEvent = e.originalEvent;
-			if (touchEvent && touchEvent.touches.length > 1) {
-				L.DomEvent.preventDefault(e);
-			}
-		});
-		toolbar.show();
+		map.addControl(L.control.sheetsBar({shownavigation: false}));
 
 		map.addControl(L.control.mobileBottomBar('spreadsheet'));
 


More information about the Libreoffice-commits mailing list