[Libreoffice-commits] online.git: bundled/include kit/KitHelper.hpp loleaflet/src loleaflet/unocommands.js

Marco Cecchetti marco.cecchetti at collabora.com
Tue Apr 3 19:41:41 UTC 2018


 bundled/include/LibreOfficeKit/LibreOfficeKit.h |    3 +
 kit/KitHelper.hpp                               |   30 +++++++++++++++++
 loleaflet/src/control/Control.Menubar.js        |    1 
 loleaflet/src/control/Control.Tabs.js           |   16 ++++++++-
 loleaflet/src/control/Parts.js                  |   42 ++++++++++++++++++++++++
 loleaflet/src/core/Socket.js                    |    7 ++++
 loleaflet/src/layer/tile/CalcTileLayer.js       |   25 ++++++++++++--
 loleaflet/unocommands.js                        |    3 +
 8 files changed, 123 insertions(+), 4 deletions(-)

New commits:
commit d887b08d60d4335c2de27ea043253f017701c317
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Thu Feb 1 16:36:24 2018 +0100

    calc: added support for hidden sheets and validation of cell content
    
    Change-Id: I5db971b8826de7d5be2f88354925cd107082da77
    Reviewed-on: https://gerrit.libreoffice.org/49112
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>
    Tested-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/bundled/include/LibreOfficeKit/LibreOfficeKit.h b/bundled/include/LibreOfficeKit/LibreOfficeKit.h
index d465d541b..0799584d3 100644
--- a/bundled/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/bundled/include/LibreOfficeKit/LibreOfficeKit.h
@@ -306,6 +306,9 @@ struct _LibreOfficeKitDocumentClass
                                          int nType,
                                          const char* pText);
 
+    /// @see lok::Document::getPartInfo().
+    char* (*getPartInfo) (LibreOfficeKitDocument* pThis, int nPart);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/kit/KitHelper.hpp b/kit/KitHelper.hpp
index 49ff8f063..6dd1a0f41 100644
--- a/kit/KitHelper.hpp
+++ b/kit/KitHelper.hpp
@@ -13,6 +13,8 @@
 #include <sstream>
 #include <string>
 
+#include <Util.hpp>
+
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
@@ -140,6 +142,34 @@ namespace LOKitHelper
 
         if (type == LOK_DOCTYPE_SPREADSHEET || type == LOK_DOCTYPE_PRESENTATION)
         {
+            if (type == LOK_DOCTYPE_SPREADSHEET)
+            {
+                std::ostringstream hposs;
+                for (int i = 0; i < parts; ++i)
+                {
+
+                    ptrValue = loKitDocument->pClass->getPartInfo(loKitDocument, i);
+                    std::string partinfo(ptrValue);
+                    std::free(ptrValue);
+                    const auto aPartInfo = Util::JsonToMap(partinfo);
+                    for (const auto prop: aPartInfo)
+                    {
+                        const std::string& name = prop.first;
+                        if (name == "visible")
+                        {
+                            if (prop.second == "0")
+                                hposs << i << ",";
+                        }
+                    }
+                }
+                std::string hiddenparts = hposs.str();
+                if (!hiddenparts.empty())
+                {
+                    hiddenparts.pop_back();
+                    oss << " hiddenparts=" << hiddenparts;
+                }
+            }
+
             for (int i = 0; i < parts; ++i)
             {
                 oss << "\n";
diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index 8d947afd4..81288d617 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -364,6 +364,7 @@ L.Control.Menubar = L.Control.extend({
 				{uno: '.uno:DataSort'},
 				{uno: '.uno:SortAscending'},
 				{uno: '.uno:SortDescending'},
+				{uno: '.uno:Validation'},
 				{type: 'separator'},
 				{uno: '.uno:DataFilterAutoFilter'},
 				{name: _UNO('.uno:FilterMenu', 'spreadsheet'), type: 'menu', menu: [
diff --git a/loleaflet/src/control/Control.Tabs.js b/loleaflet/src/control/Control.Tabs.js
index a2095457f..8295f2fd6 100644
--- a/loleaflet/src/control/Control.Tabs.js
+++ b/loleaflet/src/control/Control.Tabs.js
@@ -68,7 +68,19 @@ L.Control.Tabs = L.Control.extend({
 										map.renamePage(data.sheetname, nPos);
 									}
 								});
-							}}
+							}},
+				'showsheets': {
+					name: _UNO('.uno:Show', 'spreadsheet', true),
+					callback: function() {
+						map.showPage();
+					}
+				},
+				'hiddensheets': {
+					name: _UNO('.uno:Hide', 'spreadsheet', true),
+					callback: function() {
+						map.hidePage();
+					}
+				}
 			},
 			zIndex: 1000
 		});
@@ -103,6 +115,8 @@ L.Control.Tabs = L.Control.extend({
 				ssTabScroll.id = 'spreadsheet-tab-scroll';
 
 				for (var i = 0; i < parts; i++) {
+					if (e.hiddenParts.indexOf(i) !== -1)
+						continue;
 					var id = 'spreadsheet-tab' + i;
 					var tab = L.DomUtil.create('div', 'spreadsheet-tab', ssTabScroll);
 					tab.innerHTML = e.partNames[i];
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index d8f899447..07d1afc97 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -233,6 +233,10 @@ L.Map.include({
 			return;
 		}
 
+		if (this.getDocType() === 'spreadsheet' && docLayer._parts <= docLayer.hiddenParts() + 1) {
+			return;
+		}
+
 		this.fire('deletepage', {
 			selectedPart: docLayer._selectedPart,
 			parts:        docLayer._parts
@@ -269,6 +273,30 @@ L.Map.include({
 		}
 	},
 
+	showPage: function () {
+		if (this.getDocType() === 'spreadsheet' && this.hasAnyHiddenPart()) {
+			this._socket.sendMessage('uno .uno:Show');
+		}
+	},
+
+	hidePage: function () {
+		if (this.getDocType() === 'spreadsheet' && this.getNumberOfVisibleParts() > 1) {
+			this._socket.sendMessage('uno .uno:Hide');
+		}
+	},
+
+	isHiddenPart: function (part) {
+		if (this.getDocType() !== 'spreadsheet')
+			return false;
+		return this._docLayer.isHiddenPart(part);
+	},
+
+	hasAnyHiddenPart: function () {
+		if (this.getDocType() !== 'spreadsheet')
+			return false;
+		return this._docLayer.hasAnyHiddenPart();
+	},
+
 	getNumberOfPages: function () {
 		return this._docLayer._pages;
 	},
@@ -277,6 +305,20 @@ L.Map.include({
 		return this._docLayer._parts;
 	},
 
+	getNumberOfVisibleParts: function () {
+		return this.getNumberOfParts() - this._docLayer.hiddenParts();
+	},
+
+	getHiddenPartNames: function () {
+		var partNames = this._docLayer._partNames;
+		var names = [];
+		for (var i = 0; i < partNames.length; ++i) {
+			if (this.isHiddenPart(i))
+				names.push(partNames[i]);
+		}
+		return names.join(',');
+	},
+
 	getCurrentPageNumber: function () {
 		return this._docLayer._currentPage;
 	},
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 2458fadc7..85fcfe9a4 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -904,6 +904,13 @@ L.Socket = L.Class.extend({
 			else if (tokens[i].substring(0, 10) === 'rectangle=') {
 				command.rectangle = tokens[i].substring(10);
 			}
+			else if (tokens[i].substring(0, 12) === 'hiddenparts=') {
+				var hiddenparts = tokens[i].substring(12).split(',');
+				command.hiddenparts = [];
+				hiddenparts.forEach(function (item) {
+					command.hiddenparts.push(parseInt(item));
+				});
+			}
 		}
 		if (command.tileWidth && command.tileHeight && this._map._docLayer) {
 			var defaultZoom = this._map.options.zoom;
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 4adc14203..a53a6e34a 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -5,8 +5,8 @@
 
 L.CalcTileLayer = L.TileLayer.extend({
 	STD_EXTRA_WIDTH: 113, /* 2mm extra for optimal width,
-                              * 0.1986cm with TeX points,
-                              * 0.1993cm with PS points. */
+							  * 0.1986cm with TeX points,
+							  * 0.1993cm with PS points. */
 
 	twipsToHMM: function (twips) {
 		return (twips * 127 + 36) / 72;
@@ -103,6 +103,23 @@ L.CalcTileLayer = L.TileLayer.extend({
 		}
 	},
 
+	isHiddenPart: function (part) {
+		if (!this._hiddenParts)
+			return false;
+		return this._hiddenParts.indexOf(part) !== -1;
+	},
+
+	hiddenParts: function () {
+		if (!this._hiddenParts)
+			return 0;
+		return this._hiddenParts.length;
+	},
+
+	hasAnyHiddenPart: function () {
+		if (!this._hiddenParts)
+			return false;
+		return this.hiddenParts() !== 0;
+	},
 	_onAnnotationCancel: function (e) {
 		if (e.annotation._data.id === 'new') {
 			this.hideAnnotation(e.annotation._tag);
@@ -333,7 +350,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 
 	_onSetPartMsg: function (textMsg) {
 		var part = parseInt(textMsg.match(/\d+/g)[0]);
-		if (part !== this._selectedPart) {
+		if (part !== this._selectedPart && !this.isHiddenPart(part)) {
 			this._map.setPart(part, true);
 			this._map.fire('setpart', {selectedPart: this._selectedPart});
 			// TODO: test it!
@@ -401,6 +418,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 			else {
 				this._updateMaxBounds(true);
 			}
+			this._hiddenParts = command.hiddenparts || [];
 			this._documentInfo = textMsg;
 			var partNames = textMsg.match(/[^\r\n]+/g);
 			// only get the last matches
@@ -410,6 +428,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 				parts: this._parts,
 				docType: this._docType,
 				partNames: this._partNames,
+				hiddenParts: this._hiddenParts,
 				source: 'status'
 			});
 			this._resetPreFetching(true);
diff --git a/loleaflet/unocommands.js b/loleaflet/unocommands.js
index dca67cbae..1796222bd 100644
--- a/loleaflet/unocommands.js
+++ b/loleaflet/unocommands.js
@@ -78,6 +78,7 @@ var unoCommandsArray = {
 	GroupOutlineMenu:{spreadsheet:{menu:_('~Group and Outline'),},},
 	Grow:{global:{menu:_('Increase Size'),},},
 	HelpMenu:{global:{menu:_('~Help'),},},
+	Hide:{spreadsheet:{menu:_('~Hide Sheet'),},},
 	HideColumn:{spreadsheet:{context:_('H~ide Columns'),menu:_('~Hide'),},},
 	HideDetail:{global:{menu:_('~Hide Details'),},},
 	HideRow:{spreadsheet:{context:_('H~ide Rows'),menu:_('H~ide'),},},
@@ -196,6 +197,7 @@ var unoCommandsArray = {
 	SetOptimalRowHeight:{spreadsheet:{menu:_('~Optimal Height...'),},text:{menu:_('Optimal Row Height'),},},
 	Shadowed:{global:{menu:_('Shadow'),},},
 	SheetMenu:{spreadsheet:{menu:_('~Sheet'),},},
+	Show:{spreadsheet:{menu:_('~Show Sheet...'),},},
 	ShowColumn:{spreadsheet:{context:_('S~how Columns'),menu:_('~Show'),},},
 	ShowDetail:{global:{menu:_('~Show Details'),},},
 	ShowRow:{spreadsheet:{context:_('Sho~w Rows'),menu:_('~Show'),},},
@@ -232,6 +234,7 @@ var unoCommandsArray = {
 	Ungroup:{global:{menu:_('~Ungroup...'),},},
 	UpSearch:{global:{menu:_('Find Previous'),},},
 	UpdateCurIndex:{text:{context:_('Update index'),menu:_('Current ~Index'),},},
+	Validation:{spreadsheet:{menu:_('~Validity...'),},},
 	ViewMenu:{global:{menu:_('~View'),},},
 	WordCountDialog:{text:{menu:_('~Word Count...'),},},
 	WrapAnchorOnly:{text:{menu:_('~First Paragraph'),},},


More information about the Libreoffice-commits mailing list