mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Small fixes
This commit is contained in:
parent
3d8601367c
commit
f5b238bd45
5 changed files with 16 additions and 137 deletions
|
@ -1,5 +1,6 @@
|
||||||
package io.xpipe.app.fxcomps.impl;
|
package io.xpipe.app.fxcomps.impl;
|
||||||
|
|
||||||
|
import atlantafx.base.theme.Styles;
|
||||||
import io.xpipe.app.browser.session.BrowserChooserComp;
|
import io.xpipe.app.browser.session.BrowserChooserComp;
|
||||||
import io.xpipe.app.comp.base.ButtonComp;
|
import io.xpipe.app.comp.base.ButtonComp;
|
||||||
import io.xpipe.app.core.AppI18n;
|
import io.xpipe.app.core.AppI18n;
|
||||||
|
@ -15,39 +16,29 @@ import io.xpipe.app.storage.DataStorage;
|
||||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||||
import io.xpipe.core.store.FileNames;
|
import io.xpipe.core.store.FileNames;
|
||||||
import io.xpipe.core.store.FileSystemStore;
|
import io.xpipe.core.store.FileSystemStore;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
|
|
||||||
import atlantafx.base.theme.Styles;
|
|
||||||
import org.kordamp.ikonli.javafx.FontIcon;
|
import org.kordamp.ikonli.javafx.FontIcon;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>> {
|
public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>> {
|
||||||
|
|
||||||
private final Property<DataStoreEntryRef<? extends FileSystemStore>> fileSystem;
|
private final Property<DataStoreEntryRef<? extends FileSystemStore>> fileSystem;
|
||||||
private final Property<String> filePath;
|
private final Property<String> filePath;
|
||||||
|
private final boolean allowSync;
|
||||||
|
|
||||||
public <T extends FileSystemStore> ContextualFileReferenceChoiceComp(
|
public <T extends FileSystemStore> ContextualFileReferenceChoiceComp(
|
||||||
ObservableValue<DataStoreEntryRef<T>> fileSystem, Property<String> filePath) {
|
Property<DataStoreEntryRef<T>> fileSystem, Property<String> filePath, boolean allowSync
|
||||||
this.fileSystem = new SimpleObjectProperty<>();
|
) {
|
||||||
fileSystem.subscribe(val -> {
|
this.allowSync = allowSync;
|
||||||
this.fileSystem.setValue(val);
|
|
||||||
});
|
|
||||||
this.filePath = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends FileSystemStore> ContextualFileReferenceChoiceComp(
|
|
||||||
Property<DataStoreEntryRef<T>> fileSystem, Property<String> filePath) {
|
|
||||||
this.fileSystem = new SimpleObjectProperty<>();
|
this.fileSystem = new SimpleObjectProperty<>();
|
||||||
fileSystem.subscribe(val -> {
|
fileSystem.subscribe(val -> {
|
||||||
this.fileSystem.setValue(val);
|
this.fileSystem.setValue(val);
|
||||||
|
@ -79,7 +70,7 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
|
||||||
},
|
},
|
||||||
false);
|
false);
|
||||||
})
|
})
|
||||||
.styleClass(Styles.CENTER_PILL)
|
.styleClass(allowSync ? Styles.CENTER_PILL : Styles.RIGHT_PILL)
|
||||||
.grow(false, true);
|
.grow(false, true);
|
||||||
|
|
||||||
var gitShareButton = new ButtonComp(null, new FontIcon("mdi2g-git"), () -> {
|
var gitShareButton = new ButtonComp(null, new FontIcon("mdi2g-git"), () -> {
|
||||||
|
@ -126,7 +117,13 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
|
||||||
gitShareButton.tooltipKey("gitShareFileTooltip");
|
gitShareButton.tooltipKey("gitShareFileTooltip");
|
||||||
gitShareButton.styleClass(Styles.RIGHT_PILL).grow(false, true);
|
gitShareButton.styleClass(Styles.RIGHT_PILL).grow(false, true);
|
||||||
|
|
||||||
var layout = new HorizontalComp(List.of(fileNameComp, fileBrowseButton, gitShareButton))
|
var nodes = new ArrayList<Comp<?>>();
|
||||||
|
nodes.add(fileNameComp);
|
||||||
|
nodes.add(fileBrowseButton);
|
||||||
|
if (allowSync) {
|
||||||
|
nodes.add(gitShareButton);
|
||||||
|
}
|
||||||
|
var layout = new HorizontalComp(nodes)
|
||||||
.apply(struc -> struc.get().setFillHeight(true));
|
.apply(struc -> struc.get().setFillHeight(true));
|
||||||
|
|
||||||
layout.apply(struc -> {
|
layout.apply(struc -> {
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
package io.xpipe.app.fxcomps.impl;
|
|
||||||
|
|
||||||
import io.xpipe.app.fxcomps.SimpleComp;
|
|
||||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
|
||||||
import io.xpipe.app.util.StringSource;
|
|
||||||
import io.xpipe.core.store.ShellStore;
|
|
||||||
|
|
||||||
import javafx.beans.property.Property;
|
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
import javafx.scene.layout.Region;
|
|
||||||
import javafx.scene.layout.StackPane;
|
|
||||||
|
|
||||||
public class StringSourceComp extends SimpleComp {
|
|
||||||
|
|
||||||
private final Property<DataStoreEntryRef<ShellStore>> fileSystem;
|
|
||||||
private final Property<StringSource> stringSource;
|
|
||||||
|
|
||||||
public <T extends ShellStore> StringSourceComp(
|
|
||||||
ObservableValue<DataStoreEntryRef<T>> fileSystem, Property<StringSource> stringSource) {
|
|
||||||
this.stringSource = stringSource;
|
|
||||||
this.fileSystem = new SimpleObjectProperty<>();
|
|
||||||
fileSystem.subscribe(val -> {
|
|
||||||
this.fileSystem.setValue(val.get().ref());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Region createSimple() {
|
|
||||||
var inPlace =
|
|
||||||
new SimpleObjectProperty<>(stringSource.getValue() instanceof StringSource.InPlace i ? i.get() : null);
|
|
||||||
var fs = stringSource.getValue() instanceof StringSource.File f ? f.getFile() : null;
|
|
||||||
var file = new SimpleObjectProperty<>(
|
|
||||||
stringSource.getValue() instanceof StringSource.File f
|
|
||||||
? f.getFile().serialize()
|
|
||||||
: null);
|
|
||||||
var showText = new SimpleBooleanProperty(inPlace.get() != null);
|
|
||||||
|
|
||||||
var stringField = new TextAreaComp(inPlace);
|
|
||||||
stringField.hide(showText.not());
|
|
||||||
var fileComp = new ContextualFileReferenceChoiceComp(fileSystem, file);
|
|
||||||
fileComp.hide(showText);
|
|
||||||
|
|
||||||
var tr = stringField.createRegion();
|
|
||||||
var button = new IconButtonComp("mdi2c-checkbox-marked-outline", () -> {
|
|
||||||
showText.set(!showText.getValue());
|
|
||||||
})
|
|
||||||
.createRegion();
|
|
||||||
AnchorPane.setBottomAnchor(button, 10.0);
|
|
||||||
AnchorPane.setRightAnchor(button, 10.0);
|
|
||||||
var anchorPane = new AnchorPane(tr, button);
|
|
||||||
AnchorPane.setBottomAnchor(tr, 0.0);
|
|
||||||
AnchorPane.setTopAnchor(tr, 0.0);
|
|
||||||
AnchorPane.setLeftAnchor(tr, 0.0);
|
|
||||||
AnchorPane.setRightAnchor(tr, 0.0);
|
|
||||||
|
|
||||||
var fr = fileComp.createRegion();
|
|
||||||
|
|
||||||
return new StackPane(tr, fr);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,11 +21,7 @@ public class SyncCategory extends AppPrefsCategory {
|
||||||
builder.addTitle("sync")
|
builder.addTitle("sync")
|
||||||
.sub(new OptionsBuilder()
|
.sub(new OptionsBuilder()
|
||||||
.name("enableGitStorage")
|
.name("enableGitStorage")
|
||||||
.description(
|
.description("enableGitStorageDescription")
|
||||||
AppProperties.get().isStaging()
|
|
||||||
&& !prefs.developerMode().getValue()
|
|
||||||
? "enableGitStoragePtbDisabled"
|
|
||||||
: "enableGitStorageDescription")
|
|
||||||
.addToggle(prefs.enableGitStorage)
|
.addToggle(prefs.enableGitStorage)
|
||||||
.disable(AppProperties.get().isStaging()
|
.disable(AppProperties.get().isStaging()
|
||||||
&& !prefs.developerMode().getValue())
|
&& !prefs.developerMode().getValue())
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class ContextualFileReference {
|
||||||
|
|
||||||
private static String getDataDir() {
|
private static String getDataDir() {
|
||||||
if (DataStorage.get() == null) {
|
if (DataStorage.get() == null) {
|
||||||
return lastDataDir != null ? lastDataDir : normalized(AppPrefs.DEFAULT_STORAGE_DIR);
|
return lastDataDir != null ? lastDataDir : normalized(AppPrefs.DEFAULT_STORAGE_DIR.resolve("data"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastDataDir = normalized(DataStorage.get().getDataDir());
|
return lastDataDir = normalized(DataStorage.get().getDataDir());
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
package io.xpipe.app.util;
|
|
||||||
|
|
||||||
import io.xpipe.app.issue.ErrorEvent;
|
|
||||||
import io.xpipe.app.storage.ContextualFileReference;
|
|
||||||
import io.xpipe.core.store.ShellStore;
|
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Value;
|
|
||||||
|
|
||||||
public abstract class StringSource {
|
|
||||||
|
|
||||||
public abstract String get() throws Exception;
|
|
||||||
|
|
||||||
@Value
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public static class InPlace extends StringSource {
|
|
||||||
|
|
||||||
String value;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Value
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public static class File extends StringSource {
|
|
||||||
|
|
||||||
ShellStore host;
|
|
||||||
ContextualFileReference file;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get() throws Exception {
|
|
||||||
if (host == null || file == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
try (var sc = host.control().start()) {
|
|
||||||
var path = file.toAbsoluteFilePath(sc);
|
|
||||||
if (!sc.getShellDialect().createFileExistsCommand(sc, path).executeAndCheck()) {
|
|
||||||
throw ErrorEvent.expected(new IllegalArgumentException("File " + path + " does not exist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
var abs = file.toAbsoluteFilePath(sc);
|
|
||||||
var content = sc.getShellDialect().getFileReadCommand(sc, abs).readStdoutOrThrow();
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue