forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconflict-controller.js
More file actions
175 lines (153 loc) · 4.84 KB
/
conflict-controller.js
File metadata and controls
175 lines (153 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import React from 'react';
import PropTypes from 'prop-types';
import {remote} from 'electron';
const {Menu, MenuItem} = remote;
import {autobind} from '../helpers';
import {OURS, BASE, THEIRS} from '../models/conflicts/source';
import Decoration from '../atom/decoration';
import Octicon from '../atom/octicon';
export default class ConflictController extends React.Component {
static propTypes = {
editor: PropTypes.object.isRequired,
conflict: PropTypes.object.isRequired,
resolveAsSequence: PropTypes.func,
dismiss: PropTypes.func,
};
static defaultProps = {
resolveAsSequence: sources => {},
dismiss: () => {},
}
constructor(props, context) {
super(props, context);
autobind(this, 'showResolveMenu');
this.state = {
chosenSide: this.props.conflict.getChosenSide(),
};
}
resolveAsSequence(sources) {
this.props.resolveAsSequence(sources);
this.setState({
chosenSide: this.props.conflict.getChosenSide(),
});
}
revert(side) {
side.isModified() && side.revert();
side.isBannerModified() && side.revertBanner();
}
showResolveMenu(event) {
event.preventDefault();
const menu = new Menu();
menu.append(new MenuItem({
label: 'Resolve as Ours',
click: this.resolveAsSequence.bind(this, [OURS]),
}));
if (this.props.conflict.getSide(BASE)) {
menu.append(new MenuItem({
label: 'Resolve as Base',
click: this.resolveAsSequence.bind(this, [BASE]),
}));
}
menu.append(new MenuItem({
label: 'Resolve as Theirs',
click: this.resolveAsSequence.bind(this, [THEIRS]),
}));
menu.append(new MenuItem({type: 'separator'}));
menu.append(new MenuItem({
label: 'Resolve as Ours Then Theirs',
click: this.resolveAsSequence.bind(this, [OURS, THEIRS]),
}));
menu.append(new MenuItem({
label: 'Resolve as Theirs Then Ours',
click: this.resolveAsSequence.bind(this, [THEIRS, OURS]),
}));
menu.append(new MenuItem({type: 'separator'}));
menu.append(new MenuItem({
label: 'Dismiss',
click: this.props.dismiss,
}));
menu.popup(remote.getCurrentWindow());
}
render() {
if (!this.state.chosenSide) {
const ours = this.props.conflict.getSide(OURS);
const base = this.props.conflict.getSide(BASE);
const theirs = this.props.conflict.getSide(THEIRS);
return (
<div>
{this.renderSide(ours)}
{base && this.renderSide(base)}
<Decoration
key={this.props.conflict.getSeparator().getMarker().id}
editor={this.props.editor}
decorable={this.props.conflict.getSeparator().getMarker()}
type="line"
className="github-ConflictSeparator"
/>
{this.renderSide(theirs)}
</div>
);
} else if (!this.state.chosenSide.isEmpty()) {
return (
<Decoration
editor={this.props.editor}
decorable={this.state.chosenSide.getMarker()}
type="line"
className="github-ResolvedLines"
/>
);
} else {
return null;
}
}
renderSide(side) {
const source = side.getSource();
return (
<div>
<Decoration
key={side.banner.marker.id}
editor={this.props.editor}
decorable={side.getBannerMarker()}
type="line"
className={side.getBannerCSSClass()}
/>
{side.isBannerModified() ||
<Decoration
key={'banner-modified-' + side.banner.marker.id}
editor={this.props.editor}
decorable={side.getBannerMarker()}
type="line"
className="github-ConflictUnmodifiedBanner"
/>
}
<Decoration
key={side.marker.id}
editor={this.props.editor}
decorable={side.getMarker()}
type="line"
className={side.getLineCSSClass()}
/>
<Decoration
key={'block-' + side.marker.id}
editor={this.props.editor}
decorable={side.getBlockMarker()}
type="block"
position={side.getBlockPosition()}>
<div className={side.getBlockCSSClasses()}>
<span className="github-ResolutionControls">
<button className="btn btn-sm inline-block" onClick={() => this.resolveAsSequence([source])}>
Use me
</button>
{(side.isModified() || side.isBannerModified()) &&
<button className="btn btn-sm inline-block" onClick={() => this.revert(side)}>
Revert
</button>
}
<Octicon icon="ellipses" className="inline-block" onClick={this.showResolveMenu} />
</span>
<span className="github-SideDescription">{source.toUIString()}</span>
</div>
</Decoration>
</div>
);
}
}