diff --git a/schemas/source-data.schema.ts b/schemas/source-data.schema.ts index ef189b856..b09c88abf 100644 --- a/schemas/source-data.schema.ts +++ b/schemas/source-data.schema.ts @@ -13,6 +13,7 @@ export default function preprocessSourceDataSchema (schema) { const info = interfaces[key] ?? {} + const files = schema.properties.file_paths ?? schema.properties.file_path const singleLocationInfo = schema.properties.file_path ?? schema.properties.folder_path if (schema.properties.file_paths) { @@ -29,6 +30,11 @@ export default function preprocessSourceDataSchema (schema) { } + if (files) { + const base = singleLocationInfo ? files : files.items + if (!base.accept && info.suffixes) base.accept = info.suffixes + } + // Do not show steps if (schema.properties.gain) schema.properties.gain.step = null diff --git a/src/renderer/src/stories/FileSystemSelector.js b/src/renderer/src/stories/FileSystemSelector.js index 7a38d1f5e..5e33c5be8 100644 --- a/src/renderer/src/stories/FileSystemSelector.js +++ b/src/renderer/src/stories/FileSystemSelector.js @@ -103,6 +103,8 @@ export class FilesystemSelector extends LitElement { if (props.onSelect) this.onSelect = props.onSelect; if (props.onChange) this.onChange = props.onChange; if (props.onThrow) this.onThrow = props.onThrow; + + this.accept = props.accept; this.multiple = props.multiple; this.type = props.type ?? "file"; this.value = props.value ?? ""; @@ -125,6 +127,17 @@ export class FilesystemSelector extends LitElement { #useElectronDialog = async (type) => { const options = { ...this.dialogOptions }; + + if (!options.filters && this.accept) { + options.filters = [ + { + name: "Suggested Files", + extensions: this.accept.map((ext) => (ext[0] === "." ? ext.slice(1) : ext)), + }, + { name: "All Files", extensions: ["*"] }, + ]; + } + options.properties = [ type === "file" ? "openFile" : "openDirectory", "noResolveAliases", @@ -142,7 +155,8 @@ export class FilesystemSelector extends LitElement { return result; }; - #checkType = (value) => { + #check = (value) => { + // Check type const isLikelyFile = fs ? fs.statSync(value).isFile() : value.split(".").length; if ((this.type === "directory" && isLikelyFile) || (this.type === "file" && !isLikelyFile)) this.#onThrow("Incorrect filesystem object", `Please provide a ${this.type} instead.`); @@ -152,8 +166,8 @@ export class FilesystemSelector extends LitElement { const resolvedType = type ?? this.type; if (pathOrPaths) { - if (Array.isArray(pathOrPaths)) pathOrPaths.forEach(this.#checkType); - else if (!type) this.#checkType(pathOrPaths); + if (Array.isArray(pathOrPaths)) pathOrPaths.forEach(this.#check); + else if (!type) this.#check(pathOrPaths); } let resolvedValue = pathOrPaths; diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 3ce99b0aa..f68fb0f72 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -893,6 +893,7 @@ export class JSONSchemaInput extends LitElement { const filesystemSelectorElement = new FilesystemSelector({ type: format, value: this.value, + accept: schema.accept, onSelect: (paths = []) => { const value = paths.length ? paths : undefined; this.#updateData(fullPath, value);