[DE mobile] Add cut, copy, paste handler in context menu

This commit is contained in:
JuliaSvinareva 2021-03-17 11:46:57 +03:00
parent fd561f3687
commit c5ef8766d6
4 changed files with 56 additions and 3 deletions

View file

@ -29,7 +29,7 @@ class ContextMenuView extends Component {
{buttons.map((b, index) =>
!b.icon ?
<ListButton title={b.caption} key={index} onClick={e => this.props.onMenuItemClick(b.event)} /> :
<ListButton key={index}>
<ListButton key={index} onClick={e => this.props.onMenuItemClick(b.event)}>
<Icon slot="media" icon={`icon_mask ${b.icon}`} />
</ListButton>
)}

View file

@ -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;
}
}

View file

@ -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",

View file

@ -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: `<div class="checkbox-in-modal">
<label class="checkbox">
<input type="checkbox" name="checkbox-show" />
<i class="icon-checkbox"></i>
</label>
<span class="right-text">${_t.textDoNotShowAgain}</span>
</div>`,
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();