mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 15:10:23 +00:00
Script hierarchy fixes
This commit is contained in:
parent
35704db4c5
commit
65f51b8c2e
2 changed files with 16 additions and 7 deletions
|
@ -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<ShellStore> o) {
|
||||
if (o.getStore() instanceof LocalStore) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var state = o.getEntry().getStorePersistentState();
|
||||
if (!(state instanceof ShellStoreState shellStoreState) || shellStoreState.getShellDialect() == null) {
|
||||
return false;
|
||||
|
|
|
@ -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<ScriptStore> ref, Predicate<DataStoreEntryRef<ScriptStore>> include) {
|
||||
private static ScriptHierarchy buildHierarchy(DataStoreEntryRef<ScriptStore> ref, Predicate<DataStoreEntryRef<ScriptStore>> 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<? extends ScriptStore> base;
|
||||
List<ScriptHierarchy> children;
|
||||
|
||||
|
|
Loading…
Reference in a new issue