From 1e990389f4e2bb600b80e7b5a43d547997cb0118 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sat, 14 Oct 2023 21:24:46 +0000 Subject: [PATCH] Refactor --- .../xpipe/app/comp/base/ListBoxViewComp.java | 7 ++ .../comp/storage/store/StoreEntryComp.java | 20 ++--- .../comp/storage/store/StoreEntryWrapper.java | 6 +- .../comp/storage/store/StoreSectionComp.java | 2 +- .../storage/store/StoreSectionMiniComp.java | 2 +- .../java/io/xpipe/app/ext/ActionProvider.java | 15 ++-- .../ext/base/action/BrowseStoreAction.java | 12 +-- .../action/DeleteStoreChildrenAction.java | 15 ++-- .../ext/base/action/EditStoreAction.java | 26 +++--- .../ext/base/action/FileBrowseAction.java | 62 --------------- .../xpipe/ext/base/action/FileEditAction.java | 62 --------------- .../xpipe/ext/base/action/LaunchAction.java | 30 +++---- .../ext/base/action/LaunchShortcutAction.java | 10 +-- .../ext/base/action/ObserveStoreAction.java | 15 ++-- .../ext/base/action/RefreshStoreAction.java | 19 ++--- .../xpipe/ext/base/action/SampleAction.java | 16 ++-- .../io/xpipe/ext/base/action/ScanAction.java | 15 ++-- .../ext/base/action/ShareStoreAction.java | 19 ++--- .../ext/base/action/StreamExportAction.java | 79 ------------------- ext/base/src/main/java/module-info.java | 4 +- 20 files changed, 117 insertions(+), 319 deletions(-) delete mode 100644 ext/base/src/main/java/io/xpipe/ext/base/action/FileBrowseAction.java delete mode 100644 ext/base/src/main/java/io/xpipe/ext/base/action/FileEditAction.java delete mode 100644 ext/base/src/main/java/io/xpipe/ext/base/action/StreamExportAction.java diff --git a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java index 4f882269c..b38aaa4c3 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java @@ -25,6 +25,7 @@ public class ListBoxViewComp extends Comp> { private final ObservableList shown; private final ObservableList all; private final Function> compFunction; + private int limit = Integer.MAX_VALUE; public ListBoxViewComp(ObservableList shown, ObservableList all, Function> compFunction) { this.shown = PlatformThread.sync(shown); @@ -32,6 +33,11 @@ public class ListBoxViewComp extends Comp> { this.compFunction = compFunction; } + public ListBoxViewComp withLimit(int limit) { + this.limit = limit; + return this; + } + @Override public CompStructure createBase() { Map cache = new IdentityHashMap<>(); @@ -74,6 +80,7 @@ public class ListBoxViewComp extends Comp> { return cache.get(v); }) .filter(region -> region != null) + .limit(limit) .toList(); for (int i = 0; i < newShown.size(); i++) { diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryComp.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryComp.java index 8e6435562..cf203968e 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryComp.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryComp.java @@ -192,7 +192,7 @@ public abstract class StoreEntryComp extends SimpleComp { var list = new ArrayList>(); for (var p : wrapper.getActionProviders().entrySet()) { var actionProvider = p.getKey().getDataStoreCallSite(); - if (!actionProvider.isMajor(wrapper.getEntry().getStore().asNeeded())) { + if (!actionProvider.isMajor(wrapper.getEntry().ref())) { continue; } @@ -202,15 +202,15 @@ public abstract class StoreEntryComp extends SimpleComp { } var button = new IconButtonComp( - actionProvider.getIcon(wrapper.getEntry().getStore().asNeeded()), () -> { + actionProvider.getIcon(wrapper.getEntry().ref()), () -> { ThreadHelper.runFailableAsync(() -> { var action = actionProvider.createAction( - wrapper.getEntry().getStore().asNeeded()); + wrapper.getEntry().ref()); action.execute(); }); }); button.apply(new FancyTooltipAugment<>( - actionProvider.getName(wrapper.getEntry().getStore().asNeeded()))); + actionProvider.getName(wrapper.getEntry().ref()))); if (actionProvider.activeType() == ActionProvider.DataStoreCallSite.ActiveType.ONLY_SHOW_IF_ENABLED) { button.hide(Bindings.not(p.getValue())); } else if (actionProvider.activeType() == ActionProvider.DataStoreCallSite.ActiveType.ALWAYS_SHOW) { @@ -256,7 +256,7 @@ public abstract class StoreEntryComp extends SimpleComp { var hasSep = false; for (var p : wrapper.getActionProviders().entrySet()) { var actionProvider = p.getKey().getDataStoreCallSite(); - if (actionProvider.isMajor(wrapper.getEntry().getStore().asNeeded())) { + if (actionProvider.isMajor(wrapper.getEntry().ref())) { continue; } @@ -267,8 +267,8 @@ public abstract class StoreEntryComp extends SimpleComp { hasSep = true; } - var name = actionProvider.getName(wrapper.getEntry().getStore().asNeeded()); - var icon = actionProvider.getIcon(wrapper.getEntry().getStore().asNeeded()); + var name = actionProvider.getName(wrapper.getEntry().ref()); + var icon = actionProvider.getIcon(wrapper.getEntry().ref()); var item = actionProvider.canLinkTo() ? new Menu(null, new FontIcon(icon)) : new MenuItem(null, new FontIcon(icon)); @@ -281,7 +281,7 @@ public abstract class StoreEntryComp extends SimpleComp { contextMenu.hide(); ThreadHelper.runFailableAsync(() -> { var action = actionProvider.createAction( - wrapper.getEntry().getStore().asNeeded()); + wrapper.getEntry().ref()); action.execute(); }); }); @@ -298,7 +298,7 @@ public abstract class StoreEntryComp extends SimpleComp { run.textProperty().bind(AppI18n.observable("base.execute")); run.setOnAction(event -> { ThreadHelper.runFailableAsync(() -> { - p.getKey().getDataStoreCallSite().createAction(wrapper.getEntry().getStore().asNeeded()).execute(); + p.getKey().getDataStoreCallSite().createAction(wrapper.getEntry().ref()).execute(); }); }); menu.getItems().add(run); @@ -311,7 +311,7 @@ public abstract class StoreEntryComp extends SimpleComp { sc.setOnAction(event -> { ThreadHelper.runFailableAsync(() -> { DesktopShortcuts.create(url, - wrapper.nameProperty().getValue() + " (" + p.getKey().getDataStoreCallSite().getName(wrapper.getEntry().getStore().asNeeded()).getValue() + ")"); + wrapper.nameProperty().getValue() + " (" + p.getKey().getDataStoreCallSite().getName(wrapper.getEntry().ref()).getValue() + ")"); }); }); menu.getItems().add(sc); diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryWrapper.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryWrapper.java index 7a5a9b7d2..82bc242d2 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryWrapper.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryWrapper.java @@ -176,7 +176,7 @@ public class StoreEntryWrapper { .getApplicableClass() .isAssignableFrom(entry.getStore().getClass()) && e.getDefaultDataStoreCallSite() - .isApplicable(entry.getStore().asNeeded())) + .isApplicable(entry.ref())) .findFirst() .map(ActionProvider::getDefaultDataStoreCallSite) .orElse(null); @@ -191,7 +191,7 @@ public class StoreEntryWrapper { .isAssignableFrom(entry.getStore().getClass()) && dataStoreActionProvider .getDataStoreCallSite() - .isApplicable(entry.getStore().asNeeded())); + .isApplicable(entry.ref())); } catch (Exception ex) { ErrorEvent.fromThrowable(ex).handle(); actionProviders.get(dataStoreActionProvider).set(false); @@ -210,7 +210,7 @@ public class StoreEntryWrapper { var found = getDefaultActionProvider().getValue(); entry.updateLastUsed(); if (found != null) { - found.createAction(entry.getStore().asNeeded()).execute(); + found.createAction(entry.ref()).execute(); } else { entry.setExpanded(!entry.isExpanded()); } diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionComp.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionComp.java index 8ef6dbb74..b1aaf1d64 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionComp.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionComp.java @@ -60,7 +60,7 @@ public class StoreSectionComp extends Comp> { var content = new ListBoxViewComp<>(section.getShownChildren(), section.getAllChildren(), (StoreSection e) -> { return StoreSection.customSection(e, false).apply(GrowAugment.create(true, false)); - }).hgrow(); + }).withLimit(100).hgrow(); var expanded = Bindings.createBooleanBinding(() -> { return section.getWrapper().getExpanded().get() && section.getShownChildren().size() > 0; diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionMiniComp.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionMiniComp.java index 5682504e8..2b64b4152 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionMiniComp.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSectionMiniComp.java @@ -43,7 +43,7 @@ public class StoreSectionMiniComp extends Comp> { public CompStructure createBase() { var content = new ListBoxViewComp<>(section.getShownChildren(), section.getAllChildren(), (StoreSection e) -> { return StoreSectionMiniComp.builder().section(e).augment(this.augment).build(); - }) + }).withLimit(100) .hgrow(); var list = new ArrayList>(); diff --git a/app/src/main/java/io/xpipe/app/ext/ActionProvider.java b/app/src/main/java/io/xpipe/app/ext/ActionProvider.java index c366222ee..ae311b403 100644 --- a/app/src/main/java/io/xpipe/app/ext/ActionProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/ActionProvider.java @@ -1,6 +1,7 @@ package io.xpipe.app.ext; import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.store.DataStore; import io.xpipe.core.util.ModuleLayerLoader; import javafx.beans.value.ObservableValue; @@ -92,11 +93,11 @@ public interface ActionProvider { interface DefaultDataStoreCallSite { - Action createAction(T store); + Action createAction(DataStoreEntryRef store); Class getApplicableClass(); - default boolean isApplicable(T o) { + default boolean isApplicable(DataStoreEntryRef o) { return true; } } @@ -117,21 +118,21 @@ public interface ActionProvider { return false; } - Action createAction(T store); + Action createAction(DataStoreEntryRef store); Class getApplicableClass(); - default boolean isMajor(T o) { + default boolean isMajor(DataStoreEntryRef o) { return false; } - default boolean isApplicable(T o) { + default boolean isApplicable(DataStoreEntryRef o) { return true; } - ObservableValue getName(T store); + ObservableValue getName(DataStoreEntryRef store); - String getIcon(T store); + String getIcon(DataStoreEntryRef store); default ActiveType activeType() { return ActiveType.ONLY_SHOW_IF_ENABLED; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/BrowseStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/BrowseStoreAction.java index 6071059b9..51c52b082 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/BrowseStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/BrowseStoreAction.java @@ -4,8 +4,8 @@ import io.xpipe.app.browser.BrowserModel; import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.AppLayoutModel; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.store.ShellStore; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.value.ObservableValue; @@ -35,23 +35,23 @@ public class BrowseStoreAction implements ActionProvider { return new DataStoreCallSite() { @Override - public boolean isMajor(ShellStore o) { + public boolean isMajor(DataStoreEntryRef o) { return true; } @Override - public ObservableValue getName(ShellStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("browseFiles"); } @Override - public String getIcon(ShellStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdi2f-folder-open-outline"; } @Override - public ActionProvider.Action createAction(ShellStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/DeleteStoreChildrenAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/DeleteStoreChildrenAction.java index 639f8078b..cbe120da3 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/DeleteStoreChildrenAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/DeleteStoreChildrenAction.java @@ -4,6 +4,7 @@ import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.store.DataStore; import io.xpipe.app.util.FixedHierarchyStore; import javafx.beans.value.ObservableValue; @@ -37,8 +38,8 @@ public class DeleteStoreChildrenAction implements ActionProvider { } @Override - public ActionProvider.Action createAction(DataStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -47,20 +48,20 @@ public class DeleteStoreChildrenAction implements ActionProvider { } @Override - public boolean isApplicable(DataStore o) { - return !(o instanceof FixedHierarchyStore) && DataStorage.get() - .getStoreChildren(DataStorage.get().getStoreEntry(o), true) + public boolean isApplicable(DataStoreEntryRef o) { + return !(o.getStore() instanceof FixedHierarchyStore) && DataStorage.get() + .getStoreChildren(o.get(), true) .size() > 1; } @Override - public ObservableValue getName(DataStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("base.deleteChildren"); } @Override - public String getIcon(DataStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdal-delete_outline"; } }; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/EditStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/EditStoreAction.java index e9e72d79f..7046f30f2 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/EditStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/EditStoreAction.java @@ -3,9 +3,8 @@ package io.xpipe.ext.base.action; import io.xpipe.app.comp.store.GuiDsStoreCreator; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.ext.DataStoreProviders; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.store.DataStore; import javafx.beans.value.ObservableValue; import lombok.Value; @@ -32,18 +31,15 @@ public class EditStoreAction implements ActionProvider { public DefaultDataStoreCallSite getDefaultDataStoreCallSite() { return new DefaultDataStoreCallSite<>() { @Override - public boolean isApplicable(DataStore o) { - return DataStorage.get() - .getStoreEntryIfPresent(o) - .orElseThrow() + public boolean isApplicable(DataStoreEntryRef o) { + return o.get() .getValidity() .equals(DataStoreEntry.Validity.INCOMPLETE); } @Override - public ActionProvider.Action createAction(DataStore store) { - return new Action( - DataStorage.get().getStoreEntryIfPresent(store).orElseThrow()); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -58,8 +54,8 @@ public class EditStoreAction implements ActionProvider { return new DataStoreCallSite<>() { @Override - public boolean isMajor(DataStore o) { - var provider = DataStoreProviders.byStore(o); + public boolean isMajor(DataStoreEntryRef o) { + var provider = o.get().getProvider(); return provider.shouldEdit(); } @@ -74,8 +70,8 @@ public class EditStoreAction implements ActionProvider { } @Override - public ActionProvider.Action createAction(DataStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -84,12 +80,12 @@ public class EditStoreAction implements ActionProvider { } @Override - public ObservableValue getName(DataStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("base.edit"); } @Override - public String getIcon(DataStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdal-edit"; } }; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/FileBrowseAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/FileBrowseAction.java deleted file mode 100644 index 15a300351..000000000 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/FileBrowseAction.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.xpipe.ext.base.action; - -import io.xpipe.app.core.AppI18n; -import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.util.DesktopHelper; -import io.xpipe.core.store.FileStore; -import io.xpipe.core.store.LocalStore; -import javafx.beans.value.ObservableValue; -import lombok.Value; - -import java.nio.file.Files; -import java.nio.file.Path; - -public class FileBrowseAction implements ActionProvider { - - @Value - static class Action implements ActionProvider.Action { - - FileStore store; - - @Override - public boolean requiresJavaFXPlatform() { - return false; - } - - @Override - public void execute() { - DesktopHelper.browseFileInDirectory(Path.of(store.getPath())); - } - } - - @Override - public DataStoreCallSite getDataStoreCallSite() { - return new DataStoreCallSite() { - - @Override - public ActionProvider.Action createAction(FileStore store) { - return new Action(store); - } - - @Override - public Class getApplicableClass() { - return FileStore.class; - } - - @Override - public boolean isApplicable(FileStore o) { - return o.getFileSystem().equals(new LocalStore()) && Files.exists(Path.of(o.getPath())); - } - - @Override - public ObservableValue getName(FileStore store) { - return AppI18n.observable("base.browseFile"); - } - - @Override - public String getIcon(FileStore store) { - return "mdi2f-folder-open-outline"; - } - }; - } -} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/FileEditAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/FileEditAction.java deleted file mode 100644 index 4e40070ae..000000000 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/FileEditAction.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.xpipe.ext.base.action; - -import io.xpipe.app.core.AppI18n; -import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.util.FileOpener; -import io.xpipe.core.store.FileStore; -import io.xpipe.core.store.LocalStore; -import io.xpipe.core.store.DataFlow; -import javafx.beans.value.ObservableValue; -import lombok.Value; - -public class FileEditAction implements ActionProvider { - - @Value - static class Action implements ActionProvider.Action { - - FileStore store; - - @Override - public boolean requiresJavaFXPlatform() { - return false; - } - - @Override - public void execute() { - if (store.getFileSystem().equals(new LocalStore())) { - FileOpener.openInTextEditor(store.getPath()); - } - } - } - - @Override - public DataStoreCallSite getDataStoreCallSite() { - return new DataStoreCallSite() { - - @Override - public ActionProvider.Action createAction(FileStore store) { - return new Action(store); - } - - @Override - public Class getApplicableClass() { - return FileStore.class; - } - - @Override - public boolean isApplicable(FileStore o) { - return o.getFlow().equals(DataFlow.INPUT_OUTPUT); - } - - @Override - public ObservableValue getName(FileStore store) { - return AppI18n.observable("base.editFile"); - } - - @Override - public String getIcon(FileStore store) { - return "mdal-edit"; - } - }; - } -} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchAction.java index 2431dcc18..3c70f2f3b 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchAction.java @@ -4,6 +4,7 @@ import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.TerminalHelper; import io.xpipe.core.store.LaunchableStore; import io.xpipe.core.store.ShellStore; @@ -52,18 +53,15 @@ public class LaunchAction implements ActionProvider { } @Override - public boolean isApplicable(LaunchableStore o) { - return DataStorage.get() - .getStoreEntryIfPresent(o) - .orElseThrow() + public boolean isApplicable(DataStoreEntryRef o) { + return o.get() .getValidity() - .isUsable() && o.canLaunch(); + .isUsable() && o.getStore().canLaunch(); } @Override - public ActionProvider.Action createAction(LaunchableStore store) { - return new Action( - DataStorage.get().getStoreEntryIfPresent(store).orElseThrow()); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -72,12 +70,12 @@ public class LaunchAction implements ActionProvider { } @Override - public ObservableValue getName(LaunchableStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("launch"); } @Override - public String getIcon(LaunchableStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdi2p-play"; } }; @@ -93,17 +91,15 @@ public class LaunchAction implements ActionProvider { return new DefaultDataStoreCallSite() { @Override - public boolean isApplicable(LaunchableStore o) { - return DataStorage.get() - .getStoreEntryIfPresent(o) - .orElseThrow() + public boolean isApplicable(DataStoreEntryRef o) { + return o.get() .getValidity() - .isUsable() && o.canLaunch(); + .isUsable() && o.getStore().canLaunch(); } @Override - public ActionProvider.Action createAction(LaunchableStore store) { - return new Action(DataStorage.get().getStoreEntryIfPresent(store).orElseThrow()); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchShortcutAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchShortcutAction.java index 360f551b9..b3ee56a10 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchShortcutAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchShortcutAction.java @@ -2,8 +2,8 @@ package io.xpipe.ext.base.action; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.DesktopShortcuts; import io.xpipe.core.store.LaunchableStore; import javafx.beans.value.ObservableValue; @@ -32,8 +32,8 @@ public class LaunchShortcutAction implements ActionProvider { return new DataStoreCallSite() { @Override - public Action createAction(LaunchableStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -42,12 +42,12 @@ public class LaunchShortcutAction implements ActionProvider { } @Override - public ObservableValue getName(LaunchableStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("createShortcut"); } @Override - public String getIcon(LaunchableStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdi2c-code-greater-than"; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/ObserveStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/ObserveStoreAction.java index 294b705b2..fa76a7e00 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/ObserveStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/ObserveStoreAction.java @@ -2,6 +2,7 @@ package io.xpipe.ext.base.action; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.ObservableDataStore; import javafx.beans.value.ObservableValue; import lombok.Value; @@ -11,7 +12,7 @@ public class ObserveStoreAction implements ActionProvider { @Value static class Action implements ActionProvider.Action { - ObservableDataStore store; + DataStoreEntryRef store; @Override public boolean requiresJavaFXPlatform() { @@ -20,7 +21,7 @@ public class ObserveStoreAction implements ActionProvider { @Override public void execute() { - store.toggleObserverState(!store.getObserverState()); + store.getStore().toggleObserverState(!store.getStore().getObserverState()); } } @@ -29,7 +30,7 @@ public class ObserveStoreAction implements ActionProvider { return new DataStoreCallSite() { @Override - public ActionProvider.Action createAction(ObservableDataStore store) { + public ActionProvider.Action createAction(DataStoreEntryRef store) { return new Action(store); } @@ -39,13 +40,13 @@ public class ObserveStoreAction implements ActionProvider { } @Override - public ObservableValue getName(ObservableDataStore store) { - return store.getObserverState() ? AppI18n.observable("base.stopObserve") : AppI18n.observable("base.observe"); + public ObservableValue getName(DataStoreEntryRef store) { + return store.getStore().getObserverState() ? AppI18n.observable("base.stopObserve") : AppI18n.observable("base.observe"); } @Override - public String getIcon(ObservableDataStore store) { - return store.getObserverState() ? "mdi2e-eye-off-outline" : "mdi2e-eye-outline"; + public String getIcon(DataStoreEntryRef store) { + return store.getStore().getObserverState() ? "mdi2e-eye-off-outline" : "mdi2e-eye-outline"; } }; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/RefreshStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/RefreshStoreAction.java index 604105c8a..244f1488d 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/RefreshStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/RefreshStoreAction.java @@ -4,6 +4,7 @@ import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.FixedHierarchyStore; import javafx.beans.value.ObservableValue; import lombok.Value; @@ -31,13 +32,13 @@ public class RefreshStoreAction implements ActionProvider { return new DefaultDataStoreCallSite<>() { @Override - public boolean isApplicable(FixedHierarchyStore o) { - return DataStorage.get().getStoreChildren(DataStorage.get().getStoreEntry(o), true).size() == 0; + public boolean isApplicable(DataStoreEntryRef o) { + return DataStorage.get().getStoreChildren(o.get(), true).size() == 0; } @Override - public ActionProvider.Action createAction(FixedHierarchyStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -52,7 +53,7 @@ public class RefreshStoreAction implements ActionProvider { return new ActionProvider.DataStoreCallSite() { @Override - public boolean isMajor(FixedHierarchyStore o) { + public boolean isMajor(DataStoreEntryRef o) { return true; } @@ -62,8 +63,8 @@ public class RefreshStoreAction implements ActionProvider { } @Override - public ActionProvider.Action createAction(FixedHierarchyStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -72,12 +73,12 @@ public class RefreshStoreAction implements ActionProvider { } @Override - public ObservableValue getName(FixedHierarchyStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("base.refresh"); } @Override - public String getIcon(FixedHierarchyStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdi2r-refresh"; } }; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java index 8c6ead97f..75c27d98d 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/SampleAction.java @@ -2,12 +2,12 @@ package io.xpipe.ext.base.action; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; -import io.xpipe.core.store.LocalStore; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.process.CommandControl; import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellDialects; +import io.xpipe.core.store.LocalStore; import io.xpipe.core.store.ShellStore; import javafx.beans.value.ObservableValue; import lombok.Value; @@ -113,8 +113,8 @@ public class SampleAction implements ActionProvider { return new DataStoreCallSite() { @Override - public Action createAction(ShellStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -124,20 +124,20 @@ public class SampleAction implements ActionProvider { } @Override - public boolean isApplicable(ShellStore o) { + public boolean isApplicable(DataStoreEntryRef o) { // Allows you to individually check whether this action should be available for the specific store. // In this case it should only be available for remote shell connections, not local ones. - return !ShellStore.isLocal(o); + return !ShellStore.isLocal(o.getStore()); } @Override - public ObservableValue getName(ShellStore store) { + public ObservableValue getName(DataStoreEntryRef store) { // The displayed name of the action, allows you to use translation keys. return AppI18n.observable("installConnector"); } @Override - public String getIcon(ShellStore store) { + public String getIcon(DataStoreEntryRef store) { // The ikonli icon of the button. return "mdi2c-code-greater-than"; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/ScanAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/ScanAction.java index 8393dd8bf..d64a7f7e8 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/ScanAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/ScanAction.java @@ -2,9 +2,8 @@ package io.xpipe.ext.base.action; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.ext.DataStoreProviders; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.ScanAlert; import io.xpipe.core.store.ShellStore; import javafx.beans.value.ObservableValue; @@ -33,23 +32,23 @@ public class ScanAction implements ActionProvider { return new DataStoreCallSite() { @Override - public boolean isMajor(ShellStore o) { - return DataStoreProviders.byStore(o).shouldHaveChildren(); + public boolean isMajor(DataStoreEntryRef o) { + return o.get().getProvider().shouldHaveChildren(); } @Override - public ObservableValue getName(ShellStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("scanConnections"); } @Override - public String getIcon(ShellStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdi2m-magnify-scan"; } @Override - public ActionProvider.Action createAction(ShellStore store) { - return new Action(DataStorage.get().getStoreEntry(store)); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/ShareStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/ShareStoreAction.java index e868fd015..13a02076d 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/ShareStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/ShareStoreAction.java @@ -3,7 +3,8 @@ package io.xpipe.ext.base.action; import io.xpipe.app.core.AppActionLinkDetector; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.ext.DataStoreProviders; +import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.SecretHelper; import io.xpipe.core.store.DataStore; import javafx.beans.value.ObservableValue; @@ -18,7 +19,7 @@ public class ShareStoreAction implements ActionProvider { @Value static class Action implements ActionProvider.Action { - DataStore store; + DataStoreEntry store; @Override public boolean requiresJavaFXPlatform() { @@ -32,7 +33,7 @@ public class ShareStoreAction implements ActionProvider { @Override public void execute() { - var string = create(store); + var string = create(store.getStore()); var selection = new StringSelection(string); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); AppActionLinkDetector.setLastDetectedAction(string); @@ -45,8 +46,8 @@ public class ShareStoreAction implements ActionProvider { return new DataStoreCallSite<>() { @Override - public ActionProvider.Action createAction(DataStore store) { - return new Action(store); + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); } @Override @@ -55,17 +56,17 @@ public class ShareStoreAction implements ActionProvider { } @Override - public boolean isApplicable(DataStore o) { - return DataStoreProviders.byStore(o).isShareable(); + public boolean isApplicable(DataStoreEntryRef o) { + return o.get().getProvider().isShareable(); } @Override - public ObservableValue getName(DataStore store) { + public ObservableValue getName(DataStoreEntryRef store) { return AppI18n.observable("base.copyShareLink"); } @Override - public String getIcon(DataStore store) { + public String getIcon(DataStoreEntryRef store) { return "mdi2c-clipboard-list-outline"; } }; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/StreamExportAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/StreamExportAction.java deleted file mode 100644 index 1c5c3e438..000000000 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/StreamExportAction.java +++ /dev/null @@ -1,79 +0,0 @@ -package io.xpipe.ext.base.action; - -import io.xpipe.app.browser.StandaloneFileBrowser; -import io.xpipe.app.core.AppI18n; -import io.xpipe.app.ext.ActionProvider; -import io.xpipe.app.issue.ErrorEvent; -import io.xpipe.app.util.ThreadHelper; -import io.xpipe.core.store.FileStore; -import io.xpipe.core.store.StreamDataStore; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ObservableValue; -import lombok.Value; - -import java.io.InputStream; -import java.io.OutputStream; - -public class StreamExportAction implements ActionProvider { - - @Value - static class Action implements ActionProvider.Action { - - StreamDataStore store; - - @Override - public boolean requiresJavaFXPlatform() { - return true; - } - - @Override - public void execute() { - var outputFile = new SimpleObjectProperty(); - StandaloneFileBrowser.saveSingleFile(outputFile); - if (outputFile.get() == null) { - return; - } - - ThreadHelper.runAsync(() -> { - try (InputStream inputStream = store.openInput()) { - try (OutputStream outputStream = outputFile.get().openOutput()) { - inputStream.transferTo(outputStream); - } - } catch (Exception e) { - ErrorEvent.fromThrowable(e).handle(); - } - }); - } - } - - @Override - public DataStoreCallSite getDataStoreCallSite() { - return new DataStoreCallSite() { - - @Override - public Action createAction(StreamDataStore store) { - return new Action(store); - } - - @Override - public boolean isApplicable(StreamDataStore o) { - return o.getFlow() != null && o.getFlow().hasInput(); - } - - @Override - public Class getApplicableClass() { - return StreamDataStore.class; - } - - @Override - public ObservableValue getName(StreamDataStore store) { - return AppI18n.observable("base.exportStream"); - } - - @Override - public String getIcon(StreamDataStore store) { - return "mdi2f-file-export-outline"; - } - }; - } -} diff --git a/ext/base/src/main/java/module-info.java b/ext/base/src/main/java/module-info.java index 05f60a241..bf5d9d453 100644 --- a/ext/base/src/main/java/module-info.java +++ b/ext/base/src/main/java/module-info.java @@ -56,9 +56,7 @@ open module io.xpipe.ext.base { XPipeUrlAction, EditStoreAction, DeleteStoreChildrenAction, - FileBrowseAction, - BrowseStoreAction, - FileEditAction; + BrowseStoreAction; provides DataStoreProvider with ScriptGroupStoreProvider, SimpleScriptStoreProvider,