mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-05-03 11:20:34 +00:00
Filter systems in file chooser
This commit is contained in:
@@ -13,6 +13,7 @@ import io.xpipe.app.ext.FileSystemStore;
|
||||
import io.xpipe.app.ext.ShellStore;
|
||||
import io.xpipe.app.hub.comp.StoreEntryWrapper;
|
||||
import io.xpipe.app.hub.comp.StoreViewState;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.app.util.BindingsHelper;
|
||||
import io.xpipe.app.util.FileReference;
|
||||
@@ -37,22 +38,25 @@ import java.util.function.Supplier;
|
||||
public class BrowserFileChooserSessionComp extends ModalOverlayContentComp {
|
||||
|
||||
private final BrowserFileChooserSessionModel model;
|
||||
private final Predicate<DataStoreEntry> filter;
|
||||
|
||||
public BrowserFileChooserSessionComp(BrowserFileChooserSessionModel model) {
|
||||
public BrowserFileChooserSessionComp(BrowserFileChooserSessionModel model, Predicate<DataStoreEntry> filter) {
|
||||
this.model = model;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public static void openSingleFile(
|
||||
Supplier<DataStoreEntryRef<? extends FileSystemStore>> store,
|
||||
Supplier<FilePath> initialPath,
|
||||
Consumer<FileReference> file,
|
||||
boolean save) {
|
||||
boolean save,
|
||||
Predicate<DataStoreEntry> filter) {
|
||||
var model = new BrowserFileChooserSessionModel(BrowserFileSystemTabModel.SelectionMode.SINGLE_FILE);
|
||||
model.setOnFinish(fileStores -> {
|
||||
file.accept(fileStores.size() > 0 ? fileStores.getFirst() : null);
|
||||
});
|
||||
var comp =
|
||||
new BrowserFileChooserSessionComp(model).styleClass("browser").styleClass("chooser");
|
||||
new BrowserFileChooserSessionComp(model, filter).styleClass("browser").styleClass("chooser");
|
||||
var selection = new SimpleStringProperty();
|
||||
model.getFileSelection().addListener((ListChangeListener<? super BrowserEntry>) c -> {
|
||||
selection.set(
|
||||
@@ -86,7 +90,7 @@ public class BrowserFileChooserSessionComp extends ModalOverlayContentComp {
|
||||
protected Region createSimple() {
|
||||
Predicate<StoreEntryWrapper> applicable = storeEntryWrapper -> {
|
||||
return (storeEntryWrapper.getEntry().getStore() instanceof ShellStore)
|
||||
&& storeEntryWrapper.getEntry().getValidity().isUsable();
|
||||
&& storeEntryWrapper.getEntry().getValidity().isUsable() && filter.test(storeEntryWrapper.getEntry());
|
||||
};
|
||||
BiConsumer<StoreEntryWrapper, BooleanProperty> action = (w, busy) -> {
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
|
||||
@@ -8,10 +8,12 @@ import io.xpipe.app.core.AppLayoutModel;
|
||||
import io.xpipe.app.core.window.AppDialog;
|
||||
import io.xpipe.app.ext.FileSystemStore;
|
||||
import io.xpipe.app.ext.ProcessControlProvider;
|
||||
import io.xpipe.app.hub.comp.StoreEntryWrapper;
|
||||
import io.xpipe.app.issue.ErrorEventFactory;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.storage.ContextualFileReference;
|
||||
import io.xpipe.app.storage.DataStorageSyncHandler;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.app.util.PlatformThread;
|
||||
import io.xpipe.core.FilePath;
|
||||
@@ -36,6 +38,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>> {
|
||||
|
||||
@@ -43,6 +46,7 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
|
||||
private final Property<FilePath> filePath;
|
||||
private final ContextualFileReferenceSync sync;
|
||||
private final List<PreviousFileReference> previousFileReferences;
|
||||
private final Predicate<DataStoreEntry> filter;
|
||||
|
||||
@Setter
|
||||
private ObservableValue<FilePath> prompt;
|
||||
@@ -51,9 +55,11 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
|
||||
Property<DataStoreEntryRef<T>> fileSystem,
|
||||
Property<FilePath> filePath,
|
||||
ContextualFileReferenceSync sync,
|
||||
List<PreviousFileReference> previousFileReferences) {
|
||||
List<PreviousFileReference> previousFileReferences, Predicate<DataStoreEntry> filter
|
||||
) {
|
||||
this.sync = sync;
|
||||
this.previousFileReferences = previousFileReferences;
|
||||
this.filter = filter;
|
||||
this.fileSystem = new SimpleObjectProperty<>();
|
||||
fileSystem.subscribe(val -> {
|
||||
this.fileSystem.setValue(val);
|
||||
@@ -80,7 +86,8 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
|
||||
fileSystem.setValue(fileStore.getFileSystem());
|
||||
}
|
||||
},
|
||||
false);
|
||||
false,
|
||||
filter);
|
||||
})
|
||||
.styleClass(sync != null ? Styles.CENTER_PILL : Styles.RIGHT_PILL)
|
||||
.grow(false, true);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.xpipe.app.prefs;
|
||||
import io.xpipe.app.comp.Comp;
|
||||
import io.xpipe.app.comp.base.ContextualFileReferenceChoiceComp;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.util.LabelGraphic;
|
||||
import io.xpipe.app.util.OptionsBuilder;
|
||||
|
||||
@@ -40,7 +41,8 @@ public class FileBrowserCategory extends AppPrefsCategory {
|
||||
.ref()),
|
||||
prefs.downloadsDirectory,
|
||||
null,
|
||||
List.of())
|
||||
List.of(),
|
||||
e -> e.equals(DataStorage.get().local()))
|
||||
.maxWidth(getCompWidth()),
|
||||
prefs.downloadsDirectory)
|
||||
.pref(prefs.pinLocalMachineOnStartup)
|
||||
|
||||
@@ -121,7 +121,8 @@ public class IconsCategory extends AppPrefsCategory {
|
||||
DataStorage.get().local().ref()),
|
||||
dir,
|
||||
null,
|
||||
List.of())
|
||||
List.of(),
|
||||
en -> en.equals(DataStorage.get().local()))
|
||||
.prefWidth(350));
|
||||
modal.withDefaultButtons(() -> {
|
||||
if (dir.get() == null) {
|
||||
|
||||
@@ -35,7 +35,8 @@ public class SshCategory extends AppPrefsCategory {
|
||||
new ReadOnlyObjectWrapper<>(DataStorage.get().local().ref()),
|
||||
prefs.sshAgentSocket,
|
||||
null,
|
||||
List.of());
|
||||
List.of(),
|
||||
e -> e.equals(DataStorage.get().local()));
|
||||
choice.setPrompt(prefs.defaultSshAgentSocket);
|
||||
choice.maxWidth(600);
|
||||
options.sub(
|
||||
|
||||
@@ -52,7 +52,8 @@ public class EnpassPasswordManager implements PasswordManager {
|
||||
public static OptionsBuilder createOptions(Property<EnpassPasswordManager> p) {
|
||||
var prop = new SimpleObjectProperty<>(p.getValue().getVaultPath());
|
||||
var comp = new ContextualFileReferenceChoiceComp(
|
||||
new SimpleObjectProperty<>(DataStorage.get().local().ref()), prop, null, List.of());
|
||||
new SimpleObjectProperty<>(DataStorage.get().local().ref()), prop, null, List.of(),
|
||||
e -> e.equals(DataStorage.get().local()));
|
||||
comp.apply(struc -> {
|
||||
var text = (TextField) struc.get().getChildren().getFirst();
|
||||
text.requestFocus();
|
||||
|
||||
+2
-1
@@ -50,7 +50,8 @@ public class CustomPkcs11LibraryStrategy implements SshIdentityStrategy {
|
||||
DataStorage.get().local().ref()),
|
||||
file,
|
||||
null,
|
||||
List.of()),
|
||||
List.of(),
|
||||
e -> e.equals(DataStorage.get().local())),
|
||||
file)
|
||||
.nonNull()
|
||||
.bind(
|
||||
|
||||
@@ -71,7 +71,8 @@ public class KeyFileStrategy implements SshIdentityStrategy {
|
||||
.description("locationDescription")
|
||||
.addComp(
|
||||
new ContextualFileReferenceChoiceComp(
|
||||
config.getProxy(), keyPath, config.isAllowKeyFileSync() ? sync : null, List.of()),
|
||||
config.getProxy(), keyPath, config.isAllowKeyFileSync() ? sync : null, List.of(),
|
||||
e -> e.equals(DataStorage.get().local())),
|
||||
keyPath)
|
||||
.nonNull()
|
||||
.name("keyPassword")
|
||||
|
||||
Reference in New Issue
Block a user