use default path in windows when choosing a file (#7625)
* use default path in windows when choosing a file * fix, changed var to let
This commit is contained in:
parent
8c10617259
commit
c7ab47f54d
2 changed files with 24 additions and 2 deletions
|
@ -47,7 +47,24 @@ class FileSelector extends React.PureComponent<Props> {
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDirectoryInputSelection = () => {
|
handleDirectoryInputSelection = () => {
|
||||||
remote.dialog.showOpenDialog({ properties: ['openDirectory'] }).then((result) => {
|
let defaultPath;
|
||||||
|
let properties;
|
||||||
|
let isWin = process.platform === 'win32';
|
||||||
|
let type = this.props.type;
|
||||||
|
|
||||||
|
if (isWin === true) {
|
||||||
|
defaultPath = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'openFile') {
|
||||||
|
properties = ['openFile'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'openDirectory') {
|
||||||
|
properties = ['openDirectory'];
|
||||||
|
}
|
||||||
|
|
||||||
|
remote.dialog.showOpenDialog({ properties, defaultPath }).then((result) => {
|
||||||
const path = result && result.filePaths[0];
|
const path = result && result.filePaths[0];
|
||||||
if (path) {
|
if (path) {
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
|
@ -82,7 +99,11 @@ class FileSelector extends React.PureComponent<Props> {
|
||||||
autoFocus={autoFocus}
|
autoFocus={autoFocus}
|
||||||
button="primary"
|
button="primary"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={type === 'openDirectory' ? this.handleDirectoryInputSelection : this.fileInputButton}
|
onClick={
|
||||||
|
type === 'openDirectory' || type === 'openFile'
|
||||||
|
? this.handleDirectoryInputSelection
|
||||||
|
: this.fileInputButton
|
||||||
|
}
|
||||||
label={__('Browse')}
|
label={__('Browse')}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,6 +325,7 @@ function PublishFile(props: Props) {
|
||||||
{showFileUpload && (
|
{showFileUpload && (
|
||||||
<>
|
<>
|
||||||
<FileSelector
|
<FileSelector
|
||||||
|
type="openFile"
|
||||||
label={__('File')}
|
label={__('File')}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
currentPath={currentFile}
|
currentPath={currentFile}
|
||||||
|
|
Loading…
Reference in a new issue