This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathdirectory-select.js
More file actions
57 lines (50 loc) · 1.63 KB
/
directory-select.js
File metadata and controls
57 lines (50 loc) · 1.63 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
import React from 'react';
import PropTypes from 'prop-types';
import {remote} from 'electron';
import {TabbableTextEditor, TabbableButton} from './tabbable';
const {dialog} = remote;
export default class DirectorySelect extends React.Component {
static propTypes = {
buffer: PropTypes.object.isRequired,
disabled: PropTypes.bool,
showOpenDialog: PropTypes.func,
tabGroup: PropTypes.object.isRequired,
// Atom environment
currentWindow: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
}
static defaultProps = {
disabled: false,
showOpenDialog: /* istanbul ignore next */ (...args) => dialog.showOpenDialog(...args),
}
render() {
return (
<div className="github-Dialog-row">
<TabbableTextEditor
tabGroup={this.props.tabGroup}
commands={this.props.commands}
className="github-DirectorySelect-destinationPath"
mini={true}
readOnly={this.props.disabled}
buffer={this.props.buffer}
/>
<TabbableButton
tabGroup={this.props.tabGroup}
commands={this.props.commands}
className="btn icon icon-file-directory github-Dialog-rightBumper"
disabled={this.props.disabled}
onClick={this.chooseDirectory}
/>
</div>
);
}
chooseDirectory = async () => {
const {filePaths} = await this.props.showOpenDialog(this.props.currentWindow, {
defaultPath: this.props.buffer.getText(),
properties: ['openDirectory', 'createDirectory', 'promptToCreate'],
});
if (filePaths.length) {
this.props.buffer.setText(filePaths[0]);
}
}
}