[DE mobile] Fix adding listeners in toolbar

This commit is contained in:
JuliaSvinareva 2021-07-22 17:47:34 +03:00
parent bd57ab8c5d
commit 6d0911631c
4 changed files with 54 additions and 62 deletions

View file

@ -18,6 +18,7 @@ import LongActionsController from "./LongActions";
import PluginsController from '../../../../common/mobile/lib/controller/Plugins.jsx';
@inject(
"users",
"storeAppOptions",
"storeDocumentSettings",
"storeFocusObjects",
@ -27,7 +28,8 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins.
"storeDocumentInfo",
"storeChartSettings",
"storeApplicationSettings",
"storeLinkSettings"
"storeLinkSettings",
"storeToolbarSettings"
)
class MainController extends Component {
constructor(props) {
@ -620,6 +622,18 @@ class MainController extends Component {
onAdvancedOptions(type, advOptions, mode, formatOptions, _t, this._isDocReady, this.props.storeAppOptions.canRequestClose, this.isDRM);
if(type == Asc.c_oAscAdvancedOptionsID.DRM) this.isDRM = true;
});
// Toolbar settings
const storeToolbarSettings = this.props.storeToolbarSettings;
this.api.asc_registerCallback('asc_onCanUndo', (can) => {
if (this.props.users.isDisconnected) return;
storeToolbarSettings.setCanUndo(can);
});
this.api.asc_registerCallback('asc_onCanRedo', (can) => {
if (this.props.users.isDisconnected) return;
storeToolbarSettings.setCanRedo(can);
});
}
onProcessSaveResult (data) {

View file

@ -4,7 +4,7 @@ import { f7 } from 'framework7-react';
import { useTranslation } from 'react-i18next';
import ToolbarView from "../view/Toolbar";
const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(observer(props => {
const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'storeFocusObjects', 'storeToolbarSettings')(observer(props => {
const {t} = useTranslation();
const _t = t("Toolbar", { returnObjects: true });
@ -15,25 +15,20 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
const displayCollaboration = props.users.hasEditUsers || appOptions.canViewComments || appOptions.canReview || appOptions.canViewReview;
const readerMode = appOptions.readerMode;
const objectLocked = props.storeFocusObjects.objectLocked;
const storeToolbarSettings = props.storeToolbarSettings;
const isCanUndo = storeToolbarSettings.isCanUndo;
const isCanRedo = storeToolbarSettings.isCanRedo;
const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights;
useEffect(() => {
const onDocumentReady = () => {
const api = Common.EditorApi.get();
api.asc_registerCallback('asc_onCanUndo', onApiCanUndo);
api.asc_registerCallback('asc_onCanRedo', onApiCanRedo);
api.asc_registerCallback('asc_onFocusObject', onApiFocusObject);
Common.Notifications.on('toolbar:activatecontrols', activateControls);
Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.on('goback', goBack);
};
if ( !Common.EditorApi ) {
Common.Notifications.on('document:ready', onDocumentReady);
Common.Notifications.on('setdoctitle', setDocTitle);
Common.Gateway.on('init', loadConfig);
} else {
onDocumentReady();
}
Common.Notifications.on('setdoctitle', setDocTitle);
Common.Gateway.on('init', loadConfig);
Common.Notifications.on('toolbar:activatecontrols', activateControls);
Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.on('goback', goBack);
if (isDisconnected) {
f7.popover.close();
@ -42,16 +37,10 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
}
return () => {
Common.Notifications.off('document:ready', onDocumentReady);
Common.Notifications.off('setdoctitle', setDocTitle);
Common.Notifications.off('toolbar:activatecontrols', activateControls);
Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.off('goback', goBack);
const api = Common.EditorApi.get();
api.asc_unregisterCallback('asc_onCanUndo', onApiCanUndo);
api.asc_unregisterCallback('asc_onCanRedo', onApiCanRedo);
api.asc_unregisterCallback('asc_onFocusObject', onApiFocusObject);
}
});
@ -106,17 +95,6 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
}
}
// Undo and Redo
const [isCanUndo, setCanUndo] = useState(true);
const [isCanRedo, setCanRedo] = useState(true);
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) {
@ -130,30 +108,6 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
}
}
const [isObjectLocked, setObjectLocked] = useState(false);
const onApiFocusObject = (objects) => {
if (isDisconnected) return;
if (objects.length > 0) {
const getTopObject = (objects) => {
const arrObj = objects.reverse();
let obj;
for (let i=0; i<arrObj.length; i++) {
if (arrObj[i].get_ObjectType() != Asc.c_oAscTypeSelectElement.SpellCheck) {
obj = arrObj[i];
break;
}
}
return obj;
};
const topObject = getTopObject(objects);
const topObjectValue = topObject.get_ObjectValue();
const objectLocked = (typeof topObjectValue.get_Locked === 'function') ? topObjectValue.get_Locked() : false;
setObjectLocked(objectLocked);
}
};
const [disabledEditControls, setDisabledEditControls] = useState(false);
const [disabledSettings, setDisabledSettings] = useState(false);
const deactivateEditControls = (enableDownload) => {
@ -184,7 +138,7 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
isCanRedo={isCanRedo}
onUndo={onUndo}
onRedo={onRedo}
isObjectLocked={isObjectLocked}
isObjectLocked={objectLocked}
stateDisplayMode={stateDisplayMode}
disabledControls={disabledControls}
disabledEditControls={disabledEditControls}

View file

@ -16,7 +16,8 @@ export class storeFocusObjects {
tableObject: computed,
isTableInStack: computed,
chartObject: computed,
linkObject: computed
linkObject: computed,
objectLocked: computed
});
}
@ -77,4 +78,25 @@ export class storeFocusObjects {
get linkObject() {
return !!this.intf ? this.intf.getLinkObject() : null;
}
get objectLocked() {
if (this._focusObjects && this._focusObjects.length > 0) {
const getTopObject = (objects) => {
const arrObj = objects;
let obj;
for (let i=arrObj.length-1; i>=0; i--) {
if (arrObj[i].get_ObjectType() != Asc.c_oAscTypeSelectElement.SpellCheck) {
obj = arrObj[i];
break;
}
}
return obj;
};
const topObject = getTopObject(this._focusObjects);
const topObjectValue = topObject.get_ObjectValue();
const objectLocked = (typeof topObjectValue.get_Locked === 'function') ? topObjectValue.get_Locked() : false;
return objectLocked;
}
}
}

View file

@ -15,6 +15,7 @@ import {storeAppOptions} from "./appOptions";
import {storePalette} from "./palette";
import {storeReview} from "./review";
import {storeComments} from "../../../../common/mobile/lib/store/comments";
import {storeToolbarSettings} from "./toolbar";
export const stores = {
storeAppOptions: new storeAppOptions(),
@ -32,6 +33,7 @@ export const stores = {
storeApplicationSettings: new storeApplicationSettings(),
storePalette: new storePalette(),
storeReview: new storeReview(),
storeComments: new storeComments()
storeComments: new storeComments(),
storeToolbarSettings: new storeToolbarSettings()
};