Add model info to branching actions

This commit is contained in:
crschnick 2023-09-07 19:18:55 +00:00
parent f382f30476
commit d629fdddc8
8 changed files with 17 additions and 14 deletions

View file

@ -66,7 +66,7 @@ final class BrowserContextMenu extends ContextMenu {
if (a instanceof BranchAction la) { if (a instanceof BranchAction la) {
var m = new Menu(a.getName(model, used) + " ..."); var m = new Menu(a.getName(model, used) + " ...");
for (LeafAction sub : la.getBranchingActions()) { for (LeafAction sub : la.getBranchingActions(model, used)) {
var subUsed = resolveIfNeeded(sub, selected); var subUsed = resolveIfNeeded(sub, selected);
if (!sub.isApplicable(model, subUsed)) { if (!sub.isApplicable(model, subUsed)) {
continue; continue;

View file

@ -179,7 +179,7 @@ final class BrowserFileListComp extends SimpleComp {
private void prepareTableShortcuts(TableView<BrowserEntry> table) { private void prepareTableShortcuts(TableView<BrowserEntry> table) {
table.setOnKeyPressed(event -> { table.setOnKeyPressed(event -> {
var selected = fileList.getSelection(); var selected = fileList.getSelection();
BrowserAction.getFlattened().stream() BrowserAction.getFlattened(fileList.getFileSystemModel(), selected).stream()
.filter(browserAction -> browserAction.isApplicable(fileList.getFileSystemModel(), selected) .filter(browserAction -> browserAction.isApplicable(fileList.getFileSystemModel(), selected)
&& browserAction.isActive(fileList.getFileSystemModel(), selected)) && browserAction.isActive(fileList.getFileSystemModel(), selected))
.filter(browserAction -> browserAction.getShortcut() != null) .filter(browserAction -> browserAction.getShortcut() != null)

View file

@ -47,10 +47,10 @@ public class OpenFileSystemComp extends SimpleComp {
overview.disableProperty().bind(model.getInOverview()); overview.disableProperty().bind(model.getInOverview());
overview.setAccessibleText("System overview"); overview.setAccessibleText("System overview");
var backBtn = BrowserAction.byId("back").toButton(model, List.of()); var backBtn = BrowserAction.byId("back", model, List.of()).toButton(model, List.of());
var forthBtn = BrowserAction.byId("forward").toButton(model, List.of()); var forthBtn = BrowserAction.byId("forward", model, List.of()).toButton(model, List.of());
var refreshBtn = BrowserAction.byId("refresh").toButton(model, List.of()); var refreshBtn = BrowserAction.byId("refresh", model, List.of()).toButton(model, List.of());
var terminalBtn = BrowserAction.byId("openTerminal").toButton(model, List.of()); var terminalBtn = BrowserAction.byId("openTerminal", model, List.of()).toButton(model, List.of());
var menuButton = new MenuButton(null, new FontIcon("mdral-folder_open")); var menuButton = new MenuButton(null, new FontIcon("mdral-folder_open"));
new ContextMenuAugment<>( new ContextMenuAugment<>(

View file

@ -1,8 +1,11 @@
package io.xpipe.app.browser.action; package io.xpipe.app.browser.action;
import io.xpipe.app.browser.BrowserEntry;
import io.xpipe.app.browser.OpenFileSystemModel;
import java.util.List; import java.util.List;
public interface BranchAction extends BrowserAction { public interface BranchAction extends BrowserAction {
List<LeafAction> getBranchingActions(); List<LeafAction> getBranchingActions(OpenFileSystemModel model, List<BrowserEntry> entries);
} }

View file

@ -23,17 +23,17 @@ public interface BrowserAction {
List<BrowserAction> ALL = new ArrayList<>(); List<BrowserAction> ALL = new ArrayList<>();
static List<LeafAction> getFlattened() { static List<LeafAction> getFlattened(OpenFileSystemModel model, List<BrowserEntry> entries) {
return ALL.stream() return ALL.stream()
.map(browserAction -> browserAction instanceof LeafAction .map(browserAction -> browserAction instanceof LeafAction
? List.of((LeafAction) browserAction) ? List.of((LeafAction) browserAction)
: ((BranchAction) browserAction).getBranchingActions()) : ((BranchAction) browserAction).getBranchingActions(model, entries))
.flatMap(List::stream) .flatMap(List::stream)
.toList(); .toList();
} }
static LeafAction byId(String id) { static LeafAction byId(String id, OpenFileSystemModel model, List<BrowserEntry> entries) {
return getFlattened().stream() return getFlattened(model, entries).stream()
.filter(browserAction -> id.equals(browserAction.getId())) .filter(browserAction -> id.equals(browserAction.getId()))
.findAny() .findAny()
.orElseThrow(); .orElseThrow();

View file

@ -20,7 +20,7 @@ public abstract class MultiExecuteAction implements BranchAction {
protected abstract String createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry); protected abstract String createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry);
@Override @Override
public List<LeafAction> getBranchingActions() { public List<LeafAction> getBranchingActions(OpenFileSystemModel model, List<BrowserEntry> entries) {
return List.of( return List.of(
new LeafAction() { new LeafAction() {

View file

@ -36,7 +36,7 @@ public class CopyPathAction implements BrowserAction, BranchAction {
} }
@Override @Override
public List<LeafAction> getBranchingActions() { public List<LeafAction> getBranchingActions(OpenFileSystemModel model, List<BrowserEntry> entries) {
return List.of( return List.of(
new LeafAction() { new LeafAction() {
@Override @Override

View file

@ -49,7 +49,7 @@ public class NewItemAction implements BrowserAction, BranchAction {
} }
@Override @Override
public List<LeafAction> getBranchingActions() { public List<LeafAction> getBranchingActions(OpenFileSystemModel model, List<BrowserEntry> entries) {
return List.of( return List.of(
new LeafAction() { new LeafAction() {
@Override @Override