mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
File browser fixes
This commit is contained in:
parent
288f526019
commit
55d54fad01
5 changed files with 48 additions and 25 deletions
|
@ -25,7 +25,10 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
|
|||
@Override
|
||||
protected Region createSimple() {
|
||||
Callback<Breadcrumbs.BreadCrumbItem<String>, ButtonBase> crumbFactory = crumb -> {
|
||||
var btn = new Button(crumb.getValue().equals("/") ? "/" : FileNames.getFileName(crumb.getValue()), null);
|
||||
var name = crumb.getValue().equals("/")
|
||||
? "/"
|
||||
: FileNames.getFileName(crumb.getValue());
|
||||
var btn = new Button(name, null);
|
||||
btn.setMnemonicParsing(false);
|
||||
btn.setFocusTraversable(false);
|
||||
return btn;
|
||||
|
@ -57,7 +60,7 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
|
|||
return new Label("");
|
||||
}
|
||||
|
||||
return !item.isLast() ? new Label(sc.get().getOsType().getFileSystemSeparator()) : null;
|
||||
return new Label(sc.get().getOsType().getFileSystemSeparator());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -66,7 +69,8 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
|
|||
if (val.startsWith("/")) {
|
||||
modifiedElements.add(0, "/");
|
||||
}
|
||||
Breadcrumbs.BreadCrumbItem<String> items = Breadcrumbs.buildTreeModel(modifiedElements.toArray(String[]::new));
|
||||
Breadcrumbs.BreadCrumbItem<String> items =
|
||||
Breadcrumbs.buildTreeModel(modifiedElements.toArray(String[]::new));
|
||||
breadcrumbs.setSelectedCrumb(items);
|
||||
});
|
||||
|
||||
|
@ -78,7 +82,7 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
|
|||
}
|
||||
|
||||
breadcrumbs.selectedCrumbProperty().addListener((obs, old, val) -> {
|
||||
model.cd(val.getValue()).ifPresent(s -> {
|
||||
model.cd(val != null ? val.getValue() : null).ifPresent(s -> {
|
||||
model.cd(s);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,10 +31,10 @@ public class FileSystemHelper {
|
|||
.get()
|
||||
.getOsType()
|
||||
.getHomeDirectory(fileSystem.getShell().get());
|
||||
return FileSystemHelper.resolveDirectoryPath(model, current);
|
||||
return validateDirectoryPath(model, resolvePath(model, current));
|
||||
}
|
||||
|
||||
public static String resolveDirectoryPath(OpenFileSystemModel model, String path) throws Exception {
|
||||
public static String resolvePath(OpenFileSystemModel model, String path) {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -58,6 +58,19 @@ public class FileSystemHelper {
|
|||
return path + "\\";
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String validateDirectoryPath(OpenFileSystemModel model, String path) throws Exception {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var shell = model.getFileSystem().getShell();
|
||||
if (shell.isEmpty()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
var normalized = shell.get()
|
||||
.getShellDialect()
|
||||
.normalizeDirectory(shell.get(), path)
|
||||
|
@ -68,7 +81,6 @@ public class FileSystemHelper {
|
|||
}
|
||||
|
||||
model.getFileSystem().directoryAccessible(normalized);
|
||||
|
||||
return FileNames.toDirectory(normalized);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,47 +125,53 @@ public final class OpenFileSystemModel {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
// Fix common issues with paths
|
||||
var normalizedPath = FileSystemHelper.resolvePath(this, path);
|
||||
if (!Objects.equals(path, normalizedPath)) {
|
||||
return Optional.of(normalizedPath);
|
||||
}
|
||||
|
||||
// Handle commands typed into navigation bar
|
||||
if (!FileNames.isAbsolute(path) && fileSystem.getShell().isPresent()) {
|
||||
if (normalizedPath != null && !FileNames.isAbsolute(normalizedPath) && fileSystem.getShell().isPresent()) {
|
||||
var directory = currentPath.get();
|
||||
var name = path + " - "
|
||||
var name = normalizedPath + " - "
|
||||
+ XPipeDaemon.getInstance().getStoreName(store).orElse("?");
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
if (ShellDialects.ALL.stream().anyMatch(dialect -> path.startsWith(dialect.getOpenCommand()))) {
|
||||
if (ShellDialects.ALL.stream().anyMatch(dialect -> normalizedPath.startsWith(dialect.getOpenCommand()))) {
|
||||
var cmd = fileSystem
|
||||
.getShell()
|
||||
.get()
|
||||
.subShell(path)
|
||||
.subShell(normalizedPath)
|
||||
.initWith(fileSystem
|
||||
.getShell()
|
||||
.get()
|
||||
.getShellDialect()
|
||||
.getCdCommand(currentPath.get()))
|
||||
.prepareTerminalOpen(name);
|
||||
TerminalHelper.open(path, cmd);
|
||||
TerminalHelper.open(normalizedPath, cmd);
|
||||
} else {
|
||||
var cmd = fileSystem
|
||||
.getShell()
|
||||
.get()
|
||||
.command(path)
|
||||
.command(normalizedPath)
|
||||
.workingDirectory(directory)
|
||||
.prepareTerminalOpen(name);
|
||||
TerminalHelper.open(path, cmd);
|
||||
TerminalHelper.open(normalizedPath, cmd);
|
||||
}
|
||||
});
|
||||
return Optional.of(currentPath.get());
|
||||
}
|
||||
|
||||
String newPath = null;
|
||||
String dirPath = null;
|
||||
try {
|
||||
newPath = FileSystemHelper.resolveDirectoryPath(this, path);
|
||||
dirPath = FileSystemHelper.validateDirectoryPath(this, normalizedPath);
|
||||
} catch (Exception ex) {
|
||||
ErrorEvent.fromThrowable(ex).handle();
|
||||
return Optional.of(currentPath.get());
|
||||
}
|
||||
|
||||
if (!Objects.equals(path, newPath)) {
|
||||
return Optional.of(newPath);
|
||||
if (!Objects.equals(path, dirPath)) {
|
||||
return Optional.of(dirPath);
|
||||
}
|
||||
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
|
|
|
@ -23,10 +23,8 @@ public class OpenInNativeManagerAction implements LeafAction {
|
|||
}
|
||||
case OsType.Linux linux -> {
|
||||
var dbus = String.format("""
|
||||
dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"%s" string:""
|
||||
dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"file://%s" string:""
|
||||
""", entry.getRawFileEntry().getPath());
|
||||
// sc.executeSimpleCommand(
|
||||
// "xdg-open " + d.fileArgument(entry.getRawFileEntry().getPath()));
|
||||
sc.executeSimpleCommand(dbus);
|
||||
}
|
||||
case OsType.MacOs macOs -> {
|
||||
|
@ -49,7 +47,7 @@ public class OpenInNativeManagerAction implements LeafAction {
|
|||
|
||||
@Override
|
||||
public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
|
||||
return true;
|
||||
return model.isLocal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,9 @@ public class OpenNativeFileDetailsAction implements LeafAction {
|
|||
sub.command(content).notComplex().execute();
|
||||
}
|
||||
}
|
||||
case OsType.Linux linux -> {}
|
||||
case OsType.Linux linux -> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
case OsType.MacOs macOs -> {
|
||||
sc.osascriptCommand(String.format(
|
||||
"""
|
||||
|
@ -53,11 +55,12 @@ public class OpenNativeFileDetailsAction implements LeafAction {
|
|||
|
||||
@Override
|
||||
public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
|
||||
return true;
|
||||
var os = model.getFileSystem().getShell();
|
||||
return os.isPresent() && !os.get().getOsType().equals(OsType.LINUX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
|
||||
return "Details";
|
||||
return "Show details";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue