loleaflet/src/control/Ruler.js |   91 ++++++++++++++++++++++++++++++++---------
 1 file changed, 72 insertions(+), 19 deletions(-)

New commits:
commit f240d58f3e0a7895f6ea88110c4e0f80fe6a573a
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Jun 1 23:15:11 2020 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Jun 2 10:33:13 2020 +0200

    Add "delete tabstop" function to Ruler
    
    Change-Id: I34d381f6d3e12b0444b9c7778ef6b8c87794cbd6
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95341
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/loleaflet/src/control/Ruler.js b/loleaflet/src/control/Ruler.js
index a5537055e..f5c3dda4d 100644
--- a/loleaflet/src/control/Ruler.js
+++ b/loleaflet/src/control/Ruler.js
@@ -606,9 +606,30 @@ L.Control.Ruler = L.Control.extend({
                this._map._socket.sendMessage('uno .uno:RulerChangeState ' + 
JSON.stringify(unoObj));
        },
 
+       _getTabStopHit: function(tabstopContainer, pointX) {
+               var tabstop = null;
+               var margin = 10;
+               var tabstopDiffFromCenter = 100000000; // just a big initial 
condition
+
+               for (var i = 0; i < tabstopContainer.tabStops.length; i++) {
+                       var current = tabstopContainer.tabStops[i];
+                       var location = current.tabStopLocation;
+                       if (pointX >= location.left - margin && pointX <= 
location.right + margin) {
+                               var diff = Math.abs(pointX - location.center);
+                               if (diff < tabstopDiffFromCenter) {
+                                       tabstop = current;
+                                       tabstopDiffFromCenter = diff;
+                               }
+                       }
+               }
+               return tabstop;
+       },
        _initiateTabstopDrag: function(event) {
                // console.log('===> _initiateTabstopDrag ' + event.type);
 
+               this.currentPositionInTwips = null;
+               this.currentTabStopIndex = null;
+
                var tabstopContainer = null;
                var pointX = null;
 
@@ -622,18 +643,37 @@ L.Control.Ruler = L.Control.extend({
                }
                tabstopContainer.tabStopMarkerBeingDragged = null;
 
+               // check if we hit any tabstop
+               var tabstop = this._getTabStopHit(tabstopContainer, pointX);
+
                // Check what to do when a mouse buttons is clicked, ignore 
touch
                if (event.type !== 'panstart') {
                        // right-click inside tabstop container
                        if (event.button === 2) {
-                               this.currentPositionInTwips = 
this._map._docLayer._pixelsToTwips({x: pointX, y:0}).x;
+                               if (tabstop == null) {
+                                       this.currentPositionInTwips = 
this._map._docLayer._pixelsToTwips({x: pointX, y:0}).x;
+                               }
+                               else {
+                                       this.currentTabStopIndex = 
tabstop.tabStopNumber;
+                               }
+                               var self = this;
                                $.contextMenu({
                                        selector: 
'.loleaflet-ruler-tabstopcontainer',
                                        className: 'loleaflet-font',
                                        items: {
                                                inserttabstop: {
                                                        name: _('Insert 
tabstop'),
-                                                       callback: 
(this._insertTabstop).bind(this)
+                                                       callback: 
(this._insertTabstop).bind(this),
+                                                       visible: function() {
+                                                               return 
self.currentPositionInTwips != null;
+                                                       }
+                                               },
+                                               removetabstop: {
+                                                       name: _('Delete 
tabstop'),
+                                                       callback: 
(this._deleteTabstop).bind(this),
+                                                       visible: function() {
+                                                               return 
self.currentTabStopIndex != null;
+                                                       }
                                                }
                                        }
                                });
@@ -646,23 +686,6 @@ L.Control.Ruler = L.Control.extend({
                        }
                }
 
-               // check if we hit any tabstop
-               var tabstop = null;
-               var margin = 10;
-               var tabstopDiffFromCenter = 100000000; // just a big initial 
condition
-
-               for (var i = 0; i < tabstopContainer.tabStops.length; i++) {
-                       var current = tabstopContainer.tabStops[i];
-                       var location = current.tabStopLocation;
-                       if (pointX >= location.left - margin && pointX <= 
location.right + margin) {
-                               var diff = Math.abs(pointX - location.center);
-                               if (diff < tabstopDiffFromCenter) {
-                                       tabstop = current;
-                                       tabstopDiffFromCenter = diff;
-                               }
-                       }
-               }
-
                if (tabstop == null) {
                        return;
                }
@@ -735,6 +758,10 @@ L.Control.Ruler = L.Control.extend({
                                Position: {
                                        type : 'int32',
                                        value : positionTwip
+                               },
+                               Remove: {
+                                       type : 'boolean',
+                                       value : false
                                }
                        };
                        this._map.sendUnoCommand('.uno:ChangeTabStop', params);
@@ -764,6 +791,27 @@ L.Control.Ruler = L.Control.extend({
                }
        },
 
+       _deleteTabstop: function() {
+               if (this.currentTabStopIndex != null) {
+                       var params = {
+                               Index: {
+                                       type : 'int32',
+                                       value : this.currentTabStopIndex
+                               },
+                               Position: {
+                                       type : 'int32',
+                                       value : 0
+                               },
+                               Remove: {
+                                       type : 'boolean',
+                                       value : true
+                               }
+                       };
+                       this._map.sendUnoCommand('.uno:ChangeTabStop', params);
+                       this.currentTabStopIndex = null;
+               }
+       },
+
        _insertTabstop: function() {
                if (this.currentPositionInTwips != null) {
                        var params = {
@@ -774,9 +822,14 @@ L.Control.Ruler = L.Control.extend({
                                Position: {
                                        type : 'int32',
                                        value : this.currentPositionInTwips
+                               },
+                               Remove: {
+                                       type : 'boolean',
+                                       value : false
                                }
                        };
                        this._map.sendUnoCommand('.uno:ChangeTabStop', params);
+                       this.currentPositionInTwips = null;
                }
        },
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to