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 EditorUIController from '../lib/patch'; @inject (stores => ({ isEdit: stores.storeAppOptions.isEdit, canComments: stores.storeAppOptions.canComments, canViewComments: stores.storeAppOptions.canViewComments, canCoAuthoring: stores.storeAppOptions.canCoAuthoring, users: stores.users, isDisconnected: stores.users.isDisconnected, storeSheets: stores.sheets, wsProps: stores.storeWorksheets.wsProps, wsLock: stores.storeWorksheets.wsLock })) class ContextMenu extends ContextMenuController { constructor(props) { super(props); // console.log('context menu controller created'); this.onApiShowComment = this.onApiShowComment.bind(this); this.onApiHideComment = this.onApiHideComment.bind(this); this.isOpenWindowUser = false; this.timer; this.getUserName = this.getUserName.bind(this); this.isUserVisible = this.isUserVisible.bind(this); this.onApiMouseMove = this.onApiMouseMove.bind(this); this.onApiHyperlinkClick = this.onApiHyperlinkClick.bind(this); } static closeContextMenu() { f7.popover.close(idContextMenuElement, false); } getUserName(id) { const user = this.props.users.searchUserByCurrentId(id); return AscCommon.UserInfoParser.getParsedName(user.asc_getUserName()); } isUserVisible(id) { const user = this.props.users.searchUserByCurrentId(id); return user ? (user.asc_getIdOriginal()===this.props.users.currentUser.asc_getIdOriginal() || AscCommon.UserInfoParser.isUserVisible(user.asc_getUserName())) : true; } componentWillUnmount() { super.componentWillUnmount(); const api = Common.EditorApi.get(); if ( api ) { api.asc_unregisterCallback('asc_onShowComment', this.onApiShowComment); api.asc_unregisterCallback('asc_onHideComment', this.onApiHideComment); api.asc_unregisterCallback('asc_onMouseMove', this.onApiMouseMove); api.asc_unregisterCallback('asc_onHyperlinkClick', this.onApiHyperlinkClick); } } onApiShowComment(comments) { this.isComments = comments && comments.length > 0; } onApiHideComment() { this.isComments = false; } // onMenuClosed() { // super.onMenuClosed(); // } onApiHyperlinkClick(url) { const { t } = this.props; if(!url) { f7.dialog.create({ title: t('ContextMenu.notcriticalErrorTitle'), text: t('ContextMenu.errorInvalidLink'), buttons:[ {text: 'OK'} ] }).open(); } } onMenuItemClick(action) { const { t } = this.props; const _t = t("ContextMenu", { returnObjects: true }); super.onMenuItemClick(action); if ( EditorUIController.ContextMenu && EditorUIController.ContextMenu.handleMenuItemClick(this, action) ) return; const api = Common.EditorApi.get(); const info = api.asc_getCellInfo(); switch (action) { case 'cut': if (!LocalStorage.getBool("sse-hide-copy-cut-paste-warning")) { this.showCopyCutPasteModal(); } break; case 'copy': if (!api.asc_Copy() && !LocalStorage.getBool("sse-hide-copy-cut-paste-warning")) { this.showCopyCutPasteModal(); } break; case 'paste': if (!LocalStorage.getBool("sse-hide-copy-cut-paste-warning")) { this.showCopyCutPasteModal(); } break; case 'viewcomment': Common.Notifications.trigger('viewcomment'); break; case 'openlink': const linkinfo = info.asc_getHyperlink(); if ( linkinfo.asc_getType() == Asc.c_oAscHyperlinkType.RangeLink ) { const nameSheet = linkinfo.asc_getSheet(); const curActiveSheet = api.asc_getActiveWorksheetIndex(); api.asc_setWorksheetRange(linkinfo); const {storeSheets} = this.props; const tab = storeSheets.sheets.find((sheet) => sheet.name === nameSheet); if (tab) { const sdkIndex = tab.index; if (sdkIndex !== curActiveSheet) { const index = storeSheets.sheets.indexOf(tab); storeSheets.setActiveWorksheet(index); Common.Notifications.trigger('sheet:active', sdkIndex); } } } else { const url = linkinfo.asc_getHyperlinkUrl().replace(/\s/g, "%20"); api.asc_getUrlType(url) > 0 && this.openLink(url); } break; } } onMergeCells() { const { t } = this.props; const api = Common.EditorApi.get(); if (api.asc_mergeCellsDataLost(Asc.c_oAscMergeOptions.Merge)) { setTimeout(() => { f7.dialog.create({ title: t('ContextMenu.notcriticalErrorTitle'), text: t('ContextMenu.warnMergeLostData'), buttons: [ { text: t('ContextMenu.menuCancel') }, { text: 'OK', onClick: () => { api.asc_mergeCells(Asc.c_oAscMergeOptions.Merge); } } ] }).open(); }, 0); } else { api.asc_mergeCells(Asc.c_oAscMergeOptions.Merge); } } showCopyCutPasteModal() { const { t } = this.props; const _t = t("ContextMenu", { returnObjects: true }); f7.dialog.create({ title: _t.textCopyCutPasteActions, text: _t.errorCopyCutPaste, content: `