Hide ssh file system choice plus refactor

This commit is contained in:
crschnick 2023-07-17 06:03:47 +00:00
parent 324a48f157
commit eb341b0c08
9 changed files with 44 additions and 51 deletions

View file

@ -12,6 +12,7 @@ import javafx.stage.Window;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public class StandaloneFileBrowser {
@ -35,7 +36,7 @@ public class StandaloneFileBrowser {
});
}
public static void openSingleFile(Property<FileStore> file) {
public static void openSingleFile(Consumer<FileStore> file) {
PlatformThread.runLaterIfNeeded(() -> {
var model = new BrowserModel(BrowserModel.Mode.SINGLE_FILE_CHOOSER);
var comp = new BrowserComp(model)
@ -43,7 +44,7 @@ public class StandaloneFileBrowser {
.apply(struc -> AppFont.normal(struc.get()));
var window = AppWindowHelper.sideWindow(AppI18n.get("openFileTitle"), stage -> comp, true, null);
model.setOnFinish(fileStores -> {
file.setValue(fileStores.size() > 0 ? fileStores.get(0) : null);
file.accept(fileStores.size() > 0 ? fileStores.get(0) : null);
window.close();
});
window.show();

View file

@ -30,7 +30,9 @@ public class DsLocalFileBrowseComp extends Comp<CompStructure<Button>> {
var button = new AtomicReference<Button>();
button.set(new ButtonComp(null, getGraphic(), () -> {
if (mode == DsStreamStoreChoiceComp.Mode.OPEN) {
StandaloneFileBrowser.openSingleFile(chosenFile);
StandaloneFileBrowser.openSingleFile(fileStore -> {
chosenFile.setValue(fileStore);
});
} else {
StandaloneFileBrowser.saveSingleFile(chosenFile);
}

View file

@ -148,7 +148,8 @@ public class AppExtensionManager {
return;
}
try (var s = Files.list(dir)) {
// Order results as on unix systems the file list order is not deterministic
try (var s = Files.list(dir).sorted(Comparator.comparing(path -> path.toString()))) {
s.forEach(sub -> {
if (Files.isDirectory(sub)) {
// TODO: Better detection for x modules

View file

@ -4,11 +4,10 @@ import atlantafx.base.theme.Styles;
import io.xpipe.app.browser.StandaloneFileBrowser;
import io.xpipe.app.comp.base.ButtonComp;
import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.core.impl.FileStore;
import io.xpipe.core.store.FileSystemStore;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
@ -18,42 +17,43 @@ import java.util.List;
public class FileStoreChoiceComp extends SimpleComp {
private final boolean onlyLocal;
private final Property<FileStore> selected;
private final boolean hideFileSystem;
private final Property<FileSystemStore> fileSystem;
private final Property<String> filePath;
public FileStoreChoiceComp(boolean onlyLocal, Property<FileStore> selected) {
this.onlyLocal = onlyLocal;
this.selected = selected;
public FileStoreChoiceComp(Property<String> filePath) {
this(true, new SimpleObjectProperty<>(), filePath);
}
private void setSelected(FileSystemStore fileSystem, String file) {
selected.setValue(fileSystem != null && file != null ? new FileStore(fileSystem, file) : null);
public FileStoreChoiceComp(boolean hideFileSystem, Property<FileSystemStore> fileSystem, Property<String> filePath) {
this.hideFileSystem = hideFileSystem;
this.fileSystem = fileSystem;
this.filePath = filePath;
}
@Override
protected Region createSimple() {
var filePathProperty = new SimpleStringProperty(
selected.getValue() != null ? selected.getValue().getPath() : null);
filePathProperty.addListener((observable, oldValue, newValue) -> {
setSelected(selected.getValue() != null ? selected.getValue().getFileSystem() : null, newValue);
});
selected.addListener((observable, oldValue, newValue) -> {
filePathProperty.setValue(newValue != null ? newValue.getPath() : null);
});
var fileSystemChoiceComp =
new FileSystemStoreChoiceComp(selected).grow(false, true).styleClass(Styles.LEFT_PILL);
if (onlyLocal) {
new FileSystemStoreChoiceComp(fileSystem).grow(false, true).styleClass(Styles.LEFT_PILL);
if (hideFileSystem) {
fileSystemChoiceComp.hide(new SimpleBooleanProperty(true));
}
var fileNameComp = new TextFieldComp(filePathProperty)
var fileNameComp = new TextFieldComp(filePath)
.apply(struc -> HBox.setHgrow(struc.get(), Priority.ALWAYS))
.styleClass(onlyLocal ? Styles.LEFT_PILL : Styles.CENTER_PILL)
.styleClass(hideFileSystem ? Styles.LEFT_PILL : Styles.CENTER_PILL)
.grow(false, true);
var fileBrowseButton = new ButtonComp(null, new FontIcon("mdi2f-folder-open-outline"), () -> {
StandaloneFileBrowser.openSingleFile(selected);
StandaloneFileBrowser.openSingleFile(fileStore -> {
if (fileStore == null) {
filePath.setValue(null);
fileSystem.setValue(null);
} else {
filePath.setValue(fileStore.getPath());
fileSystem.setValue(fileStore.getFileSystem());
}
});
})
.styleClass(Styles.RIGHT_PILL)
.grow(false, true);

View file

@ -4,10 +4,8 @@ import io.xpipe.app.ext.DataStoreProviders;
import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.util.CustomComboBoxBuilder;
import io.xpipe.core.impl.FileStore;
import io.xpipe.core.store.FileSystemStore;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
@ -16,9 +14,9 @@ import javafx.scene.layout.Region;
public class FileSystemStoreChoiceComp extends SimpleComp {
private final Property<FileStore> selected;
private final Property<FileSystemStore> selected;
public FileSystemStoreChoiceComp(Property<FileStore> selected) {
public FileSystemStoreChoiceComp(Property<FileSystemStore> selected) {
this.selected = selected;
}
@ -45,20 +43,7 @@ public class FileSystemStoreChoiceComp extends SimpleComp {
@Override
protected Region createSimple() {
var fileSystemProperty = new SimpleObjectProperty<>(
selected.getValue() != null ? selected.getValue().getFileSystem() : null);
fileSystemProperty.addListener((observable, oldValue, newValue) -> {
selected.setValue(FileStore.builder()
.fileSystem(newValue)
.path(selected.getValue() != null ? selected.getValue().getPath() : null)
.build());
});
selected.addListener((observable, oldValue, newValue) -> {
fileSystemProperty.setValue(newValue != null ? newValue.getFileSystem() : null);
});
var comboBox = new CustomComboBoxBuilder<>(fileSystemProperty, this::createGraphic, null, v -> true);
var comboBox = new CustomComboBoxBuilder<>(selected, this::createGraphic, null, v -> true);
comboBox.setAccessibleNames(store -> getName(store));
comboBox.setSelectedDisplay(this::createDisplayGraphic);
DataStorage.get().getUsableStores().stream()

View file

@ -127,7 +127,9 @@ public interface ShellDialect {
String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file);
String runScript(ShellControl parent, String file);
String runScriptCommand(ShellControl parent, String file);
String runScriptSilentlyCommand(ShellControl parent, String file);
String sourceScript(String file);
@ -153,12 +155,14 @@ public interface ShellDialect {
CommandControl createScriptTextFileWriteCommand(ShellControl parent, String content, String file);
CommandControl deleteFile(ShellControl sc, String file);
CommandControl deleteFileOrDirectory(ShellControl sc, String file);
CommandControl createFileExistsCommand(ShellControl sc, String file);
CommandControl symbolicLink(ShellControl sc, String linkFile, String targetFile);
String getFileDeleteCommand(String file);
String getFileTouchCommand(String file);
String getWhichCommand(String executable);

View file

@ -92,7 +92,7 @@ public class ConnectionFileSystem implements FileSystem {
@Override
public void delete(String file) throws Exception {
try (var pc = shellControl.getShellDialect().deleteFile(shellControl, file)
try (var pc = shellControl.getShellDialect().deleteFileOrDirectory(shellControl, file)
.start()) {
pc.discardOrThrow();
}

View file

@ -32,7 +32,7 @@ public class XPipeExecTempDirectory {
var legacyExecTemp = FileNames.join(legacyTemp, "exec");
// Always delete legacy directory and do not care whether it partially fails
d.deleteFile(proc, legacyExecTemp).executeAndCheck();
d.deleteFileOrDirectory(proc, legacyExecTemp).executeAndCheck();
// Check permissions for home directory
// If this is somehow messed up, we can still default back to the system directory
@ -48,7 +48,7 @@ public class XPipeExecTempDirectory {
d.prepareUserTempDirectory(proc, targetTemp).execute();
} else if (!usedSystems.contains(proc.getSystemId())) {
// Try to clear directory and do not care about errors
d.deleteFile(proc, targetTemp).executeAndCheck();
d.deleteFileOrDirectory(proc, targetTemp).executeAndCheck();
d.prepareUserTempDirectory(proc, targetTemp).executeAndCheck();
} else {
// Still attempt to properly set permissions every time

View file

@ -65,6 +65,6 @@ public class RunAction extends MultiExecuteAction {
@Override
protected String createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry) {
return sc.getShellDialect().runScript(sc, entry.getFileName());
return sc.getShellDialect().runScriptCommand(sc, entry.getFileName());
}
}