Script hierarchy fixes

This commit is contained in:
crschnick 2024-07-29 11:48:11 +00:00
parent 35704db4c5
commit 65f51b8c2e
2 changed files with 16 additions and 7 deletions

View file

@ -6,7 +6,6 @@ import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.TerminalLauncher; import io.xpipe.app.util.TerminalLauncher;
import io.xpipe.core.process.ShellStoreState; import io.xpipe.core.process.ShellStoreState;
import io.xpipe.core.store.LocalStore;
import io.xpipe.core.store.ShellStore; import io.xpipe.core.store.ShellStore;
import io.xpipe.ext.base.script.ScriptHierarchy; import io.xpipe.ext.base.script.ScriptHierarchy;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
@ -171,10 +170,6 @@ public class RunScriptActionMenu implements ActionProvider {
@Override @Override
public boolean isApplicable(DataStoreEntryRef<ShellStore> o) { public boolean isApplicable(DataStoreEntryRef<ShellStore> o) {
if (o.getStore() instanceof LocalStore) {
return true;
}
var state = o.getEntry().getStorePersistentState(); var state = o.getEntry().getStorePersistentState();
if (!(state instanceof ShellStoreState shellStoreState) || shellStoreState.getShellDialect() == null) { if (!(state instanceof ShellStoreState shellStoreState) || shellStoreState.getShellDialect() == null) {
return false; return false;

View file

@ -54,13 +54,14 @@ public class ScriptHierarchy {
return all.contains(check); return all.contains(check);
})) }))
.map(hierarchy -> condenseHierarchy(hierarchy))
.filter(hierarchy -> hierarchy.show()) .filter(hierarchy -> hierarchy.show())
.sorted(Comparator.comparing(scriptHierarchy -> scriptHierarchy.getBase().get().getName().toLowerCase())) .sorted(Comparator.comparing(scriptHierarchy -> scriptHierarchy.getBase().get().getName().toLowerCase()))
.toList(); .toList();
return new ScriptHierarchy(null, mapped); return condenseHierarchy(new ScriptHierarchy(null, mapped));
} }
public static ScriptHierarchy buildHierarchy(DataStoreEntryRef<ScriptStore> ref, Predicate<DataStoreEntryRef<ScriptStore>> include) { private static ScriptHierarchy buildHierarchy(DataStoreEntryRef<ScriptStore> ref, Predicate<DataStoreEntryRef<ScriptStore>> include) {
if (ref.getStore() instanceof ScriptGroupStore groupStore) { if (ref.getStore() instanceof ScriptGroupStore groupStore) {
var children = groupStore.getEffectiveScripts().stream().filter(include) var children = groupStore.getEffectiveScripts().stream().filter(include)
.map(c -> buildHierarchy(c, 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<? extends ScriptStore> base; DataStoreEntryRef<? extends ScriptStore> base;
List<ScriptHierarchy> children; List<ScriptHierarchy> children;