Skip to main content
Sign in
Snippets Groups Projects
Commit 311f5c09 authored by Alexander Rose's avatar Alexander Rose
Browse files

use Asset.File[] for PD.FileList

parent be443945
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ import { Task } from '../../mol-task';
import { getFileInfo } from '../../mol-util/file-info';
import { ParamDefinition as PD } from '../../mol-util/param-definition';
import { PluginStateObject } from '../objects';
import { Asset } from '../../mol-util/assets';
export const OpenFiles = StateAction.build({
display: { name: 'Open Files', description: 'Load one or more files and optionally create default visuals' },
......@@ -31,12 +30,11 @@ export const OpenFiles = StateAction.build({
plugin.log.error('No file(s) selected');
return;
}
for (let i = 0, il = params.files.length; i < il; ++i) {
for (const file of params.files) {
try {
const file = params.files[i];
const info = getFileInfo(file);
const info = getFileInfo(file.file!);
const isBinary = plugin.dataFormats.binaryExtensions.has(info.ext);
const { data } = await plugin.builders.data.readFile({ file: Asset.File(file), isBinary });
const { data } = await plugin.builders.data.readFile({ file, isBinary });
const provider = params.format === 'auto'
? plugin.dataFormats.auto(info, data.cell?.obj!)
: plugin.dataFormats.get(params.format);
......
......
......@@ -834,7 +834,13 @@ export class FileControl extends React.PureComponent<ParamProps<PD.FileParam>> {
export class FileListControl extends React.PureComponent<ParamProps<PD.FileListParam>> {
change(value: FileList) {
this.props.onChange({ name: this.props.name, param: this.props.param, value });
const files: Asset.File[] = [];
if (value) {
for (let i = 0, il = value.length; i < il; ++i) {
files.push(Asset.File(value[i]));
}
}
this.props.onChange({ name: this.props.name, param: this.props.param, value: files });
}
onChangeFileList = (e: React.ChangeEvent<HTMLInputElement>) => {
......@@ -846,8 +852,8 @@ export class FileListControl extends React.PureComponent<ParamProps<PD.FileListP
const names: string[] = [];
if (value) {
for (let i = 0, il = value.length; i < il; ++i) {
names.push(value[i].name);
for (const file of value) {
names.push(file.name);
}
}
const label = names.length === 0
......
......
......@@ -167,7 +167,7 @@ export namespace ParamDefinition {
return ret;
}
export interface FileListParam extends Base<FileList | null> {
export interface FileListParam extends Base<Asset.File[] | null> {
type: 'file-list'
accept?: string
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment