diff --git a/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java b/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java index 452a0f4d..eeb6408d 100644 --- a/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java @@ -101,6 +101,10 @@ public interface DataStoreProvider { return null; } + default boolean canClone() { + return getCreationCategory() != null; + } + default DataStoreEntry getDisplayParent(DataStoreEntry store) { return getSyntheticParent(store); } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/CloneStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/CloneStoreAction.java new file mode 100644 index 00000000..7eda77fb --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/CloneStoreAction.java @@ -0,0 +1,66 @@ +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.core.store.DataStore; +import javafx.beans.value.ObservableValue; +import lombok.Value; + +public class CloneStoreAction implements ActionProvider { + + @Value + static class Action implements ActionProvider.Action { + + DataStoreEntry store; + + @Override + public boolean requiresJavaFXPlatform() { + return false; + } + + @Override + public void execute() { + DataStorage.get().addStoreEntryIfNotPresent( + DataStoreEntry.createNew(store.getName() + " (Copy)",store.getStore())); + } + } + + @Override + public DataStoreCallSite getDataStoreCallSite() { + return new DataStoreCallSite<>() { + + @Override + public boolean isSystemAction() { + return true; + } + + @Override + public ActionProvider.Action createAction(DataStoreEntryRef store) { + return new Action(store.get()); + } + + @Override + public Class getApplicableClass() { + return DataStore.class; + } + + @Override + public boolean isApplicable(DataStoreEntryRef o) { + return o.get().getProvider().canClone(); + } + + @Override + public ObservableValue getName(DataStoreEntryRef store) { + return AppI18n.observable("base.clone"); + } + + @Override + public String getIcon(DataStoreEntryRef store) { + return "mdi2c-content-copy"; + } + }; + } +} diff --git a/ext/base/src/main/java/module-info.java b/ext/base/src/main/java/module-info.java index 5205b613..5fa9585f 100644 --- a/ext/base/src/main/java/module-info.java +++ b/ext/base/src/main/java/module-info.java @@ -50,6 +50,7 @@ open module io.xpipe.ext.base { JavapAction, JarAction; provides ActionProvider with + CloneStoreAction, RefreshStoreAction, ScanAction, LaunchAction, diff --git a/ext/base/src/main/resources/io/xpipe/ext/base/resources/lang/translations_en.properties b/ext/base/src/main/resources/io/xpipe/ext/base/resources/lang/translations_en.properties index aa4c88c9..c7c2b956 100644 --- a/ext/base/src/main/resources/io/xpipe/ext/base/resources/lang/translations_en.properties +++ b/ext/base/src/main/resources/io/xpipe/ext/base/resources/lang/translations_en.properties @@ -19,6 +19,7 @@ observe=Start observing stopObserve=Stop observing createShortcut=Create desktop shortcut browseFiles=Browse Files +clone=Clone targetPath=Target path newDirectory=New directory copyShareLink=Copy link