From fb70b6766b34dce3e3605e2998d08b344a6b65cd Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 5 Dec 2023 16:04:13 +0000 Subject: [PATCH] Add chmod browser action --- .../io/xpipe/core/process/CommandBuilder.java | 6 ++ dist/changelogs/1.7.9.md | 2 - .../xpipe/ext/base/browser/ChmodAction.java | 58 +++++++++++++++++++ ext/base/src/main/java/module-info.java | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/ChmodAction.java diff --git a/core/src/main/java/io/xpipe/core/process/CommandBuilder.java b/core/src/main/java/io/xpipe/core/process/CommandBuilder.java index 850defd9b..a3b0eea54 100644 --- a/core/src/main/java/io/xpipe/core/process/CommandBuilder.java +++ b/core/src/main/java/io/xpipe/core/process/CommandBuilder.java @@ -5,6 +5,7 @@ import lombok.SneakyThrows; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.SequencedCollection; public class CommandBuilder { @@ -121,6 +122,11 @@ public class CommandBuilder { return this; } + public CommandBuilder addFiles(SequencedCollection s) { + s.forEach(this::addFile); + return this; + } + public String build(ShellControl sc) throws Exception { List list = new ArrayList<>(); for (Element element : elements) { diff --git a/dist/changelogs/1.7.9.md b/dist/changelogs/1.7.9.md index 94f391b53..99dbe22ac 100644 --- a/dist/changelogs/1.7.9.md +++ b/dist/changelogs/1.7.9.md @@ -1,5 +1,3 @@ -## Changes in 1.7.9 - ### Git storage rework The git storage functionality has been in a bad state, hopefully this update will change that. diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/ChmodAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/ChmodAction.java new file mode 100644 index 000000000..4e9ec5b37 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/ChmodAction.java @@ -0,0 +1,58 @@ +package io.xpipe.ext.base.browser; + +import io.xpipe.app.browser.BrowserEntry; +import io.xpipe.app.browser.OpenFileSystemModel; +import io.xpipe.app.browser.action.BranchAction; +import io.xpipe.app.browser.action.LeafAction; +import io.xpipe.core.process.CommandBuilder; +import io.xpipe.core.process.OsType; +import javafx.scene.Node; +import org.kordamp.ikonli.javafx.FontIcon; + +import java.util.List; + +public class ChmodAction implements BranchAction { + + @Override + public boolean isApplicable(OpenFileSystemModel model, List entries) { + return model.getFileSystem().getShell().orElseThrow().getOsType() != OsType.WINDOWS; + } + + @Override + public Category getCategory() { + return Category.MUTATION; + } + + @Override + public Node getIcon(OpenFileSystemModel model, List entries) { + return new FontIcon("mdi2w-wrench"); + } + + @Override + public String getName(OpenFileSystemModel model, List entries) { + return "Chmod"; + } + + private static class Chmod implements LeafAction { + + private final String option; + + private Chmod(String option) {this.option = option;} + + @Override + public String getName(OpenFileSystemModel model, List entries) { + return option; + } + + @Override + public void execute(OpenFileSystemModel model, List entries) throws Exception { + model.getFileSystem().getShell().orElseThrow().executeSimpleCommand(CommandBuilder.of().add("chmod", option) + .addFiles(entries.stream().map(browserEntry -> browserEntry.getRawFileEntry().getPath()).toList())); + } + } + + @Override + public List getBranchingActions(OpenFileSystemModel model, List entries) { + return List.of(new Chmod("600"), new Chmod("644"), new Chmod("700"), new Chmod("777"), new Chmod("u+x"), new Chmod("a+x")); + } +} diff --git a/ext/base/src/main/java/module-info.java b/ext/base/src/main/java/module-info.java index 6a9e53471..5205b6130 100644 --- a/ext/base/src/main/java/module-info.java +++ b/ext/base/src/main/java/module-info.java @@ -39,6 +39,7 @@ open module io.xpipe.ext.base { BrowseInNativeManagerAction, EditFileAction, RunAction, + ChmodAction, CopyAction, CopyPathAction, PasteAction,