Store children rework and script fixes

This commit is contained in:
crschnick 2023-10-12 15:23:51 +00:00
parent 09052de9ee
commit 0d065dc14e
22 changed files with 101 additions and 83 deletions

View file

@ -1,9 +1,7 @@
package io.xpipe.app.comp;
import io.xpipe.app.comp.base.BackgroundImageComp;
import io.xpipe.app.comp.base.SideMenuBarComp;
import io.xpipe.app.core.AppFont;
import io.xpipe.app.core.AppImages;
import io.xpipe.app.core.AppLayoutModel;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.CompStructure;
@ -11,18 +9,18 @@ import io.xpipe.app.fxcomps.SimpleCompStructure;
import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.prefs.AppPrefs;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import java.util.HashMap;
import java.util.Map;
public class AppLayoutComp extends Comp<CompStructure<StackPane>> {
public class AppLayoutComp extends Comp<CompStructure<Pane>> {
private final AppLayoutModel model = AppLayoutModel.get();
@Override
public CompStructure<StackPane> createBase() {
public CompStructure<Pane> createBase() {
var map = new HashMap<AppLayoutModel.Entry, Region>();
getRegion(model.getEntries().get(0), map);
getRegion(model.getEntries().get(1), map);
@ -31,6 +29,7 @@ public class AppLayoutComp extends Comp<CompStructure<StackPane>> {
var sidebar = new SideMenuBarComp(model.getSelected(), model.getEntries());
pane.setCenter(getRegion(model.getSelected().getValue(), map));
pane.setRight(sidebar.createRegion());
pane.getStyleClass().add("background");
model.getSelected().addListener((c, o, n) -> {
if (o != null && o.equals(model.getEntries().get(2))) {
AppPrefs.get().save();
@ -41,12 +40,7 @@ public class AppLayoutComp extends Comp<CompStructure<StackPane>> {
});
});
AppFont.normal(pane);
var bg = new BackgroundImageComp(AppImages.image("bg.png"))
.styleClass("background")
.hide(AppPrefs.get().performanceMode());
return new SimpleCompStructure<>(new StackPane(bg.createRegion(), pane));
return new SimpleCompStructure<>(pane);
}
private Region getRegion(AppLayoutModel.Entry entry, Map<AppLayoutModel.Entry, Region> map) {

View file

@ -20,7 +20,7 @@ import javafx.scene.input.KeyCombination;
import javafx.scene.layout.*;
import org.kordamp.ikonli.javafx.FontIcon;
public class StoreEntryListSideComp extends SimpleComp {
public class StoreEntryListStatusComp extends SimpleComp {
private Region createGroupListHeader() {
var label = new Label();

View file

@ -4,9 +4,7 @@ import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.fxcomps.impl.StoreCategoryListComp;
import io.xpipe.app.fxcomps.impl.VerticalComp;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import java.util.List;
@ -15,12 +13,12 @@ public class StoreSidebarComp extends SimpleComp {
@Override
protected Region createSimple() {
var sideBar = new VerticalComp(List.of(
new StoreEntryListSideComp(),
new StoreEntryListStatusComp(),
new StoreSortComp(),
new StoreCategoryListComp(),
Comp.of(() -> new Region()).styleClass("bar").styleClass("filler-bar")));
new StoreCategoryListComp(StoreViewState.get().getAllConnectionsCategory()),
new StoreCategoryListComp(StoreViewState.get().getAllScriptsCategory()),
Comp.of(() -> new Region()).styleClass("bar").styleClass("filler-bar").vgrow()));
sideBar.apply(struc -> struc.get().setFillWidth(true));
sideBar.apply(s -> VBox.setVgrow(s.get().getChildren().get(2), Priority.ALWAYS));
sideBar.styleClass("sidebar");
sideBar.prefWidth(240);
return sideBar.createRegion();

View file

@ -58,7 +58,7 @@ public class StoreCategoryComp extends SimpleComp {
var name = new LazyTextFieldComp(category.nameProperty())
.apply(struc -> {
struc.get().prefWidthProperty().unbind();
struc.get().setPrefWidth(100);
struc.get().setPrefWidth(150);
struc.getTextField().minWidthProperty().bind(struc.get().widthProperty());
})
.styleClass("name")

View file

@ -1,7 +1,6 @@
package io.xpipe.app.fxcomps.impl;
import io.xpipe.app.comp.storage.store.StoreViewState;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.comp.storage.store.StoreCategoryWrapper;
import io.xpipe.app.fxcomps.SimpleComp;
import javafx.scene.layout.Region;
@ -9,14 +8,16 @@ import java.util.List;
public class StoreCategoryListComp extends SimpleComp {
private final StoreCategoryWrapper root;
public StoreCategoryListComp(StoreCategoryWrapper root) {
this.root = root;
}
@Override
protected Region createSimple() {
var all = StoreViewState.get().getAllConnectionsCategory();
var scripts = StoreViewState.get().getAllScriptsCategory();
return new VerticalComp(List.of(
new StoreCategoryComp(all),
Comp.vspacer(10),
new StoreCategoryComp(scripts)))
new StoreCategoryComp(root)))
.apply(struc -> struc.get().setFillWidth(true))
.apply(struc -> struc.get().setSpacing(3))
.styleClass("store-category-bar")

View file

@ -115,7 +115,7 @@ public abstract class DataStorage {
}
e.setInRefresh(true);
Map<String, FixedChildStore> newChildren;
List<? extends DataStoreEntryRef<? extends FixedChildStore>> newChildren;
try {
newChildren = ((FixedHierarchyStore) (e.getStore())).listChildren(e);
e.setInRefresh(false);
@ -127,19 +127,19 @@ public abstract class DataStorage {
var oldChildren = getStoreEntries().stream().filter(other -> e.equals(other.getProvider().getLogicalParent(other))).toList();
var toRemove = oldChildren.stream()
.filter(entry -> newChildren.entrySet().stream()
.filter(entry -> newChildren.stream()
.noneMatch(
nc -> nc.getValue().getFixedId() == ((FixedChildStore) entry.getStore()).getFixedId()))
nc -> nc.getStore().getFixedId() == ((FixedChildStore) entry.getStore()).getFixedId()))
.toList();
var toAdd = newChildren.entrySet().stream()
var toAdd = newChildren.stream()
.filter(entry -> oldChildren.stream()
.noneMatch(oc -> ((FixedChildStore) oc.getStore()).getFixedId()
== entry.getValue().getFixedId()))
== entry.getStore().getFixedId()))
.toList();
var toUpdate = oldChildren.stream()
.map(entry -> {
FixedChildStore found = newChildren.values().stream()
.filter(nc -> nc.getFixedId() == ((FixedChildStore) entry.getStore()).getFixedId())
var found = newChildren.stream()
.filter(nc -> nc.getStore().getFixedId() == ((FixedChildStore) entry.getStore()).getFixedId())
.findFirst()
.orElse(null);
return new Pair<>(entry, found);
@ -153,18 +153,14 @@ public abstract class DataStorage {
deleteWithChildren(toRemove.toArray(DataStoreEntry[]::new));
addStoreEntriesIfNotPresent(toAdd.stream()
.map(stringDataStoreEntry -> DataStoreEntry.createNew(
UUID.randomUUID(),
e.getCategoryUuid(),
stringDataStoreEntry.getKey(),
stringDataStoreEntry.getValue()))
.map(DataStoreEntryRef::get)
.toArray(DataStoreEntry[]::new));
toUpdate.forEach(entry -> {
toUpdate.forEach(pair -> {
propagateUpdate(
() -> {
entry.getKey().setStoreInternal(entry.getValue(), false);
pair.getKey().setStoreInternal(pair.getValue().getStore(), false);
},
entry.getKey());
pair.getKey());
});
saveAsync();
return !newChildren.isEmpty();

View file

@ -94,6 +94,10 @@ public class DataStoreEntry extends StorageElement {
this.storePersistentStateNode = storePersistentState;
}
public static DataStoreEntry createNew(@NonNull String name, @NonNull DataStore store) {
return createNew(UUID.randomUUID(), DataStorage.get().getSelectedCategory().getUuid(), name, store);
}
@SneakyThrows
public static DataStoreEntry createNew(
@NonNull UUID uuid, @NonNull UUID categoryUuid, @NonNull String name, @NonNull DataStore store) {

View file

@ -28,6 +28,10 @@ public class DataStoreFormatter {
}
public static String capitalize(String name) {
if (name == null) {
return null;
}
return name.substring(0, 1).toUpperCase()
+ name.substring(1).toLowerCase();
}

View file

@ -1,12 +1,13 @@
package io.xpipe.app.util;
import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FixedChildStore;
import java.util.Map;
import java.util.List;
public interface FixedHierarchyStore extends DataStore {
Map<String, FixedChildStore> listChildren(DataStoreEntry self) throws Exception;
List<? extends DataStoreEntryRef<? extends FixedChildStore>> listChildren(DataStoreEntry self) throws Exception;
}

View file

@ -109,7 +109,7 @@ public class ScriptHelper {
var fileName = "exec-" + getScriptId();
var temp = processControl.getSubTemporaryDirectory();
var file = FileNames.join(temp, fileName + "." + type.getScriptFileEnding());
return createExecScript(processControl.getShellDialect(), processControl, file, content);
return createExecScript(type, processControl, file, content);
}
@SneakyThrows

Binary file not shown.

Before

Width:  |  Height:  |  Size: 646 KiB

View file

@ -6,6 +6,10 @@ none=None
common=Common
key=Key
color=Color
share=Add to git repository
unshare=Remove from git repository
remove=Remove
newCategory=New subcategory
passwordManager=Password manager
prompt=Prompt
customCommand=Custom command

View file

@ -1,5 +1,5 @@
.category-button {
-fx-opacity: 0.6;
-fx-opacity: 0.8;
}
.category-button .settings {
@ -10,7 +10,6 @@
-fx-underline: true ;
}
.category:selected .category-button {
-fx-opacity: 1.0;
-fx-background-radius: 4px;

View file

@ -17,12 +17,12 @@
}
.root:dark .background {
-fx-opacity: 0.06;
.root:dark.background {
-fx-background-color: linear-gradient(from 100% 0% to 0% 100%, derive(-color-bg-default, 5%) 40%, derive(-color-bg-default, 2%) 50%, derive(-color-bg-default, 5%) 100%);
}
.root:light .background {
-fx-opacity: 0.2;
.root:light.background {
-fx-background-color: linear-gradient(from 100% 0% to 0% 100%, derive(-color-bg-default, -9%) 40%, derive(-color-bg-default, 1%) 50%, derive(-color-bg-default, -9%) 100%);
}
.edit-button.icon-button-comp {

View file

@ -15,6 +15,10 @@ import java.util.function.Predicate;
public interface ShellControl extends ProcessControl {
ShellControl withTargetTerminalShellDialect(ShellDialect d);
ShellDialect getTargetTerminalShellDialect();
default boolean hasLocalSystemAccess() {
return getSystemId().equals(XPipeSystemId.getLocal());
}

View file

@ -34,32 +34,23 @@ public enum PredefinedScriptStore {
""")
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.build()),
STARSHIP_SETUP_UNIX("Starship Unix Setup", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.SH)
.commands(file("starship_setup.sh"))
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.build()),
STARSHIP_BASH("Starship Bash", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.BASH)
.commands("eval \"$(starship init bash)\"")
.commands(file("starship_bash.sh"))
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.script(STARSHIP_SETUP_UNIX.getEntry())
.build()),
STARSHIP_ZSH("Starship Zsh", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.ZSH)
.commands("eval \"$(starship init zsh)\"")
.commands(file("starship_zsh.sh"))
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.script(STARSHIP_SETUP_UNIX.getEntry())
.build()),
STARSHIP_FISH("Starship Fish", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.FISH)
.commands("starship init fish | source")
.commands(file("starship_fish.fish"))
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.script(STARSHIP_SETUP_UNIX.getEntry())
.build()),
STARSHIP_CMD(
"Starship Cmd",

View file

@ -13,7 +13,9 @@ import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import java.util.*;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@SuperBuilder
@ -22,7 +24,7 @@ import java.util.stream.Collectors;
public abstract class ScriptStore extends JacksonizedValue implements DataStore, StatefulDataStore<ScriptStore.State> {
public static ShellControl controlWithDefaultScripts(ShellControl pc) {
return controlWithScripts(pc,getDefaultScripts());
return controlWithScripts(pc, getDefaultScripts());
}
public static ShellControl controlWithScripts(ShellControl pc, List<DataStoreEntryRef<ScriptStore>> refs) {
@ -56,9 +58,8 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore,
public static List<SimpleScriptStore> flatten(List<DataStoreEntryRef<ScriptStore>> scripts) {
var seen = new LinkedHashSet<SimpleScriptStore>();
scripts
.forEach(scriptStoreDataStoreEntryRef ->
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(seen));
scripts.forEach(scriptStoreDataStoreEntryRef ->
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(seen));
return seen.stream().toList();
}

View file

@ -28,12 +28,11 @@ public class SimpleScriptStore extends ScriptStore {
return assemble(shellControl, ExecutionType.TERMINAL_ONLY);
}
private String assemble(
ShellControl shellControl, ExecutionType type) {
if ((executionType == type || executionType == ExecutionType.BOTH)
&& minimumDialect.isCompatibleTo(shellControl.getShellDialect())) {
var script = ScriptHelper.createExecScript(minimumDialect, shellControl, commands);
return shellControl.getShellDialect().sourceScriptCommand(shellControl, script);
private String assemble(ShellControl shellControl, ExecutionType type) {
var targetType = type == ExecutionType.TERMINAL_ONLY ? shellControl.getTargetTerminalShellDialect() : shellControl.getShellDialect();
if ((executionType == type || executionType == ExecutionType.BOTH) && minimumDialect.isCompatibleTo(targetType)) {
var script = ScriptHelper.createExecScript(targetType, shellControl, commands);
return targetType.sourceScriptCommand(shellControl, script);
}
return null;
@ -47,9 +46,11 @@ public class SimpleScriptStore extends ScriptStore {
}
public void queryFlattenedScripts(LinkedHashSet<SimpleScriptStore> all) {
getEffectiveScripts().stream().filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef.getStore())).forEach(scriptStoreDataStoreEntryRef -> {
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(all);
});
getEffectiveScripts().stream()
.filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef.getStore()))
.forEach(scriptStoreDataStoreEntryRef -> {
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(all);
});
all.add(this);
}

View file

@ -0,0 +1,9 @@
dir=~/.xpipe/scriptdata/starship
export PATH="$PATH:$dir"
which starship > /dev/null
if [ "$?" != 0 ]; then
mkdir -p "$dir" && \
which curl > /dev/null && \
curl -sS https://starship.rs/install.sh | sh /dev/stdin -y --bin-dir "$dir" > /dev/null
fi
eval "$(starship init bash)"

View file

@ -0,0 +1,9 @@
set dir ~/.xpipe/scriptdata/starship
export PATH="$PATH:$dir"
which starship > /dev/null
if [ $status != 0 ]
mkdir -p "$dir" && \
which curl > /dev/null && \
curl -sS https://starship.rs/install.sh | sh /dev/stdin -y --bin-dir "$dir" > /dev/null
end
starship init fish | source

View file

@ -1,7 +0,0 @@
dir=~/.xpipe/scriptdata/starship
export PATH="$PATH:$dir"
which starship > /dev/null
if [ "$?" != 0 ]; then
mkdir -p "$dir"
sh <(curl -sS https://starship.rs/install.sh) -y --bin-dir "$dir" > /dev/null
fi

View file

@ -0,0 +1,9 @@
dir=~/.xpipe/scriptdata/starship
export PATH="$PATH:$dir"
which starship > /dev/null
if [ "$?" != 0 ]; then
mkdir -p "$dir" && \
which curl > /dev/null && \
curl -sS https://starship.rs/install.sh | sh /dev/stdin -y --bin-dir "$dir" > /dev/null
fi
eval "$(starship init zsh)"