Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use default path in windows when choosing a file #7625

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions ui/component/common/file-selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,24 @@ class FileSelector extends React.PureComponent<Props> {
};

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice,
tested in console in linux
x = require('@electron/remote')
x.dialog.showOpenDialog({properties: ['openFile'], defaultPath: undefined})
And it worked fine.

const path = result && result.filePaths[0];
if (path) {
// $FlowFixMe
Expand Down Expand Up @@ -82,7 +99,11 @@ class FileSelector extends React.PureComponent<Props> {
autoFocus={autoFocus}
button="primary"
disabled={disabled}
onClick={type === 'openDirectory' ? this.handleDirectoryInputSelection : this.fileInputButton}
onClick={
type === 'openDirectory' || type === 'openFile'
? this.handleDirectoryInputSelection
: this.fileInputButton
}
label={__('Browse')}
/>
}
Expand Down
1 change: 1 addition & 0 deletions ui/component/publishFile/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function PublishFile(props: Props) {
{showFileUpload && (
<>
<FileSelector
type="openFile"
label={__('File')}
disabled={disabled}
currentPath={currentFile}
Expand Down