From d629fdddc86fd9a74c0b7e2455ba6f0b4d80b5c8 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 7 Sep 2023 19:18:55 +0000 Subject: [PATCH] Add model info to branching actions --- .../java/io/xpipe/app/browser/BrowserContextMenu.java | 2 +- .../java/io/xpipe/app/browser/BrowserFileListComp.java | 2 +- .../java/io/xpipe/app/browser/OpenFileSystemComp.java | 8 ++++---- .../java/io/xpipe/app/browser/action/BranchAction.java | 5 ++++- .../java/io/xpipe/app/browser/action/BrowserAction.java | 8 ++++---- .../io/xpipe/app/browser/action/MultiExecuteAction.java | 2 +- .../java/io/xpipe/ext/base/browser/CopyPathAction.java | 2 +- .../java/io/xpipe/ext/base/browser/NewItemAction.java | 2 +- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserContextMenu.java b/app/src/main/java/io/xpipe/app/browser/BrowserContextMenu.java index bee1fc6aa..15e1c1edd 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserContextMenu.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserContextMenu.java @@ -66,7 +66,7 @@ final class BrowserContextMenu extends ContextMenu { if (a instanceof BranchAction la) { 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); if (!sub.isApplicable(model, subUsed)) { continue; diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java index 0b076749e..311404ff3 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java @@ -179,7 +179,7 @@ final class BrowserFileListComp extends SimpleComp { private void prepareTableShortcuts(TableView table) { table.setOnKeyPressed(event -> { var selected = fileList.getSelection(); - BrowserAction.getFlattened().stream() + BrowserAction.getFlattened(fileList.getFileSystemModel(), selected).stream() .filter(browserAction -> browserAction.isApplicable(fileList.getFileSystemModel(), selected) && browserAction.isActive(fileList.getFileSystemModel(), selected)) .filter(browserAction -> browserAction.getShortcut() != null) diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemComp.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemComp.java index 69c50d1f2..0ad61d9e4 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemComp.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemComp.java @@ -47,10 +47,10 @@ public class OpenFileSystemComp extends SimpleComp { overview.disableProperty().bind(model.getInOverview()); overview.setAccessibleText("System overview"); - var backBtn = BrowserAction.byId("back").toButton(model, List.of()); - var forthBtn = BrowserAction.byId("forward").toButton(model, List.of()); - var refreshBtn = BrowserAction.byId("refresh").toButton(model, List.of()); - var terminalBtn = BrowserAction.byId("openTerminal").toButton(model, List.of()); + var backBtn = BrowserAction.byId("back", model, List.of()).toButton(model, List.of()); + var forthBtn = BrowserAction.byId("forward", model, List.of()).toButton(model, List.of()); + var refreshBtn = BrowserAction.byId("refresh", model, List.of()).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")); new ContextMenuAugment<>( diff --git a/app/src/main/java/io/xpipe/app/browser/action/BranchAction.java b/app/src/main/java/io/xpipe/app/browser/action/BranchAction.java index 17c69caf7..31e7a4ce1 100644 --- a/app/src/main/java/io/xpipe/app/browser/action/BranchAction.java +++ b/app/src/main/java/io/xpipe/app/browser/action/BranchAction.java @@ -1,8 +1,11 @@ package io.xpipe.app.browser.action; +import io.xpipe.app.browser.BrowserEntry; +import io.xpipe.app.browser.OpenFileSystemModel; + import java.util.List; public interface BranchAction extends BrowserAction { - List getBranchingActions(); + List getBranchingActions(OpenFileSystemModel model, List entries); } diff --git a/app/src/main/java/io/xpipe/app/browser/action/BrowserAction.java b/app/src/main/java/io/xpipe/app/browser/action/BrowserAction.java index 77ca9beaa..7bf8993d6 100644 --- a/app/src/main/java/io/xpipe/app/browser/action/BrowserAction.java +++ b/app/src/main/java/io/xpipe/app/browser/action/BrowserAction.java @@ -23,17 +23,17 @@ public interface BrowserAction { List ALL = new ArrayList<>(); - static List getFlattened() { + static List getFlattened(OpenFileSystemModel model, List entries) { return ALL.stream() .map(browserAction -> browserAction instanceof LeafAction ? List.of((LeafAction) browserAction) - : ((BranchAction) browserAction).getBranchingActions()) + : ((BranchAction) browserAction).getBranchingActions(model, entries)) .flatMap(List::stream) .toList(); } - static LeafAction byId(String id) { - return getFlattened().stream() + static LeafAction byId(String id, OpenFileSystemModel model, List entries) { + return getFlattened(model, entries).stream() .filter(browserAction -> id.equals(browserAction.getId())) .findAny() .orElseThrow(); diff --git a/app/src/main/java/io/xpipe/app/browser/action/MultiExecuteAction.java b/app/src/main/java/io/xpipe/app/browser/action/MultiExecuteAction.java index 08f8d98ec..81b522daa 100644 --- a/app/src/main/java/io/xpipe/app/browser/action/MultiExecuteAction.java +++ b/app/src/main/java/io/xpipe/app/browser/action/MultiExecuteAction.java @@ -20,7 +20,7 @@ public abstract class MultiExecuteAction implements BranchAction { protected abstract String createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry); @Override - public List getBranchingActions() { + public List getBranchingActions(OpenFileSystemModel model, List entries) { return List.of( new LeafAction() { diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/CopyPathAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/CopyPathAction.java index ecde59cbd..4d1bacb1e 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/CopyPathAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/CopyPathAction.java @@ -36,7 +36,7 @@ public class CopyPathAction implements BrowserAction, BranchAction { } @Override - public List getBranchingActions() { + public List getBranchingActions(OpenFileSystemModel model, List entries) { return List.of( new LeafAction() { @Override diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/NewItemAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/NewItemAction.java index bd229de1d..5a79e2777 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/NewItemAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/NewItemAction.java @@ -49,7 +49,7 @@ public class NewItemAction implements BrowserAction, BranchAction { } @Override - public List getBranchingActions() { + public List getBranchingActions(OpenFileSystemModel model, List entries) { return List.of( new LeafAction() { @Override