Skip to content

Commit

Permalink
Calc: Don't switch tabs when context menu is triggered
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
Change-Id: I5b25a8cb363b8e04fd6dcec1f500e7ff2982b678
  • Loading branch information
bayramcicek committed Jan 18, 2024
1 parent cad59f4 commit 872e17b
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions browser/src/control/Control.Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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
};

Expand Down Expand Up @@ -204,7 +204,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;
Expand All @@ -226,9 +225,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));
}
Expand Down Expand Up @@ -309,17 +307,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() {
Expand Down

0 comments on commit 872e17b

Please sign in to comment.