diff --git a/browser/src/control/Control.Tabs.js b/browser/src/control/Control.Tabs.js index f90cde8ea..0af675bfe 100644 --- a/browser/src/control/Control.Tabs.js +++ b/browser/src/control/Control.Tabs.js @@ -74,6 +74,10 @@ L.Control.Tabs = L.Control.extend({ '.uno:Name': {name: _UNO('.uno:RenameTable', 'spreadsheet', true), callback: (this._renameSheet).bind(this) }, + '.uno:Protect': { + name: _UNO('.uno:Protect', 'spreadsheet', true), + callback: (this._protectSheet).bind(this), + }, '.uno:Show': { name: _UNO('.uno:Show', 'spreadsheet', true), callback: (this._showSheet).bind(this), @@ -291,16 +295,21 @@ L.Control.Tabs = L.Control.extend({ } }, - _setPart: function (e) { + // Set the part by index. Return true if cancelled. + _setPartIndex: function(index) { if (cool.Comment.isAnyEdit()) { cool.CommentSection.showCommentEditingWarning(); - return; + return true; } + this._map._docLayer._clearReferences(); + this._map.setPart(index, /*external:*/ false, /*calledFromSetPartHandler:*/ true); + }, + + _setPart: function (e) { var part = e.target.id.match(/\d+/g)[0]; if (part !== null) { - this._map._docLayer._clearReferences(); - this._map.setPart(parseInt(part), /*external:*/ false, /*calledFromSetPartHandler:*/ true); + this._setPartIndex(parseInt(part)); } }, @@ -370,6 +379,14 @@ L.Control.Tabs = L.Control.extend({ }); }, + // Trigger sheet protection. It seems that it does it for the current sheet + // so we select it first. + _protectSheet: function() { + if (!this._setPartIndex(this._tabForContextMenu)) { + this._map.sendUnoCommand('.uno:Protect'); + } + }, + _showSheet: function() { this._map.showPage(); },