loleaflet/Makefile.am | 1 loleaflet/src/control/Control.FormulaBar.js | 185 ++++++++++++++++++++++++++++ loleaflet/src/control/Control.Toolbar.js | 133 -------------------- loleaflet/src/layer/tile/CalcTileLayer.js | 33 ---- 4 files changed, 189 insertions(+), 163 deletions(-)
New commits: commit cca7a440093237af0bdcb87d44a77f383324c4bc Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Wed Apr 15 13:38:46 2020 +0200 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Wed Apr 15 16:52:12 2020 +0200 Move formula bar to separate file Change-Id: If380e8bc8091151872a728cc632313aa3f4cfda1 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92269 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am index 0cb94a244..c5693d351 100644 --- a/loleaflet/Makefile.am +++ b/loleaflet/Makefile.am @@ -267,6 +267,7 @@ LOLEAFLET_JS =\ src/control/Control.MobileTopBar.js \ src/control/Control.MobileBottomBar.js \ src/control/Control.UserList.js \ + src/control/Control.FormulaBar.js \ src/control/Control.Layers.js \ src/control/Search.js \ src/control/Permission.js \ diff --git a/loleaflet/src/control/Control.FormulaBar.js b/loleaflet/src/control/Control.FormulaBar.js new file mode 100644 index 000000000..e90e3f141 --- /dev/null +++ b/loleaflet/src/control/Control.FormulaBar.js @@ -0,0 +1,185 @@ +/* -*- js-indent-level: 8 -*- */ +/* + * L.Control.FormulaBar + */ + +/* global $ w2ui _ */ +L.Control.FormulaBar = L.Control.extend({ + options: { + showfunctionwizard: true + }, + + onAdd: function (map) { + this.map = map; + this.create(); + + map.on('doclayerinit', this.onDocLayerInit, this); + map.on('updatepermission', this.onUpdatePermission, this); + + map.on('celladdress', function (e) { + if (document.activeElement !== L.DomUtil.get('addressInput')) { + // if the user is not editing the address field + L.DomUtil.get('addressInput').value = e.address; + } + }); + }, + + create: function() { + var that = this; + var toolbar = $('#formulabar'); + toolbar.w2toolbar({ + name: 'formulabar', + tooltip: 'bottom', + hidden: true, + items: [ + {type: 'html', id: 'left'}, + {type: 'html', id: 'address', html: '<input id="addressInput" type="text">'}, + {type: 'break', hidden: !this.options.showfunctionwizard}, + {type: 'button', hidden: !this.options.showfunctionwizard, id: 'functiondialog', img: 'functiondialog', hint: _('Function Wizard'), uno: '.uno:FunctionDialog'}, + {type: 'html', id: 'formula', html: '<div id="calc-inputbar-wrapper"><div id="calc-inputbar"></div></div>'} + ], + onClick: function (e) { + that.onClick(e, e.target); + window.hideTooltip(this, e.target); + }, + onRefresh: function() { + $('#addressInput').off('keyup', this.onAddressInput, this).on('keyup', this.onAddressInput, this); + } + }); + toolbar.bind('touchstart', function(e) { + w2ui['formulabar'].touchStarted = true; + var touchEvent = e.originalEvent; + if (touchEvent && touchEvent.touches.length > 1) { + L.DomEvent.preventDefault(e); + } + }); + + $(w2ui.formulabar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide(); + w2ui.formulabar.on('resize', function(target, e) { + e.isCancelled = true; + }); + }, + + onClick: function(e, id, item) { + if ('formulabar' in w2ui && w2ui['formulabar'].get(id) !== null) { + var toolbar = w2ui['formulabar']; + 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 (item.uno) { + if (item.unosheet && this.map.getDocType() === 'spreadsheet') { + this.map.toggleCommandState(item.unosheet); + } + else { + this.map.toggleCommandState(window.getUNOCommand(item.uno)); + } + } + }, + + onDocLayerInit: function() { + var docType = this.map.getDocType(); + if (docType == 'spreadsheet') { + $('#formulabar').show(); + } + }, + + onUpdatePermission: function(e) { + var formulaBarButtons = ['functiondialog', 'sum', 'function']; + var toolbar = w2ui.formulabar; + + if (e.perm === 'edit') { + // Enable formula bar + $('#addressInput').prop('disabled', false); + $('#formulaInput').prop('disabled', false); + + if (toolbar) { + formulaBarButtons.forEach(function(id) { + toolbar.enable(id); + }); + } + } else { + // Disable formula bar + $('#addressInput').prop('disabled', true); + $('#formulaInput').prop('disabled', true); + + if (toolbar) { + formulaBarButtons.forEach(function(id) { + toolbar.disable(id); + }); + } + } + }, + + onFormulaInput: function(e) { + // keycode = 13 is 'enter' + if (e.keyCode === 13) { + // formula bar should not have focus anymore + this.map.focus(); + + // forward the 'enter' keystroke to map to deal with the formula entered + var data = { + originalEvent: e + }; + this.map.fire('keypress', data); + } else if (e.keyCode === 27) { // 27 = esc key + this.map.sendUnoCommand('.uno:Cancel'); + this.map.focus(); + } else { + this.map.cellEnterString(L.DomUtil.get('formulaInput').value); + } + }, + + onFormulaBarFocus: function() { + var formulabar = w2ui.formulabar; + formulabar.hide('sum'); + formulabar.hide('function'); + formulabar.show('cancelformula'); + formulabar.show('acceptformula'); + }, + + onFormulaBarBlur: function() { + // The timeout is needed because we want 'click' event on 'cancel', + // 'accept' button to act before we hide these buttons because + // once hidden, click event won't be processed. + // TODO: Some better way to do it ? + setTimeout(function() { + var formulabar = w2ui.formulabar; + formulabar.show('sum'); + formulabar.show('function'); + formulabar.hide('cancelformula'); + formulabar.hide('acceptformula'); + }, 250); + }, + + onAddressInput: function(e) { + if (e.keyCode === 13) { + // address control should not have focus anymore + this.map.focus(); + var value = L.DomUtil.get('addressInput').value; + var command = { + ToPoint : { + type: 'string', + value: value + } + + }; + this.map.sendUnoCommand('.uno:GoToCell', command); + } else if (e.keyCode === 27) { // 27 = esc key + this.map.sendUnoCommand('.uno:Cancel'); + this.map.focus(); + } + } +}); + +L.control.formulaBar = function (options) { + return new L.Control.FormulaBar(options); +}; diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js index be3101358..3f38a5958 100644 --- a/loleaflet/src/control/Control.Toolbar.js +++ b/loleaflet/src/control/Control.Toolbar.js @@ -91,10 +91,6 @@ function onClick(e, id, item) { var toolbar = w2ui['editbar']; item = toolbar.get(id); } - else if ('formulabar' in w2ui && w2ui['formulabar'].get(id) !== null) { - toolbar = w2ui['formulabar']; - item = toolbar.get(id); - } else if ('document-signing-bar' in w2ui && w2ui['document-signing-bar'].get(id) !== null) { toolbar = w2ui['document-signing-bar']; item = toolbar.get(id); @@ -907,37 +903,6 @@ function createMainToolbar() { }); } -function createFormulaBar() { - var toolbar = $('#formulabar'); - toolbar.w2toolbar({ - name: 'formulabar', - tooltip: 'bottom', - hidden: true, - items: [ - {type: 'html', id: 'left'}, - {type: 'html', id: 'address', html: '<input id="addressInput" type="text">'}, - {type: 'break'}, - {type: 'button', id: 'functiondialog', img: 'functiondialog', hint: _('Function Wizard'), uno: '.uno:FunctionDialog'}, - {type: 'html', id: 'formula', html: '<div id="calc-inputbar-wrapper"><div id="calc-inputbar"></div></div>'} - ], - onClick: function (e) { - onClick(e, e.target); - hideTooltip(this, e.target); - }, - onRefresh: function() { - $('#addressInput').off('keyup', onAddressInput).on('keyup', onAddressInput); - } - }); - toolbar.bind('touchstart', function() { - w2ui['formulabar'].touchStarted = true; - }); - - $(w2ui.formulabar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide(); - w2ui.formulabar.on('resize', function(target, e) { - e.isCancelled = true; - }); -} - function createSigningBar() { if (L.DomUtil.get('document-signing-bar') !== null) { var toolbar = $('#document-signing-bar'); @@ -1008,7 +973,7 @@ function createPresentationToolbar() { function initNormalToolbar() { createMainToolbar(); - createFormulaBar(); + map.addControl(L.control.formulaBar({showfunctionwizard: true})); createSigningBar(); createSpreadsheetToolbar(); createPresentationToolbar(); @@ -1226,68 +1191,6 @@ function onInsertBackground() { return false; } -function onAddressInput(e) { - if (e.keyCode === 13) { - // address control should not have focus anymore - map.focus(); - var value = L.DomUtil.get('addressInput').value; - var command = { - ToPoint : { - type: 'string', - value: value - } - - }; - map.sendUnoCommand('.uno:GoToCell', command); - } else if (e.keyCode === 27) { // 27 = esc key - map.sendUnoCommand('.uno:Cancel'); - map.focus(); - } -} - -function onFormulaInput(e) { - // keycode = 13 is 'enter' - if (e.keyCode === 13) { - // formula bar should not have focus anymore - map.focus(); - - // forward the 'enter' keystroke to map to deal with the formula entered - var data = { - originalEvent: e - }; - map.fire('keypress', data); - } else if (e.keyCode === 27) { // 27 = esc key - map.sendUnoCommand('.uno:Cancel'); - map.focus(); - } else { - map.cellEnterString(L.DomUtil.get('formulaInput').value); - } -} - -function onFormulaBarFocus() { - var formulabar = w2ui.formulabar; - formulabar.hide('sum'); - formulabar.hide('function'); - formulabar.show('cancelformula'); - formulabar.show('acceptformula'); -} - -function onFormulaBarBlur() { - // The timeout is needed because we want 'click' event on 'cancel', - // 'accept' button to act before we hide these buttons because - // once hidden, click event won't be processed. - // TODO: Some better way to do it ? - setTimeout(function() { - var formulabar = w2ui.formulabar; - formulabar.show('sum'); - formulabar.show('function'); - formulabar.hide('cancelformula'); - formulabar.hide('acceptformula'); - }, 250); -} - - - function onWopiProps(e) { if (e.HideSaveOption) { w2ui['editbar'].hide('save'); @@ -1347,7 +1250,6 @@ function onDocLayerInit() { if (!window.mode.isMobile()) { $('#spreadsheet-toolbar').show(); } - $('#formulabar').show(); break; case 'text': @@ -1841,7 +1743,6 @@ function onUpdatePermission(e) { } var spreadsheetButtons = ['insertsheet']; - var formulaBarButtons = ['functiondialog', 'sum', 'function']; var presentationButtons = ['insertpage', 'duplicatepage', 'deletepage']; if (e.perm === 'edit') { // Enable list boxes @@ -1849,16 +1750,6 @@ function onUpdatePermission(e) { $('.fonts-select').prop('disabled', false); $('.fontsizes-select').prop('disabled', false); - // Enable formula bar - $('#addressInput').prop('disabled', false); - $('#formulaInput').prop('disabled', false); - toolbar = w2ui.formulabar; - if (toolbar) { - formulaBarButtons.forEach(function(id) { - toolbar.enable(id); - }); - } - toolbar = w2ui['spreadsheet-toolbar']; if (toolbar) { spreadsheetButtons.forEach(function(id) { @@ -1903,17 +1794,6 @@ function onUpdatePermission(e) { $('.fonts-select').prop('disabled', true); $('.fontsizes-select').prop('disabled', true); - // Disable formula bar - $('#addressInput').prop('disabled', true); - $('#formulaInput').prop('disabled', true); - - toolbar = w2ui.formulabar; - if (toolbar) { - formulaBarButtons.forEach(function(id) { - toolbar.disable(id); - }); - } - toolbar = w2ui['spreadsheet-toolbar']; if (toolbar) { spreadsheetButtons.forEach(function(id) { @@ -2005,13 +1885,6 @@ function setupToolbar(e) { } }); - map.on('celladdress', function (e) { - if (document.activeElement !== L.DomUtil.get('addressInput')) { - // if the user is not editing the address field - L.DomUtil.get('addressInput').value = e.address; - } - }); - if (!window.mode.isMobile()) { map.on('updatetoolbarcommandvalues', function(e) { updateCommandValues(e); @@ -2044,10 +1917,6 @@ function setupToolbar(e) { global.setupToolbar = setupToolbar; global.onClick = onClick; global.hideTooltip = hideTooltip; -global.onAddressInput = onAddressInput; -global.onFormulaInput = onFormulaInput; -global.onFormulaBarBlur = onFormulaBarBlur; -global.onFormulaBarFocus = onFormulaBarFocus; global.onStyleSelect = onStyleSelect; global.insertTable = insertTable; global.insertShapes = insertShapes; diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js index e6cb0ec1a..f4767648f 100644 --- a/loleaflet/src/layer/tile/CalcTileLayer.js +++ b/loleaflet/src/layer/tile/CalcTileLayer.js @@ -73,38 +73,9 @@ L.CalcTileLayer = L.TileLayer.extend({ onMobileInit: function (map) { map.addControl(L.control.mobileTopBar('spreadsheet')); - var toolbar = $('#formulabar'); - toolbar.w2toolbar({ - name: 'formulabar', - tooltip: 'bottom', - hidden: true, - items: [ - {type: 'html', id: 'left'}, - {type: 'html', id: 'address', html: '<input id="addressInput" type="text">'}, - {type: 'html', id: 'formula', html: '<div id="calc-inputbar-wrapper"><div id="calc-inputbar"></div></div>'} - ], - onClick: function (e) { - window.onClick(e, e.target); - window.hideTooltip(this, e.target); - }, - onRefresh: function() { - $('#addressInput').off('keyup', window.onAddressInput).on('keyup', window.onAddressInput); - } - }); - toolbar.bind('touchstart', function(e) { - w2ui['formulabar'].touchStarted = true; - var touchEvent = e.originalEvent; - if (touchEvent && touchEvent.touches.length > 1) { - L.DomEvent.preventDefault(e); - } - }); - - $(w2ui.formulabar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide(); - w2ui.formulabar.on('resize', function(target, e) { - e.isCancelled = true; - }); + map.addControl(L.control.formulaBar({showfunctionwizard: false})); - toolbar = $('#spreadsheet-toolbar'); + var toolbar = $('#spreadsheet-toolbar'); toolbar.w2toolbar({ name: 'spreadsheet-toolbar', tooltip: 'bottom', _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits