Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2696 from matrix-org/t3chguy/pretty_view_source
Browse files Browse the repository at this point in the history
make ViewSource less awkward
  • Loading branch information
turt2live authored Feb 25, 2019
2 parents acbd3fb + 7b88d5d commit 2b9b07c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
6 changes: 0 additions & 6 deletions res/css/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,6 @@ textarea {
box-shadow: none;
}

/* View Source Dialog overide */
.mx_Dialog_wrapper.mx_Dialog_viewsource .mx_Dialog {
padding-left: 10px;
padding-right: 10px;
}

.mx_Dialog {
background-color: $primary-bg-color;
color: $light-fg-color;
Expand Down
13 changes: 13 additions & 0 deletions res/css/structures/_ViewSource.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_ViewSource_label_left {
float: left;
}

.mx_ViewSource_label_right {
float: right;
}

.mx_ViewSource_label_bottom {
clear: both;
border-bottom: 1px solid #e5e5e5;
}

.mx_ViewSource pre {
text-align: left;
font-size: 12px;
Expand Down
40 changes: 17 additions & 23 deletions src/components/structures/ViewSource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 Michael Telatynski <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,11 +15,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict';

import React from 'react';
import PropTypes from 'prop-types';
import SyntaxHighlight from '../views/elements/SyntaxHighlight';
import {_t} from "../../languageHandler";
import sdk from "../../index";


module.exports = React.createClass({
Expand All @@ -27,31 +28,24 @@ module.exports = React.createClass({
propTypes: {
content: PropTypes.object.isRequired,
onFinished: PropTypes.func.isRequired,
},

componentDidMount: function() {
document.addEventListener("keydown", this.onKeyDown);
},

componentWillUnmount: function() {
document.removeEventListener("keydown", this.onKeyDown);
},

onKeyDown: function(ev) {
if (ev.keyCode == 27) { // escape
ev.stopPropagation();
ev.preventDefault();
this.props.onFinished();
}
roomId: PropTypes.string.isRequired,
eventId: PropTypes.string.isRequired,
},

render: function() {
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
return (
<div className="mx_ViewSource">
<SyntaxHighlight className="json">
{ JSON.stringify(this.props.content, null, 2) }
</SyntaxHighlight>
</div>
<BaseDialog className="mx_ViewSource" onFinished={this.props.onFinished} title={_t('View Source')}>
<div className="mx_ViewSource_label_left">Room ID: { this.props.roomId }</div>
<div className="mx_ViewSource_label_right">Event ID: { this.props.eventId }</div>
<div className="mx_ViewSource_label_bottom" />

<div className="mx_Dialog_content">
<SyntaxHighlight className="json">
{ JSON.stringify(this.props.content, null, 2) }
</SyntaxHighlight>
</div>
</BaseDialog>
);
},
});
4 changes: 4 additions & 0 deletions src/components/views/context_menus/MessageContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ module.exports = React.createClass({
onViewSourceClick: function() {
const ViewSource = sdk.getComponent('structures.ViewSource');
Modal.createTrackedDialog('View Event Source', '', ViewSource, {
roomId: this.props.mxEvent.getRoomId(),
eventId: this.props.mxEvent.getId(),
content: this.props.mxEvent.event,
}, 'mx_Dialog_viewsource');
this.closeMenu();
Expand All @@ -106,6 +108,8 @@ module.exports = React.createClass({
onViewClearSourceClick: function() {
const ViewSource = sdk.getComponent('structures.ViewSource');
Modal.createTrackedDialog('View Clear Event Source', '', ViewSource, {
roomId: this.props.mxEvent.getRoomId(),
eventId: this.props.mxEvent.getId(),
// FIXME: _clearEvent is private
content: this.props.mxEvent._clearEvent,
}, 'mx_Dialog_viewsource');
Expand Down

0 comments on commit 2b9b07c

Please sign in to comment.