From c5ef8766d6c5735a94bcd9d9a502a58bd1ec23bf Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Wed, 17 Mar 2021 11:46:57 +0300 Subject: [PATCH] [DE mobile] Add cut, copy, paste handler in context menu --- apps/common/mobile/lib/view/ContextMenu.jsx | 2 +- apps/common/mobile/resources/less/common.less | 9 ++++ apps/documenteditor/mobile/locale/en.json | 5 ++- .../mobile/src/controller/ContextMenu.jsx | 43 ++++++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/apps/common/mobile/lib/view/ContextMenu.jsx b/apps/common/mobile/lib/view/ContextMenu.jsx index 2447ba24d..47c954162 100644 --- a/apps/common/mobile/lib/view/ContextMenu.jsx +++ b/apps/common/mobile/lib/view/ContextMenu.jsx @@ -29,7 +29,7 @@ class ContextMenuView extends Component { {buttons.map((b, index) => !b.icon ? this.props.onMenuItemClick(b.event)} /> : - + this.props.onMenuItemClick(b.event)}> )} diff --git a/apps/common/mobile/resources/less/common.less b/apps/common/mobile/resources/less/common.less index 53f4f6848..8d2746af8 100644 --- a/apps/common/mobile/resources/less/common.less +++ b/apps/common/mobile/resources/less/common.less @@ -660,6 +660,15 @@ input[type="number"]::-webkit-inner-spin-button { background-position: -16px -192px; } +.checkbox-in-modal { + margin-top: 10px; + display: flex; + align-items: center; + .right-text { + margin-left: 10px; + } +} + diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index 54937afbf..e8858a48a 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -142,7 +142,10 @@ "menuReview": "Review", "menuOpenLink": "Open Link", "menuMore": "More", - "menuCancel": "Cancel" + "menuCancel": "Cancel", + "textCopyCutPasteActions": "Copy, Cut and Paste Actions", + "errorCopyCutPaste": "Copy, cut and paste actions using the context menu will be performed within the current file only.", + "textDoNotShowAgain": "Don't show again" }, "Settings": { "textCancel": "Cancel", diff --git a/apps/documenteditor/mobile/src/controller/ContextMenu.jsx b/apps/documenteditor/mobile/src/controller/ContextMenu.jsx index 793a3e3d9..60a124754 100644 --- a/apps/documenteditor/mobile/src/controller/ContextMenu.jsx +++ b/apps/documenteditor/mobile/src/controller/ContextMenu.jsx @@ -1,10 +1,12 @@ import React, { useContext } from 'react'; import { f7 } from 'framework7-react'; import { inject, observer } from "mobx-react"; +import { withTranslation} from 'react-i18next'; +import { LocalStorage } from '../../../../common/mobile/utils/LocalStorage'; + import ContextMenuController from '../../../../common/mobile/lib/controller/ContextMenu'; import { idContextMenuElement } from '../../../../common/mobile/lib/view/ContextMenu'; import { Device } from '../../../../common/mobile/utils/device'; -import { withTranslation} from 'react-i18next'; @inject ( stores => ({ isEdit: stores.storeAppOptions.isEdit, @@ -48,7 +50,23 @@ class ContextMenu extends ContextMenuController { onMenuItemClick(action) { super.onMenuItemClick(action); + const api = Common.EditorApi.get(); switch (action) { + case 'cut': + if (!api.Cut() && !LocalStorage.getBool("de-hide-copy-cut-paste-warning")) { + this.showCopyCutPasteModal(); + } + break; + case 'copy': + if (!api.Copy() && !LocalStorage.getBool("de-hide-copy-cut-paste-warning")) { + this.showCopyCutPasteModal(); + } + break; + case 'paste': + if (!api.Paste() && !LocalStorage.getBool("de-hide-copy-cut-paste-warning")) { + this.showCopyCutPasteModal(); + } + break; case 'addcomment': Common.Notifications.trigger('addcomment'); break; @@ -60,6 +78,29 @@ class ContextMenu extends ContextMenuController { console.log("click context menu item: " + action); } + showCopyCutPasteModal() { + const { t } = this.props; + const _t = t("ContextMenu", { returnObjects: true }); + f7.dialog.create({ + title: _t.textCopyCutPasteActions, + text: _t.errorCopyCutPaste, + content: `
+ + ${_t.textDoNotShowAgain} +
`, + buttons: [{ + text: 'OK', + onClick: () => { + const dontShow = $$('input[name="checkbox-show"]').prop('checked'); + if (dontShow) LocalStorage.setItem("de-hide-copy-cut-paste-warning", 1); + } + }] + }).open(); + } + onDocumentReady() { super.onDocumentReady();