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

feat(FilePickerBuilder): Allow to configure the dialog container element #950

Merged
merged 1 commit into from
Aug 25, 2023
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
12 changes: 6 additions & 6 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ msgstr ""
msgid "All files"
msgstr ""

#: lib/filepicker.ts:188
#: lib/filepicker.ts:207
msgid "Choose"
msgstr ""

#: lib/filepicker.ts:188
#: lib/filepicker.ts:207
msgid "Choose {file}"
msgstr ""

#: lib/filepicker.ts:195
#: lib/filepicker.ts:214
msgid "Copy"
msgstr ""

#: lib/filepicker.ts:195
#: lib/filepicker.ts:214
msgid "Copy to {target}"
msgstr ""

Expand Down Expand Up @@ -59,11 +59,11 @@ msgstr ""
msgid "Modified"
msgstr ""

#: lib/filepicker.ts:203
#: lib/filepicker.ts:222
msgid "Move"
msgstr ""

#: lib/filepicker.ts:203
#: lib/filepicker.ts:222
msgid "Move to {target}"
msgstr ""

Expand Down
29 changes: 24 additions & 5 deletions lib/filepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,24 @@ export class FilePicker<IsMultiSelect extends boolean> {
private buttons: IFilePickerButton[] | IFilePickerButtonFactory
private path?: string
private filter?: IFilePickerFilter
private container?: string

public constructor(title: string,
multiSelect: IsMultiSelect,
mimeTypeFilter: string[],
directoriesAllowed: boolean,
buttons: IFilePickerButton[] | IFilePickerButtonFactory,
path?: string,
filter?: IFilePickerFilter) {
filter?: IFilePickerFilter,
container?: string) {
this.title = title
this.multiSelect = multiSelect
this.mimeTypeFilter = mimeTypeFilter
this.directoriesAllowed = directoriesAllowed
this.path = path
this.filter = filter
this.buttons = buttons
this.container = container
}

/**
Expand All @@ -78,17 +81,21 @@ export class FilePicker<IsMultiSelect extends boolean> {
spawnDialog(FilePickerVue, {
allowPickDirectory: this.directoriesAllowed,
buttons: this.buttons,
container: this.container,
name: this.title,
path: this.path,
mimetypeFilter: this.mimeTypeFilter,
multiselect: this.multiSelect,
filterFn: this.filter,
}, (...nodes: unknown[]) => {
if (!nodes) reject(new Error('Nothing selected'))
if (this.multiSelect) {
resolve((nodes as Node[]).map((node) => node.path) as (IsMultiSelect extends true ? string[] : string))
if (!nodes) {
reject(new Error('Nothing selected'))
} else {
resolve(((nodes as Node[])[0]?.path || '/') as (IsMultiSelect extends true ? string[] : string))
if (this.multiSelect) {
resolve((nodes as Node[]).map((node) => node.path) as (IsMultiSelect extends true ? string[] : string))
} else {
resolve(((nodes as Node[])[0]?.path || '/') as (IsMultiSelect extends true ? string[] : string))
}
}
})
})
Expand All @@ -105,6 +112,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
private path?: string
private filter?: IFilePickerFilter
private buttons: IFilePickerButton[] | IFilePickerButtonFactory = []
private container?: string

/**
* Construct a new FilePicker
Expand All @@ -115,6 +123,17 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
this.title = title
}

/**
* Set the container where the FilePicker will be mounted
* By default 'body' is used
*
* @param container The dialog container
*/
public setContainer(container: string) {
this.container = container
return this
}

/**
* Enable or disable picking multiple files
*
Expand Down
Loading