[SSE mobile] Change to add listeners on events in toolbar

This commit is contained in:
JuliaSvinareva 2021-07-22 01:10:25 +03:00
parent 40b9837d55
commit bd57ab8c5d
5 changed files with 57 additions and 46 deletions

View file

@ -21,6 +21,7 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins.
import { StatusbarController } from "./Statusbar"; import { StatusbarController } from "./Statusbar";
@inject( @inject(
"users",
"storeAppOptions", "storeAppOptions",
"storeFocusObjects", "storeFocusObjects",
"storeCellSettings", "storeCellSettings",
@ -28,7 +29,8 @@ import { StatusbarController } from "./Statusbar";
"storeChartSettings", "storeChartSettings",
"storeSpreadsheetSettings", "storeSpreadsheetSettings",
"storeSpreadsheetInfo", "storeSpreadsheetInfo",
"storeApplicationSettings" "storeApplicationSettings",
"storeToolbarSettings"
) )
class MainController extends Component { class MainController extends Component {
constructor(props) { constructor(props) {
@ -360,6 +362,18 @@ class MainController extends Component {
if(type == Asc.c_oAscAdvancedOptionsID.DRM) this.isDRM = true; 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) { _onLongActionEnd(type, id) {

View file

@ -6,16 +6,19 @@ import { f7 } from 'framework7-react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Device } from '../../../../common/mobile/utils/device'; 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 sheets = props.sheets;
const storeFocusObjects = props.storeFocusObjects;
useEffect(() => { useEffect(() => {
Common.Notifications.on('engineCreated', api => { Common.Notifications.on('engineCreated', api => {
api.asc_registerCallback('asc_onWorkbookLocked', (locked) => { api.asc_registerCallback('asc_onWorkbookLocked', (locked) => {
sheets.setWorkbookLocked(locked); sheets.setWorkbookLocked(locked);
storeFocusObjects.setIsLocked(api.asc_getCellInfo());
}); });
api.asc_registerCallback('asc_onWorksheetLocked', (index, locked) => { api.asc_registerCallback('asc_onWorksheetLocked', (index, locked) => {
sheets.setWorksheetLocked(index, locked); sheets.setWorksheetLocked(index, locked);
storeFocusObjects.setIsLocked(api.asc_getCellInfo());
}); });
api.asc_registerCallback('asc_onSheetsChanged', onApiSheetsChanged); api.asc_registerCallback('asc_onSheetsChanged', onApiSheetsChanged);
api.asc_registerCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged); api.asc_registerCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged);

View file

@ -4,7 +4,7 @@ import { f7 } from 'framework7-react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import ToolbarView from "../view/Toolbar"; 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} = useTranslation();
const _t = t("Toolbar", { returnObjects: true }); const _t = t("Toolbar", { returnObjects: true });
@ -16,26 +16,17 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn
const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights; const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights;
const storeToolbarSettings = props.storeToolbarSettings;
const isCanUndo = storeToolbarSettings.isCanUndo;
const isCanRedo = storeToolbarSettings.isCanRedo;
useEffect(() => { useEffect(() => {
const onDocumentReady = () => { Common.Gateway.on('init', loadConfig);
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);
Common.Notifications.on('toolbar:activatecontrols', activateControls); Common.Notifications.on('toolbar:activatecontrols', activateControls);
Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls); Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.on('goback', goBack); Common.Notifications.on('goback', goBack);
Common.Notifications.on('sheet:active', onApiActiveSheetChanged); Common.Notifications.on('sheet:active', onApiActiveSheetChanged);
};
if ( !Common.EditorApi ) {
Common.Notifications.on('document:ready', onDocumentReady);
Common.Gateway.on('init', loadConfig);
} else {
onDocumentReady();
}
if (isDisconnected) { if (isDisconnected) {
f7.popover.close(); f7.popover.close();
@ -44,18 +35,10 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn
} }
return () => { return () => {
Common.Notifications.off('document:ready', onDocumentReady);
Common.Notifications.off('toolbar:activatecontrols', activateControls); Common.Notifications.off('toolbar:activatecontrols', activateControls);
Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls); Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.off('goback', goBack); Common.Notifications.off('goback', goBack);
Common.Notifications.off('sheet:active', onApiActiveSheetChanged); 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 onUndo = () => {
const api = Common.EditorApi.get(); const api = Common.EditorApi.get();
if (api) { if (api) {
@ -132,10 +104,6 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetIn
} }
const [disabledEditControls, setDisabledEditControls] = useState(false); const [disabledEditControls, setDisabledEditControls] = useState(false);
const onApiLocked = () => {
if (isDisconnected) return;
props.storeFocusObjects.setIsLocked(Common.EditorApi.get().asc_getCellInfo());
};
const onApiActiveSheetChanged = (index) => { const onApiActiveSheetChanged = (index) => {
Common.Notifications.trigger('comments:filterchange', ['doc', 'sheet' + Common.EditorApi.get().asc_getWorksheetId(index)], false ); Common.Notifications.trigger('comments:filterchange', ['doc', 'sheet' + Common.EditorApi.get().asc_getWorksheetId(index)], false );

View file

@ -16,6 +16,7 @@ import {storeAppOptions} from "./appOptions";
import {storeChartSettings} from "./chartSettings"; import {storeChartSettings} from "./chartSettings";
import {storeSpreadsheetSettings} from "./spreadsheetSettings"; import {storeSpreadsheetSettings} from "./spreadsheetSettings";
import {storeComments} from "../../../../common/mobile/lib/store/comments"; import {storeComments} from "../../../../common/mobile/lib/store/comments";
import {storeToolbarSettings} from "./toolbar";
export const stores = { export const stores = {
storeFocusObjects: new storeFocusObjects(), storeFocusObjects: new storeFocusObjects(),
@ -34,6 +35,7 @@ export const stores = {
storeCellSettings: new storeCellSettings(), storeCellSettings: new storeCellSettings(),
// storeImageSettings: new storeImageSettings(), // storeImageSettings: new storeImageSettings(),
// storeTableSettings: new storeTableSettings() // storeTableSettings: new storeTableSettings()
storeComments: new storeComments() storeComments: new storeComments(),
storeToolbarSettings: new storeToolbarSettings()
}; };

View file

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