diff --git a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx index 84c07a9e0..f35162df2 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx @@ -21,6 +21,7 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins. import { StatusbarController } from "./Statusbar"; @inject( + "users", "storeAppOptions", "storeFocusObjects", "storeCellSettings", @@ -28,7 +29,8 @@ import { StatusbarController } from "./Statusbar"; "storeChartSettings", "storeSpreadsheetSettings", "storeSpreadsheetInfo", - "storeApplicationSettings" + "storeApplicationSettings", + "storeToolbarSettings" ) class MainController extends Component { constructor(props) { @@ -360,6 +362,18 @@ class MainController extends Component { if(type == Asc.c_oAscAdvancedOptionsID.DRM) this.isDRM = true; }); + // Toolbar settings + + const storeToolbarSettings = this.props.storeToolbarSettings; + this.api.asc_registerCallback('asc_onCanUndoChanged', (can) => { + if (this.props.users.isDisconnected) return; + storeToolbarSettings.setCanUndo(can); + }); + this.api.asc_registerCallback('asc_onCanRedoChanged', (can) => { + if (this.props.users.isDisconnected) return; + storeToolbarSettings.setCanRedo(can); + }); + } _onLongActionEnd(type, id) { diff --git a/apps/spreadsheeteditor/mobile/src/controller/Statusbar.jsx b/apps/spreadsheeteditor/mobile/src/controller/Statusbar.jsx index 7e093e1f0..c9725fffe 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Statusbar.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Statusbar.jsx @@ -6,16 +6,19 @@ import { f7 } from 'framework7-react'; import { useTranslation } from 'react-i18next'; import { Device } from '../../../../common/mobile/utils/device'; -const StatusbarController = inject('sheets')(observer(props => { +const StatusbarController = inject('sheets', 'storeFocusObjects')(observer(props => { const sheets = props.sheets; + const storeFocusObjects = props.storeFocusObjects; useEffect(() => { Common.Notifications.on('engineCreated', api => { api.asc_registerCallback('asc_onWorkbookLocked', (locked) => { sheets.setWorkbookLocked(locked); + storeFocusObjects.setIsLocked(api.asc_getCellInfo()); }); api.asc_registerCallback('asc_onWorksheetLocked', (index, locked) => { sheets.setWorksheetLocked(index, locked); + storeFocusObjects.setIsLocked(api.asc_getCellInfo()); }); api.asc_registerCallback('asc_onSheetsChanged', onApiSheetsChanged); api.asc_registerCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged); diff --git a/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx b/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx index c778040af..6b6ceb0b4 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx @@ -4,7 +4,7 @@ import { f7 } from 'framework7-react'; import { useTranslation } from 'react-i18next'; import ToolbarView from "../view/Toolbar"; -const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetInfo', 'storeFocusObjects')(observer(props => { +const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetInfo', 'storeFocusObjects', 'storeToolbarSettings')(observer(props => { const {t} = useTranslation(); const _t = t("Toolbar", { returnObjects: true }); @@ -16,26 +16,17 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights; - useEffect(() => { - const onDocumentReady = () => { - const api = Common.EditorApi.get(); - api.asc_registerCallback('asc_onCanUndoChanged', onApiCanUndo); - api.asc_registerCallback('asc_onCanRedoChanged', onApiCanRedo); - api.asc_registerCallback('asc_onWorkbookLocked', onApiLocked); - api.asc_registerCallback('asc_onWorksheetLocked', onApiLocked); - api.asc_registerCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged); + const storeToolbarSettings = props.storeToolbarSettings; + const isCanUndo = storeToolbarSettings.isCanUndo; + const isCanRedo = storeToolbarSettings.isCanRedo; - Common.Notifications.on('toolbar:activatecontrols', activateControls); - Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls); - Common.Notifications.on('goback', goBack); - Common.Notifications.on('sheet:active', onApiActiveSheetChanged); - }; - if ( !Common.EditorApi ) { - Common.Notifications.on('document:ready', onDocumentReady); - Common.Gateway.on('init', loadConfig); - } else { - onDocumentReady(); - } + useEffect(() => { + Common.Gateway.on('init', loadConfig); + + Common.Notifications.on('toolbar:activatecontrols', activateControls); + Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls); + Common.Notifications.on('goback', goBack); + Common.Notifications.on('sheet:active', onApiActiveSheetChanged); if (isDisconnected) { f7.popover.close(); @@ -44,18 +35,10 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn } return () => { - Common.Notifications.off('document:ready', onDocumentReady); Common.Notifications.off('toolbar:activatecontrols', activateControls); Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls); Common.Notifications.off('goback', goBack); Common.Notifications.off('sheet:active', onApiActiveSheetChanged); - - const api = Common.EditorApi.get(); - api.asc_unregisterCallback('asc_onCanUndoChanged', onApiCanUndo); - api.asc_unregisterCallback('asc_onCanRedoChanged', onApiCanRedo); - api.asc_unregisterCallback('asc_onWorkbookLocked', onApiLocked); - api.asc_unregisterCallback('asc_onWorksheetLocked', onApiLocked); - api.asc_unregisterCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged); } }); @@ -107,17 +90,6 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn //} } - // Undo and Redo - const [isCanUndo, setCanUndo] = useState(false); - const [isCanRedo, setCanRedo] = useState(false); - const onApiCanUndo = (can) => { - if (isDisconnected) return; - setCanUndo(can); - }; - const onApiCanRedo = (can) => { - if (isDisconnected) return; - setCanRedo(can); - }; const onUndo = () => { const api = Common.EditorApi.get(); if (api) { @@ -132,10 +104,6 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn } const [disabledEditControls, setDisabledEditControls] = useState(false); - const onApiLocked = () => { - if (isDisconnected) return; - props.storeFocusObjects.setIsLocked(Common.EditorApi.get().asc_getCellInfo()); - }; const onApiActiveSheetChanged = (index) => { Common.Notifications.trigger('comments:filterchange', ['doc', 'sheet' + Common.EditorApi.get().asc_getWorksheetId(index)], false ); diff --git a/apps/spreadsheeteditor/mobile/src/store/mainStore.js b/apps/spreadsheeteditor/mobile/src/store/mainStore.js index 0190760f3..de8a2c11e 100644 --- a/apps/spreadsheeteditor/mobile/src/store/mainStore.js +++ b/apps/spreadsheeteditor/mobile/src/store/mainStore.js @@ -16,6 +16,7 @@ import {storeAppOptions} from "./appOptions"; import {storeChartSettings} from "./chartSettings"; import {storeSpreadsheetSettings} from "./spreadsheetSettings"; import {storeComments} from "../../../../common/mobile/lib/store/comments"; +import {storeToolbarSettings} from "./toolbar"; export const stores = { storeFocusObjects: new storeFocusObjects(), @@ -34,6 +35,7 @@ export const stores = { storeCellSettings: new storeCellSettings(), // storeImageSettings: new storeImageSettings(), // storeTableSettings: new storeTableSettings() - storeComments: new storeComments() + storeComments: new storeComments(), + storeToolbarSettings: new storeToolbarSettings() }; diff --git a/apps/spreadsheeteditor/mobile/src/store/toolbar.js b/apps/spreadsheeteditor/mobile/src/store/toolbar.js new file mode 100644 index 000000000..ff0d1764a --- /dev/null +++ b/apps/spreadsheeteditor/mobile/src/store/toolbar.js @@ -0,0 +1,24 @@ +import {action, observable, makeObservable} from 'mobx'; + +export class storeToolbarSettings { + constructor() { + makeObservable(this, { + isCanUndo: observable, + setCanUndo: action, + isCanRedo: observable, + setCanRedo: action + }) + } + + isCanUndo = false; + + setCanUndo(can) { + this.isCanUndo = can; + } + + isCanRedo = false; + + setCanRedo(can) { + this.isCanRedo = can; + } +} \ No newline at end of file