Various fixes

This commit is contained in:
crschnick
2024-04-24 12:42:35 +00:00
parent a974e7aac2
commit 04bca4295d
14 changed files with 50 additions and 48 deletions
@@ -4,6 +4,7 @@ import io.xpipe.app.browser.action.LeafAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.util.LocalShell;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.process.ShellDialect;
@@ -17,34 +18,34 @@ public class BrowseInNativeManagerAction implements LeafAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
ShellControl sc = model.getFileSystem().getShell().get();
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
ShellDialect d = sc.getShellDialect();
for (BrowserEntry entry : entries) {
var e = entry.getRawFileEntry().getPath();
var localFile = sc.getLocalSystemAccess().translateToLocalSystemPath(e);
switch (OsType.getLocal()) {
case OsType.Windows windows -> {
if (entry.getRawFileEntry().getKind() == FileKind.DIRECTORY) {
sc.executeSimpleCommand("explorer " + d.fileArgument(localFile));
} else {
sc.executeSimpleCommand("explorer /select," + d.fileArgument(localFile));
try (var local = LocalShell.getShell().start()) {
switch (OsType.getLocal()) {
case OsType.Windows windows -> {
// Explorer does not support single quotes, so use normal quotes
if (entry.getRawFileEntry().getKind() == FileKind.DIRECTORY) {
local.executeSimpleCommand("explorer " + d.quoteArgument(localFile));
} else {
local.executeSimpleCommand("explorer /select," + d.quoteArgument(localFile));
}
}
case OsType.Linux linux -> {
var action = entry.getRawFileEntry().getKind() == FileKind.DIRECTORY ?
"org.freedesktop.FileManager1.ShowFolders" :
"org.freedesktop.FileManager1.ShowItems";
var dbus = String.format("""
dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 %s array:string:"file://%s" string:""
""", action, localFile);
local.executeSimpleCommand(dbus);
}
case OsType.MacOs macOs -> {
local.executeSimpleCommand(
"open " + (entry.getRawFileEntry().getKind() == FileKind.DIRECTORY ? "" : "-R ") + d.fileArgument(localFile));
}
}
case OsType.Linux linux -> {
var action = entry.getRawFileEntry().getKind() == FileKind.DIRECTORY
? "org.freedesktop.FileManager1.ShowFolders"
: "org.freedesktop.FileManager1.ShowItems";
var dbus = String.format(
"""
dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 %s array:string:"file://%s" string:""
""",
action, localFile);
sc.executeSimpleCommand(dbus);
}
case OsType.MacOs macOs -> {
sc.executeSimpleCommand(
"open " + (entry.getRawFileEntry().getKind() == FileKind.DIRECTORY ? "" : "-R ")
+ d.fileArgument(localFile));
}
}
}
@@ -0,0 +1,35 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.ApplicationPathAction;
import io.xpipe.app.browser.action.LeafAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.core.process.ShellControl;
import java.util.List;
public abstract class ExecuteApplicationAction implements LeafAction, ApplicationPathAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var command = createCommand(model, entry);
try (var cc = sc.command(command)
.withWorkingDirectory(model.getCurrentDirectory().getPath())
.start()) {
cc.discardOrThrow();
}
}
if (refresh()) {
model.refreshSync();
}
}
protected boolean refresh() {
return false;
}
protected abstract String createCommand(OpenFileSystemModel model, BrowserEntry entry);
}
@@ -1,7 +1,6 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.BrowserActionFormatter;
import io.xpipe.app.browser.action.MultiExecuteAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.browser.icon.BrowserIconFileType;
@@ -1,7 +1,6 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.BrowserActionFormatter;
import io.xpipe.app.browser.action.ToFileCommandAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.browser.icon.BrowserIconFileType;
@@ -0,0 +1,78 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.BranchAction;
import io.xpipe.app.browser.action.LeafAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.util.TerminalLauncher;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.process.ShellControl;
import javafx.beans.value.ObservableValue;
import java.util.List;
public abstract class MultiExecuteAction implements BranchAction {
protected abstract CommandBuilder createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry);
@Override
public List<LeafAction> getBranchingActions(OpenFileSystemModel model, List<BrowserEntry> entries) {
return List.of(
new LeafAction() {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) {
model.withShell(
pc -> {
for (BrowserEntry entry : entries) {
TerminalLauncher.open(
model.getEntry().getEntry(),
entry.getRawFileEntry().getName(),
model.getCurrentDirectory() != null
? model.getCurrentDirectory()
.getPath()
: null,
pc.command(createCommand(pc, model, entry)));
}
},
false);
}
@Override
public ObservableValue<String> getName(OpenFileSystemModel model, List<BrowserEntry> entries) {
var t = AppPrefs.get().terminalType().getValue();
return AppI18n.observable(
"executeInTerminal",
t != null ? t.toTranslatedString().getValue() : "?");
}
@Override
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
return AppPrefs.get().terminalType().getValue() != null;
}
},
new LeafAction() {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) {
model.withShell(
pc -> {
for (BrowserEntry entry : entries) {
pc.command(createCommand(pc, model, entry))
.withWorkingDirectory(model.getCurrentDirectory()
.getPath())
.execute();
}
},
false);
}
@Override
public ObservableValue<String> getName(OpenFileSystemModel model, List<BrowserEntry> entries) {
return AppI18n.observable("executeInBackground");
}
});
}
}
@@ -40,7 +40,7 @@ public class RenameAction implements LeafAction {
@Override
public ObservableValue<String> getName(OpenFileSystemModel model, List<BrowserEntry> entries) {
return AppI18n.observable("openWithDefaultApplication");
return AppI18n.observable("rename");
}
@Override
@@ -1,6 +1,5 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.MultiExecuteAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.core.AppI18n;
@@ -0,0 +1,29 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.ApplicationPathAction;
import io.xpipe.app.browser.action.LeafAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.util.FileOpener;
import io.xpipe.core.process.ShellControl;
import java.util.List;
public abstract class ToFileCommandAction implements LeafAction, ApplicationPathAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var command = createCommand(model, entry);
try (var cc = sc.command(command)
.withWorkingDirectory(model.getCurrentDirectory().getPath())
.start()) {
cc.discardErr();
FileOpener.openCommandOutput(entry.getFileName(), entry, cc);
}
}
}
protected abstract String createCommand(OpenFileSystemModel model, BrowserEntry entry);
}
@@ -1,6 +1,5 @@
package io.xpipe.ext.base.browser;
import io.xpipe.app.browser.action.ExecuteApplicationAction;
import io.xpipe.app.browser.file.BrowserEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
import io.xpipe.app.browser.icon.BrowserIconFileType;