kit/ChildSession.cpp                          |    9 +++++++--
 kit/ChildSession.hpp                          |    3 +++
 kit/Kit.cpp                                   |   10 ++++++++--
 loleaflet/css/partsPreviewControl.css         |   13 +++++++++++--
 loleaflet/src/control/Control.PartsPreview.js |   11 ++++++++---
 loleaflet/src/control/Parts.js                |   23 +++++++++++++++++------
 loleaflet/src/core/Socket.js                  |    8 ++++----
 loleaflet/src/layer/tile/ImpressTileLayer.js  |    2 ++
 test/WhiteBoxTests.cpp                        |    5 +++++
 9 files changed, 65 insertions(+), 19 deletions(-)

New commits:
commit d45ecd586cc4490d219bf494d9de7b9aedcd2ed5
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Mon Sep 17 06:31:36 2018 -0400
Commit:     Ashod Nakashian <ashnak...@gmail.com>
CommitDate: Sat Aug 17 04:41:36 2019 +0200

    wsd: leaflet: track multi-selection
    
    Change-Id: I17c092e950fb4d7a0cb4129c537d60a8e5edd06a
    Reviewed-on: https://gerrit.libreoffice.org/69636
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/71100

diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index be169fc6f..b044adeba 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -1959,6 +1959,11 @@ bool ChildSession::selectClientPart(const char* 
/*buffer*/, int /*length*/, cons
     if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT && nPart != 
getLOKitDocument()->getPart())
     {
         getLOKitDocument()->selectPart(nPart, nSelect);
+
+        // Notify the client of the selection update.
+        const std::string status = 
LOKitHelper::documentStatus(getLOKitDocument()->get());
+        if (!status.empty())
+            return sendTextFrame("statusupdate: " + status);
     }
     else
     {
@@ -1984,10 +1989,10 @@ bool ChildSession::moveSelectedClientParts(const char* 
/*buffer*/, int /*length*
     {
         getLOKitDocument()->moveSelectedParts(nPosition, false); // Move, 
don't duplicate.
 
-        // Get the status to recreate the previews and correctly order parts.
+        // Get the status to notify clients of the reordering and selection 
change.
         const std::string status = 
LOKitHelper::documentStatus(getLOKitDocument()->get());
         if (!status.empty())
-            return sendTextFrame("statusupdate: " + status);
+            return _docManager->notifyAll("statusupdate: " + status);
     }
     else
     {
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 1d2cd3fdd..4880bc4dc 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -59,6 +59,9 @@ public:
     /// Access to the document instance.
     virtual std::shared_ptr<lok::Document> getLOKitDocument() = 0;
 
+    /// Send msg to all active sessions.
+    virtual bool notifyAll(const std::string& msg) = 0;
+
     /// Send updated view info to all active sessions.
     virtual void notifyViewInfo() = 0;
     virtual void updateEditorSpeeds(int id, int speed) = 0;
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 75d208e64..40fe64ff9 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -1594,6 +1594,13 @@ private:
         return _editorId;
     }
 
+    /// Notify all views with the given message
+    bool notifyAll(const std::string& msg) override
+    {
+        // Broadcast updated viewinfo to all clients.
+        return sendTextFrame("client-all " + msg);
+    }
+
     /// Notify all views of viewId and their associated usernames
     void notifyViewInfo() override
     {
@@ -1641,10 +1648,9 @@ private:
 
         oss.seekp(-1, std::ios_base::cur); // Remove last comma.
         oss << "]";
-        const std::string msg = oss.str();
 
         // Broadcast updated viewinfo to all clients.
-        sendTextFrame("client-all " + msg);
+        notifyAll(oss.str());
     }
 
     void updateEditorSpeeds(int id, int speed) override
diff --git a/loleaflet/css/partsPreviewControl.css 
b/loleaflet/css/partsPreviewControl.css
index 66e47c9bb..39bba0121 100644
--- a/loleaflet/css/partsPreviewControl.css
+++ b/loleaflet/css/partsPreviewControl.css
@@ -27,10 +27,19 @@
        border: 2px solid #dfdfdf;
        }
 
-.preview-img-selected {
-       border-color: #000000;
+/* The current part the user is on. */
+.preview-img-currentpart {
+    border-color: #000000;
+    border-style: solid;
 }
 
+/* One of (potentially many) selected parts, but not the current. */
+.preview-img-selectedpart {
+    border-color: #000000;
+    border-style: dotted;
+}
+
+/* Highlight where a slide can be dropped when reordering by drag-and-drop. */
 .preview-img-dropsite {
     border-bottom: 2px solid red;
 }
diff --git a/loleaflet/src/control/Control.PartsPreview.js 
b/loleaflet/src/control/Control.PartsPreview.js
index 8f0629957..25ffd099d 100644
--- a/loleaflet/src/control/Control.PartsPreview.js
+++ b/loleaflet/src/control/Control.PartsPreview.js
@@ -25,6 +25,7 @@ L.Control.PartsPreview = L.Control.extend({
        _updateDisabled: function (e) {
                var parts = e.parts;
                var selectedPart = e.selectedPart;
+               var selectedParts = e.selectedParts;
                var docType = e.docType;
                if (docType === 'text') {
                        return;
@@ -65,7 +66,7 @@ L.Control.PartsPreview = L.Control.extend({
                                for (var i = 0; i < parts; i++) {
                                        
this._previewTiles.push(this._createPreview(i, e.partNames[i], bottomBound));
                                }
-                               
L.DomUtil.addClass(this._previewTiles[selectedPart], 'preview-img-selected');
+                               
L.DomUtil.addClass(this._previewTiles[selectedPart], 'preview-img-currentpart');
                                this._previewInitialized = true;
                        }
                        else
@@ -76,9 +77,13 @@ L.Control.PartsPreview = L.Control.extend({
 
                                // change the border style of the selected 
preview.
                                for (var j = 0; j < parts; j++) {
-                                       
L.DomUtil.removeClass(this._previewTiles[j], 'preview-img-selected');
+                                       
L.DomUtil.removeClass(this._previewTiles[j], 'preview-img-currentpart');
+                                       
L.DomUtil.removeClass(this._previewTiles[j], 'preview-img-selectedpart');
+                                       if (j === selectedPart)
+                                               
L.DomUtil.addClass(this._previewTiles[j], 'preview-img-currentpart');
+                                       else if (selectedParts.indexOf(j) >= 0)
+                                               
L.DomUtil.addClass(this._previewTiles[j], 'preview-img-selectedpart');
                                }
-                               
L.DomUtil.addClass(this._previewTiles[selectedPart], 'preview-img-selected');
                        }
                }
        },
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 24e57ba55..95e5bc2a0 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -6,6 +6,7 @@ L.Map.include({
        setPart: function (part, external, calledFromSetPartHandler) {
                var docLayer = this._docLayer;
                docLayer._prevSelectedPart = docLayer._selectedPart;
+               docLayer._selectedParts = [];
                if (part === 'prev') {
                        if (docLayer._selectedPart > 0) {
                                docLayer._selectedPart -= 1;
@@ -22,12 +23,17 @@ L.Map.include({
                else {
                        return;
                }
+
+               docLayer._selectedParts.push(docLayer._selectedPart);
+
                if (docLayer.isCursorVisible()) {
                        // a click outside the slide to clear any selection
                        this._socket.sendMessage('resetselection');
                }
+
                this.fire('updateparts', {
                        selectedPart: docLayer._selectedPart,
+                       selectedParts: docLayer._selectedParts,
                        parts: docLayer._parts,
                        docType: docLayer._docType
                });
@@ -57,16 +63,21 @@ 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) {
-               //TODO: Update/track selected parts.
+               //TODO: Update/track selected parts(?).
                var docLayer = this._docLayer;
-               if (typeof (part) === 'number' && part >= 0 && part < 
docLayer._parts) {
-                       var selectedPart = part;
+               var index = docLayer._selectedParts.indexOf(part);
+               if (index >= 0 && how != 1) {
+                       // Remove (i.e. deselect)
+                       docLayer._selectedParts.splice(index, 1);
                }
-               else {
-                       return;
+               else if (how != 0) {
+                       // Add (i.e. select)
+                       docLayer._selectedParts.push(part);
                }
+
                this.fire('updateparts', {
                        selectedPart: docLayer._selectedPart,
+                       selectedParts: docLayer._selectedParts,
                        parts: docLayer._parts,
                        docType: docLayer._docType
                });
@@ -74,7 +85,7 @@ L.Map.include({
                // 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);
+                       this._socket.sendMessage('selectclientpart part=' + 
part + ' how=' + how);
                }
        },
 
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 5488697c9..1b4ba67ca 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -977,10 +977,10 @@ L.Socket = L.Class.extend({
                                });
                        }
                        else if (tokens[i].startsWith('selectedparts=')) {
-                               var selectedparts = 
tokens[i].substring(14).split(',');
-                               command.selectedparts = [];
-                               selectedparts.forEach(function (item) {
-                                       
command.selectedparts.push(parseInt(item));
+                               var selectedParts = 
tokens[i].substring(14).split(',');
+                               command.selectedParts = [];
+                               selectedParts.forEach(function (item) {
+                                       
command.selectedParts.push(parseInt(item));
                                });
                        }
                }
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js 
b/loleaflet/src/layer/tile/ImpressTileLayer.js
index 784c11445..5f2e91ac0 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -633,6 +633,7 @@ L.ImpressTileLayer = L.TileLayer.extend({
                        this._parts = command.parts;
                        this._viewId = parseInt(command.viewid);
                        this._selectedPart = command.selectedPart;
+                       this._selectedParts = command.selectedParts || 
[command.selectedPart];
                        this._resetPreFetching(true);
                        this._update();
                        if (this._preFetchPart !== this._selectedPart) {
@@ -644,6 +645,7 @@ L.ImpressTileLayer = L.TileLayer.extend({
                        this._partHashes = partMatch.slice(partMatch.length - 
this._parts);
                        this._map.fire('updateparts', {
                                selectedPart: this._selectedPart,
+                               selectedParts: this._selectedParts,
                                parts: this._parts,
                                docType: this._docType,
                                partNames: this._partHashes
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index 39aa197e3..fddf5e7bd 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -520,6 +520,11 @@ public:
         return nullptr;
     }
 
+    bool notifyAll(const std::string&) override
+    {
+        return true;
+    }
+
     void notifyViewInfo() override
     {
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to