From e11202ea49ca479630751c123083502db839451b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Mon, 20 Apr 2020 09:28:25 +0200 Subject: [PATCH] ruler: insert tabstop from a context menu (right click) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0699b53a6972b304f358948d49619a5004329eff Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92548 Tested-by: Jenkins CollaboraOffice Reviewed-by: Tomaž Vajngerl --- loleaflet/src/control/Ruler.js | 56 +++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/loleaflet/src/control/Ruler.js b/loleaflet/src/control/Ruler.js index 3b9e52fb2..ea1bd1a01 100644 --- a/loleaflet/src/control/Ruler.js +++ b/loleaflet/src/control/Ruler.js @@ -388,11 +388,7 @@ L.Control.Ruler = L.Control.extend({ _initiateTabstopDrag: function(event) { // console.log('===> _initiateTabstopDrag ' + event.type); - if (event.button !== 0) { - event.stopPropagation(); // prevent handling of the mother event elsewhere - return; - } - + var tabstopContainer = null; var pointX = null; @@ -405,6 +401,28 @@ L.Control.Ruler = L.Control.extend({ pointX = event.layerX; } + if (event.button === 2) { + this.currentPositionInTwips = this._map._docLayer._pixelsToTwips({x: pointX, y:0}).x; + + $.contextMenu({ + selector: '.loleaflet-ruler-tabstopcontainer', + className: 'loleaflet-font', + items: { + inserttabstop: { + name: _('Insert tabstop'), + callback: (this._insertTabstop).bind(this) + } + } + }); + + event.stopPropagation(); + return; + } + else if (event.button !== 0) { + event.stopPropagation(); // prevent handling of the mother event elsewhere + return; + } + // check if we hit any tabstop var tabstop = null; var margin = 10; @@ -423,18 +441,6 @@ L.Control.Ruler = L.Control.extend({ } if (tabstop == null) { - var positionTwip = this._map._docLayer._pixelsToTwips({x: pointX, y:0}).x; - var params = { - Index: { - type : 'int32', - value : -1 - }, - Position: { - type : 'int32', - value : positionTwip - } - }; - this._map.sendUnoCommand('.uno:ChangeTabStop', params); return; } @@ -506,6 +512,22 @@ L.Control.Ruler = L.Control.extend({ L.DomEvent.off(this._rTSContainer, 'mouseout', this._endTabstopDrag, this); }, + _insertTabstop: function() { + if (this.currentPositionInTwips != null) { + var params = { + Index: { + type : 'int32', + value : -1 + }, + Position: { + type : 'int32', + value : this.currentPositionInTwips + } + }; + this._map.sendUnoCommand('.uno:ChangeTabStop', params); + } + }, + });