loleaflet/dist/menubar.css | 5 ++- loleaflet/src/control/Control.Menubar.js | 50 ++++++++++++++++++++++--------- loleaflet/src/map/handler/Map.WOPI.js | 46 ++++++++++++++++------------ 3 files changed, 67 insertions(+), 34 deletions(-)
New commits: commit 4d481791517bcba0cfc6599248c68077c5d166ac Author: Pranav Kant <pran...@collabora.co.uk> Date: Tue Jun 13 15:23:21 2017 +0530 loleaflet: Add button to menu bar if toolbar doesn't exist ... in case of Insert_Button PostMessage API when the document is loaded in readonly mode. Change-Id: I65a316d0b3cf22751a6926bc7aa430a249be5244 (cherry picked from commit caa4aa12c7beeb112dbd58222bd5928326e7e101) Reviewed-on: https://gerrit.libreoffice.org/38731 Reviewed-by: Jan Holesovsky <ke...@collabora.com> Tested-by: Jan Holesovsky <ke...@collabora.com> diff --git a/loleaflet/dist/menubar.css b/loleaflet/dist/menubar.css index eb115d77..9d57445b 100644 --- a/loleaflet/dist/menubar.css +++ b/loleaflet/dist/menubar.css @@ -223,7 +223,10 @@ */ #menu-closedocument.readonly { display: block; - top: 3px; /* This is not a menu, plain action, but we want it to appear like a menu */ + } + + .readonly { + top: 3px; } } diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js index 6974935c..0bf811d3 100644 --- a/loleaflet/src/control/Control.Menubar.js +++ b/loleaflet/src/control/Control.Menubar.js @@ -2,7 +2,7 @@ * Control.Menubar */ -/* global $ _ map title vex revHistoryEnabled closebutton */ +/* global $ _ map title vex revHistoryEnabled closebutton L */ L.Control.Menubar = L.Control.extend({ // TODO: Some mechanism to stop the need to copy duplicate menus (eg. Help) options: { @@ -298,6 +298,25 @@ L.Control.Menubar = L.Control.extend({ this._menubarCont = L.DomUtil.get('main-menu'); map.on('doclayerinit', this._onDocLayerInit, this); + map.on('addmenu', this._addMenu, this); + }, + + _addMenu: function(e) { + var alreadyExists = L.DomUtil.get('menu-' + e.id); + if (alreadyExists) + return; + + var liItem = L.DomUtil.create('li', ''); + liItem.id = 'menu-' + e.id; + if (map._permission === 'readonly') { + L.DomUtil.addClass(liItem, 'readonly'); + } + var aItem = L.DomUtil.create('a', '', liItem); + $(aItem).text(e.label); + $(aItem).data('id', e.id); + $(aItem).data('type', 'action'); + $(aItem).data('postmessage', 'true'); + this._menubarCont.insertBefore(liItem, this._menubarCont.firstChild); }, _onDocLayerInit: function() { @@ -418,7 +437,8 @@ L.Control.Menubar = L.Control.extend({ }); }, - _executeAction: function(id) { + _executeAction: function(item) { + var id = $(item).data('id'); if (id === 'save') { map.save(true, true); } else if (id === 'print') { @@ -431,7 +451,7 @@ L.Control.Menubar = L.Control.extend({ fileName = fileName === '' ? 'document' : fileName; map.downloadAs(fileName + '.' + format, format); } else if (id === 'findandreplace') { - findReplaceContent = + var findReplaceContent = '\ <table class="findreplacetable">\ <tr>\ @@ -462,7 +482,7 @@ L.Control.Menubar = L.Control.extend({ $.extend({}, vex.dialog.buttons.replace, { text: _('Replace'), click: function($vexContent, e) { - $vexContent.data().vex.option = 'replace' + $vexContent.data().vex.option = 'replace'; }}), $.extend({}, vex.dialog.buttons.replaceAll, { text: _('Replace All'), @@ -509,8 +529,8 @@ L.Control.Menubar = L.Control.extend({ xPos = e.pageX; yPos = e.pageY; if (selected !== null) { - isOutVert = (yPos - yElem >= 0 && (yPos - yElem + selected.offsetHeight) <= maxH); - isOutHor = (xPos - xElem >= 0 && (xPos - xElem + selected.offsetWidth) <= maxW); + var isOutVert = (yPos - yElem >= 0 && (yPos - yElem + selected.offsetHeight) <= maxH); + var isOutHor = (xPos - xElem >= 0 && (xPos - xElem + selected.offsetWidth) <= maxW); if (isOutHor) { selected.style.left = (xPos - xElem) + 'px'; } @@ -521,13 +541,13 @@ L.Control.Menubar = L.Control.extend({ }); }, onSubmit: function(event) { - $vexContent = $(this).parent(); + var $vexContent = $(this).parent(); event.preventDefault(); event.stopPropagation(); - opt = $vexContent.data().vex.option; - findText = this.findthis.value; - replaceText = this.replacewith.value; + var opt = $vexContent.data().vex.option; + var findText = this.findthis.value; + var replaceText = this.replacewith.value; if (findText.length != 0) { if (opt === 'next') { @@ -632,6 +652,11 @@ L.Control.Menubar = L.Control.extend({ map.sendUnoCommand('.uno:AttributePageSize {"AttributePageSize.Height":{"type":"long", "value": "21590"},"AttributePageSize.Width":{"type":"long", "value": "35560"}}'); map.sendUnoCommand('.uno:AttributePage {"AttributePage.Landscape":{"type":"boolean", "value": "true"}}'); } + + // Inform the host if asked + if ($(item).data('postmessage') === 'true') { + map.fire('postMessage', {msgId: 'Clicked_Button', args: {Id: id} }); + } }, _onDeleteSlide: function(e) { @@ -647,11 +672,10 @@ L.Control.Menubar = L.Control.extend({ var unoCommand = $(item).data('uno'); map.sendUnoCommand(unoCommand); } else if (type === 'action') { - var id = $(item).data('id'); - self._executeAction(id); + self._executeAction(item); } - if (id !== 'insertcomment') + if ($(item).data('id') !== 'insertcomment') map.focus(); }, diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index 6ff295d2..44f4917b 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -103,29 +103,35 @@ L.Map.WOPI = L.Handler.extend({ if (msg.MessageId === 'Insert_Button') { if (msg.Values) { if (msg.Values.id && !w2ui['toolbar-up'].get(msg.Values.id) - && msg.Values.imgurl) { - // add the css rule for the image - $('html > head > style').append('.w2ui-icon.' + msg.Values.id + '{background: url(' + msg.Values.imgurl + ')}'); - - // add the item to the toolbar - w2ui['toolbar-up'].insert('save', [ + && msg.Values.imgurl) { + if (this._map._permission === 'edit') { + // add the css rule for the image + $('html > head > style').append('.w2ui-icon.' + msg.Values.id + '{background: url(' + msg.Values.imgurl + ')}'); + + // add the item to the toolbar + w2ui['toolbar-up'].insert('save', [ + { + type: 'button', + id: msg.Values.id, + img: msg.Values.id, + hint: _(msg.Values.hint), /* "Try" to localize ! */ + postmessage: true /* Notify the host back when button is clicked */ + } + ]); + if (msg.Values.mobile) { - type: 'button', - id: msg.Values.id, - img: msg.Values.id, - hint: _(msg.Values.hint), /* "Try" to localize ! */ - postmessage: true /* Notify the host back when button is clicked */ + // Add to our list of items to preserve when in mobile mode + // FIXME: Wrap the toolbar in a class so that we don't make use + // global variables and functions like this + var idx = toolbarUpMobileItems.indexOf('save'); + toolbarUpMobileItems.splice(idx, 0, msg.Values.id); } - ]); - if (msg.Values.mobile) - { - // Add to our list of items to preserve when in mobile mode - // FIXME: Wrap the toolbar in a class so that we don't make use - // global variables and functions like this - var idx = toolbarUpMobileItems.indexOf('save'); - toolbarUpMobileItems.splice(idx, 0, msg.Values.id); + resizeToolbar(); + } + else if (this._map._permission === 'readonly') { + // Just add a menu entry for it + this._map.fire('addmenu', {id: msg.Values.id, label: msg.Values.hint}); } - resizeToolbar(); } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits