Skip to content
Snippets Groups Projects
Commit e4f630db authored by Alexander Rose's avatar Alexander Rose
Browse files

improve drag and drop support

- any file type
- multiple files
- if session, only first is loaded
parent ccaf18af
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,11 @@ Note that since we don't clearly distinguish between a public and private interf ...@@ -7,8 +7,11 @@ Note that since we don't clearly distinguish between a public and private interf
## [Unreleased] ## [Unreleased]
- Add ``bumpiness`` (per-object and per-group), ``bumpFrequency`` & ``bumpAmplitude`` (per-object) render parameters (#299) - Add ``bumpiness`` (per-object and per-group), ``bumpFrequency`` & ``bumpAmplitude`` (per-object) render parameters (#299)
- Change ``label`` representation defaults: Use text border instead of rectangle background. - Change ``label`` representation defaults: Use text border instead of rectangle background
- Add outline color option to renderer - Add outline color option to renderer
- Fix false positives in Model.isFromPdbArchive
- Add drag and drop support for loading any file, including multiple at once
- If there are session files (.molx or .molj) among the dropped files, only the first session will be loaded
## [v3.0.0-dev.3] - 2021-12-4 ## [v3.0.0-dev.3] - 2021-12-4
......
...@@ -18,6 +18,8 @@ import { Toasts } from './toast'; ...@@ -18,6 +18,8 @@ import { Toasts } from './toast';
import { Viewport, ViewportControls } from './viewport'; import { Viewport, ViewportControls } from './viewport';
import { PluginCommands } from '../mol-plugin/commands'; import { PluginCommands } from '../mol-plugin/commands';
import { PluginUIContext } from './context'; import { PluginUIContext } from './context';
import { OpenFiles } from '../mol-plugin-state/actions/file';
import { Asset } from '../mol-util/assets';
export class Plugin extends React.Component<{ plugin: PluginUIContext }, {}> { export class Plugin extends React.Component<{ plugin: PluginUIContext }, {}> {
region(kind: 'left' | 'right' | 'bottom' | 'main', element: JSX.Element) { region(kind: 'left' | 'right' | 'bottom' | 'main', element: JSX.Element) {
...@@ -102,22 +104,34 @@ class Layout extends PluginUIComponent { ...@@ -102,22 +104,34 @@ class Layout extends PluginUIComponent {
onDrop = (ev: React.DragEvent<HTMLDivElement>) => { onDrop = (ev: React.DragEvent<HTMLDivElement>) => {
ev.preventDefault(); ev.preventDefault();
let file: File | undefined | null; const files: File[] = [];
if (ev.dataTransfer.items) { if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s) // Use DataTransferItemList interface to access the file(s)
for (let i = 0; i < ev.dataTransfer.items.length; i++) { for (let i = 0; i < ev.dataTransfer.items.length; i++) {
if (ev.dataTransfer.items[i].kind !== 'file') continue; if (ev.dataTransfer.items[i].kind !== 'file') continue;
file = ev.dataTransfer.items[i].getAsFile(); const file = ev.dataTransfer.items[i].getAsFile();
break; if (file) files.push(file);
} }
} else { } else {
file = ev.dataTransfer.files[0]; for (let i = 0; i < ev.dataTransfer.files.length; i++) {
const file = ev.dataTransfer.files[0];
if (file) files.push(file);
}
} }
if (!file) return;
const fn = file?.name.toLowerCase() || ''; const sessions = files.filter(f => {
if (fn.endsWith('molx') || fn.endsWith('molj')) { const fn = f.name.toLowerCase();
PluginCommands.State.Snapshots.OpenFile(this.plugin, { file }); return fn.endsWith('.molx') || fn.endsWith('.molj');
});
if (sessions.length > 0) {
PluginCommands.State.Snapshots.OpenFile(this.plugin, { file: sessions[0] });
} else {
this.plugin.runTask(this.plugin.state.data.applyAction(OpenFiles, {
files: files.map(f => Asset.File(f)),
format: { name: 'auto', params: {} },
visuals: true
}));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment