loleaflet/README | 21 ++-- loleaflet/build/deps.js | 18 +-- loleaflet/debug/document/document_simple_example.html | 3 loleaflet/dist/images/edit.png |binary loleaflet/dist/images/selection.png |binary loleaflet/dist/leaflet.css | 6 - loleaflet/src/control/Buttons.js | 23 ---- loleaflet/src/control/Control.Buttons.js | 64 ++++++++++-- loleaflet/src/control/Control.Fonts.js | 91 ++++++++++++++++++ loleaflet/src/control/Control.Styles.js | 29 +++-- loleaflet/src/control/Permission.js | 8 + loleaflet/src/control/Styles.js | 17 --- loleaflet/src/control/Toolbar.js | 66 +++++++++++++ loleaflet/src/core/Socket.js | 1 loleaflet/src/layer/tile/TileLayer.js | 33 ++++-- loolwsd/LOOLSession.cpp | 59 ++++++++--- loolwsd/LOOLSession.hpp | 6 - 17 files changed, 336 insertions(+), 109 deletions(-)
New commits: commit 9a23b7abb9d851f2f04aea391f47abb8c2191b39 Author: Mihai Varga <mihai.va...@collabora.com> Date: Thu Sep 10 11:29:19 2015 +0300 loleaflet: renamed setStyle to applyStyle diff --git a/loleaflet/README b/loleaflet/README index f3073d7..c9b1144 100644 --- a/loleaflet/README +++ b/loleaflet/README @@ -204,6 +204,7 @@ CommandValues: + returns a JSON mapping of all possible values for the command map.applyFont(fontName) map.applyFontSize(fontSize) + map.applyStyle(style, styleFamily) - events map.on('updatetoolbarcommandvalues', function (e) {}) where + e.commandName = '.uno:StyleAplly', etc diff --git a/loleaflet/src/control/Control.Styles.js b/loleaflet/src/control/Control.Styles.js index c82a892..cfc4133 100644 --- a/loleaflet/src/control/Control.Styles.js +++ b/loleaflet/src/control/Control.Styles.js @@ -59,10 +59,10 @@ L.Control.Styles = L.Control.extend({ return; } if (this._map.getDocType() === 'text') { - this._map.setStyle(style, 'ParagraphStyles'); + this._map.applyStyle(style, 'ParagraphStyles'); } else if (this._map.getDocType() === 'presentation') { - this._map.setStyle(style, 'Default'); + this._map.applyStyle(style, 'Default'); } } }); diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index e3a1bea..16790d4 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -44,7 +44,7 @@ L.Map.include({ 'options=' + options); }, - setStyle: function (style, familyName) { + applyStyle: function (style, familyName) { if (!style || !familyName) { this.fire('error', {cmd: 'setStyle', kind: 'incorrectparam'}); return; commit 87fae7f8547e715f4360e4cac9d8900e772ac2e3 Author: Mihai Varga <mihai.va...@collabora.com> Date: Thu Sep 10 11:26:47 2015 +0300 loleaflet: fonts control diff --git a/loleaflet/README b/loleaflet/README index 864d661..f3073d7 100644 --- a/loleaflet/README +++ b/loleaflet/README @@ -202,6 +202,8 @@ CommandValues: - api: map.getToolbarCommandValues(command) + returns a JSON mapping of all possible values for the command + map.applyFont(fontName) + map.applyFontSize(fontSize) - events map.on('updatetoolbarcommandvalues', function (e) {}) where + e.commandName = '.uno:StyleAplly', etc diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js index 4ac6c3c..dae1e80 100644 --- a/loleaflet/build/deps.js +++ b/loleaflet/build/deps.js @@ -315,6 +315,13 @@ var deps = { desc: 'Handles styles selection' }, + ControlFonts: { + src: ['control/Control.js', + 'control/Control.Fonts.js'], + heading: 'Controls', + desc: 'Handles fonts selection' + }, + ControlAttrib: { src: ['control/Control.js', 'control/Control.Attribution.js'], diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html index 03cd8d8..356dc6a 100644 --- a/loleaflet/debug/document/document_simple_example.html +++ b/loleaflet/debug/document/document_simple_example.html @@ -67,6 +67,7 @@ ////// Controls ///// globalMap.addControl(L.control.styles()); + globalMap.addControl(L.control.fonts()); globalMap.addControl(L.control.buttons()); globalMap.addControl(L.control.zoom()); globalMap.addControl(L.control.parts()); diff --git a/loleaflet/dist/leaflet.css b/loleaflet/dist/leaflet.css index 7923877..b72dd39 100644 --- a/loleaflet/dist/leaflet.css +++ b/loleaflet/dist/leaflet.css @@ -790,7 +790,11 @@ input.leaflet-control-search-bar { padding: 0.3em; } -.leaflet-control-styles { +.leaflet-control-fonts-container { + display: inline; +} + +select { padding: 0.2em 0.4em 0.4em 0em; background-color: white; } diff --git a/loleaflet/src/control/Control.Fonts.js b/loleaflet/src/control/Control.Fonts.js new file mode 100644 index 0000000..b341a4f --- /dev/null +++ b/loleaflet/src/control/Control.Fonts.js @@ -0,0 +1,91 @@ +/* + * L.Control.Fonts is used to display a dropdown list of fonts + */ + +L.Control.Fonts = L.Control.extend({ + options: { + fontsInfo: '- Fonts -', + sizesInfo: '- Sizes -' + }, + + onAdd: function (map) { + var fontsName = 'leaflet-control-fonts'; + var sizesName = 'leaflet-control-sizes'; + this._container = L.DomUtil.create('div', 'leaflet-control-fonts-container'); + this._fontSelect = L.DomUtil.create('select', fontsName + ' leaflet-bar', this._container); + this._sizeSelect = L.DomUtil.create('select', sizesName + ' leaflet-bar', this._container); + + map.on('updatepermission', this._onUpdatePermission, this); + map.on('updatetoolbarcommandvalues', this._initList, this); + L.DomEvent.on(this._fontSelect, 'change', this._onChangeFont, this); + L.DomEvent.on(this._sizeSelect, 'change', this._onChangeSize, this); + + return this._container; + }, + + onRemove: function (map) { + map.off('updatepermission', this._searchResultFound, this); + }, + + _initList: function (e) { + if (e.commandName === '.uno:CharFontName') { + this._commandValues = e.commandValues; + var container = this._fontSelect; + var first = L.DomUtil.create('option', '', container); + first.innerHTML = this.options.fontsInfo; + var fonts = e.commandValues; + for (font in fonts) { + var item = L.DomUtil.create('option', '', container); + item.value = font; + item.innerHTML = font; + }; + + // Don't show any font sizes yet + first = L.DomUtil.create('option', '', this._sizeSelect); + first.innerHTML = this.options.sizesInfo; + } + }, + + _onUpdatePermission: function (e) { + if (e.perm === 'edit') { + this._fontSelect.disabled = false; + this._sizeSelect.disabled = false; + } + else { + this._fontSelect.disabled = true; + this._sizeSelect.disabled = true; + } + }, + + _onChangeFont: function (e) { + var font = e.target.value; + if (font === this.options.fontsInfo) { + return; + } + var container = this._sizeSelect; + for(var i = container.options.length - 1; i >= 0; i--) { + container.remove(i); + } + var first = L.DomUtil.create('option', '', container); + first.innerHTML = this.options.sizesInfo; + var sizes = this._commandValues[font]; + sizes.forEach(function (size) { + var item = L.DomUtil.create('option', '', container); + item.value = size; + item.innerHTML = size; + }); + this._map.applyFont(font); + }, + + _onChangeSize: function (e) { + var size = e.target.value; + if (size === this.options.sizesInfo) { + return; + } + this._map.applyFontSize(size); + } +}); + +L.control.fonts = function (options) { + return new L.Control.Fonts(options); +}; diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index 1331197..e3a1bea 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -5,9 +5,28 @@ L.Map.include({ // a mapping of uno commands to more readable toolbar items unoToolbarCommands: [ + '.uno:CharFontName', '.uno:StyleApply' ], + applyFont: function (fontName) { + if (this.getPermission() === 'edit') { + var msg = 'uno .uno:CharFontName {' + + '"CharFontName.FamilyName": ' + + '{"type": "string", "value": "' + fontName + '"}}'; + L.Socket.sendMessage(msg); + } + }, + + applyFontSize: function (fontSize) { + if (this.getPermission() === 'edit') { + var msg = 'uno .uno:FontHeight {' + + '"FontHeight.Height": ' + + '{"type": "float", "value": "' + fontSize + '"}}'; + L.Socket.sendMessage(msg); + } + }, + getToolbarCommandValues: function (command) { return this._docLayer._toolbarCommandValues[command]; }, commit d7251aabefaf7642f47f9fd9a8405dba36ab5cb8 Author: Mihai Varga <mihai.va...@collabora.com> Date: Thu Sep 10 10:24:40 2015 +0300 loleaflet: show styles depending on docType diff --git a/loleaflet/src/control/Control.Styles.js b/loleaflet/src/control/Control.Styles.js index 436d3c1..c82a892 100644 --- a/loleaflet/src/control/Control.Styles.js +++ b/loleaflet/src/control/Control.Styles.js @@ -4,7 +4,7 @@ L.Control.Styles = L.Control.extend({ options: { - info: '- Please select a style -' + info: '- Styles -' }, onAdd: function (map) { @@ -27,14 +27,20 @@ L.Control.Styles = L.Control.extend({ var container = this._container; var first = L.DomUtil.create('option', '', container); first.innerHTML = this.options.info; - if (this._map._docLayer._docType === 'text') { - var styles = e.commandValues.ParagraphStyles.slice(0, 12); - styles.forEach(function (style) { - var item = L.DomUtil.create('option', '', container); - item.value = style; - item.innerHTML = style; - }); + if (this._map.getDocType() === 'text') { + var styles = e.commandValues['ParagraphStyles'].slice(0, 12); } + else if (this._map.getDocType() === 'presentation') { + styles = e.commandValues['Default']; + } + else { + styles = []; + } + styles.forEach(function (style) { + var item = L.DomUtil.create('option', '', container); + item.value = style; + item.innerHTML = style; + }); } }, @@ -52,9 +58,12 @@ L.Control.Styles = L.Control.extend({ if (style === this.options.info) { return; } - if (this._map._docLayer._docType === 'text') { + if (this._map.getDocType() === 'text') { this._map.setStyle(style, 'ParagraphStyles'); } + else if (this._map.getDocType() === 'presentation') { + this._map.setStyle(style, 'Default'); + } } }); commit c904486115109ea07b45fbbd7c1ce0a5a72d0e7b Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 20:35:36 2015 +0300 loleaflet: use the commandvalues server cmd diff --git a/loleaflet/README b/loleaflet/README index cd97f1d..864d661 100644 --- a/loleaflet/README +++ b/loleaflet/README @@ -191,15 +191,6 @@ Writer pages: map.on('invalidatepreview', function (e) {}) + e.id = the preview's id -Styles: - - API: - map.getStyles() - + returns a JSON object as a mapping of style families to a list of styles - map.setStyle(style, familyName) - - events: - map.on('updatestyles', function (e) {}) where: - e.styles = a JSON object as a mapping of style families to a list of styles - Error: - events map.on('error', function (e) {}) where @@ -207,6 +198,15 @@ Error: + [e.cmd] = the command that caused the error + [e.kind] = the kind of error +CommandValues: + - api: + map.getToolbarCommandValues(command) + + returns a JSON mapping of all possible values for the command + - events + map.on('updatetoolbarcommandvalues', function (e) {}) where + + e.commandName = '.uno:StyleAplly', etc + + e.commandValues = a JSON mapping of all possible values for the command + Testing ------- - to simulate an editing session and to get the tile loading times diff --git a/loleaflet/src/control/Control.Styles.js b/loleaflet/src/control/Control.Styles.js index 27708ed..436d3c1 100644 --- a/loleaflet/src/control/Control.Styles.js +++ b/loleaflet/src/control/Control.Styles.js @@ -12,7 +12,7 @@ L.Control.Styles = L.Control.extend({ this._container = L.DomUtil.create('select', stylesName + ' leaflet-bar'); map.on('updatepermission', this._onUpdatePermission, this); - map.on('updatestyles', this._initList, this); + map.on('updatetoolbarcommandvalues', this._initList, this); L.DomEvent.on(this._container, 'change', this._onChange, this); return this._container; @@ -23,16 +23,18 @@ L.Control.Styles = L.Control.extend({ }, _initList: function (e) { - var container = this._container; - var first = L.DomUtil.create('option', '', container); - first.innerHTML = this.options.info; - if (this._map._docLayer._docType === 'text') { - var styles = e.styles.ParagraphStyles.slice(0, 12); - styles.forEach(function (style) { - var item = L.DomUtil.create('option', '', container); - item.value = style; - item.innerHTML = style; - }); + if (e.commandName === '.uno:StyleApply') { + var container = this._container; + var first = L.DomUtil.create('option', '', container); + first.innerHTML = this.options.info; + if (this._map._docLayer._docType === 'text') { + var styles = e.commandValues.ParagraphStyles.slice(0, 12); + styles.forEach(function (style) { + var item = L.DomUtil.create('option', '', container); + item.value = style; + item.innerHTML = style; + }); + } } }, diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index cce5bc6..1331197 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -4,12 +4,12 @@ L.Map.include({ // a mapping of uno commands to more readable toolbar items - unoToolbarCommands: { - '.uno:StyleApply': 'styles' - }, + unoToolbarCommands: [ + '.uno:StyleApply' + ], - getStyles: function () { - return this._docLayer._docStyles; + getToolbarCommandValues: function (command) { + return this._docLayer._toolbarCommandValues[command]; }, saveAs: function (url, format, options) { diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 4e2846f..57852d7 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -52,7 +52,6 @@ L.Socket = { } this.socket.send(msg); this.socket.send('status'); - this.socket.send('styles'); for (var i = 0; i < this._msgQueue.length; i++) { this.socket.send(this._msgQueue[i].msg); L.Log.log(this._msgQueue[i].msg, this._msgQueue[i].coords); diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 2050675..bd22086 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -91,10 +91,12 @@ L.TileLayer = L.GridLayer.extend({ }); this._emptyTilesCount = 0; this._msgQueue = []; + this._toolbarCommandValues = {}; }, onAdd: function (map) { this._initContainer(); + this._getToolbarCommandsValues(); this._selections = new L.LayerGroup(); map.addLayer(this._selections); @@ -173,8 +175,18 @@ L.TileLayer = L.GridLayer.extend({ return tile; }, + _getToolbarCommandsValues: function() { + for (var i = 0; i < this._map.unoToolbarCommands.length; i++) { + var command = this._map.unoToolbarCommands[i]; + L.Socket.sendMessage('commandvalues command=' + command); + } + }, + _onMessage: function (textMsg, img) { - if (textMsg.startsWith('cursorvisible:')) { + if (textMsg.startsWith('commandvalues:')) { + this._onCommandValuesMsg(textMsg); + } + else if (textMsg.startsWith('cursorvisible:')) { this._onCursorVisibleMsg(textMsg); } else if (textMsg.startsWith('error:')) { @@ -204,9 +216,6 @@ L.TileLayer = L.GridLayer.extend({ else if (textMsg.startsWith('statusindicator')) { this._onStatusIndicatorMsg(textMsg); } - else if (textMsg.startsWith('styles:')) { - this._onStylesMsg(textMsg); - } else if (textMsg.startsWith('textselection:')) { this._onTextSelectionMsg(textMsg); } @@ -224,6 +233,17 @@ L.TileLayer = L.GridLayer.extend({ } }, + _onCommandValuesMsg: function (textMsg) { + var obj = JSON.parse(textMsg.substring(textMsg.indexOf('{'))); + if (this._map.unoToolbarCommands.indexOf(obj.commandName) !== -1) { + this._toolbarCommandValues[obj.commandName] = obj.commandValues; + this._map.fire('updatetoolbarcommandvalues', { + commandName: obj.commandName, + commandValues: obj.commandValues + }); + } + }, + _onCursorVisibleMsg: function(textMsg) { var command = textMsg.match('cursorvisible: true'); this._isCursorVisible = command ? true : false; @@ -292,11 +312,6 @@ L.TileLayer = L.GridLayer.extend({ } }, - _onStylesMsg: function (textMsg) { - this._docStyles = JSON.parse(textMsg.substring(8)); - this._map.fire('updatestyles', {styles: this._docStyles}); - }, - _onTextSelectionMsg: function (textMsg) { var strTwips = textMsg.match(/\d+/g); this._selections.clearLayers(); commit d1ecdbc3df047ee9d42429a25a61ba0ec90f1612 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 20:23:49 2015 +0300 loolwsd: parse the `commandvalues` command and cache the values The values are chaced in the file named "cmdValues" + unoCmd + ".txt" diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index 06efe26..233e999 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -28,8 +28,11 @@ #include <LibreOfficeKit/LibreOfficeKit.h> #include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <Poco/Dynamic/Var.h> #include <Poco/Exception.h> #include <Poco/File.h> +#include <Poco/JSON/Object.h> +#include <Poco/JSON/Parser.h> #include <Poco/Net/HTTPStreamFactory.h> #include <Poco/Net/WebSocket.h> #include <Poco/Path.h> @@ -57,8 +60,11 @@ using namespace LOOLProtocol; +using Poco::Dynamic::Var; using Poco::File; using Poco::IOException; +using Poco::JSON::Object; +using Poco::JSON::Parser; using Poco::Net::HTTPStreamFactory; using Poco::Net::WebSocket; using Poco::Path; @@ -198,9 +204,15 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) { peer->_tileCache->saveTextFile(std::string(buffer, length), "status.txt"); } - else if (tokens[0] == "styles:") + else if (tokens[0] == "commandvalues:") { - peer->_tileCache->saveTextFile(std::string(buffer, length), "styles.txt"); + std::string stringMsg(buffer); + std::string stringJSON = stringMsg.substr(stringMsg.find_first_of("{")); + Parser parser; + Var result = parser.parse(stringJSON); + Object::Ptr object = result.extract<Object::Ptr>(); + std::string commandName = object->get("commandName").toString(); + peer->_tileCache->saveTextFile(std::string(buffer, length), "cmdValues" + commandName + ".txt"); } else if (tokens[0] == "invalidatetiles:") { @@ -270,6 +282,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) return loadDocument(buffer, length, tokens); } else if (tokens[0] != "canceltiles" && + tokens[0] != "commandvalues" && tokens[0] != "gettextselection" && tokens[0] != "invalidatetiles" && tokens[0] != "key" && @@ -282,7 +295,6 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) tokens[0] != "setclientpart" && tokens[0] != "setpage" && tokens[0] != "status" && - tokens[0] != "styles" && tokens[0] != "tile" && tokens[0] != "uno") { @@ -299,6 +311,10 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) if (!_peer.expired()) forwardToPeer(buffer, length); } + else if (tokens[0] == "commandvalues") + { + return getCommandValues(buffer, length, tokens); + } else if (tokens[0] == "invalidatetiles") { return invalidateTiles(buffer, length, tokens); @@ -307,10 +323,6 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) { return getStatus(buffer, length); } - else if (tokens[0] == "styles") - { - return getStyles(buffer, length); - } else if (tokens[0] == "tile") { sendTile(buffer, length, tokens); @@ -420,14 +432,19 @@ bool MasterProcessSession::getStatus(const char *buffer, int length) return true; } -bool MasterProcessSession::getStyles(const char *buffer, int length) +bool MasterProcessSession::getCommandValues(const char *buffer, int length, StringTokenizer& tokens) { - std::string styles; + std::string command; + if (tokens.count() != 2 || !getTokenString(tokens[1], "command", command)) + { + sendTextFrame("error: cmd=commandvalues kind=syntax"); + return false; + } - styles = _tileCache->getTextFile("styles.txt"); - if (styles.size() > 0) + std::string cmdValues = _tileCache->getTextFile("cmdValues" + command + ".txt"); + if (cmdValues.size() > 0) { - sendTextFrame(styles); + sendTextFrame(cmdValues); return true; } @@ -612,6 +629,10 @@ bool ChildProcessSession::handleInput(const char *buffer, int length) Application::instance().logger().information(Util::logPrefix() + _kindString + ",Input," + getAbbreviatedMessage(buffer, length)); + if (tokens[0] == "commandvalues") + { + return getCommandValues(buffer, length, tokens); + } if (tokens[0] == "load") { if (_docURL != "") @@ -638,10 +659,6 @@ bool ChildProcessSession::handleInput(const char *buffer, int length) { return getStatus(buffer, length); } - else if (tokens[0] == "styles") - { - return getStyles(buffer, length); - } else if (tokens[0] == "tile") { sendTile(buffer, length, tokens); @@ -866,9 +883,15 @@ bool ChildProcessSession::getStatus(const char *buffer, int length) return true; } -bool ChildProcessSession::getStyles(const char *buffer, int length) +bool ChildProcessSession::getCommandValues(const char *buffer, int length, StringTokenizer& tokens) { - sendTextFrame("styles: " + std::string(_loKitDocument->pClass->getStyles(_loKitDocument))); + std::string command; + if (tokens.count() != 2 || !getTokenString(tokens[1], "command", command)) + { + sendTextFrame("error: cmd=commandvalues kind=syntax"); + return false; + } + sendTextFrame("commandvalues: " + std::string(_loKitDocument->pClass->getCommandValues(_loKitDocument, command.c_str()))); return true; } diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp index fdd4008..247012c 100644 --- a/loolwsd/LOOLSession.hpp +++ b/loolwsd/LOOLSession.hpp @@ -45,7 +45,7 @@ public: virtual bool getStatus(const char *buffer, int length) = 0; - virtual bool getStyles(const char *buffer, int length) = 0; + virtual bool getCommandValues(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0; virtual bool handleInput(const char *buffer, int length) = 0; @@ -111,7 +111,7 @@ public: virtual bool getStatus(const char *buffer, int length); - virtual bool getStyles(const char *buffer, int length); + virtual bool getCommandValues(const char *buffer, int length, Poco::StringTokenizer& tokens); protected: bool invalidateTiles(const char *buffer, int length, Poco::StringTokenizer& tokens); @@ -159,7 +159,7 @@ public: virtual bool getStatus(const char *buffer, int length); - virtual bool getStyles(const char *buffer, int length); + virtual bool getCommandValues(const char *buffer, int length, Poco::StringTokenizer& tokens); LibreOfficeKitDocument *_loKitDocument; std::string _docType; commit 3fc7766d7d6991730197b5e6a588d8225e973724 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 19:54:32 2015 +0300 loleaflet: fixed typo diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index f07e68d..cce5bc6 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -5,7 +5,7 @@ L.Map.include({ // a mapping of uno commands to more readable toolbar items unoToolbarCommands: { - 'uno.StyleApply': 'styles' + '.uno:StyleApply': 'styles' }, getStyles: function () { commit c10b6da7a12e37b7db5b2293bd64798b50243b47 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 19:48:10 2015 +0300 loleaflet: only set the style in editing mode diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index 02a7325..f07e68d 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -30,11 +30,13 @@ L.Map.include({ this.fire('error', {cmd: 'setStyle', kind: 'incorrectparam'}); return; } - var msg = 'uno .uno:StyleApply {' + - '"Style":{"type":"string", "value": "' + style + '"},' + - '"FamilyName":{"type":"string", "value":"' + familyName + '"}' + - '}'; - L.Socket.sendMessage(msg); + if (this._docLayer._permission === 'edit') { + var msg = 'uno .uno:StyleApply {' + + '"Style":{"type":"string", "value": "' + style + '"},' + + '"FamilyName":{"type":"string", "value":"' + familyName + '"}' + + '}'; + L.Socket.sendMessage(msg); + } }, toggleCommandState: function (unoState) { commit a9f5209f5a575c467f1752c10863b0b852331943 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 19:46:39 2015 +0300 loleaflet: uno command alias for the toolbar diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index e255bf4..02a7325 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -2,6 +2,12 @@ * Toolbar handler */ L.Map.include({ + + // a mapping of uno commands to more readable toolbar items + unoToolbarCommands: { + 'uno.StyleApply': 'styles' + }, + getStyles: function () { return this._docLayer._docStyles; }, commit abe296c0b9a23aeecca66a7674da20042b8b2163 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 19:36:11 2015 +0300 loleaflet: buttons for enabiling editing / selection mode Use those instead of the checkboxes to save some space in the toolbar diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html index eaa173a..03cd8d8 100644 --- a/loleaflet/debug/document/document_simple_example.html +++ b/loleaflet/debug/document/document_simple_example.html @@ -71,8 +71,6 @@ globalMap.addControl(L.control.zoom()); globalMap.addControl(L.control.parts()); globalMap.addControl(L.control.search()); - globalMap.addControl(L.control.permissionSwitch()); - globalMap.addControl(L.control.selection()); globalMap.addControl(L.control.statusIndicator()); globalMap.addControl(L.control.scroll()); globalMap.addControl(L.control.dialog()); diff --git a/loleaflet/dist/images/edit.png b/loleaflet/dist/images/edit.png new file mode 100644 index 0000000..d0dfaa5 Binary files /dev/null and b/loleaflet/dist/images/edit.png differ diff --git a/loleaflet/dist/images/selection.png b/loleaflet/dist/images/selection.png new file mode 100644 index 0000000..f9121b9 Binary files /dev/null and b/loleaflet/dist/images/selection.png differ diff --git a/loleaflet/src/control/Control.Buttons.js b/loleaflet/src/control/Control.Buttons.js index dd7625c..f2622cb 100644 --- a/loleaflet/src/control/Control.Buttons.js +++ b/loleaflet/src/control/Control.Buttons.js @@ -21,11 +21,13 @@ L.Control.Buttons = L.Control.extend({ 'alignright': {title: 'Align right', uno: 'RightPara', iconName: 'alignright.png'}, 'alignblock': {title: 'Justified', uno: 'JustifyPara', iconName: 'alignblock.png'}, 'save': {title: 'Save', uno: 'Save', iconName: 'save.png'}, - 'saveas': {title: 'Save As', uno: '', iconName: 'saveas.png'} + 'saveas': {title: 'Save As', iconName: 'saveas.png'}, + 'edit': {title: 'Enable editing', iconName: 'edit.png'}, + 'selection': {title: 'Enable selection', iconName: 'selection.png'} }; for (var key in this._buttons) { var button = this._buttons[key]; - if (key === 'alignleft' || key === 'save') { + if (key === 'alignleft' || key === 'save' || key === 'edit') { // add a separator L.DomUtil.create('span', 'leaflet-control-button-separator', container); } @@ -65,9 +67,27 @@ L.Control.Buttons = L.Control.extend({ callback: L.bind(this._onSaveAs, this) }); } - else if (this._map._docLayer._permission === 'edit') { + else if (button.uno && this._map._docLayer._permission === 'edit') { this._map.toggleCommandState(button.uno); } + else if (id === 'edit' && !L.DomUtil.hasClass(button.el.firstChild, 'leaflet-control-buttons-disabled')) { + if (this._map.getPermission() === 'edit') { + this._map.setPermission('view'); + } + else if (this._map.getPermission() === 'view') { + this._map.setPermission('edit'); + } + } + else if (id === 'selection' && !L.DomUtil.hasClass(button.el.firstChild, 'leaflet-control-buttons-disabled')) { + if (this._map.isSelectionEnabled()) { + this._map.disableSelection(); + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-active'); + } + else { + this._map.enableSelection(); + L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-active'); + } + } }, _onStateChange: function (e) { @@ -109,13 +129,39 @@ L.Control.Buttons = L.Control.extend({ }, _onPermissionUpdate: function (e) { - for (var key in this._buttons) { - var button = this._buttons[key]; - if (e.perm !== 'edit') { - L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + for (var id in this._buttons) { + var button = this._buttons[id]; + if (button.uno) { + if (e.perm !== 'edit') { + L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } + else { + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } } - else { - L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + else if (id === 'edit') { + if (e.perm === 'edit') { + L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-active'); + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } + else if (e.perm === 'view') { + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-active'); + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } + else if (e.perm === 'readonly') { + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-active'); + L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } + } + else if (id === 'selection') { + if (e.perm === 'edit') { + L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-active'); + L.DomUtil.addClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } + else if (e.perm === 'view' || e.perm === 'readonly') { + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-active'); + L.DomUtil.removeClass(button.el.firstChild, 'leaflet-control-buttons-disabled'); + } } } } commit f735791f4ea330742eda5a76bb4a2f401f413589 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 19:34:59 2015 +0300 loleaflet: method for getting the permission & mouse selection status diff --git a/loleaflet/src/control/Permission.js b/loleaflet/src/control/Permission.js index 5bb8a9a..b0689e5 100644 --- a/loleaflet/src/control/Permission.js +++ b/loleaflet/src/control/Permission.js @@ -31,5 +31,13 @@ L.Map.include({ return; } this.dragging.enable(); + }, + + isSelectionEnabled: function () { + return !this.dragging.enabled(); + }, + + getPermission: function () { + return this._docLayer._permission; } }); commit baa0806b7cc752e5d9e3a47513cf28c776c3cc74 Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 18:59:53 2015 +0300 loleaflet: moved the style formating methods in Toolbar.js diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js index b55b129..4ac6c3c 100644 --- a/loleaflet/build/deps.js +++ b/loleaflet/build/deps.js @@ -358,11 +358,6 @@ var deps = { desc: 'Scroll handler.' }, - Styles: { - src: ['control/Styles.js'], - desc: 'Document styles handler.' - }, - AnimationPan: { src: [ 'dom/DomEvent.js', diff --git a/loleaflet/src/control/Styles.js b/loleaflet/src/control/Styles.js deleted file mode 100644 index 2e37af2..0000000 --- a/loleaflet/src/control/Styles.js +++ /dev/null @@ -1,17 +0,0 @@ -L.Map.include({ - getStyles: function () { - return this._docLayer._docStyles; - }, - - setStyle: function (style, familyName) { - if (!style || !familyName) { - this.fire('error', {cmd: 'setStyle', kind: 'incorrectparam'}); - return; - } - var msg = 'uno .uno:StyleApply {' + - '"Style":{"type":"string", "value": "' + style + '"},' + - '"FamilyName":{"type":"string", "value":"' + familyName + '"}' + - '}'; - L.Socket.sendMessage(msg); - } -}); diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index 4385dcc..e255bf4 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -2,10 +2,8 @@ * Toolbar handler */ L.Map.include({ - toggleCommandState: function (unoState) { - if (this._docLayer._permission === 'edit') { - L.Socket.sendMessage('uno .uno:' + unoState); - } + getStyles: function () { + return this._docLayer._docStyles; }, saveAs: function (url, format, options) { @@ -19,5 +17,23 @@ L.Map.include({ 'url=' + url + ' ' + 'format=' + format + ' ' + 'options=' + options); + }, + + setStyle: function (style, familyName) { + if (!style || !familyName) { + this.fire('error', {cmd: 'setStyle', kind: 'incorrectparam'}); + return; + } + var msg = 'uno .uno:StyleApply {' + + '"Style":{"type":"string", "value": "' + style + '"},' + + '"FamilyName":{"type":"string", "value":"' + familyName + '"}' + + '}'; + L.Socket.sendMessage(msg); + }, + + toggleCommandState: function (unoState) { + if (this._docLayer._permission === 'edit') { + L.Socket.sendMessage('uno .uno:' + unoState); + } } }); commit 95463adc442368b80dcd6d4e5ddb84d16bd1b02d Author: Mihai Varga <mihai.va...@collabora.com> Date: Wed Sep 9 18:47:14 2015 +0300 loleaflet: created a general toolbar methods handler diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js index c35d667..b55b129 100644 --- a/loleaflet/build/deps.js +++ b/loleaflet/build/deps.js @@ -343,9 +343,9 @@ var deps = { desc: 'Permission change handler (edit, view, readonly).' }, - Buttons: { - src: ['control/Buttons.js'], - desc: 'Toolbar buttons handler.' + Toolbar: { + src: ['control/Toolbar.js'], + desc: 'Toolbar handler.' }, Parts: { diff --git a/loleaflet/src/control/Buttons.js b/loleaflet/src/control/Toolbar.js similarity index 94% rename from loleaflet/src/control/Buttons.js rename to loleaflet/src/control/Toolbar.js index d9327c8..4385dcc 100644 --- a/loleaflet/src/control/Buttons.js +++ b/loleaflet/src/control/Toolbar.js @@ -1,5 +1,5 @@ /* - * Toolbar buttons handler + * Toolbar handler */ L.Map.include({ toggleCommandState: function (unoState) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits