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

[Enhancement]: Allow Drag&Drop of files/folders into another folder #17

Open
pkerschbaum opened this issue Jan 17, 2022 · 0 comments
Open
Labels
kind/enhancement New feature or request

Comments

@pkerschbaum
Copy link
Owner

pkerschbaum commented Jan 17, 2022

Motivation

As other file explorers can do, it should be able to select multiple files/folders and move them into another folder via Drag&Drop.
It would be even better if this file explorer could "react" to files/folders dropped into it from the outside, e.g. from the MacOS Finder or Windows File Explorer.

See this screenshot for illustration purposes:
2022-01-17 13_36_04-New Issue · pkerschbaum_file-explorer - Brave

Implementation Notes

There is already a onDragStart handler on resource rows / resource tiles which allows to drag the selected resource outside of the file explorer into other applications. E.g. if a .pdf file is dragged from the file explorer to a web browser, the browser opens the PDF file.
See these lines of code:

onDragStart: (e: React.DragEvent<HTMLTableRowElement>) => {
e.preventDefault();
startNativeDnDForSelectedResources();
},

The implementation of startNativeFileDnD is based on the Electron native file drag & drop API (https://www.electronjs.org/docs/latest/tutorial/native-file-drag-drop). It runs in the main process here:

import { ipcMain, IpcMainEvent, Item } from 'electron';
import invariant from 'tiny-invariant';
import {
IpcFileDragStart,
FILEDRAGSTART_CHANNEL,
} from '@app/platform/electron/ipc/common/file-drag-start';
import { OUTLINE_INSERT_DRIVE_FILE_ICON_PATH } from '@app/static-resources-main';
export function registerListeners(): void {
ipcMain.on(FILEDRAGSTART_CHANNEL, fileDragStartHandler);
}
function fileDragStartHandler(
e: IpcMainEvent,
{ fsPaths }: IpcFileDragStart.Args,
): IpcFileDragStart.ReturnValue {
invariant(fsPaths.length > 0);
const startDragArg: Omit<Item, 'file'> = {
files: fsPaths,
icon: OUTLINE_INSERT_DRIVE_FILE_ICON_PATH,
};
// @ts-expect-error -- electron typings have the property "file" defined as required, although that is actually not necessary (https://www.electronjs.org/docs/latest/api/web-contents#contentsstartdragitem)
e.sender.startDrag(startDragArg);
}

@pkerschbaum pkerschbaum added the kind/enhancement New feature or request label Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant