forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-dialog.js
More file actions
94 lines (78 loc) · 2.33 KB
/
init-dialog.js
File metadata and controls
94 lines (78 loc) · 2.33 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
import React from 'react';
import PropTypes from 'prop-types';
import {TextBuffer} from 'atom';
import AtomTextEditor from '../atom/atom-text-editor';
import AutoFocus from '../autofocus';
import DialogView from './dialog-view';
export default class InitDialog extends React.Component {
static propTypes = {
// Model
request: PropTypes.shape({
getParams: PropTypes.func.isRequired,
accept: PropTypes.func.isRequired,
cancel: PropTypes.func.isRequired,
}).isRequired,
inProgress: PropTypes.bool,
error: PropTypes.instanceOf(Error),
// Atom environment
workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
}
constructor(props) {
super(props);
this.autofocus = new AutoFocus();
this.destinationPath = new TextBuffer({
text: this.props.request.getParams().dirPath,
});
this.sub = this.destinationPath.onDidChange(this.setAcceptEnablement);
this.state = {
acceptEnabled: !this.destinationPath.isEmpty(),
};
}
render() {
return (
<DialogView
progressMessage="Initializing..."
acceptEnabled={this.state.acceptEnabled}
acceptClassName="icon icon-repo-create"
acceptText="Init"
accept={this.accept}
cancel={this.props.request.cancel}
autofocus={this.autofocus}
inProgress={this.props.inProgress}
error={this.props.error}
workspace={this.props.workspace}
commands={this.props.commands}>
<label className="github-DialogLabel">
Initialize git repository in directory
<AtomTextEditor
ref={this.autofocus.target}
mini={true}
readOnly={this.props.inProgress}
preselect={true}
buffer={this.destinationPath}
/>
</label>
</DialogView>
);
}
componentDidMount() {
this.autofocus.trigger();
}
componentWillUnmount() {
this.sub.dispose();
}
accept = () => {
const destPath = this.destinationPath.getText();
if (destPath.length === 0) {
return Promise.resolve();
}
return this.props.request.accept(destPath);
}
setAcceptEnablement = () => {
const enablement = !this.destinationPath.isEmpty();
if (enablement !== this.state.acceptEnabled) {
this.setState({acceptEnabled: enablement});
}
}
}