loleaflet/src/control/Control.MobileBottomBar.js |    2 ++
 loleaflet/src/control/Control.MobileTopBar.js    |   20 +++++++++++++++++++-
 loleaflet/src/control/Control.PresentationBar.js |   21 +++++++++++++++++++++
 loleaflet/src/control/Control.Toolbar.js         |   10 ++--------
 loleaflet/src/control/Control.TopToolbar.js      |    3 +++
 5 files changed, 47 insertions(+), 9 deletions(-)

New commits:
commit 799235eb38a8fdbf43a07463f2fecbc9893ab1e7
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Apr 22 09:15:03 2020 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Wed Apr 22 10:06:18 2020 +0200

    Move command state updates handler to toolbar implementations
    
    Change-Id: I3b9b4a7c05a0c6f40f86f6a69ea8873a1120180c
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92670
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/loleaflet/src/control/Control.MobileBottomBar.js 
b/loleaflet/src/control/Control.MobileBottomBar.js
index 078e8d880..8a11179b9 100644
--- a/loleaflet/src/control/Control.MobileBottomBar.js
+++ b/loleaflet/src/control/Control.MobileBottomBar.js
@@ -17,6 +17,8 @@ L.Control.MobileBottomBar = L.Control.extend({
        onAdd: function (map) {
                this.map = map;
                this.create();
+
+               map.on('commandstatechanged', window.onCommandStateChanged);
        },
 
        getToolItems: function(docType) {
diff --git a/loleaflet/src/control/Control.MobileTopBar.js 
b/loleaflet/src/control/Control.MobileTopBar.js
index 76874fb9c..8543a3221 100644
--- a/loleaflet/src/control/Control.MobileTopBar.js
+++ b/loleaflet/src/control/Control.MobileTopBar.js
@@ -19,6 +19,7 @@ L.Control.MobileTopBar = L.Control.extend({
                this.create();
 
                map.on('updatepermission', this.onUpdatePermission, this);
+               map.on('commandstatechanged', this.onCommandStateChanged, this);
        },
 
        getToolItems: function(docType) {
@@ -184,7 +185,24 @@ L.Control.MobileTopBar = L.Control.extend({
                                });
                        }
                }
-       }
+       },
+
+       onCommandStateChanged: function(e) {
+               var commandName = e.commandName;
+               var state = e.state;
+
+               if (this.map._permission === 'edit' && (state === 'enabled' || 
state === 'disabled')) {
+                       var id = window.unoCmdToToolbarId(commandName);
+                       var toolbar = w2ui['actionbar'];
+
+                       if (state === 'enabled') {
+                               toolbar.enable(id);
+                       } else {
+                               toolbar.uncheck(id);
+                               toolbar.disable(id);
+                       }
+               }
+       },
 });
 
 L.control.mobileTopBar = function (docType) {
diff --git a/loleaflet/src/control/Control.PresentationBar.js 
b/loleaflet/src/control/Control.PresentationBar.js
index 9cf159bd5..eeb3cfac8 100644
--- a/loleaflet/src/control/Control.PresentationBar.js
+++ b/loleaflet/src/control/Control.PresentationBar.js
@@ -16,6 +16,7 @@ L.Control.PresentationBar = L.Control.extend({
                map.on('wopiprops', this.onWopiProps, this);
                map.on('doclayerinit', this.onDocLayerInit, this);
                map.on('updatepermission', this.onUpdatePermission, this);
+               map.on('commandstatechanged', this.onCommandStateChanged, this);
        },
 
        create: function() {
@@ -149,6 +150,26 @@ L.Control.PresentationBar = L.Control.extend({
                        }
                }
        },
+
+       onCommandStateChanged: function(e) {
+               var commandName = e.commandName;
+               var state = e.state;
+
+               if (this.map._permission === 'edit' && (state === 'enabled' || 
state === 'disabled')) {
+                       var id = window.unoCmdToToolbarId(commandName);
+
+                       if (id === 'deletepage' || id === 'insertpage' || id 
=== 'duplicatepage') {
+                               var toolbar = w2ui['presentation-toolbar'];
+
+                               if (state === 'enabled') {
+                                       toolbar.enable(id);
+                               } else {
+                                       toolbar.uncheck(id);
+                                       toolbar.disable(id);
+                               }
+                       }
+               }
+       },
 });
 
 L.control.presentationBar = function (options) {
diff --git a/loleaflet/src/control/Control.Toolbar.js 
b/loleaflet/src/control/Control.Toolbar.js
index 021065f43..bdfbbee9e 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -733,7 +733,6 @@ function onWopiProps(e) {
 
 function onCommandStateChanged(e) {
        var toolbar = w2ui['editbar'];
-       var statusbar = w2ui['actionbar'];
        var commandName = e.commandName;
        var state = e.state;
        var color, div;
@@ -832,12 +831,6 @@ function onCommandStateChanged(e) {
        // If in non-edit mode, will be taken care of when permission is 
changed to 'edit'
        else if (map._permission === 'edit' && (state === 'enabled' || state 
=== 'disabled')) {
                var toolbarUp = toolbar;
-               if (window.mode.isMobile()) {
-                       toolbarUp = statusbar;
-               }
-               else if (map.getDocType() === 'presentation' && (id === 
'deletepage' || id === 'insertpage' || id === 'duplicatepage')) {
-                       toolbarUp = w2ui['presentation-toolbar'];
-               }
                if (state === 'enabled') {
                        toolbarUp.enable(id);
                } else {
@@ -1018,7 +1011,6 @@ function setupToolbar(e) {
        map.on('wopiprops', onWopiProps);
        map.on('commandresult', onCommandResult);
        map.on('updateparts pagenumberchanged', onUpdateParts);
-       map.on('commandstatechanged', onCommandStateChanged);
 
        if (!L.Params.closeButtonEnabled) {
                $('#closebuttonwrapper').hide();
@@ -1049,5 +1041,7 @@ global.createShapesPanel = createShapesPanel;
 global.onUpdatePermission = onUpdatePermission;
 global.setupSearchInput = setupSearchInput;
 global.getUNOCommand = getUNOCommand;
+global.unoCmdToToolbarId = unoCmdToToolbarId;
+global.onCommandStateChanged = onCommandStateChanged;
 
 }(window));
diff --git a/loleaflet/src/control/Control.TopToolbar.js 
b/loleaflet/src/control/Control.TopToolbar.js
index 20a178f1b..bb13a1fb4 100644
--- a/loleaflet/src/control/Control.TopToolbar.js
+++ b/loleaflet/src/control/Control.TopToolbar.js
@@ -546,6 +546,9 @@ L.Control.TopToolbar = L.Control.extend({
                        }
                        $('.fontsizes-select').val(state).trigger('change');
                }
+
+               // call shared handler for font color and higlight items 
handling
+               window.onCommandStateChanged(e);
        }
 });
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to