loleaflet/js/main.js | 4 ++- loleaflet/reference.html | 24 +++++++++++++++++++++- loleaflet/src/control/Control.Menubar.js | 33 +++++++++++++++++++++++++++++++ loleaflet/src/map/handler/Map.WOPI.js | 25 +++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-)
New commits: commit 16ba97e7ae4a06932bdd63dbf32dd9e09b6b227e Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Thu Jun 6 17:51:48 2019 +0200 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jun 17 13:27:05 2019 +0200 Add API to remove menu items Change-Id: I59f2e3e1ed467f58bcd56db945e0d4807c1cff6e Reviewed-on: https://gerrit.libreoffice.org/74128 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/loleaflet/js/main.js b/loleaflet/js/main.js index 15e859606..54180dcaf 100644 --- a/loleaflet/js/main.js +++ b/loleaflet/js/main.js @@ -68,7 +68,9 @@ var map = L.map('map', { }); ////// Controls ///// -map.addControl(L.control.menubar()); +var menubar = L.control.menubar(); +map.menubar = menubar; +map.addControl(menubar); setupToolbar(map); map.addControl(L.control.scroll()); map.addControl(L.control.alertDialog()); diff --git a/loleaflet/reference.html b/loleaflet/reference.html index 58bdb351b..8350a9fe9 100644 --- a/loleaflet/reference.html +++ b/loleaflet/reference.html @@ -3136,12 +3136,34 @@ WOPI host to editor <code><nobr>id: <string></nobr></code> </td> <td> - Hides a button from the toolbar.<br/> + Shows a button from the toolbar.<br/> <code>id</code> is the button ID as defined in the <a href="https://opengrok.libreoffice.org/search?project=online&q=&defs=createToolbar">createToolbar</a> function in <a href="https://opengrok.libreoffice.org/xref/online/loleaflet/js/toolbar.js">loleaflet/js/toolbar.js</a>. </td> </tr> + <tr> + <td><code><b>Hide_Menu_Item</b></code></td> + <td> + <code><nobr>id: <string></nobr></code> + </td> + <td> + Hides an item from the menu.<br/> + <code>id</code> is the item ID as defined in the + <a href="https://opengrok.libreoffice.org/xref/online/loleaflet/src/control/Control.Menubar.js">loleaflet/src/control/Control.Menubar.js</a>. + </td> + </tr> + <tr> + <td><code><b>Show_Menu_Item</b></code></td> + <td> + <code><nobr>id: <string></nobr></code> + </td> + <td> + Shows an item from the menu.<br/> + <code>id</code> is the item ID as defined in the + <a href="https://opengrok.libreoffice.org/xref/online/loleaflet/src/control/Control.Menubar.js">loleaflet/src/control/Control.Menubar.js</a>. + </td> + </tr> </table> Editor to WOPI host <table data-id='postmessage-misc-to-host'> diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js index 32591f830..1d03ac4b5 100644 --- a/loleaflet/src/control/Control.Menubar.js +++ b/loleaflet/src/control/Control.Menubar.js @@ -986,6 +986,39 @@ L.Control.Menubar = L.Control.extend({ return itemList; }, + _getItems: function() { + return $(this._menubarCont).children().children('ul').children('li').add($(this._menubarCont).children('li')); + }, + + _getItem: function(targetId) { + var items = this._getItems(); + var found = $(items).filter(function() { + var item = this; + var id = $(item).attr('id'); + if (id && id == 'menu-' + targetId) { + return true; + } + return false + }); + return found.length ? found : null; + }, + + hasItem: function(targetId) { + return this._getItem(targetId) != null; + }, + + hideItem: function(targetId) { + var item = this._getItem(targetId); + if (item) + $(item).css('display', 'none'); + }, + + showItem: function(targetId) { + var item = this._getItem(targetId); + if (item) + $(item).css('display', ''); + }, + _initializeMenu: function(menu) { var menuHtml = this._createMenu(menu); for (var i in menuHtml) { diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index ff9200086..42a84aa7d 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -218,6 +218,31 @@ L.Map.WOPI = L.Handler.extend({ w2ui['editbar'].hide(msg.Values.id); } } + else if (msg.MessageId === 'Show_Menu_Item' || msg.MessageId === 'Hide_Menu_Item') { + if (!msg.Values) { + console.error('Property "Values" not set'); + return; + } + if (!msg.Values.id) { + console.error('Property "Values.id" not set'); + return; + } + if (this._map._permission !== 'edit') { + console.log('Readonly mode - ignoring Hide_Menu_Item request.'); + return; + } + + if (!this._map.menubar || !this._map.menubar.hasItem(msg.Values.id)) { + console.error('Menu item with id "' + msg.Values.id + '" not found.'); + return; + } + + if (msg.MessageId === 'Show_Menu_Item') { + this._map.menubar.showItem(msg.Values.id); + } else { + this._map.menubar.hideItem(msg.Values.id); + } + } else if (msg.MessageId === 'Set_Settings') { if (msg.Values) { var alwaysActive = msg.Values.AlwaysActive; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits