[Libreoffice-commits] online.git: kit/ChildSession.cpp kit/ChildSession.hpp loleaflet/src wsd/ClientSession.cpp wsd/protocol.txt

Ashod Nakashian (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 17 02:30:24 UTC 2019


 kit/ChildSession.cpp                          |   30 ++++++++++++++++++++++++++
 kit/ChildSession.hpp                          |    1 
 loleaflet/src/control/Control.PartsPreview.js |   12 +++++++++-
 loleaflet/src/control/Parts.js                |   25 ++++++++++++++++++++-
 wsd/ClientSession.cpp                         |   20 +++++++++++++++++
 wsd/protocol.txt                              |    9 +++++++
 6 files changed, 95 insertions(+), 2 deletions(-)

New commits:
commit eaed3615bb08b50a27592346e6e18aa8c438ff0f
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Tue Sep 11 19:30:55 2018 -0400
Commit:     Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Sat Aug 17 04:30:05 2019 +0200

    wsd: loleaflet: select multiple parts
    
    Primarily support for selecting multiple slides
    to edit their properties together.
    
    Change-Id: I96c7ec048668494b5b769677db6874df91cbb42d
    Reviewed-on: https://gerrit.libreoffice.org/69631
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/71095

diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index c3dd0a3ae..fc41597e5 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -228,6 +228,10 @@ bool ChildSession::_handleInput(const char *buffer, int length)
     {
         return setClientPart(buffer, length, tokens);
     }
+    else if (tokens[0] == "selectclientpart")
+    {
+        return selectClientPart(buffer, length, tokens);
+    }
     else if (tokens[0] == "setpage")
     {
         return setPage(buffer, length, tokens);
@@ -1934,6 +1938,32 @@ bool ChildSession::setClientPart(const char* /*buffer*/, int /*length*/, const s
     return true;
 }
 
+bool ChildSession::selectClientPart(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
+{
+    int nPart;
+    int nSelect;
+    if (tokens.size() < 3 ||
+        !getTokenInteger(tokens[1], "part", nPart) ||
+        !getTokenInteger(tokens[2], "how", nSelect))
+    {
+        sendTextFrame("error: cmd=selectclientpart kind=invalid");
+        return false;
+    }
+
+    getLOKitDocument()->setView(_viewId);
+
+    if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT && nPart != getLOKitDocument()->getPart())
+    {
+        getLOKitDocument()->selectPart(nPart, nSelect);
+    }
+    else
+    {
+        LOG_WRN("ChildSession::selectClientPart[" << getName() << "]: error selecting part on text documents.");
+    }
+
+    return true;
+}
+
 bool ChildSession::setPage(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
 {
     int page;
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 3a2f6b3cf..cc5ff6a15 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -268,6 +268,7 @@ private:
     bool resetSelection(const char* buffer, int length, const std::vector<std::string>& tokens);
     bool saveAs(const char* buffer, int length, const std::vector<std::string>& tokens);
     bool setClientPart(const char* buffer, int length, const std::vector<std::string>& tokens);
+    bool selectClientPart(const char* buffer, int length, const std::vector<std::string>& tokens);
     bool setPage(const char* buffer, int length, const std::vector<std::string>& tokens);
     bool sendWindowCommand(const char* buffer, int length, const std::vector<std::string>& tokens);
     bool signDocumentContent(const char* buffer, int length, const std::vector<std::string>& tokens);
diff --git a/loleaflet/src/control/Control.PartsPreview.js b/loleaflet/src/control/Control.PartsPreview.js
index 82aa8af45..3ebe4baaa 100644
--- a/loleaflet/src/control/Control.PartsPreview.js
+++ b/loleaflet/src/control/Control.PartsPreview.js
@@ -138,7 +138,17 @@ L.Control.PartsPreview = L.Control.extend({
 	_setPart: function (e) {
 		var part = $('#slide-sorter .mCSB_container .preview-frame').index(e.target.parentNode);
 		if (part !== null) {
-			this._map.setPart(parseInt(part));
+			var partId = parseInt(part);
+
+			if (e.ctrlKey) {
+				this._map.selectPart(partId, 2, false); // Toggle selection on ctrl+click.
+			} else if (e.altKey) {
+				console.log('alt');
+			} else if (e.shiftKey) {
+				console.log('shift');
+			} else {
+				this._map.setPart(partId);
+			}
 		}
 	},
 
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 1b309146c..49a8de3ec 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -1,6 +1,6 @@
 /* -*- js-indent-level: 8 -*- */
 /*
- * Document parts switching handler
+ * Document parts switching and selecting handler
  */
 L.Map.include({
 	setPart: function (part, external, calledFromSetPartHandler) {
@@ -54,6 +54,29 @@ L.Map.include({
 		}
 	},
 
+	// part is the part index/id
+	// how is 0 to deselect, 1 to select, and 2 to toggle selection
+	selectPart: function (part, how, external) {
+		var docLayer = this._docLayer;
+		if (typeof (part) === 'number' && part >= 0 && part < docLayer._parts) {
+			var selectedPart = part;
+		}
+		else {
+			return;
+		}
+		this.fire('updateparts', {
+			selectedPart: docLayer._selectedPart,
+			parts: docLayer._parts,
+			docType: docLayer._docType
+		});
+
+		// If this wasn't triggered from the server,
+		// then notify the server of the change.
+		if (!external) {
+			this._socket.sendMessage('selectclientpart part=' + selectedPart + ' how=' + how);
+		}
+	},
+
 	getPreview: function (id, index, maxWidth, maxHeight, options) {
 		if (!this._docPreviews) {
 			this._docPreviews = {};
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index bc48cde32..e12f57a46 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -401,6 +401,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
              tokens[0] != "selectgraphic" &&
              tokens[0] != "selecttext" &&
              tokens[0] != "setclientpart" &&
+             tokens[0] != "selectclientpart" &&
              tokens[0] != "setpage" &&
              tokens[0] != "status" &&
              tokens[0] != "tile" &&
@@ -558,6 +559,25 @@ bool ClientSession::_handleInput(const char *buffer, int length)
             }
         }
     }
+    else if (tokens[0] == "selectclientpart")
+    {
+        if(!_isTextDocument)
+        {
+            int part;
+            int how;
+            if (tokens.size() != 3 ||
+                !getTokenInteger(tokens[1], "part", part) ||
+                !getTokenInteger(tokens[2], "how", how))
+            {
+                sendTextFrame("error: cmd=selectclientpart kind=syntax");
+                return false;
+            }
+            else
+            {
+                return forwardToChild(std::string(buffer, length), docBroker);
+            }
+        }
+    }
     else if (tokens[0] == "clientzoom")
     {
         int tilePixelWidth, tilePixelHeight, tileTwipWidth, tileTwipHeight;
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index 02428b7c5..0df5bdb9c 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -140,6 +140,15 @@ setclientpart part=<partNumber>
 
     Informs the server that the client changed to part <partNumber>.
 
+selectclientpart part=<partNumber>
+
+    Informs the server that the client changed the selection state of <partNumber>.
+
+setpage page=<pageNumber>
+
+    Valid only for text documents.
+    Informs the server that the client changed to page <pageNumber>.
+
 status
 
 styles


More information about the Libreoffice-commits mailing list