From 65f51b8c2e337bc2c72fc88eb45c6177262f0b30 Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 29 Jul 2024 11:48:11 +0000 Subject: [PATCH] Script hierarchy fixes --- .../ext/base/action/RunScriptActionMenu.java | 5 ----- .../xpipe/ext/base/script/ScriptHierarchy.java | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java b/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java index 19f768573..94808806c 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java @@ -6,7 +6,6 @@ import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.TerminalLauncher; import io.xpipe.core.process.ShellStoreState; -import io.xpipe.core.store.LocalStore; import io.xpipe.core.store.ShellStore; import io.xpipe.ext.base.script.ScriptHierarchy; import javafx.beans.property.SimpleStringProperty; @@ -171,10 +170,6 @@ public class RunScriptActionMenu implements ActionProvider { @Override public boolean isApplicable(DataStoreEntryRef o) { - if (o.getStore() instanceof LocalStore) { - return true; - } - var state = o.getEntry().getStorePersistentState(); if (!(state instanceof ShellStoreState shellStoreState) || shellStoreState.getShellDialect() == null) { return false; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptHierarchy.java b/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptHierarchy.java index 5a60690a9..8a198ac1a 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptHierarchy.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptHierarchy.java @@ -54,13 +54,14 @@ public class ScriptHierarchy { return all.contains(check); })) + .map(hierarchy -> condenseHierarchy(hierarchy)) .filter(hierarchy -> hierarchy.show()) .sorted(Comparator.comparing(scriptHierarchy -> scriptHierarchy.getBase().get().getName().toLowerCase())) .toList(); - return new ScriptHierarchy(null, mapped); + return condenseHierarchy(new ScriptHierarchy(null, mapped)); } - public static ScriptHierarchy buildHierarchy(DataStoreEntryRef ref, Predicate> include) { + private static ScriptHierarchy buildHierarchy(DataStoreEntryRef ref, Predicate> include) { if (ref.getStore() instanceof ScriptGroupStore groupStore) { var children = groupStore.getEffectiveScripts().stream().filter(include) .map(c -> buildHierarchy(c, include)) @@ -73,6 +74,19 @@ public class ScriptHierarchy { } } + + public static ScriptHierarchy condenseHierarchy(ScriptHierarchy hierarchy) { + var children = hierarchy.getChildren().stream() + .map(c -> condenseHierarchy(c)) + .toList(); + if (children.size() == 1 && !children.getFirst().isLeaf()) { + var nestedChildren = children.getFirst().getChildren(); + return new ScriptHierarchy(hierarchy.getBase(), nestedChildren); + } else { + return new ScriptHierarchy(hierarchy.getBase(), children); + } + } + DataStoreEntryRef base; List children;