loleaflet/Makefile.am                            |    1 
 loleaflet/src/control/Control.PresentationBar.js |  156 +++++++++++++++++++++++
 loleaflet/src/control/Control.Toolbar.js         |  100 --------------
 loleaflet/src/layer/tile/ImpressTileLayer.js     |    8 -
 4 files changed, 158 insertions(+), 107 deletions(-)

New commits:
commit 2f57f0c34eacbba7bd897713a74e1ccc73c095f4
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Apr 15 15:25:22 2020 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Wed Apr 15 16:52:51 2020 +0200

    Move presentation toolbar to separate file
    
    Change-Id: I47faf807bbbd79e27c9eb5156fc24dc4bc053aab
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92272
    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 2a6355431..385bb96a6 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -269,6 +269,7 @@ LOLEAFLET_JS =\
        src/control/Control.UserList.js \
        src/control/Control.FormulaBar.js \
        src/control/Control.SheetsBar.js \
+       src/control/Control.PresentationBar.js \
        src/control/Control.Layers.js \
        src/control/Search.js \
        src/control/Permission.js \
diff --git a/loleaflet/src/control/Control.PresentationBar.js 
b/loleaflet/src/control/Control.PresentationBar.js
new file mode 100644
index 000000000..9cf159bd5
--- /dev/null
+++ b/loleaflet/src/control/Control.PresentationBar.js
@@ -0,0 +1,156 @@
+/* -*- js-indent-level: 8 -*- */
+/*
+ * L.Control.PresentationBar
+ */
+
+/* global $ w2ui _ _UNO vex */
+L.Control.PresentationBar = L.Control.extend({
+       options: {
+               shownavigation: true
+       },
+
+       onAdd: function (map) {
+               this.map = map;
+               this.create();
+
+               map.on('wopiprops', this.onWopiProps, this);
+               map.on('doclayerinit', this.onDocLayerInit, this);
+               map.on('updatepermission', this.onUpdatePermission, this);
+       },
+
+       create: function() {
+               var that = this;
+               var toolbar = $('#presentation-toolbar');
+               toolbar.w2toolbar({
+                       name: 'presentation-toolbar',
+                       tooltip: 'bottom',
+                       hidden: true,
+                       items: [
+                               {type: 'html',  id: 'left'},
+                               {type: 'button',  id: 'presentation', img: 
'presentation', hidden:true, hint: _('Fullscreen presentation')},
+                               {type: 'break', id: 'presentationbreak', 
hidden:true},
+                               {type: 'button',  id: 'insertpage', img: 
'insertpage', hint: _UNO('.uno:TaskPaneInsertPage', 'presentation')},
+                               {type: 'button',  id: 'duplicatepage', img: 
'duplicatepage', hint: _UNO('.uno:DuplicateSlide', 'presentation')},
+                               {type: 'button',  id: 'deletepage', img: 
'deletepage', hint: _UNO('.uno:DeleteSlide', 'presentation')},
+                               {type: 'html',  id: 'right'}
+                       ],
+                       onClick: function (e) {
+                               that.onClick(e, e.target);
+                               window.hideTooltip(this, e.target);
+                       }
+               });
+               toolbar.bind('touchstart', function() {
+                       w2ui['presentation-toolbar'].touchStarted = true;
+               });
+       },
+
+       onDelete: function(e) {
+               if (e !== false) {
+                       this.map.deletePage();
+               }
+       },
+
+       onClick: function(e, id, item) {
+               if ('presentation-toolbar' in w2ui && 
w2ui['presentation-toolbar'].get(id) !== null) {
+                       var toolbar = w2ui['presentation-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 === 'presentation') && this.map.getDocType() === 
'presentation') {
+                       this.map.fire('fullscreen');
+               }
+               else if (id === 'insertpage') {
+                       this.map.insertPage();
+               }
+               else if (id === 'duplicatepage') {
+                       this.map.duplicatePage();
+               }
+               else if (id === 'deletepage') {
+                       vex.dialog.confirm({
+                               message: _('Are you sure you want to delete 
this page?'),
+                               buttons: [
+                                       $.extend({}, vex.dialog.buttons.YES, { 
text: _('OK') }),
+                                       $.extend({}, vex.dialog.buttons.NO, { 
text: _('Cancel') })
+                               ],
+                               callback: this.onDelete.bind(this)
+                       });
+               }
+       },
+
+       onWopiProps: function(e) {
+               if (e.HideExportOption) {
+                       w2ui['presentation-toolbar'].hide('presentation', 
'presentationbreak');
+               }
+       },
+
+       onDocLayerInit: function() {
+               var docType = this.map.getDocType();
+               switch (docType) {
+               case 'presentation':
+                       var presentationToolbar = w2ui['presentation-toolbar'];
+                       if (!this.map['wopi'].HideExportOption && 
presentationToolbar) {
+                               presentationToolbar.show('presentation', 
'presentationbreak');
+                       }
+
+                       // FALLTHROUGH intended
+               case 'drawing':
+                       if (!window.mode.isMobile()) {
+                               $('#presentation-toolbar').show();
+                       }
+               }
+       },
+
+       onUpdatePermission: function(e) {
+               var presentationButtons = ['insertpage', 'duplicatepage', 
'deletepage'];
+               var that = this;
+
+               if (e.perm === 'edit') {
+                       var toolbar = w2ui['presentation-toolbar'];
+                       if (toolbar) {
+                               presentationButtons.forEach(function(id) {
+                                       toolbar.enable(id);
+                               });
+                       }
+
+                       if (toolbar) {
+                               presentationButtons.forEach(function(id) {
+                                       if (id === 'deletepage') {
+                                               var itemState = 
that.map['stateChangeHandler'].getItemValue('.uno:DeletePage');
+                                       } else if (id === 'insertpage') {
+                                               itemState = 
that.map['stateChangeHandler'].getItemValue('.uno:InsertPage');
+                                       } else if (id === 'duplicatepage') {
+                                               itemState = 
that.map['stateChangeHandler'].getItemValue('.uno:DuplicatePage');
+                                       } else {
+                                               itemState = 'enabled';
+                                       }
+
+                                       if (itemState === 'enabled') {
+                                               toolbar.enable(id);
+                                       } else {
+                                               toolbar.disable(id);
+                                       }
+                               });
+                       }
+               } else {
+                       toolbar = w2ui['presentation-toolbar'];
+                       if (toolbar) {
+                               presentationButtons.forEach(function(id) {
+                                       toolbar.disable(id);
+                               });
+                       }
+               }
+       },
+});
+
+L.control.presentationBar = function (options) {
+       return new L.Control.PresentationBar(options);
+};
diff --git a/loleaflet/src/control/Control.Toolbar.js 
b/loleaflet/src/control/Control.Toolbar.js
index a8f7b2204..df1822d26 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -9,12 +9,6 @@
 
 var map;
 
-function onDelete(e) {
-       if (e !== false) {
-               map.deletePage();
-       }
-}
-
 function _updateVisibilityForToolbar(toolbar) {
        if (!toolbar)
                return;
@@ -99,10 +93,6 @@ function onClick(e, id, item) {
                toolbar = w2ui['actionbar'];
                item = toolbar.get(id);
        }
-       else if ('presentation-toolbar' in w2ui && 
w2ui['presentation-toolbar'].get(id) !== null) {
-               toolbar = w2ui['presentation-toolbar'];
-               item = toolbar.get(id);
-       }
        else if (w2ui['searchbar'].get(id) !== null) {
                toolbar = w2ui['searchbar'];
                item = toolbar.get(id);
@@ -158,22 +148,6 @@ function onClick(e, id, item) {
        else if (id === 'insertannotation') {
                map.insertComment();
        }
-       else if (id === 'insertpage') {
-               map.insertPage();
-       }
-       else if (id === 'duplicatepage') {
-               map.duplicatePage();
-       }
-       else if (id === 'deletepage') {
-               vex.dialog.confirm({
-                       message: _('Are you sure you want to delete this 
page?'),
-                       buttons: [
-                               $.extend({}, vex.dialog.buttons.YES, { text: 
_('OK') }),
-                               $.extend({}, vex.dialog.buttons.NO, { text: 
_('Cancel') })
-                       ],
-                       callback: onDelete
-               });
-       }
        else if (id === 'insertgraphic' || item.id === 'localgraphic') {
                L.DomUtil.get('insertgraphic').click();
        }
@@ -899,37 +873,12 @@ function createSigningBar() {
        }
 }
 
-function createPresentationToolbar() {
-       var toolbar = $('#presentation-toolbar');
-       toolbar.w2toolbar({
-               name: 'presentation-toolbar',
-               tooltip: 'bottom',
-               hidden: true,
-               items: [
-                       {type: 'html',  id: 'left'},
-                       {type: 'button',  id: 'presentation', img: 
'presentation', hidden:true, hint: _('Fullscreen presentation')},
-                       {type: 'break', id: 'presentationbreak', hidden:true},
-                       {type: 'button',  id: 'insertpage', img: 'insertpage', 
hint: _UNO('.uno:TaskPaneInsertPage', 'presentation')},
-                       {type: 'button',  id: 'duplicatepage', img: 
'duplicatepage', hint: _UNO('.uno:DuplicateSlide', 'presentation')},
-                       {type: 'button',  id: 'deletepage', img: 'deletepage', 
hint: _UNO('.uno:DeleteSlide', 'presentation')},
-                       {type: 'html',  id: 'right'}
-               ],
-               onClick: function (e) {
-                       onClick(e, e.target);
-                       hideTooltip(this, e.target);
-               }
-       });
-       toolbar.bind('touchstart', function() {
-               w2ui['presentation-toolbar'].touchStarted = true;
-       });
-}
-
 function initNormalToolbar() {
        createMainToolbar();
        map.addControl(L.control.formulaBar({showfunctionwizard: true}));
        createSigningBar();
        map.addControl(L.control.sheetsBar({shownavigation: true}));
-       createPresentationToolbar();
+       map.addControl(L.control.presentationBar());
 }
 
 function setupSearchInput() {
@@ -1148,9 +1097,6 @@ function onWopiProps(e) {
        if (e.HideSaveOption) {
                w2ui['editbar'].hide('save');
        }
-       if (e.HideExportOption) {
-               w2ui['presentation-toolbar'].hide('presentation', 
'presentationbreak');
-       }
        if (e.HidePrintOption) {
                w2ui['editbar'].hide('print');
        }
@@ -1230,21 +1176,12 @@ function onDocLayerInit() {
                        toolbarUp.show('breaksidebar', 'modifypage');
                }
 
-               var presentationToolbar = w2ui['presentation-toolbar'];
-               if (!map['wopi'].HideExportOption && presentationToolbar) {
-                       presentationToolbar.show('presentation', 
'presentationbreak');
-               }
-
                // FALLTHROUGH intended
        case 'drawing':
                if (toolbarUp)
                        toolbarUp.show('leftpara', 'centerpara', 'rightpara', 
'justifypara', 'breakpara', 'linespacing',
                        'breakspacing', 'defaultbullet', 'defaultnumbering', 
'breakbullet', 'inserttextbox', 'inserttable', 'backcolor',
                        'breaksidebar', 'modifypage', 'slidechangewindow', 
'customanimation', 'masterslidespanel');
-
-               if (!window.mode.isMobile()) {
-                       $('#presentation-toolbar').show();
-               }
                break;
        }
 
@@ -1685,40 +1622,12 @@ function onUpdatePermission(e) {
                }
        }
 
-       var presentationButtons = ['insertpage', 'duplicatepage', 'deletepage'];
        if (e.perm === 'edit') {
                // Enable list boxes
                $('.styles-select').prop('disabled', false);
                $('.fonts-select').prop('disabled', false);
                $('.fontsizes-select').prop('disabled', false);
 
-               toolbar = w2ui['presentation-toolbar'];
-               if (toolbar) {
-                       presentationButtons.forEach(function(id) {
-                               toolbar.enable(id);
-                       });
-               }
-
-               if (toolbar) {
-                       presentationButtons.forEach(function(id) {
-                               if (id === 'deletepage') {
-                                       var itemState = 
map['stateChangeHandler'].getItemValue('.uno:DeletePage');
-                               } else if (id === 'insertpage') {
-                                       itemState = 
map['stateChangeHandler'].getItemValue('.uno:InsertPage');
-                               } else if (id === 'duplicatepage') {
-                                       itemState = 
map['stateChangeHandler'].getItemValue('.uno:DuplicatePage');
-                               } else {
-                                       itemState = 'enabled';
-                               }
-
-                               if (itemState === 'enabled') {
-                                       toolbar.enable(id);
-                               } else {
-                                       toolbar.disable(id);
-                               }
-                       });
-               }
-
                if (window.mode.isMobile()) {
                        $('#toolbar-down').show();
                }
@@ -1729,13 +1638,6 @@ function onUpdatePermission(e) {
                $('.fonts-select').prop('disabled', true);
                $('.fontsizes-select').prop('disabled', true);
 
-               toolbar = w2ui['presentation-toolbar'];
-               if (toolbar) {
-                       presentationButtons.forEach(function(id) {
-                               toolbar.disable(id);
-                       });
-               }
-
                if (window.mode.isMobile()) {
                        $('#toolbar-down').hide();
                }
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js 
b/loleaflet/src/layer/tile/ImpressTileLayer.js
index 30648c179..886509798 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -116,14 +116,6 @@ L.ImpressTileLayer = L.TileLayer.extend({
        onMobileInit: function (map) {
                map.addControl(L.control.mobileTopBar('presentation'));
 
-               var toolbar = $('#presentation-toolbar');
-               toolbar.w2toolbar({
-                       name: 'presentation-toolbar',
-                       tooltip: 'bottom',
-                       hidden: true,
-                       items: []
-               });
-
                map.addControl(L.control.mobileBottomBar('presentation'));
 
                map.addControl(L.control.searchBar());
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to