forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-tab-view.js
More file actions
290 lines (261 loc) · 10.9 KB
/
git-tab-view.js
File metadata and controls
290 lines (261 loc) · 10.9 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import {CompositeDisposable} from 'atom';
import StagingView from './staging-view';
import CommitController from '../controllers/commit-controller';
import RecentCommitsController from '../controllers/recent-commits-controller';
import RefHolder from '../models/ref-holder';
import {isValidWorkdir, autobind} from '../helpers';
import {AuthorPropType, UserStorePropType, RefHolderPropType} from '../prop-types';
export default class GitTabView extends React.Component {
static focus = {
...StagingView.focus,
...CommitController.focus,
...RecentCommitsController.focus,
};
static propTypes = {
refRoot: RefHolderPropType,
refStagingView: RefHolderPropType,
repository: PropTypes.object.isRequired,
isLoading: PropTypes.bool.isRequired,
lastCommit: PropTypes.object.isRequired,
currentBranch: PropTypes.object,
recentCommits: PropTypes.arrayOf(PropTypes.object).isRequired,
isMerging: PropTypes.bool,
isRebasing: PropTypes.bool,
hasUndoHistory: PropTypes.bool,
unstagedChanges: PropTypes.arrayOf(PropTypes.object),
stagedChanges: PropTypes.arrayOf(PropTypes.object),
mergeConflicts: PropTypes.arrayOf(PropTypes.object),
workingDirectoryPath: PropTypes.string,
mergeMessage: PropTypes.string,
userStore: UserStorePropType.isRequired,
selectedCoAuthors: PropTypes.arrayOf(AuthorPropType),
updateSelectedCoAuthors: PropTypes.func.isRequired,
workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
grammars: PropTypes.object.isRequired,
resolutionProgress: PropTypes.object.isRequired,
notificationManager: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
project: PropTypes.object.isRequired,
tooltips: PropTypes.object.isRequired,
openInitializeDialog: PropTypes.func.isRequired,
abortMerge: PropTypes.func.isRequired,
commit: PropTypes.func.isRequired,
undoLastCommit: PropTypes.func.isRequired,
prepareToCommit: PropTypes.func.isRequired,
resolveAsOurs: PropTypes.func.isRequired,
resolveAsTheirs: PropTypes.func.isRequired,
undoLastDiscard: PropTypes.func.isRequired,
attemptStageAllOperation: PropTypes.func.isRequired,
attemptFileStageOperation: PropTypes.func.isRequired,
discardWorkDirChangesForPaths: PropTypes.func.isRequired,
openFiles: PropTypes.func.isRequired,
};
constructor(props, context) {
super(props, context);
autobind(this, 'initializeRepo', 'blur', 'advanceFocus', 'retreatFocus', 'quietlySelectItem');
this.subscriptions = new CompositeDisposable();
this.refCommitController = new RefHolder();
this.refRecentCommitsController = new RefHolder();
}
componentDidMount() {
this.props.refRoot.map(root => {
return this.subscriptions.add(
this.props.commands.add(root, {
'tool-panel:unfocus': this.blur,
'core:focus-next': this.advanceFocus,
'core:focus-previous': this.retreatFocus,
}),
);
});
}
render() {
if (this.props.repository.isTooLarge()) {
return (
<div className="github-Git is-empty" tabIndex="-1" ref={this.props.refRoot.setter}>
<div ref="noRepoMessage" className="github-Git too-many-changes">
<div className="github-Git-LargeIcon icon icon-diff" />
<h1>Too many changes</h1>
<div className="initialize-repo-description">
The repository at <strong>{this.props.workingDirectoryPath}</strong> has too many changed files
to display in Atom. Ensure that you have set up an appropriate <code>.gitignore</code> file.
</div>
</div>
</div>
);
} else if (this.props.repository.hasDirectory() &&
!isValidWorkdir(this.props.repository.getWorkingDirectoryPath())) {
return (
<div className="github-Git is-empty" tabIndex="-1" ref={this.props.refRoot.setter}>
<div ref="noRepoMessage" className="github-Git unsupported-directory">
<div className="github-Git-LargeIcon icon icon-alert" />
<h1>Unsupported directory</h1>
<div className="initialize-repo-description">
Atom does not support managing Git repositories in your home or root directories.
</div>
</div>
</div>
);
} else if (this.props.repository.showGitTabInit()) {
const inProgress = this.props.repository.showGitTabInitInProgress();
const message = this.props.repository.hasDirectory()
?
(
<span>Initialize <strong>{this.props.workingDirectoryPath}</strong> with a
Git repository</span>
)
: <span>Initialize a new project directory with a Git repository</span>;
return (
<div className="github-Git is-empty" tabIndex="-1" ref={this.props.refRoot.setter}>
<div ref="noRepoMessage" className="github-Git no-repository">
<div className="github-Git-LargeIcon icon icon-repo" />
<h1>Create Repository</h1>
<div className="initialize-repo-description">{message}</div>
<button onClick={this.initializeRepo} disabled={inProgress} className="btn btn-primary">
{inProgress ? 'Creating repository...' : 'Create repository'}
</button>
</div>
</div>
);
} else {
const isLoading = this.props.isLoading || this.props.repository.showGitTabLoading();
return (
<div
className={cx('github-Git', {'is-loading': isLoading})}
tabIndex="-1"
ref={this.props.refRoot.setter}>
<StagingView
ref={this.props.refStagingView.setter}
commands={this.props.commands}
notificationManager={this.props.notificationManager}
workspace={this.props.workspace}
stagedChanges={this.props.stagedChanges}
unstagedChanges={this.props.unstagedChanges}
mergeConflicts={this.props.mergeConflicts}
workingDirectoryPath={this.props.workingDirectoryPath}
resolutionProgress={this.props.resolutionProgress}
openFiles={this.props.openFiles}
discardWorkDirChangesForPaths={this.props.discardWorkDirChangesForPaths}
attemptFileStageOperation={this.props.attemptFileStageOperation}
attemptStageAllOperation={this.props.attemptStageAllOperation}
undoLastDiscard={this.props.undoLastDiscard}
abortMerge={this.props.abortMerge}
resolveAsOurs={this.props.resolveAsOurs}
resolveAsTheirs={this.props.resolveAsTheirs}
lastCommit={this.props.lastCommit}
isLoading={this.props.isLoading}
hasUndoHistory={this.props.hasUndoHistory}
isMerging={this.props.isMerging}
/>
<CommitController
ref={this.refCommitController.setter}
tooltips={this.props.tooltips}
config={this.props.config}
stagedChangesExist={this.props.stagedChanges.length > 0}
mergeConflictsExist={this.props.mergeConflicts.length > 0}
prepareToCommit={this.props.prepareToCommit}
commit={this.props.commit}
abortMerge={this.props.abortMerge}
currentBranch={this.props.currentBranch}
workspace={this.props.workspace}
commands={this.props.commands}
notificationManager={this.props.notificationManager}
grammars={this.props.grammars}
mergeMessage={this.props.mergeMessage}
isMerging={this.props.isMerging}
isLoading={this.props.isLoading}
lastCommit={this.props.lastCommit}
repository={this.props.repository}
userStore={this.props.userStore}
selectedCoAuthors={this.props.selectedCoAuthors}
updateSelectedCoAuthors={this.props.updateSelectedCoAuthors}
/>
<RecentCommitsController
ref={this.refRecentCommitsController.setter}
commands={this.props.commands}
commits={this.props.recentCommits}
isLoading={this.props.isLoading}
undoLastCommit={this.props.undoLastCommit}
workspace={this.props.workspace}
repository={this.props.repository}
/>
</div>
);
}
}
componentWillUnmount() {
this.subscriptions.dispose();
}
initializeRepo(event) {
event.preventDefault();
const workdir = this.props.repository.isAbsent() ? null : this.props.repository.getWorkingDirectoryPath();
return this.props.openInitializeDialog(workdir);
}
getFocus(element) {
for (const ref of [this.props.refStagingView, this.refCommitController, this.refRecentCommitsController]) {
const focus = ref.map(sub => sub.getFocus(element)).getOr(null);
if (focus !== null) {
return focus;
}
}
return null;
}
setFocus(focus) {
for (const ref of [this.props.refStagingView, this.refCommitController, this.refRecentCommitsController]) {
if (ref.map(sub => sub.setFocus(focus)).getOr(false)) {
return true;
}
}
return false;
}
blur() {
this.props.workspace.getCenter().activate();
}
async advanceFocus(evt) {
const currentFocus = this.getFocus(document.activeElement);
let nextSeen = false;
for (const subHolder of [this.props.refStagingView, this.refCommitController, this.refRecentCommitsController]) {
const next = await subHolder.map(sub => sub.advanceFocusFrom(currentFocus)).getOr(null);
if (next !== null && !nextSeen) {
nextSeen = true;
evt.stopPropagation();
if (next !== currentFocus) {
this.setFocus(next);
}
}
}
}
async retreatFocus(evt) {
const currentFocus = this.getFocus(document.activeElement);
let previousSeen = false;
for (const subHolder of [this.refRecentCommitsController, this.refCommitController, this.props.refStagingView]) {
const previous = await subHolder.map(sub => sub.retreatFocusFrom(currentFocus)).getOr(null);
if (previous !== null && !previousSeen) {
previousSeen = true;
evt.stopPropagation();
if (previous !== currentFocus) {
this.setFocus(previous);
}
}
}
}
async focusAndSelectStagingItem(filePath, stagingStatus) {
await this.quietlySelectItem(filePath, stagingStatus);
this.setFocus(GitTabView.focus.STAGING);
}
focusAndSelectRecentCommit() {
this.setFocus(RecentCommitsController.focus.RECENT_COMMIT);
}
focusAndSelectCommitPreviewButton() {
this.setFocus(GitTabView.focus.COMMIT_PREVIEW_BUTTON);
}
quietlySelectItem(filePath, stagingStatus) {
return this.props.refStagingView.map(view => view.quietlySelectItem(filePath, stagingStatus)).getOr(false);
}
hasFocus() {
return this.props.refRoot.map(root => root.contains(document.activeElement)).getOr(false);
}
}