[DE mobile] Fix adding listeners in toolbar
This commit is contained in:
parent
bd57ab8c5d
commit
6d0911631c
|
@ -18,6 +18,7 @@ import LongActionsController from "./LongActions";
|
||||||
import PluginsController from '../../../../common/mobile/lib/controller/Plugins.jsx';
|
import PluginsController from '../../../../common/mobile/lib/controller/Plugins.jsx';
|
||||||
|
|
||||||
@inject(
|
@inject(
|
||||||
|
"users",
|
||||||
"storeAppOptions",
|
"storeAppOptions",
|
||||||
"storeDocumentSettings",
|
"storeDocumentSettings",
|
||||||
"storeFocusObjects",
|
"storeFocusObjects",
|
||||||
|
@ -27,7 +28,8 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins.
|
||||||
"storeDocumentInfo",
|
"storeDocumentInfo",
|
||||||
"storeChartSettings",
|
"storeChartSettings",
|
||||||
"storeApplicationSettings",
|
"storeApplicationSettings",
|
||||||
"storeLinkSettings"
|
"storeLinkSettings",
|
||||||
|
"storeToolbarSettings"
|
||||||
)
|
)
|
||||||
class MainController extends Component {
|
class MainController extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -620,6 +622,18 @@ class MainController extends Component {
|
||||||
onAdvancedOptions(type, advOptions, mode, formatOptions, _t, this._isDocReady, this.props.storeAppOptions.canRequestClose, this.isDRM);
|
onAdvancedOptions(type, advOptions, mode, formatOptions, _t, this._isDocReady, this.props.storeAppOptions.canRequestClose, this.isDRM);
|
||||||
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_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) {
|
onProcessSaveResult (data) {
|
||||||
|
|
|
@ -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', 'storeReview')(observer(props => {
|
const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'storeFocusObjects', 'storeToolbarSettings')(observer(props => {
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
const _t = t("Toolbar", { returnObjects: true });
|
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 displayCollaboration = props.users.hasEditUsers || appOptions.canViewComments || appOptions.canReview || appOptions.canViewReview;
|
||||||
const readerMode = appOptions.readerMode;
|
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;
|
const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onDocumentReady = () => {
|
Common.Notifications.on('setdoctitle', setDocTitle);
|
||||||
const api = Common.EditorApi.get();
|
Common.Gateway.on('init', loadConfig);
|
||||||
api.asc_registerCallback('asc_onCanUndo', onApiCanUndo);
|
Common.Notifications.on('toolbar:activatecontrols', activateControls);
|
||||||
api.asc_registerCallback('asc_onCanRedo', onApiCanRedo);
|
Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls);
|
||||||
api.asc_registerCallback('asc_onFocusObject', onApiFocusObject);
|
Common.Notifications.on('goback', goBack);
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDisconnected) {
|
if (isDisconnected) {
|
||||||
f7.popover.close();
|
f7.popover.close();
|
||||||
|
@ -42,16 +37,10 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
Common.Notifications.off('document:ready', onDocumentReady);
|
|
||||||
Common.Notifications.off('setdoctitle', setDocTitle);
|
Common.Notifications.off('setdoctitle', setDocTitle);
|
||||||
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);
|
||||||
|
|
||||||
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 onUndo = () => {
|
||||||
const api = Common.EditorApi.get();
|
const api = Common.EditorApi.get();
|
||||||
if (api) {
|
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 [disabledEditControls, setDisabledEditControls] = useState(false);
|
||||||
const [disabledSettings, setDisabledSettings] = useState(false);
|
const [disabledSettings, setDisabledSettings] = useState(false);
|
||||||
const deactivateEditControls = (enableDownload) => {
|
const deactivateEditControls = (enableDownload) => {
|
||||||
|
@ -184,7 +138,7 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview')(obse
|
||||||
isCanRedo={isCanRedo}
|
isCanRedo={isCanRedo}
|
||||||
onUndo={onUndo}
|
onUndo={onUndo}
|
||||||
onRedo={onRedo}
|
onRedo={onRedo}
|
||||||
isObjectLocked={isObjectLocked}
|
isObjectLocked={objectLocked}
|
||||||
stateDisplayMode={stateDisplayMode}
|
stateDisplayMode={stateDisplayMode}
|
||||||
disabledControls={disabledControls}
|
disabledControls={disabledControls}
|
||||||
disabledEditControls={disabledEditControls}
|
disabledEditControls={disabledEditControls}
|
||||||
|
|
|
@ -16,7 +16,8 @@ export class storeFocusObjects {
|
||||||
tableObject: computed,
|
tableObject: computed,
|
||||||
isTableInStack: computed,
|
isTableInStack: computed,
|
||||||
chartObject: computed,
|
chartObject: computed,
|
||||||
linkObject: computed
|
linkObject: computed,
|
||||||
|
objectLocked: computed
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,4 +78,25 @@ export class storeFocusObjects {
|
||||||
get linkObject() {
|
get linkObject() {
|
||||||
return !!this.intf ? this.intf.getLinkObject() : null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ import {storeAppOptions} from "./appOptions";
|
||||||
import {storePalette} from "./palette";
|
import {storePalette} from "./palette";
|
||||||
import {storeReview} from "./review";
|
import {storeReview} from "./review";
|
||||||
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 = {
|
||||||
storeAppOptions: new storeAppOptions(),
|
storeAppOptions: new storeAppOptions(),
|
||||||
|
@ -32,6 +33,7 @@ export const stores = {
|
||||||
storeApplicationSettings: new storeApplicationSettings(),
|
storeApplicationSettings: new storeApplicationSettings(),
|
||||||
storePalette: new storePalette(),
|
storePalette: new storePalette(),
|
||||||
storeReview: new storeReview(),
|
storeReview: new storeReview(),
|
||||||
storeComments: new storeComments()
|
storeComments: new storeComments(),
|
||||||
|
storeToolbarSettings: new storeToolbarSettings()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue