[Libreoffice-commits] online.git: 2 commits - loleaflet/build loleaflet/dist loleaflet/src
Pranav Kant
pranavk at collabora.co.uk
Wed May 3 15:52:03 UTC 2017
loleaflet/build/deps.js | 5 +
loleaflet/dist/menubar.css | 16 ++++
loleaflet/dist/toolbar/toolbar.js | 89 +++++++++-----------------
loleaflet/src/control/Control.Menubar.js | 17 ++--
loleaflet/src/map/handler/Map.StateChanges.js | 44 ++++++++++++
5 files changed, 104 insertions(+), 67 deletions(-)
New commits:
commit e032cb72fa230f27a9a90f0b74411b9a3c63c96e
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed May 3 21:18:36 2017 +0530
tdf#106447: Support checked items in menubar
Bin the internal command state recorder to Menubar and use the global
state recorder available in the map.
Change-Id: I32e81700e38c2d544b2d874e6a30fbe58e8d43bd
diff --git a/loleaflet/dist/menubar.css b/loleaflet/dist/menubar.css
index 70fdaee7..eb115d77 100644
--- a/loleaflet/dist/menubar.css
+++ b/loleaflet/dist/menubar.css
@@ -62,7 +62,7 @@
cursor: default;
}
.lo-menu a, .lo-menu a:hover, .lo-menu a:focus, .lo-menu a:active, .lo-menu a.highlighted {
- padding: 5px 15px;
+ padding: 5px 22px;
color: #000;
}
.lo-menu a:hover, .lo-menu a:focus, .lo-menu a:active, .lo-menu a.highlighted {
@@ -226,3 +226,17 @@
top: 3px; /* This is not a menu, plain action, but we want it to appear like a menu */
}
}
+
+/* Some more lo-menu specific customizations */
+
+/* The smartmenus plugin doesn't seem to have support for icons, so implement our own pseudo-elements */
+.lo-menu-item-checked::before {
+ position: absolute;
+ content: '\2713';
+ left: 5px;
+ top: 5px;
+}
+
+.lo-menu-item-checked:hover::before {
+ color: #fff;
+}
diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index 4cbc6b71..89048a3b 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -296,15 +296,6 @@ L.Control.Menubar = L.Control.extend({
this._menubarCont = L.DomUtil.get('main-menu');
map.on('doclayerinit', this._onDocLayerInit, this);
- map.on('commandstatechanged', this._onCommandStateChanged, this);
- },
-
- _onCommandStateChanged: function(e) {
- // Store information about enabled/disabled commands
- // Used later just before showing menu to enable/disable menu items
- if (e.state === 'enabled' || e.state === 'disabled') {
- this.options.commandStates[e.commandName] = e.state;
- }
},
_onDocLayerInit: function() {
@@ -382,11 +373,17 @@ L.Control.Menubar = L.Control.extend({
if (map._permission === 'edit') {
if (type === 'unocommand') { // enable all depending on stored commandStates
var unoCommand = $(aItem).data('uno');
- if (self.options.commandStates[unoCommand] === 'disabled') {
+ if (map['stateChangeHandler'].getItemValue(unoCommand) === 'disabled') {
$(aItem).addClass('disabled');
} else {
$(aItem).removeClass('disabled');
}
+
+ if (map['stateChangeHandler'].getItemValue(unoCommand) === 'true') {
+ $(aItem).addClass('lo-menu-item-checked');
+ } else {
+ $(aItem).removeClass('lo-menu-item-checked');
+ }
} else if (type === 'action') { // enable all except fullscreen on windows
if (id === 'fullscreen' && (L.Browser.ie || L.Browser.edge)) { // Full screen works weirdly on IE 11 and on Edge
$(aItem).addClass('disabled');
commit ffaf42410389ba750125eaf51651983d1ce71fab
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed May 3 19:31:07 2017 +0530
loleaflet: Store state change handlers in new stateChangeHandler class
... instead of having this logic in our toolbar. All the elements like
menubar or toolbar can then use the map store to see the value of last
state change event for any particular uno command. We will be using it
when menubar starts using this store.
The frivolous logic in toolbar of reading the value of last uno command
should be removed. We don't expect loleaflet to change the permission
dynamically after loading the document anymore. But for now, just change
it accordingly and defer the task of removing it when we refactor
loleaflet codebase to trim our permission model (remove the 'view'
mode).
Change-Id: I1be54a62e96179b7db3f61470a92e3ddc745f52d
diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 34575612..e671dea3 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -248,6 +248,11 @@ var deps = {
desc: 'Handles inserting a file (image) in the document.'
},
+ StateChanges: {
+ src: ['map/handler/Map.StateChanges.js'],
+ desc: 'Handles state changes for the opened document'
+ },
+
WOPI: {
src: ['map/handler/Map.WOPI.js'],
desc: 'Handles WOPI related logic.'
diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js
index 6e596511..793bd910 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -438,11 +438,6 @@ function onColorPick(e, color) {
map.focus();
}
-// This object is used to store enabled/disabled state of each and every eligible item
-// (i.e the one having UNO command) of toolbar-up. When the permission is changed to/from
-// edit/view mode, state from this object is read and then applied on corresponding buttons
-var formatButtons = {};
-
var stylesSelectValue;
var fontsSelectValue;
var fontsizesSelectValue;
@@ -609,15 +604,6 @@ $(function () {
}
}
- // Intialize the formatButtons object
- if (Object.keys(formatButtons).length === 0) {
- for (var itemIdx in w2ui['toolbar-up'].items) {
- if (w2ui['toolbar-up'].items[itemIdx].uno) {
- formatButtons[w2ui['toolbar-up'].items[itemIdx].id] = true;
- }
- }
- }
-
updateCommandValues();
insertTable();
@@ -1198,41 +1184,28 @@ map.on('commandstatechanged', function (e) {
}
var id = unoCmdToToolbarId(commandName);
- if (typeof formatButtons[id] !== 'undefined') {
- if (state === 'true') {
- toolbar.enable(id);
- toolbar.check(id);
- toolbarUpMore.check(id);
- }
- else if (state === 'false') {
+ if (state === 'true') {
+ toolbar.enable(id);
+ toolbar.check(id);
+ toolbarUpMore.check(id);
+ }
+ else if (state === 'false') {
+ toolbar.enable(id);
+ toolbar.uncheck(id);
+ toolbarUpMore.uncheck(id);
+ }
+ // Change the toolbar button states if we are in editmode
+ // If in non-edit mode, will be taken care of when permission is changed to 'edit'
+ else if (map._permission === 'edit' && (state === 'enabled' || state === 'disabled')) {
+ // in case some buttons are in toolbar-up-more, find
+ // them and en/dis-able them.
+ if (state === 'enabled') {
toolbar.enable(id);
+ toolbarUpMore.enable(id);
+ } else {
toolbar.uncheck(id);
- toolbarUpMore.uncheck(id);
- }
- // only store the state for now;
- // buttons with stored state === enabled will
- // be enabled later (if we are in editmode)
- // If we are in viewmode, these store states will be used
- // when we get the edit access
- else if (state === 'enabled') {
- formatButtons[id] = true;
- }
- else if (state === 'disabled') {
- formatButtons[id] = false;
- }
-
- // Change the toolbar button states immediately if we are in editmode
- if (map._permission === 'edit' && (state === 'enabled' || state === 'disabled')) {
- // in case some buttons are in toolbar-up-more, find
- // them and en/dis-able them.
- if (formatButtons[id]) {
- toolbar.enable(id);
- toolbarUpMore.enable(id);
- } else {
- toolbar.uncheck(id);
- toolbar.disable(id);
- toolbarUpMore.disable(id);
- }
+ toolbar.disable(id);
+ toolbarUpMore.disable(id);
}
}
@@ -1455,16 +1428,20 @@ map.on('updatepermission', function (e) {
var toolbar = w2ui['toolbar-up'];
var toolbarUpMore = w2ui['toolbar-up-more'];
- // {En,Dis}able toolbar buttons
- for (var id in formatButtons) {
- if (e.perm === 'edit' && formatButtons[id]) {
- // restore the state from stored object (formatButtons)
- toolbar.enable(id);
- // some might be hidden in toolbar-up-more
- toolbarUpMore.enable(id);
+ // copy the first array
+ var items = toolbar.items.slice();
+ items.concat(toolbarUpMore.items);
+ for (var idx in items) {
+ var unoCmd = map.getDocType() === 'spreadsheet' ? items[idx].unosheet : items[idx].uno;
+ var keepDisabled = map['stateChangeHandler'].getItemValue(unoCmd) === 'disabled';
+ if (e.perm === 'edit') {
+ if (!keepDisabled) {
+ toolbar.enable(items[idx].id);
+ toolbarUpMore.enable(items[idx].id);
+ }
} else {
- toolbar.disable(id);
- toolbarUpMore.disable(id);
+ toolbar.disable(items[idx].id);
+ toolbarUpMore.disable(items[idx].id);
}
}
diff --git a/loleaflet/src/map/handler/Map.StateChanges.js b/loleaflet/src/map/handler/Map.StateChanges.js
new file mode 100644
index 00000000..6c31981e
--- /dev/null
+++ b/loleaflet/src/map/handler/Map.StateChanges.js
@@ -0,0 +1,44 @@
+/*
+ * L.Map.StateChanges stores the state changes commands coming from core
+ * LOK_CALLBACK_STATE_CHANGED callback
+ */
+
+L.Map.mergeOptions({
+ stateChangeHandler: true
+});
+
+L.Map.StateChangeHandler = L.Handler.extend({
+
+ initialize: function (map) {
+ this._map = map;
+ // Contains the items for which state will be tracked
+ // Stores the last received value from core ('true', 'false', 'enabled', 'disabled')
+ this._items = {};
+ },
+
+ addHooks: function () {
+ this._map.on('commandstatechanged', this._onStateChanged, this);
+ },
+
+ removeHooks: function () {
+ this._map.off('commandstatechanged', this._onStateChanged, this);
+ },
+
+ _onStateChanged: function(e) {
+ this._items[e.commandName] = e.state;
+ },
+
+ getItems: function() {
+ return this._items;
+ },
+
+ getItemValue: function(unoCmd) {
+ if (unoCmd && unoCmd.substring(0, 5) !== '.uno:') {
+ unoCmd = '.uno:' + unoCmd;
+ }
+
+ return this._items[unoCmd];
+ }
+});
+
+L.Map.addInitHook('addHandler', 'stateChangeHandler', L.Map.StateChangeHandler);
More information about the Libreoffice-commits
mailing list