2019-11-21 05:17:42 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {_t} from '../../../languageHandler';
|
2019-11-28 21:16:59 +03:00
|
|
|
import {MenuItem} from "../../structures/ContextualMenu";
|
2019-11-21 05:17:42 +03:00
|
|
|
|
|
|
|
export default class WidgetContextMenu extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
onFinished: PropTypes.func,
|
|
|
|
|
|
|
|
// Callback for when the revoke button is clicked. Required.
|
|
|
|
onRevokeClicked: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
// Callback for when the snapshot button is clicked. Button not shown
|
|
|
|
// without a callback.
|
|
|
|
onSnapshotClicked: PropTypes.func,
|
|
|
|
|
|
|
|
// Callback for when the reload button is clicked. Button not shown
|
|
|
|
// without a callback.
|
|
|
|
onReloadClicked: PropTypes.func,
|
|
|
|
|
|
|
|
// Callback for when the edit button is clicked. Button not shown
|
|
|
|
// without a callback.
|
|
|
|
onEditClicked: PropTypes.func,
|
|
|
|
|
|
|
|
// Callback for when the delete button is clicked. Button not shown
|
|
|
|
// without a callback.
|
|
|
|
onDeleteClicked: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
proxyClick(fn) {
|
|
|
|
fn();
|
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: It's annoying that our context menus require us to hit onFinished() to close :(
|
|
|
|
|
|
|
|
onEditClicked = () => {
|
|
|
|
this.proxyClick(this.props.onEditClicked);
|
|
|
|
};
|
|
|
|
|
|
|
|
onReloadClicked = () => {
|
|
|
|
this.proxyClick(this.props.onReloadClicked);
|
|
|
|
};
|
|
|
|
|
|
|
|
onSnapshotClicked = () => {
|
|
|
|
this.proxyClick(this.props.onSnapshotClicked);
|
|
|
|
};
|
|
|
|
|
|
|
|
onDeleteClicked = () => {
|
|
|
|
this.proxyClick(this.props.onDeleteClicked);
|
|
|
|
};
|
|
|
|
|
|
|
|
onRevokeClicked = () => {
|
|
|
|
this.proxyClick(this.props.onRevokeClicked);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const options = [];
|
|
|
|
|
|
|
|
if (this.props.onEditClicked) {
|
|
|
|
options.push(
|
2019-11-28 21:16:59 +03:00
|
|
|
<MenuItem className='mx_WidgetContextMenu_option' onClick={this.onEditClicked} key='edit'>
|
2019-11-21 05:17:42 +03:00
|
|
|
{_t("Edit")}
|
2019-11-28 21:16:59 +03:00
|
|
|
</MenuItem>,
|
2019-11-21 05:17:42 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.onReloadClicked) {
|
|
|
|
options.push(
|
2019-11-28 21:16:59 +03:00
|
|
|
<MenuItem className='mx_WidgetContextMenu_option' onClick={this.onReloadClicked} key='reload'>
|
2019-11-21 05:17:42 +03:00
|
|
|
{_t("Reload")}
|
2019-11-28 21:16:59 +03:00
|
|
|
</MenuItem>,
|
2019-11-21 05:17:42 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.onSnapshotClicked) {
|
|
|
|
options.push(
|
2019-11-28 21:16:59 +03:00
|
|
|
<MenuItem className='mx_WidgetContextMenu_option' onClick={this.onSnapshotClicked} key='snap'>
|
2019-11-21 05:17:42 +03:00
|
|
|
{_t("Take picture")}
|
2019-11-28 21:16:59 +03:00
|
|
|
</MenuItem>,
|
2019-11-21 05:17:42 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.onDeleteClicked) {
|
|
|
|
options.push(
|
2019-11-28 21:16:59 +03:00
|
|
|
<MenuItem className='mx_WidgetContextMenu_option' onClick={this.onDeleteClicked} key='delete'>
|
2019-11-21 05:17:42 +03:00
|
|
|
{_t("Remove for everyone")}
|
2019-11-28 21:16:59 +03:00
|
|
|
</MenuItem>,
|
2019-11-21 05:17:42 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push this last so it appears last. It's always present.
|
|
|
|
options.push(
|
2019-11-28 21:16:59 +03:00
|
|
|
<MenuItem className='mx_WidgetContextMenu_option' onClick={this.onRevokeClicked} key='revoke'>
|
2019-11-21 05:17:42 +03:00
|
|
|
{_t("Remove for me")}
|
2019-11-28 21:16:59 +03:00
|
|
|
</MenuItem>,
|
2019-11-21 05:17:42 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Put separators between the options
|
|
|
|
if (options.length > 1) {
|
|
|
|
const length = options.length;
|
|
|
|
for (let i = 0; i < length - 1; i++) {
|
|
|
|
const sep = <hr key={i} className="mx_WidgetContextMenu_separator" />;
|
|
|
|
|
|
|
|
// Insert backwards so the insertions don't affect our math on where to place them.
|
|
|
|
// We also use our cached length to avoid worrying about options.length changing
|
|
|
|
options.splice(length - 1 - i, 0, sep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="mx_WidgetContextMenu">{options}</div>;
|
|
|
|
}
|
|
|
|
}
|