[SSE mobile] Change to add listeners on events in toolbar
This commit is contained in:
parent
40b9837d55
commit
bd57ab8c5d
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
const storeToolbarSettings = props.storeToolbarSettings;
|
||||
const isCanUndo = storeToolbarSettings.isCanUndo;
|
||||
const isCanRedo = storeToolbarSettings.isCanRedo;
|
||||
|
||||
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);
|
||||
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 ( !Common.EditorApi ) {
|
||||
Common.Notifications.on('document:ready', onDocumentReady);
|
||||
Common.Gateway.on('init', loadConfig);
|
||||
} else {
|
||||
onDocumentReady();
|
||||
}
|
||||
|
||||
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 );
|
||||
|
|
|
@ -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()
|
||||
};
|
||||
|
||||
|
|
24
apps/spreadsheeteditor/mobile/src/store/toolbar.js
Normal file
24
apps/spreadsheeteditor/mobile/src/store/toolbar.js
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue