Rework file transfer modes

This commit is contained in:
crschnick 2024-05-06 04:01:29 +00:00
parent 4c7f91fec9
commit 0e10d2508a
8 changed files with 40 additions and 24 deletions

View file

@ -1,6 +1,7 @@
package io.xpipe.app.browser;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.file.BrowserFileTransferMode;
import io.xpipe.app.browser.file.LocalFileSystem;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.ThreadHelper;
@ -54,7 +55,7 @@ public class BrowserClipboard {
entries.add(LocalFileSystem.getLocalBrowserEntry(file));
}
currentCopyClipboard.setValue(new Instance(UUID.randomUUID(), null, entries));
currentCopyClipboard.setValue(new Instance(UUID.randomUUID(), null, entries, BrowserFileTransferMode.COPY));
} catch (Exception e) {
ErrorEvent.fromThrowable(e).expected().omit().handle();
}
@ -63,14 +64,14 @@ public class BrowserClipboard {
}
@SneakyThrows
public static ClipboardContent startDrag(FileSystem.FileEntry base, List<BrowserEntry> selected) {
public static ClipboardContent startDrag(FileSystem.FileEntry base, List<BrowserEntry> selected, BrowserFileTransferMode mode) {
if (selected.isEmpty()) {
return null;
}
var content = new ClipboardContent();
var id = UUID.randomUUID();
currentDragClipboard = new Instance(id, base, new ArrayList<>(selected));
currentDragClipboard = new Instance(id, base, new ArrayList<>(selected), mode);
content.putString(currentDragClipboard.toClipboardString());
return content;
}
@ -83,7 +84,7 @@ public class BrowserClipboard {
}
var id = UUID.randomUUID();
currentCopyClipboard.setValue(new Instance(id, base, new ArrayList<>(selected)));
currentCopyClipboard.setValue(new Instance(id, base, new ArrayList<>(selected), BrowserFileTransferMode.COPY));
}
public static Instance retrieveCopy() {
@ -118,6 +119,7 @@ public class BrowserClipboard {
UUID uuid;
FileSystem.FileEntry baseDirectory;
List<BrowserEntry> entries;
BrowserFileTransferMode mode;
public String toClipboardString() {
return entries.stream()

View file

@ -1,5 +1,6 @@
package io.xpipe.app.browser;
import io.xpipe.app.browser.file.BrowserFileTransferMode;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.comp.base.LoadingOverlayComp;
import io.xpipe.app.core.AppI18n;
@ -150,7 +151,7 @@ public class BrowserTransferComp extends SimpleComp {
.toList();
Dragboard db = struc.get().startDragAndDrop(TransferMode.COPY);
var cc = BrowserClipboard.startDrag(null, selected);
var cc = BrowserClipboard.startDrag(null, selected, BrowserFileTransferMode.NORMAL);
if (cc == null) {
return;
}

View file

@ -1,6 +1,7 @@
package io.xpipe.app.browser;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.file.BrowserFileTransferMode;
import io.xpipe.app.browser.file.BrowserFileTransferOperation;
import io.xpipe.app.browser.file.LocalFileSystem;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
@ -125,11 +126,11 @@ public class BrowserTransferModel {
}
try {
try (var b = new BooleanScope(downloading).start()) {
try (var ignored = new BooleanScope(downloading).start()) {
var op = new BrowserFileTransferOperation(
LocalFileSystem.getLocalFileEntry(TEMP),
List.of(item.getBrowserEntry().getRawFileEntry()),
true,
BrowserFileTransferMode.COPY,
false,
progress -> {
item.getProgress().setValue(progress);

View file

@ -3,13 +3,11 @@ package io.xpipe.app.browser.file;
import io.xpipe.app.browser.BrowserClipboard;
import io.xpipe.app.browser.BrowserSelectionListComp;
import io.xpipe.core.store.FileKind;
import javafx.geometry.Point2D;
import javafx.scene.Node;
import javafx.scene.control.TableView;
import javafx.scene.image.Image;
import javafx.scene.input.*;
import lombok.Getter;
import java.io.File;
@ -157,7 +155,7 @@ public class BrowserFileListCompEntry {
var target = item != null && item.getRawFileEntry().getKind() == FileKind.DIRECTORY
? item.getRawFileEntry()
: model.getFileSystemModel().getCurrentDirectory();
model.getFileSystemModel().dropFilesIntoAsync(target, files.stream().map(browserEntry -> browserEntry.getRawFileEntry()).toList(), false);
model.getFileSystemModel().dropFilesIntoAsync(target, files.stream().map(browserEntry -> browserEntry.getRawFileEntry()).toList(), db.getMode());
event.setDropCompleted(true);
event.consume();
}
@ -184,7 +182,7 @@ public class BrowserFileListCompEntry {
var selected = model.getSelection();
Dragboard db = row.startDragAndDrop(TransferMode.COPY);
db.setContent(BrowserClipboard.startDrag(model.getFileSystemModel().getCurrentDirectory(), selected));
db.setContent(BrowserClipboard.startDrag(model.getFileSystemModel().getCurrentDirectory(), selected, event.isAltDown() ? BrowserFileTransferMode.MOVE : BrowserFileTransferMode.NORMAL));
Image image = BrowserSelectionListComp.snapshot(selected);
db.setDragView(image, -20, 15);

View file

@ -0,0 +1,8 @@
package io.xpipe.app.browser.file;
public enum BrowserFileTransferMode {
NORMAL,
COPY,
MOVE
}

View file

@ -21,23 +21,23 @@ public class BrowserFileTransferOperation {
private final FileSystem.FileEntry target;
private final List<FileSystem.FileEntry> files;
private final boolean explicitCopy;
private final BrowserFileTransferMode transferMode;
private final boolean checkConflicts;
private final Consumer<BrowserTransferProgress> progress;
BrowserAlerts.FileConflictChoice lastConflictChoice;
public BrowserFileTransferOperation(FileSystem.FileEntry target, List<FileSystem.FileEntry> files, boolean explicitCopy, boolean checkConflicts,
public BrowserFileTransferOperation(FileSystem.FileEntry target, List<FileSystem.FileEntry> files, BrowserFileTransferMode transferMode, boolean checkConflicts,
Consumer<BrowserTransferProgress> progress
) {
this.target = target;
this.files = files;
this.explicitCopy = explicitCopy;
this.transferMode = transferMode;
this.checkConflicts = checkConflicts;
this.progress = progress;
}
public static BrowserFileTransferOperation ofLocal(FileSystem.FileEntry target, List<Path> files, boolean explicitCopy, boolean checkConflicts, Consumer<BrowserTransferProgress> progress) {
public static BrowserFileTransferOperation ofLocal(FileSystem.FileEntry target, List<Path> files, BrowserFileTransferMode transferMode, boolean checkConflicts, Consumer<BrowserTransferProgress> progress) {
var entries = files.stream()
.map(path -> {
try {
@ -47,7 +47,7 @@ public class BrowserFileTransferOperation {
}
})
.toList();
return new BrowserFileTransferOperation(target, entries, explicitCopy, checkConflicts, progress);
return new BrowserFileTransferOperation(target, entries, transferMode, checkConflicts, progress);
}
private void updateProgress(BrowserTransferProgress progress) {
@ -103,7 +103,8 @@ public class BrowserFileTransferOperation {
}
var same = files.getFirst().getFileSystem().equals(target.getFileSystem());
if (same && !explicitCopy) {
var doesMove = transferMode == BrowserFileTransferMode.MOVE || (same && transferMode == BrowserFileTransferMode.NORMAL);
if (doesMove) {
if (!BrowserAlerts.showMoveAlert(files, target)) {
return;
}
@ -142,10 +143,12 @@ public class BrowserFileTransferOperation {
return;
}
if (explicitCopy) {
target.getFileSystem().copy(sourceFile, targetFile);
} else {
var same = files.getFirst().getFileSystem().equals(target.getFileSystem());
var doesMove = transferMode == BrowserFileTransferMode.MOVE || (same && transferMode == BrowserFileTransferMode.NORMAL);
if (doesMove) {
target.getFileSystem().move(sourceFile, targetFile);
} else {
target.getFileSystem().copy(sourceFile, targetFile);
}
}

View file

@ -4,6 +4,7 @@ import io.xpipe.app.browser.BrowserSavedState;
import io.xpipe.app.browser.BrowserTransferProgress;
import io.xpipe.app.browser.action.BrowserAction;
import io.xpipe.app.browser.file.BrowserFileListModel;
import io.xpipe.app.browser.file.BrowserFileTransferMode;
import io.xpipe.app.browser.file.BrowserFileTransferOperation;
import io.xpipe.app.browser.file.FileSystemHelper;
import io.xpipe.app.browser.session.BrowserAbstractSessionModel;
@ -342,7 +343,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
}
startIfNeeded();
var op = BrowserFileTransferOperation.ofLocal(entry, files,false,true, progress::setValue);
var op = BrowserFileTransferOperation.ofLocal(entry, files,BrowserFileTransferMode.COPY,true, progress::setValue);
op.execute();
refreshSync();
});
@ -350,7 +351,8 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
}
public void dropFilesIntoAsync(
FileSystem.FileEntry target, List<FileSystem.FileEntry> files, boolean explicitCopy) {
FileSystem.FileEntry target, List<FileSystem.FileEntry> files, BrowserFileTransferMode mode
) {
// We don't have to do anything in this case
if (files.isEmpty()) {
return;
@ -363,7 +365,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
}
startIfNeeded();
var op = new BrowserFileTransferOperation(target, files,false,true, progress::setValue);
var op = new BrowserFileTransferOperation(target, files, mode,true, progress::setValue);
op.execute();
refreshSync();
});

View file

@ -3,6 +3,7 @@ package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.BrowserClipboard;
import io.xpipe.app.browser.action.LeafAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.file.BrowserFileTransferMode;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.core.AppI18n;
import io.xpipe.core.store.FileKind;
@ -34,7 +35,7 @@ public class PasteAction implements LeafAction {
return;
}
model.dropFilesIntoAsync(target, files.stream().map(browserEntry -> browserEntry.getRawFileEntry()).toList(), true);
model.dropFilesIntoAsync(target, files.stream().map(browserEntry -> browserEntry.getRawFileEntry()).toList(), BrowserFileTransferMode.COPY);
}
@Override