diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2022-04-15 13:05:35 +0200 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2022-04-23 10:58:55 +0200 |
commit | 3144a9f8e02ecf713bfe0ae8a98702bb64ca7235 (patch) | |
tree | a44571d26649398add8b771fc3b27975a08d30d8 | |
parent | jsdialog: a11y: ignore containers while traversing using keyboard (diff) | |
download | online-3144a9f8e02ecf713bfe0ae8a98702bb64ca7235.tar.gz online-3144a9f8e02ecf713bfe0ae8a98702bb64ca7235.zip |
Introduce map.dispatch(action) to share code in UI handlers
This will allow us to improve code sharing between jsdialogs
and menubar / toolbars.
In the future could be used instead of special buttons which trigger
actions from menubar in jsdialog (what creates temp Menubar instance...).
in jsdialogs toolitem which will trigger shared action from map.dispatch
is a type 'customtoolitem'
Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: If528e8eb142b76d24cb9145cb265a505e7e9a5df
-rw-r--r-- | browser/src/control/Control.JSDialogBuilder.js | 15 | ||||
-rw-r--r-- | browser/src/control/Control.MobileTopBar.js | 13 | ||||
-rw-r--r-- | browser/src/control/Toolbar.js | 31 |
3 files changed, 47 insertions, 12 deletions
diff --git a/browser/src/control/Control.JSDialogBuilder.js b/browser/src/control/Control.JSDialogBuilder.js index 756e727970..899897d2d3 100644 --- a/browser/src/control/Control.JSDialogBuilder.js +++ b/browser/src/control/Control.JSDialogBuilder.js @@ -109,6 +109,7 @@ L.Control.JSDialogBuilder = L.Control.extend({ this._controlHandlers['spinnerimg'] = this._spinnerImgControl; this._controlHandlers['image'] = this._imageHandler; this._controlHandlers['scrollwindow'] = this._scrollWindowControl; + this._controlHandlers['customtoolitem'] = this._mapDispatchToolItem; this._controlHandlers['mainmenu'] = this._containerHandler; this._controlHandlers['submenu'] = this._subMenuHandler; @@ -2441,6 +2442,20 @@ L.Control.JSDialogBuilder = L.Control.extend({ return controls; }, + _mapDispatchToolItem: function (parentContainer, data, builder) { + if (!data.command) + data.command = data.id; + + var control = builder._unoToolButton(parentContainer, data, builder); + + $(control.container).unbind('click.toolbutton'); + if (!builder.map.isLockedItem(data)) { + $(control.container).click(function () { + builder.map.dispatch(data.command); + }); + } + }, + _divContainerHandler: function (parentContainer, data, builder) { if (!(data.children && data.children.length)) return false; diff --git a/browser/src/control/Control.MobileTopBar.js b/browser/src/control/Control.MobileTopBar.js index abf42ed78d..171cb72d7d 100644 --- a/browser/src/control/Control.MobileTopBar.js +++ b/browser/src/control/Control.MobileTopBar.js @@ -118,19 +118,10 @@ L.Control.MobileTopBar = L.Control.extend({ } } else if (id === 'cancelformula') { - this.map.sendUnoCommand('.uno:Cancel'); - w2ui['actionbar'].hide('acceptformula', 'cancelformula'); - w2ui['actionbar'].show('undo', 'redo'); + this.map.dispatch('cancelformula'); } else if (id === 'acceptformula') { - // focus on map, and press enter - this.map.focus(); - this.map._docLayer.postKeyboardEvent('input', - this.map.keyboard.keyCodes.enter, - this.map.keyboard._toUNOKeyCode(this.map.keyboard.keyCodes.enter)); - - w2ui['actionbar'].hide('acceptformula', 'cancelformula'); - w2ui['actionbar'].show('undo', 'redo'); + this.map.dispatch('acceptformula'); } else if (id === 'comment_wizard') { if (window.commentWizard) { diff --git a/browser/src/control/Toolbar.js b/browser/src/control/Toolbar.js index d8ed1e279b..1ef9c517fd 100644 --- a/browser/src/control/Toolbar.js +++ b/browser/src/control/Toolbar.js @@ -3,7 +3,7 @@ * Toolbar handler */ -/* global app $ window vex sanitizeUrl brandProductName brandProductURL _ Hammer */ +/* global app $ w2ui window vex sanitizeUrl brandProductName brandProductURL _ Hammer */ L.Map.include({ // a mapping of uno commands to more readable toolbar items @@ -756,4 +756,33 @@ L.Map.include({ var map = this; map.fire('postMessage', {msgId: 'UI_SaveAs'}); }, + + // map.dispatch() will be used to call some actions so we can share the code + dispatch: function(action) { + switch (action) { + case 'acceptformula': + { + // focus on map, and press enter + this.focus(); + this._docLayer.postKeyboardEvent('input', + this.keyboard.keyCodes.enter, + this.keyboard._toUNOKeyCode(this.keyboard.keyCodes.enter)); + + if (window.mode.isMobile()) { + w2ui['actionbar'].hide('acceptformula', 'cancelformula'); + w2ui['actionbar'].show('undo', 'redo'); + } + } + break; + case 'cancelformula': + { + this.sendUnoCommand('.uno:Cancel'); + if (window.mode.isMobile()) { + w2ui['actionbar'].hide('acceptformula', 'cancelformula'); + w2ui['actionbar'].show('undo', 'redo'); + } + } + break; + } + }, }); |