From ab03f1bc0a820e6fff1adcf12ab155a7f1b771c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bayram=20=C3=87i=C3=A7ek?= Date: Fri, 6 Oct 2023 10:59:22 +0300 Subject: [PATCH] Calc: Don't switch tabs when context menu is triggered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Trying to open context menu from a sheet tab, also changes the active tab. This occurs when right click on a sheet tab (or long tap on mobile or tablet) - moveLeft and moveRight of inactive tabs are implemented. - added _moveSheetLR and _moveOrCopySheet functions. Signed-off-by: Bayram Çiçek Change-Id: I5b25a8cb363b8e04fd6dcec1f500e7ff2982b678 --- browser/src/control/Control.Tabs.js | 37 ++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/browser/src/control/Control.Tabs.js b/browser/src/control/Control.Tabs.js index 3c74857343ddc..5e1a3f1f070bf 100644 --- a/browser/src/control/Control.Tabs.js +++ b/browser/src/control/Control.Tabs.js @@ -94,7 +94,7 @@ L.Control.Tabs = L.Control.extend({ // no blacklisting available for this context menu so only add when needed this._menuItem['.uno:Move'] = { name: _UNO('.uno:Move', 'spreadsheet', true), - callback: function() {this._map.sendUnoCommand('.uno:Move');}.bind(this), + callback: (this._moveOrCopySheet).bind(this), visible: areTabsMultiple }; @@ -195,7 +195,6 @@ L.Control.Tabs = L.Control.extend({ .on('press', function (j) { return function(e) { this._tabForContextMenu = j; - this._setPart(e); if (!this._map.isReadOnlyMode()) { if (window.mode.isMobile()) { window.contextMenuWizard = true; @@ -217,9 +216,8 @@ L.Control.Tabs = L.Control.extend({ }; }(i).bind(this)); L.DomEvent.on(tab, 'contextmenu', function(j) { - return function(e) { + return function() { this._tabForContextMenu = j; - this._setPart(e); }; }(i).bind(this)); } @@ -283,17 +281,38 @@ L.Control.Tabs = L.Control.extend({ this._map.sendUnoCommand('.uno:Move?Copy:bool=false&UseCurrentDocument:bool=true&Index=' + newIndex); }, + _moveOrCopySheet: function () { + var contextMenuTab = this._tabForContextMenu; + this._map.sendUnoCommand('.uno:Move?FromContextMenu:bool=true&MoveOrCopySheetDialog:bool=true&ContextMenuIndex=' + contextMenuTab); + }, + + _moveSheetLR: function (contextMenuTab, newIndex) { + if (contextMenuTab !== undefined && contextMenuTab >= 0) + this._map.sendUnoCommand('.uno:Move?Copy:bool=false&UseCurrentDocument:bool=true&FromContextMenu:bool=true&ContextMenuIndex=' + contextMenuTab + '&Index=' + newIndex); + }, + _moveSheetLeft: function () { - var targetIndex = this._map._docLayer._partNames.indexOf(this._map._docLayer._partNames[this._map._docLayer._selectedPart]); //core handles sheet with 1 base indexing // 0 index means last sheet - if (targetIndex <= 0) return; - this._moveSheet(targetIndex); + var contextMenuTab = this._tabForContextMenu; + if (contextMenuTab <= 0) return; + + // core handles the decreasing of contextMenuTab by 1 + // so, no need to do it here (for the second parameter) + this._moveSheetLR(contextMenuTab, contextMenuTab); }, _moveSheetRight: function () { - var targetIndex = this._map._docLayer._partNames.indexOf(this._map._docLayer._partNames[this._map._docLayer._selectedPart]) + 3; - this._moveSheet(targetIndex); + var contextMenuTab = this._tabForContextMenu; + + /* + Why there is '+3' ? + - core handles sheet with 1 base indexing, add +1. + - since we move right, add +1. + - on the core side, there is a -1 for this value, + so we add +1 again. + */ + this._moveSheetLR(contextMenuTab, contextMenuTab + 3); }, _insertSheetBefore: function() {