Skip to content

Commit

Permalink
Many small fixes [release]
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Mar 5, 2023
1 parent c936e37 commit b7fa352
Show file tree
Hide file tree
Showing 25 changed files with 164 additions and 85 deletions.
31 changes: 16 additions & 15 deletions app/src/main/java/io/xpipe/app/browser/FileBrowserClipboard.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.xpipe.app.browser;

import io.xpipe.core.store.FileSystem;
import io.xpipe.core.util.XPipeTempDirectory;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import lombok.SneakyThrows;
import lombok.Value;

import java.nio.file.Files;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class FileBrowserClipboard {

Expand All @@ -18,25 +18,22 @@ public static class Instance {
List<FileSystem.FileEntry> entries;
}

public static Map<UUID, List<FileSystem.FileEntry>> CLIPBOARD = new HashMap<>();
public static Instance currentCopyClipboard;
public static Instance currentDragClipboard;

@SneakyThrows
public static ClipboardContent startDrag(List<FileSystem.FileEntry> selected) {
var content = new ClipboardContent();
var idea = UUID.randomUUID();
var file = XPipeTempDirectory.getLocal().resolve(idea.toString());
Files.createFile(file);
currentDragClipboard = new Instance(idea, selected);
content.putFiles(List.of(file.toFile()));
content.putString(idea.toString());
return content;
}

@SneakyThrows
public static void startCopy(List<FileSystem.FileEntry> selected) {
var idea = UUID.randomUUID();
currentCopyClipboard = new Instance(idea, new ArrayList<>(selected));
var id = UUID.randomUUID();
currentCopyClipboard = new Instance(id, new ArrayList<>(selected));
}

public static Instance retrieveCopy() {
Expand All @@ -45,15 +42,19 @@ public static Instance retrieveCopy() {
}

public static Instance retrieveDrag(Dragboard dragboard) {
if (dragboard.getFiles().size() != 1) {
if (dragboard.getString() == null) {
return null;
}

var idea = UUID.fromString(dragboard.getFiles().get(0).toPath().getFileName().toString());
if (idea.equals(currentDragClipboard.uuid)) {
var current = currentDragClipboard;
currentDragClipboard = null;
return current;
try {
var idea = UUID.fromString(dragboard.getString());
if (idea.equals(currentDragClipboard.uuid)) {
var current = currentDragClipboard;
currentDragClipboard = null;
return current;
}
} catch (Exception ex) {
return null;
}

return null;
Expand Down
49 changes: 35 additions & 14 deletions app/src/main/java/io/xpipe/app/browser/FileContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import io.xpipe.app.comp.source.GuiDsCreatorMultiStep;
import io.xpipe.app.ext.DataSourceProvider;
import io.xpipe.app.util.*;
import io.xpipe.app.util.FileOpener;
import io.xpipe.app.util.ScriptHelper;
import io.xpipe.app.util.TerminalHelper;
import io.xpipe.app.util.ThreadHelper;
import io.xpipe.core.impl.FileNames;
import io.xpipe.core.impl.FileStore;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
Expand All @@ -13,10 +17,11 @@
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import org.apache.commons.io.FilenameUtils;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.util.List;

final class FileContextMenu extends ContextMenu {
Expand Down Expand Up @@ -73,8 +78,7 @@ private void createMenu() {
var execute = new MenuItem("Run in terminal");
execute.setOnAction(event -> {
ThreadHelper.runFailableAsync(() -> {
ShellControl pc =
model.getFileSystem().getShell().orElseThrow();
ShellControl pc = model.getFileSystem().getShell().orElseThrow();
pc.executeBooleanSimpleCommand(pc.getShellDialect().getMakeExecutableCommand(entry.getPath()));
var cmd = pc.command("\"" + entry.getPath() + "\"").prepareTerminalOpen();
TerminalHelper.open(FilenameUtils.getBaseName(entry.getPath()), cmd);
Expand All @@ -86,8 +90,7 @@ private void createMenu() {
var executeInBackground = new MenuItem("Run in background");
executeInBackground.setOnAction(event -> {
ThreadHelper.runFailableAsync(() -> {
ShellControl pc =
model.getFileSystem().getShell().orElseThrow();
ShellControl pc = model.getFileSystem().getShell().orElseThrow();
pc.executeBooleanSimpleCommand(pc.getShellDialect().getMakeExecutableCommand(entry.getPath()));
var cmd = ScriptHelper.createDetachCommand(pc, "\"" + entry.getPath() + "\"");
pc.executeBooleanSimpleCommand(cmd);
Expand All @@ -112,30 +115,48 @@ private void createMenu() {
GuiDsCreatorMultiStep.showForStore(DataSourceProvider.Category.STREAM, store, null);
event.consume();
});
getItems().add(pipe);
// getItems().add(pipe);

var edit = new MenuItem("Edit");
edit.setOnAction(event -> {
FileOpener.openInTextEditor(entry);
ThreadHelper.runAsync(() -> FileOpener.openInTextEditor(entry));
event.consume();
});
getItems().add(edit);
}

var cut = new MenuItem("Delete");
cut.setOnAction(event -> {
getItems().add(new SeparatorMenuItem());

var copyName = new MenuItem("Copy name");
copyName.setOnAction(event -> {
var selection = new StringSelection(FileNames.getFileName(entry.getPath()));
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
event.consume();
});
getItems().add(copyName);

var copyPath = new MenuItem("Copy full path");
copyPath.setOnAction(event -> {
var selection = new StringSelection(entry.getPath());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
event.consume();
});
getItems().add(copyPath);

var delete = new MenuItem("Delete");
delete.setOnAction(event -> {
event.consume();
model.deleteAsync(entry.getPath());
});
cut.setAccelerator(new KeyCodeCombination(KeyCode.DELETE));

var rename = new MenuItem("Rename");
rename.setOnAction(event -> {
event.consume();
editing.setValue(entry.getPath());
});
rename.setAccelerator(new KeyCodeCombination(KeyCode.F2));

getItems().addAll(new SeparatorMenuItem(), cut, rename);
getItems().addAll(new SeparatorMenuItem(), rename, delete);
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public static String normalizeDirectoryPath(OpenFileSystemModel model, String pa
return null;
}

// Handle special case when file system creation has failed
if (model.getFileSystem() == null) {
return path;
}

var shell = model.getFileSystem().getShell();
if (shell.isEmpty()) {
return path;
Expand Down
42 changes: 34 additions & 8 deletions app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.xpipe.core.store.ShellStore;
import javafx.beans.property.*;
import lombok.Getter;
import lombok.SneakyThrows;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -40,13 +41,14 @@ public OpenFileSystemModel(FileBrowserModel browserModel) {
fileList = new FileListModel(this);
}

@SneakyThrows
public void refresh() {
BusyProperty.execute(busy, () -> {
cdSync(currentPath.get());
});
}

private void refreshInternal() {
private void refreshInternal() throws Exception {
cdSync(currentPath.get());
}

Expand All @@ -68,7 +70,13 @@ public Optional<String> cd(String path) {
return Optional.empty();
}

private void cdSync(String path) {
private void cdSync(String path) throws Exception {
if (fileSystem == null) {
var fs = store.getValue().createFileSystem();
fs.open();
this.fileSystem = fs;
}

path = FileSystemHelper.normalizeDirectoryPath(this, path);

navigateToSync(path);
Expand Down Expand Up @@ -99,6 +107,10 @@ private boolean navigateToSync(String dir) {
public void dropLocalFilesIntoAsync(FileSystem.FileEntry entry, List<Path> files) {
ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
if (fileSystem == null) {
return;
}

FileSystemHelper.dropLocalFilesInto(entry, files);
refreshInternal();
});
Expand All @@ -109,6 +121,10 @@ public void dropFilesIntoAsync(
FileSystem.FileEntry target, List<FileSystem.FileEntry> files, boolean explicitCopy) {
ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
if (fileSystem == null) {
return;
}

FileSystemHelper.dropFilesInto(target, files, explicitCopy);
refreshInternal();
});
Expand All @@ -122,6 +138,10 @@ public void createDirectoryAsync(String path) {

ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
if (fileSystem == null) {
return;
}

fileSystem.mkdirs(path);
refreshInternal();
});
Expand All @@ -135,6 +155,10 @@ public void createFileAsync(String path) {

ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
if (fileSystem == null) {
return;
}

fileSystem.touch(path);
refreshInternal();
});
Expand All @@ -144,6 +168,10 @@ public void createFileAsync(String path) {
public void deleteAsync(String path) {
ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
if (fileSystem == null) {
return;
}

fileSystem.delete(path);
refreshInternal();
});
Expand All @@ -164,12 +192,6 @@ void closeSync() {
store = null;
}

public void switchFileSystem(FileSystemStore fileSystem) throws Exception {
BusyProperty.execute(busy, () -> {
switchSync(fileSystem);
});
}

private void switchSync(FileSystemStore fileSystem) throws Exception {
closeSync();
this.store.setValue(fileSystem);
Expand Down Expand Up @@ -198,6 +220,10 @@ public void switchAsync(FileSystemStore fileSystem) {

public void openTerminalAsync(String directory) {
ThreadHelper.runFailableAsync(() -> {
if (fileSystem == null) {
return;
}

BusyProperty.execute(busy, () -> {
if (store.getValue() instanceof ShellStore s) {
var connection = ((ConnectionFileSystem) fileSystem).getShellControl();
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/io/xpipe/app/comp/about/AboutTabComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.xpipe.app.util.Hyperlinks;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import org.kordamp.ikonli.javafx.FontIcon;
Expand Down Expand Up @@ -62,10 +62,10 @@ public CompStructure<?> createBase() {
.styleClass("information");

return Comp.derive(box, boxS -> {
var bp = new BorderPane();
bp.setLeft(boxS);
var bp = new SplitPane();
bp.getItems().add(boxS);
var deps = createThirdPartyDeps();
bp.setRight(createThirdPartyDeps());
bp.getItems().add(createThirdPartyDeps());
deps.prefWidthProperty().bind(bp.widthProperty().divide(2));
boxS.prefWidthProperty().bind(bp.widthProperty().divide(2));
bp.getStyleClass().add("about-tab");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ private TitledPane createPane(ThirdPartyDependency t) {
var sp = new StackPane(link, licenseName);
StackPane.setAlignment(licenseName, Pos.CENTER_RIGHT);
StackPane.setAlignment(link, Pos.CENTER_LEFT);
sp.prefWidthProperty().bind(tp.widthProperty().subtract(40));
sp.prefWidthProperty().bind(tp.widthProperty().subtract(65));
tp.setGraphic(sp);

var text = new TextArea();
text.setEditable(false);
text.setText(t.licenseText());
text.setWrapText(true);
text.setPrefHeight(300);
text.prefWidthProperty().bind(tp.widthProperty());
text.maxWidthProperty().bind(tp.widthProperty());
AppFont.setSize(text, -4);
tp.setContent(text);
AppFont.verySmall(tp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ protected Region createSimple() {
}

private Region createOpenButton(Region container) {
var name = identifier + (fileType != null ? "." + fileType : "");
var button = new IconButtonComp("mdal-edit", () -> FileOpener
.openString(identifier, fileType, this, value.getValue(), (s) -> {
.openString(name, this, value.getValue(), (s) -> {
Platform.runLater(() -> value.setValue(s));
}))
.createRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void showEdit(DataStoreEntry e) {
e.applyChanges(newE);
if (!DataStorage.get().getStoreEntries().contains(e)) {
DataStorage.get().addStoreEntry(e);
ScanAlert.showIfNeeded(e.getStore());
ScanAlert.showIfNeeded(e.getStore(), true);
}
DataStorage.get().refresh();
});
Expand All @@ -104,7 +104,7 @@ public static void showCreation(Predicate<DataStoreProvider> filter) {
show(null, null, null, filter, e -> {
try {
DataStorage.get().addStoreEntry(e);
ScanAlert.showIfNeeded(e.getStore());
ScanAlert.showIfNeeded(e.getStore(), true);
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle();
}
Expand Down Expand Up @@ -183,6 +183,9 @@ private Region createStoreProperties(Comp<?> comp, Validator propVal) {
public CompStructure<? extends Region> createBase() {
var layout = new BorderPane();
var providerChoice = new DsStoreProviderChoiceComp(filter, provider);
if (provider.getValue() != null) {
providerChoice.apply(struc -> struc.get().setDisable(true));
}
providerChoice.apply(GrowAugment.create(true, false));

SimpleChangeListener.apply(provider, n -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Region createSimple() {
});

var scanButton = new Button(AppI18n.get("detectConnections"), new FontIcon("mdi2m-magnify"));
scanButton.setOnAction(event -> ScanAlert.showIfNeeded(new LocalStore()));
scanButton.setOnAction(event -> ScanAlert.showIfNeeded(new LocalStore(), false));
var scanPane = new StackPane(scanButton);
scanPane.setAlignment(Pos.CENTER);

Expand Down
Loading

0 comments on commit b7fa352

Please sign in to comment.