mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-06-22 14:29:18 -04:00
Introduce file kinds
This commit is contained in:
@@ -2,6 +2,7 @@ package io.xpipe.app.browser;
|
||||
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.core.AppWindowHelper;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import javafx.scene.control.Alert;
|
||||
|
||||
@@ -11,7 +12,7 @@ import java.util.stream.Collectors;
|
||||
public class BrowserAlerts {
|
||||
|
||||
public static boolean showMoveAlert(List<FileSystem.FileEntry> source, FileSystem.FileEntry target) {
|
||||
if (source.stream().noneMatch(entry -> entry.isDirectory())) {
|
||||
if (source.stream().noneMatch(entry -> entry.getKind() == FileKind.DIRECTORY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ public class BrowserAlerts {
|
||||
}
|
||||
|
||||
public static boolean showDeleteAlert(List<FileSystem.FileEntry> source) {
|
||||
if (source.stream().noneMatch(entry -> entry.isDirectory())) {
|
||||
if (source.stream().noneMatch(entry -> entry.getKind() == FileKind.DIRECTORY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.xpipe.app.browser;
|
||||
import io.xpipe.app.browser.icon.DirectoryType;
|
||||
import io.xpipe.app.browser.icon.FileType;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -24,7 +25,7 @@ public class BrowserEntry {
|
||||
}
|
||||
|
||||
private static FileType fileType(FileSystem.FileEntry rawFileEntry) {
|
||||
if (rawFileEntry.isDirectory()) {
|
||||
if (rawFileEntry.getKind() == FileKind.DIRECTORY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ public class BrowserEntry {
|
||||
}
|
||||
|
||||
private static DirectoryType directoryType(FileSystem.FileEntry rawFileEntry) {
|
||||
if (!rawFileEntry.isDirectory()) {
|
||||
if (rawFileEntry.getKind() != FileKind.DIRECTORY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.xpipe.app.util.HumanReadableFormat;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
@@ -111,7 +112,7 @@ final class BrowserFileListComp extends SimpleComp {
|
||||
|
||||
var syntheticFirst = Comparator.<BrowserEntry, Boolean>comparing(path -> !path.isSynthetic());
|
||||
var dirsFirst = Comparator.<BrowserEntry, Boolean>comparing(
|
||||
path -> !path.getRawFileEntry().isDirectory());
|
||||
path -> path.getRawFileEntry().getKind() != FileKind.DIRECTORY);
|
||||
|
||||
Comparator<? super BrowserEntry> us =
|
||||
syntheticFirst.thenComparing(dirsFirst).thenComparing(comp);
|
||||
@@ -149,9 +150,9 @@ final class BrowserFileListComp extends SimpleComp {
|
||||
.getCurrentParentDirectory()
|
||||
.getPath()));
|
||||
// Remove unsuitable selection
|
||||
toSelect.removeIf(browserEntry -> (browserEntry.getRawFileEntry().isDirectory()
|
||||
toSelect.removeIf(browserEntry -> (browserEntry.getRawFileEntry().getKind() == FileKind.DIRECTORY
|
||||
&& !fileList.getMode().isAcceptsDirectories())
|
||||
|| (!browserEntry.getRawFileEntry().isDirectory()
|
||||
|| (browserEntry.getRawFileEntry().getKind() != FileKind.DIRECTORY
|
||||
&& !fileList.getMode().isAcceptsFiles()));
|
||||
fileList.getSelection().setAll(toSelect);
|
||||
|
||||
@@ -233,11 +234,11 @@ final class BrowserFileListComp extends SimpleComp {
|
||||
return event.getButton() == MouseButton.SECONDARY;
|
||||
}
|
||||
|
||||
if (row.getItem() != null && row.getItem().getRawFileEntry().isDirectory()) {
|
||||
if (row.getItem() != null && row.getItem().getRawFileEntry().getKind() == FileKind.DIRECTORY) {
|
||||
return event.getButton() == MouseButton.SECONDARY;
|
||||
}
|
||||
|
||||
if (row.getItem() != null && !row.getItem().getRawFileEntry().isDirectory()) {
|
||||
if (row.getItem() != null && row.getItem().getRawFileEntry().getKind() != FileKind.DIRECTORY) {
|
||||
return event.getButton() == MouseButton.SECONDARY || event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2;
|
||||
}
|
||||
|
||||
@@ -261,9 +262,9 @@ final class BrowserFileListComp extends SimpleComp {
|
||||
row.itemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
row.pseudoClassStateChanged(EMPTY, newValue == null);
|
||||
row.pseudoClassStateChanged(
|
||||
FILE, newValue != null && !newValue.getRawFileEntry().isDirectory());
|
||||
FILE, newValue != null && newValue.getRawFileEntry().getKind() != FileKind.DIRECTORY);
|
||||
row.pseudoClassStateChanged(
|
||||
FOLDER, newValue != null && newValue.getRawFileEntry().isDirectory());
|
||||
FOLDER, newValue != null && newValue.getRawFileEntry().getKind() == FileKind.DIRECTORY);
|
||||
});
|
||||
|
||||
fileList.getDraggedOverDirectory().addListener((observable, oldValue, newValue) -> {
|
||||
@@ -455,7 +456,7 @@ final class BrowserFileListComp extends SimpleComp {
|
||||
: getTableRow().getItem().getRawFileEntry(),
|
||||
isParentLink));
|
||||
|
||||
var isDirectory = getTableRow().getItem().getRawFileEntry().isDirectory();
|
||||
var isDirectory = getTableRow().getItem().getRawFileEntry().getKind() == FileKind.DIRECTORY;
|
||||
pseudoClassStateChanged(FOLDER, isDirectory);
|
||||
|
||||
var fileName = isParentLink ? ".." : FileNames.getFileName(fullPath);
|
||||
@@ -477,7 +478,7 @@ final class BrowserFileListComp extends SimpleComp {
|
||||
setText(null);
|
||||
} else {
|
||||
var path = getTableRow().getItem();
|
||||
if (path.getRawFileEntry().isDirectory()) {
|
||||
if (path.getRawFileEntry().getKind() == FileKind.DIRECTORY) {
|
||||
setText("");
|
||||
} else {
|
||||
setText(byteCount(fileSize.longValue()));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.xpipe.app.browser;
|
||||
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.TableView;
|
||||
@@ -80,7 +81,7 @@ public class BrowserFileListCompEntry {
|
||||
// Prevent drag and drops of files into the current directory
|
||||
if (BrowserClipboard.currentDragClipboard
|
||||
.getBaseDirectory().getPath()
|
||||
.equals(model.getFileSystemModel().getCurrentDirectory().getPath()) && (item == null || !item.getRawFileEntry().isDirectory())) {
|
||||
.equals(model.getFileSystemModel().getCurrentDirectory().getPath()) && (item == null || item.getRawFileEntry().getKind() != FileKind.DIRECTORY)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ public class BrowserFileListCompEntry {
|
||||
if (event.getGestureSource() == null && event.getDragboard().hasFiles()) {
|
||||
Dragboard db = event.getDragboard();
|
||||
var list = db.getFiles().stream().map(File::toPath).toList();
|
||||
var target = item != null && item.getRawFileEntry().isDirectory()
|
||||
var target = item != null && item.getRawFileEntry().getKind() == FileKind.DIRECTORY
|
||||
? item.getRawFileEntry()
|
||||
: model.getFileSystemModel().getCurrentDirectory();
|
||||
model.getFileSystemModel().dropLocalFilesIntoAsync(target, list);
|
||||
@@ -111,7 +112,7 @@ public class BrowserFileListCompEntry {
|
||||
// Accept drops from inside the app window
|
||||
if (event.getGestureSource() != null) {
|
||||
var files = BrowserClipboard.retrieveDrag(event.getDragboard()).getEntries();
|
||||
var target = item != null && item.getRawFileEntry().isDirectory()
|
||||
var target = item != null && item.getRawFileEntry().getKind() == FileKind.DIRECTORY
|
||||
? item.getRawFileEntry()
|
||||
: model.getFileSystemModel().getCurrentDirectory();
|
||||
model.getFileSystemModel().dropFilesIntoAsync(target, files, false);
|
||||
@@ -121,7 +122,7 @@ public class BrowserFileListCompEntry {
|
||||
}
|
||||
|
||||
public void onDragExited(DragEvent event) {
|
||||
if (item != null && item.getRawFileEntry().isDirectory()) {
|
||||
if (item != null && item.getRawFileEntry().getKind() == FileKind.DIRECTORY) {
|
||||
model.getDraggedOverDirectory().setValue(null);
|
||||
} else {
|
||||
model.getDraggedOverEmpty().setValue(false);
|
||||
@@ -151,13 +152,13 @@ public class BrowserFileListCompEntry {
|
||||
}
|
||||
|
||||
private void acceptDrag(DragEvent event) {
|
||||
model.getDraggedOverEmpty().setValue(item == null || !item.getRawFileEntry().isDirectory());
|
||||
model.getDraggedOverEmpty().setValue(item == null || item.getRawFileEntry().getKind() != FileKind.DIRECTORY);
|
||||
model.getDraggedOverDirectory().setValue(item);
|
||||
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
|
||||
}
|
||||
|
||||
private void handleHoverTimer(DragEvent event) {
|
||||
if (item == null || !item.getRawFileEntry().isDirectory()) {
|
||||
if (item == null || item.getRawFileEntry().getKind() != FileKind.DIRECTORY) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.xpipe.app.browser;
|
||||
import io.xpipe.app.fxcomps.util.BindingsHelper;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
@@ -23,7 +24,7 @@ import java.util.stream.Stream;
|
||||
public final class BrowserFileListModel {
|
||||
|
||||
static final Comparator<BrowserEntry> FILE_TYPE_COMPARATOR =
|
||||
Comparator.comparing(path -> !path.getRawFileEntry().isDirectory());
|
||||
Comparator.comparing(path -> path.getRawFileEntry().getKind() != FileKind.DIRECTORY);
|
||||
static final Predicate<BrowserEntry> PREDICATE_ANY = path -> true;
|
||||
static final Predicate<BrowserEntry> PREDICATE_NOT_HIDDEN = path -> true;
|
||||
|
||||
@@ -112,12 +113,12 @@ public final class BrowserFileListModel {
|
||||
}
|
||||
|
||||
public void onDoubleClick(BrowserEntry entry) {
|
||||
if (!entry.getRawFileEntry().isDirectory() && getMode().equals(BrowserModel.Mode.SINGLE_FILE_CHOOSER)) {
|
||||
if (entry.getRawFileEntry().getKind() != FileKind.DIRECTORY && getMode().equals(BrowserModel.Mode.SINGLE_FILE_CHOOSER)) {
|
||||
getFileSystemModel().getBrowserModel().finishChooser();
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.getRawFileEntry().isDirectory()) {
|
||||
if (entry.getRawFileEntry().getKind() == FileKind.DIRECTORY) {
|
||||
var dir = fileSystemModel.cd(entry.getRawFileEntry().getPath());
|
||||
if (dir.isPresent()) {
|
||||
fileSystemModel.cd(dir.get());
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.store.ConnectionFileSystem;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
|
||||
import java.nio.file.Files;
|
||||
@@ -96,11 +97,11 @@ public class FileSystemHelper {
|
||||
localFileSystem,
|
||||
file.toString(),
|
||||
Files.getLastModifiedTime(file).toInstant(),
|
||||
Files.isDirectory(file),
|
||||
Files.isHidden(file),
|
||||
Files.isExecutable(file),
|
||||
Files.size(file),
|
||||
null
|
||||
null,
|
||||
Files.isDirectory(file) ? FileKind.DIRECTORY : FileKind.FILE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ public class FileSystemHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
if (source.isDirectory()) {
|
||||
if (source.getKind() == FileKind.DIRECTORY) {
|
||||
var directoryName = FileNames.getFileName(source.getPath());
|
||||
flatFiles.put(source, directoryName);
|
||||
|
||||
@@ -197,7 +198,7 @@ public class FileSystemHelper {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (sourceFile.isDirectory()) {
|
||||
if (sourceFile.getKind() == FileKind.DIRECTORY) {
|
||||
target.getFileSystem().mkdirs(targetFile);
|
||||
} else {
|
||||
try (var in = sourceFile.getFileSystem().openInput(sourceFile.getPath());
|
||||
|
||||
@@ -10,10 +10,7 @@ import io.xpipe.app.util.XPipeDaemon;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
import io.xpipe.core.store.ConnectionFileSystem;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import io.xpipe.core.store.FileSystemStore;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
import io.xpipe.core.store.*;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.*;
|
||||
import lombok.Getter;
|
||||
@@ -94,7 +91,7 @@ public final class OpenFileSystemModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FileSystem.FileEntry(fileSystem, parent, null, true, false, false, 0, null);
|
||||
return new FileSystem.FileEntry(fileSystem, parent, null, false, false, 0, null, FileKind.DIRECTORY);
|
||||
}
|
||||
|
||||
public FileSystem.FileEntry getCurrentDirectory() {
|
||||
@@ -102,7 +99,7 @@ public final class OpenFileSystemModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FileSystem.FileEntry(fileSystem, currentPath.get(), null, true, false, false, 0, null);
|
||||
return new FileSystem.FileEntry(fileSystem, currentPath.get(), null, false, false, 0, null, FileKind.DIRECTORY);
|
||||
}
|
||||
|
||||
public Optional<String> cd(String path) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.xpipe.app.browser.icon;
|
||||
|
||||
import io.xpipe.app.core.AppResources;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -94,7 +95,7 @@ public interface DirectoryType {
|
||||
|
||||
@Override
|
||||
public boolean matches(FileSystem.FileEntry entry) {
|
||||
if (!entry.isDirectory()) {
|
||||
if (entry.getKind() != FileKind.DIRECTORY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.xpipe.app.browser.icon;
|
||||
import io.xpipe.app.core.AppImages;
|
||||
import io.xpipe.app.core.AppResources;
|
||||
import io.xpipe.app.fxcomps.impl.SvgCache;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import javafx.scene.image.Image;
|
||||
import lombok.Getter;
|
||||
@@ -46,7 +47,7 @@ public class FileIconManager {
|
||||
|
||||
loadIfNecessary();
|
||||
|
||||
if (!entry.isDirectory()) {
|
||||
if (entry.getKind() != FileKind.DIRECTORY) {
|
||||
for (var f : FileType.ALL) {
|
||||
if (f.matches(entry)) {
|
||||
return getIconPath(f.getIcon());
|
||||
@@ -60,7 +61,7 @@ public class FileIconManager {
|
||||
}
|
||||
}
|
||||
|
||||
return entry.isDirectory() ? (open ? "default_folder_opened.svg" : "default_folder.svg") : "default_file.svg";
|
||||
return entry.getKind() == FileKind.DIRECTORY ? (open ? "default_folder_opened.svg" : "default_folder.svg") : "default_file.svg";
|
||||
}
|
||||
|
||||
private static String getIconPath(String name) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.xpipe.app.browser.icon;
|
||||
|
||||
import io.xpipe.app.core.AppResources;
|
||||
import io.xpipe.core.store.FileKind;
|
||||
import io.xpipe.core.store.FileSystem;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -65,7 +66,7 @@ public interface FileType {
|
||||
|
||||
@Override
|
||||
public boolean matches(FileSystem.FileEntry entry) {
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.getKind() == FileKind.DIRECTORY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -64,12 +63,6 @@ public class App extends Application {
|
||||
|
||||
public void setupWindow() {
|
||||
var content = new AppLayoutComp();
|
||||
content.apply(struc -> {
|
||||
struc.get().addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
|
||||
// AppActionLinkDetector.detectOnFocus();
|
||||
});
|
||||
});
|
||||
|
||||
var titleBinding = Bindings.createStringBinding(
|
||||
() -> {
|
||||
var base = String.format(
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.util.DefaultSecretValue;
|
||||
import io.xpipe.app.util.FileBridge;
|
||||
import io.xpipe.app.util.LockedSecretValue;
|
||||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.core.util.JacksonMapper;
|
||||
|
||||
public class BaseMode extends OperationMode {
|
||||
@@ -37,6 +38,7 @@ public class BaseMode extends OperationMode {
|
||||
JacksonMapper.configure(objectMapper -> {
|
||||
objectMapper.registerSubtypes(LockedSecretValue.class, DefaultSecretValue.class);
|
||||
});
|
||||
LocalStore.init();
|
||||
AppPrefs.init();
|
||||
AppCharsets.init();
|
||||
AppCharsetter.init();
|
||||
|
||||
@@ -47,6 +47,8 @@ public class TerminalErrorHandler implements ErrorHandler {
|
||||
event.clearAttachments();
|
||||
handleSecondaryException(event, r);
|
||||
return;
|
||||
} else {
|
||||
PlatformState.setCurrent(PlatformState.RUNNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user