loleaflet/src/control/Control.MobileWizard.js |   29 +---------------
 loleaflet/src/control/Control.Toolbar.js      |   46 ++++++++++++++------------
 loleaflet/src/core/LOUtil.js                  |   24 +++++++++++++
 3 files changed, 53 insertions(+), 46 deletions(-)

New commits:
commit 5766ed7706a30c75fd9876f1d90d50854f407a9f
Author:     Michael Meeks <[email protected]>
AuthorDate: Thu Mar 26 12:58:48 2020 +0000
Commit:     Michael Meeks <[email protected]>
CommitDate: Thu Mar 26 19:35:37 2020 +0100

    Re-factor JSON node searching into LOUtil.
    
    Change-Id: Ib6e42371441b15999cad35262c07aa1e9b38c429
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91099
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Meeks <[email protected]>

diff --git a/loleaflet/src/control/Control.MobileWizard.js 
b/loleaflet/src/control/Control.MobileWizard.js
index 2df267c54..ca8486600 100644
--- a/loleaflet/src/control/Control.MobileWizard.js
+++ b/loleaflet/src/control/Control.MobileWizard.js
@@ -362,13 +362,12 @@ L.Control.MobileWizard = L.Control.extend({
        },
 
        _modifySidebarLayout: function (data) {
-               var deck = this._findItemByTypeRecursive(data, 'deck');
+               var deck = L.LOUtil.findItemWithAttributeRecursive(data, 
'type', 'deck');
                if (deck)
                {
                        // merge styles into text-panel for elegance
-                       var stylesIdx = this._findIdxInParentById(deck, 
'StylesPropertyPanel');
-                       var textName = 'TextPropertyPanel';
-                       var textIdx = this._findIdxInParentById(deck, textName);
+                       var stylesIdx = 
L.LOUtil.findIndexInParentByAttribute(deck, 'id', 'StylesPropertyPanel');
+                       var textIdx = 
L.LOUtil.findIndexInParentByAttribute(deck, 'id', 'TextPropertyPanel');
 
                        if (stylesIdx >= 0 && this.map.getDocType() === 
'spreadsheet')
                        {       // remove rather useless calc styles panel
@@ -392,28 +391,6 @@ L.Control.MobileWizard = L.Control.extend({
                }
        },
 
-       _findItemByTypeRecursive: function(data, t) {
-               var found = null;
-               if (data.type === t)
-                       return data;
-               if (data.children)
-               {
-                       for (var i = 0; !found && i < data.children.length; i++)
-                               found = 
this._findItemByTypeRecursive(data.children[i], t);
-               }
-               return found;
-       },
-
-       _findIdxInParentById: function(data, id) {
-               if (data.children)
-               {
-                       for (var i = 0; i < data.children.length; i++)
-                               if (data.children[i].id === id)
-                                       return i;
-               }
-               return -1;
-       },
-
        _removeItems: function (data, items) {
                if (data.children) {
                        for (var i = 0; i < data.children.length;) {
diff --git a/loleaflet/src/core/LOUtil.js b/loleaflet/src/core/LOUtil.js
index d9cf252c9..d66090d71 100644
--- a/loleaflet/src/core/LOUtil.js
+++ b/loleaflet/src/core/LOUtil.js
@@ -103,6 +103,30 @@ L.LOUtil = {
                if (commandName.indexOf('?')!== -1)
                        return false;
                return res;
+       },
+
+       /// Searching in JSON trees for data with a given field
+       findItemWithAttributeRecursive: function(node, idName, idValue) {
+               var found = null;
+               if (node[idName] === idValue)
+                       return node;
+               if (node.children)
+               {
+                       for (var i = 0; !found && i < node.children.length; i++)
+                               found = 
L.LOUtil.findItemWithAttributeRecursive(node.children[i], idName, idValue);
+               }
+               return found;
+       },
+
+       /// Searching in JSON trees for an identifier and return the index in 
parent
+       findIndexInParentByAttribute: function(node, idName, idValue) {
+               if (node.children)
+               {
+                       for (var i = 0; i < node.children.length; i++)
+                               if (node.children[i][idName] === idValue)
+                                       return i;
+               }
+               return -1;
        }
 };
 
commit 877e4fd5873f5344f6367fbbbfbc60c3f9dde465
Author:     Michael Meeks <[email protected]>
AuthorDate: Thu Mar 26 12:45:11 2020 +0000
Commit:     Michael Meeks <[email protected]>
CommitDate: Thu Mar 26 19:35:24 2020 +0100

    Allow optional color to be passed into setBorders.
    
    Change-Id: I8a5cc57bda07d1c0671262c22b93d012f2018eb0
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91098
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Meeks <[email protected]>

diff --git a/loleaflet/src/control/Control.Toolbar.js 
b/loleaflet/src/control/Control.Toolbar.js
index 4a115f5e2..6ac3cbd26 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -376,15 +376,15 @@ function onClick(e, id, item, subItem) {
        }
 }
 
-function setBorders(left, right, bottom, top, horiz, vert) {
+function _setBorders(left, right, bottom, top, horiz, vert, color) {
        var params = {
                OuterBorder: {
                        type : '[]any',
                        value : [
-                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : 0 }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : left }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
-                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : 0 }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : right }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
-                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : 0 }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : bottom }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
-                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : 0 }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : top }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
+                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : color }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : left }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
+                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : color }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : right }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
+                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : color }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : bottom }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
+                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : color }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : top }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
                                { type : 'long', value : 0 },
                                { type : 'long', value : 0 },
                                { type : 'long', value : 0 },
@@ -395,8 +395,8 @@ function setBorders(left, right, bottom, top, horiz, vert) {
                InnerBorder: {
                        type : '[]any',
                        value : [
-                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : 0 }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : horiz }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
-                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : 0 }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : vert }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
+                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : color }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : horiz }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
+                               { type : 'com.sun.star.table.BorderLine2', 
value : { Color : { type : 'com.sun.star.util.Color', value : color }, 
InnerLineWidth : { type : 'short', value : 0 }, OuterLineWidth : { type : 
'short', value : vert }, LineDistance : { type : 'short', value : 0 },  
LineStyle : { type : 'short', value : 0 }, LineWidth : { type : 'unsigned 
long', value : 0 } } },
                                { type : 'short', value : 0 },
                                { type : 'short', value : 127 },
                                { type : 'long', value : 0 }
@@ -413,24 +413,30 @@ function closePopup() {
        map.focus();
 }
 
-function setBorderStyle(num) {
+function setBorderStyle(num, color) {
+       if (color === undefined)
+               color = 0; // black
+
+       if (color.startsWith('#'))
+               color = parseInt('0x' + color.substring(1, color.length));
+
        switch (num) {
        case 0: map.sendUnoCommand('.uno:FormatCellBorders'); break;
 
-       case 1: setBorders(0, 0, 0, 0, 0, 0); break;
-       case 2: setBorders(1, 0, 0, 0, 0, 0); break;
-       case 3: setBorders(0, 1, 0, 0, 0, 0); break;
-       case 4: setBorders(1, 1, 0, 0, 0, 0); break;
+       case 1: _setBorders(0, 0, 0, 0, 0, 0, color); break;
+       case 2: _setBorders(1, 0, 0, 0, 0, 0, color); break;
+       case 3: _setBorders(0, 1, 0, 0, 0, 0, color); break;
+       case 4: _setBorders(1, 1, 0, 0, 0, 0, color); break;
 
-       case 5: setBorders(0, 0, 0, 1, 0, 0); break;
-       case 6: setBorders(0, 0, 1, 0, 0, 0); break;
-       case 7: setBorders(0, 0, 1, 1, 0, 0); break;
-       case 8: setBorders(1, 1, 1, 1, 0, 0); break;
+       case 5: _setBorders(0, 0, 0, 1, 0, 0, color); break;
+       case 6: _setBorders(0, 0, 1, 0, 0, 0, color); break;
+       case 7: _setBorders(0, 0, 1, 1, 0, 0, color); break;
+       case 8: _setBorders(1, 1, 1, 1, 0, 0, color); break;
 
-       case 9: setBorders(0, 0, 1, 1, 1, 0); break;
-       case 10: setBorders(1, 1, 1, 1, 1, 0); break;
-       case 11: setBorders(1, 1, 1, 1, 0, 1); break;
-       case 12: setBorders(1, 1, 1, 1, 1, 1); break;
+       case 9:  _setBorders(0, 0, 1, 1, 1, 0, color); break;
+       case 10: _setBorders(1, 1, 1, 1, 1, 0, color); break;
+       case 11: _setBorders(1, 1, 1, 1, 0, 1, color); break;
+       case 12: _setBorders(1, 1, 1, 1, 1, 1, color); break;
 
        default: console.log('ignored border: ' + num);
        }
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to