Add context menu
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
bd5efc7ceb
commit
9312becee5
1 changed files with 47 additions and 1 deletions
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, { createRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
||||||
import {formatDate} from '../../../DateUtils';
|
import {formatDate} from '../../../DateUtils';
|
||||||
|
@ -26,6 +26,9 @@ import * as sdk from "../../../index";
|
||||||
import {Key} from "../../../Keyboard";
|
import {Key} from "../../../Keyboard";
|
||||||
import FocusLock from "react-focus-lock";
|
import FocusLock from "react-focus-lock";
|
||||||
import MemberAvatar from "../avatars/MemberAvatar";
|
import MemberAvatar from "../avatars/MemberAvatar";
|
||||||
|
import {ContextMenuTooltipButton} from "../../../accessibility/context_menu/ContextMenuTooltipButton";
|
||||||
|
import MessageContextMenu from "../context_menus/MessageContextMenu";
|
||||||
|
import {aboveLeftOf, ContextMenu} from '../../structures/ContextMenu';
|
||||||
|
|
||||||
export default class ImageView extends React.Component {
|
export default class ImageView extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -53,9 +56,11 @@ export default class ImageView extends React.Component {
|
||||||
translationX: 0,
|
translationX: 0,
|
||||||
translationY: 0,
|
translationY: 0,
|
||||||
moving: false,
|
moving: false,
|
||||||
|
contextMenuDisplay: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contextMenuButton = createRef();
|
||||||
initX = 0;
|
initX = 0;
|
||||||
initY = 0;
|
initY = 0;
|
||||||
lastX = 0;
|
lastX = 0;
|
||||||
|
@ -179,6 +184,20 @@ export default class ImageView extends React.Component {
|
||||||
a.click();
|
a.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOpenContextMenu = (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.setState({
|
||||||
|
contextMenuDisplay: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onCloseContextMenu = () => {
|
||||||
|
this.setState({
|
||||||
|
contextMenuDisplay: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onPanelClick = (ev) => {
|
onPanelClick = (ev) => {
|
||||||
this.props.onFinished();
|
this.props.onFinished();
|
||||||
}
|
}
|
||||||
|
@ -210,6 +229,30 @@ export default class ImageView extends React.Component {
|
||||||
this.setState({moving: false});
|
this.setState({moving: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderContextMenu() {
|
||||||
|
let contextMenu = null;
|
||||||
|
if (this.state.contextMenuDisplay) {
|
||||||
|
contextMenu = (
|
||||||
|
<ContextMenu
|
||||||
|
{...aboveLeftOf(this.contextMenuButton.current.getBoundingClientRect())}
|
||||||
|
onFinished={this.onCloseContextMenu}
|
||||||
|
>
|
||||||
|
<MessageContextMenu
|
||||||
|
mxEvent={this.props.mxEvent}
|
||||||
|
permalinkCreator={this.props.permalinkCreator}
|
||||||
|
onFinished={this.onCloseContextMenu}
|
||||||
|
/>
|
||||||
|
</ContextMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
{ contextMenu }
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const showEventMeta = !!this.props.mxEvent;
|
const showEventMeta = !!this.props.mxEvent;
|
||||||
|
|
||||||
|
@ -313,12 +356,15 @@ export default class ImageView extends React.Component {
|
||||||
<ContextMenuTooltipButton
|
<ContextMenuTooltipButton
|
||||||
className="mx_ImageView_button mx_ImageView_button_more"
|
className="mx_ImageView_button mx_ImageView_button_more"
|
||||||
title={_t("Options")}
|
title={_t("Options")}
|
||||||
|
onClick={this.onOpenContextMenu}
|
||||||
|
inputRef={this.contextMenuButton}
|
||||||
/>
|
/>
|
||||||
<AccessibleTooltipButton
|
<AccessibleTooltipButton
|
||||||
className="mx_ImageView_button mx_ImageView_button_close"
|
className="mx_ImageView_button mx_ImageView_button_close"
|
||||||
title={_t("Close")}
|
title={_t("Close")}
|
||||||
onClick={ this.props.onFinished }>
|
onClick={ this.props.onFinished }>
|
||||||
</AccessibleTooltipButton>
|
</AccessibleTooltipButton>
|
||||||
|
{this.renderContextMenu()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue