loleaflet/dist/editor.css             |    3 ++
 loleaflet/dist/toolbar/toolbar.js     |   51 ++++++++++++++++++++++++++++++----
 loleaflet/main.css                    |    1 
 loleaflet/src/layer/tile/TileLayer.js |   23 ++++++++++++++-
 loleaflet/src/map/Map.js              |    6 ++++
 5 files changed, 77 insertions(+), 7 deletions(-)

New commits:
commit 49032d1dab93c74ae57bd92c2a72d019a9340cf6
Author: Aditya Dewan <iit2015...@iiita.ac.in>
Date:   Mon Jun 26 07:16:12 2017 +0530

    tdf#108341 Follow any user from the userlist
    
    Change-Id: Iab6d386f0c0b294dcd5adc9bf654de88a3804933
    Reviewed-on: https://gerrit.libreoffice.org/39247
    Reviewed-by: pranavk <pran...@collabora.co.uk>
    Tested-by: pranavk <pran...@collabora.co.uk>

diff --git a/loleaflet/dist/editor.css b/loleaflet/dist/editor.css
new file mode 100644
index 00000000..be24c214
--- /dev/null
+++ b/loleaflet/dist/editor.css
@@ -0,0 +1,3 @@
+.selected-user {
+       background-color: darkgrey;
+}
\ No newline at end of file
diff --git a/loleaflet/dist/toolbar/toolbar.js 
b/loleaflet/dist/toolbar/toolbar.js
index 50392499..b615af4d 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -1577,15 +1577,38 @@ map.on('keydown', function (e) {
 });
 
 function onUseritemClicked(e) {
+       var docLayer = map._docLayer;
        var viewId = parseInt(e.currentTarget.id.replace('user-', ''));
 
-       if (map._docLayer) {
-               if (map.getDocType() === 'spreadsheet') {
-                       map._docLayer.goToCellViewCursor(viewId);
-               } else if (map.getDocType() === 'text') {
-                       map._docLayer.goToViewCursor(viewId);
-               }
+       if (map.getDocType() === 'spreadsheet') {
+               docLayer.goToCellViewCursor(viewId);
+       } else if (map.getDocType() === 'text' || map.getDocType() === 
'presentation') {
+               docLayer.goToViewCursor(viewId);
        }
+
+       if (viewId === map._docLayer._viewId) {
+               $('#tb_toolbar-down_item_userlist').w2overlay('');
+               return;
+       } else if (docLayer._followThis !== -1) {
+               map.fire('setFollowOff');
+       }
+
+       docLayer._followThis = viewId;
+       docLayer._followUser = true;
+       docLayer._followEditor = false;
+
+       selectUser(viewId);
+}
+
+function selectUser(viewId) {
+       var userlistItem = w2ui['toolbar-down'].get('userlist');
+       userlistItem.html = $(userlistItem.html).find('#user-' + 
viewId).addClass('selected-user').parent().parent().parent()[0].outerHTML;
+       $('#tb_toolbar-down_item_userlist').w2overlay('');
+}
+
+function deselectUser(viewId) {
+       var userlistItem = w2ui['toolbar-down'].get('userlist');
+       userlistItem.html = $(userlistItem.html).find('#user-' + 
viewId).removeClass('selected-user').parent().parent().parent()[0].outerHTML;
 }
 
 function getUserItem(viewId, userName, extraInfo, color) {
@@ -1670,11 +1693,27 @@ map.on('removeview', function(e) {
                userPopupTimeout = null;
        }, 3000);
 
+       if (e.viewId === map._docLayer._followThis) {
+               map._docLayer._followThis = -1;
+               map._docLayer._followUser = false;
+       }
+
        var userlistItem = w2ui['toolbar-down'].get('userlist');
        userlistItem.html = $(userlistItem.html).find('#user-' + 
e.viewId).remove().end()[0].outerHTML;
        updateUserListCount();
 });
 
+map.on('setFollowOff', function(e) {
+       var docLayer = map._docLayer;
+       var viewId = docLayer._followThis;
+       if (viewId !== -1 && map._viewInfo[viewId]) {
+               deselectUser(viewId);
+       }
+       docLayer._followThis = -1;
+       docLayer._followUser = false;
+       docLayer._followEditor = false;
+});
+
 $(window).resize(function() {
        resizeToolbar();
 });
diff --git a/loleaflet/main.css b/loleaflet/main.css
index 1d8ccec4..729b21b3 100644
--- a/loleaflet/main.css
+++ b/loleaflet/main.css
@@ -6,6 +6,7 @@
 @import url('dist/scrollBar.css');
 @import url('dist/searchControl.css');
 @import url('dist/spreadsheet.css');
+@import url('dist/editor.css');
 
 @import url('plugins/draw-0.2.4/dist/leaflet.draw.css');
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 3dfe8ac2..9c20b055 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -142,6 +142,10 @@ L.TileLayer = L.GridLayer.extend({
                        'tiletwipwidth=' + this.options.tileWidthTwips + ' ' +
                        'tiletwipheight=' + this.options.tileHeightTwips;
 
+               this._followThis = -1;
+               this._followUser = false;
+               this._followEditor = false;
+
                // Mark visible area as dirty by default.
                this._invalidateClientVisibleArea();
        },
@@ -702,6 +706,7 @@ L.TileLayer = L.GridLayer.extend({
        },
 
        _onInvalidateCursorMsg: function (textMsg) {
+               var docLayer = this._map._docLayer;
                var strTwips = textMsg.match(/\d+/g);
                var topLeftTwips = new L.Point(parseInt(strTwips[0]), 
parseInt(strTwips[1]));
                var offset = new L.Point(parseInt(strTwips[2]), 
parseInt(strTwips[3]));
@@ -711,6 +716,10 @@ L.TileLayer = L.GridLayer.extend({
                                                
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
                this._visibleCursorOnLostFocus = this._visibleCursor;
                this._isCursorOverlayVisible = true;
+               if ((docLayer._followEditor || docLayer._followUser) && 
this._map.lastActionByUser) {
+                       this._map.fire('setFollowOff');
+               }
+               this._map.lastActionByUser = false;
                this._onUpdateCursor();
        },
 
@@ -718,6 +727,7 @@ L.TileLayer = L.GridLayer.extend({
                textMsg = textMsg.substring('invalidateviewcursor:'.length + 1);
                var obj = JSON.parse(textMsg);
                var viewId = parseInt(obj.viewId);
+               var docLayer = this._map._docLayer;
 
                // Ignore if viewid is same as ours or not in our db
                if (viewId === this._viewId || !this._map._viewInfo[viewId]) {
@@ -741,6 +751,15 @@ L.TileLayer = L.GridLayer.extend({
                }
 
                this._onUpdateViewCursor(viewId);
+
+               if (docLayer._followThis === viewId && (docLayer._followEditor 
|| docLayer._followUser)) {
+                       if (this._map.getDocType() === 'text' || 
this._map.getDocType() === 'presentation') {
+                               this.goToViewCursor(viewId);
+                       }
+                       else if (this._map.getDocType() === 'spreadsheet') {
+                               this.goToCellViewCursor(viewId);
+                       }
+               }
        },
 
        _onCellViewCursorMsg: function (textMsg) {
@@ -1315,6 +1334,7 @@ L.TileLayer = L.GridLayer.extend({
        // Update cursor layer (blinking cursor).
        _onUpdateCursor: function (e) {
                var cursorPos = this._visibleCursor.getNorthWest();
+               var docLayer = this._map._docLayer;
 
                if (!e && !this._map.getBounds().contains(this._visibleCursor) 
&& this._isCursorVisible) {
                        var center = this._map.project(cursorPos);
@@ -1323,7 +1343,8 @@ L.TileLayer = L.GridLayer.extend({
                        center.y = Math.round(center.y < 0 ? 0 : center.y);
 
                        if (!(this._selectionHandles.start && 
this._selectionHandles.start.isDragged) &&
-                           !(this._selectionHandles.end && 
this._selectionHandles.end.isDragged)) {
+                           !(this._selectionHandles.end && 
this._selectionHandles.end.isDragged) &&
+                           !(docLayer._followEditor || docLayer._followUser)) {
                                this._map.fire('scrollto', {x: center.x, y: 
center.y});
                        }
                }
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 29a7cf8e..9df2940e 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -1026,6 +1026,12 @@ L.Map = L.Evented.extend({
                        }
                }
 
+               // we need to keep track about the last action, this
+               // will help us to avoid wrongly removing the editor
+               if (type === 'click' || type === 'keypress') {
+                       this.lastActionByUser = true;
+               }
+
                // we need to keep track if we have entered/left the map
                this._mouseEnteringLeaving = false;
                // mouse leaving the map ?
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to