From 195300607ef4d94ebbcd13b57c0a95a596dea283 Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 28 Nov 2023 18:22:56 +0000 Subject: [PATCH] Rework git storage handling some more --- .../app/fxcomps/impl/StoreCategoryComp.java | 10 ++++---- .../io/xpipe/app/storage/DataStorage.java | 3 +++ .../xpipe/app/storage/DataStoreCategory.java | 24 +++++++++++++++++++ .../xpipe/app/storage/GitStorageHandler.java | 2 ++ .../io/xpipe/app/storage/StandardStorage.java | 5 ++++ .../resources/lang/preferences_en.properties | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/StoreCategoryComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/StoreCategoryComp.java index 8548356b..c984681a 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/StoreCategoryComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/StoreCategoryComp.java @@ -43,7 +43,7 @@ public class StoreCategoryComp extends SimpleComp { @Override protected Region createSimple() { var i = Bindings.createStringBinding(() -> { - if (!DataStorage.get().supportsSharing() || category.getCategory().getParentCategory() == null) { + if (!DataStorage.get().supportsSharing() || !category.getCategory().canShare()) { return "mdal-keyboard_arrow_right"; } @@ -108,7 +108,7 @@ public class StoreCategoryComp extends SimpleComp { }); contextMenu.getItems().add(newCategory); - if (category.getCategory().getParentCategory() != null) { + if (category.getCategory().canShare()) { var share = new MenuItem(); share.textProperty().bind(Bindings.createStringBinding(() -> { if (category.getShare().getValue()) { @@ -130,11 +130,11 @@ public class StoreCategoryComp extends SimpleComp { contextMenu.getItems().add(share); } - var refresh = new MenuItem(AppI18n.get("rename"), new FontIcon("mdal-360")); - refresh.setOnAction(event -> { + var rename = new MenuItem(AppI18n.get("rename"), new FontIcon("mdal-edit")); + rename.setOnAction(event -> { text.requestFocus(); }); - contextMenu.getItems().add(refresh); + contextMenu.getItems().add(rename); var del = new MenuItem(AppI18n.get("remove"), new FontIcon("mdal-delete_outline")); del.setOnAction(event -> { diff --git a/app/src/main/java/io/xpipe/app/storage/DataStorage.java b/app/src/main/java/io/xpipe/app/storage/DataStorage.java index 18d09bb2..1ab31c25 100644 --- a/app/src/main/java/io/xpipe/app/storage/DataStorage.java +++ b/app/src/main/java/io/xpipe/app/storage/DataStorage.java @@ -104,10 +104,13 @@ public abstract class DataStorage { return; } + INSTANCE.onReset(); INSTANCE.save(); INSTANCE = null; } + protected void onReset() {} + public static DataStorage get() { return INSTANCE; } diff --git a/app/src/main/java/io/xpipe/app/storage/DataStoreCategory.java b/app/src/main/java/io/xpipe/app/storage/DataStoreCategory.java index df4ae110..1496c20e 100644 --- a/app/src/main/java/io/xpipe/app/storage/DataStoreCategory.java +++ b/app/src/main/java/io/xpipe/app/storage/DataStoreCategory.java @@ -101,6 +101,30 @@ public class DataStoreCategory extends StorageElement { return new DataStoreCategory(dir, uuid, name, lastUsed, lastModified, false, parentUuid, sortMode, share); } + public boolean canShare() { + if (parentCategory == null) { + return false; + } + + if (getUuid().equals(DataStorage.PREDEFINED_SCRIPTS_CATEGORY_UUID)) { + return false; + } + + return true; + } + + public boolean shouldShareChildren() { + if (parentCategory == null) { + return true; + } + + if (!canShare()) { + return false; + } + + return isShare(); + } + @Override public Path[] getShareableFiles() { return new Path[] {directory.resolve("category.json")}; diff --git a/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java b/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java index 942bec14..89c7a45b 100644 --- a/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java +++ b/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java @@ -10,6 +10,8 @@ public interface GitStorageHandler { return (GitStorageHandler) ProcessControlProvider.get().createStorageHandler(); } + void onReset(); + boolean supportsShare(); void init(Path dir); diff --git a/app/src/main/java/io/xpipe/app/storage/StandardStorage.java b/app/src/main/java/io/xpipe/app/storage/StandardStorage.java index e57bfb99..e601fb25 100644 --- a/app/src/main/java/io/xpipe/app/storage/StandardStorage.java +++ b/app/src/main/java/io/xpipe/app/storage/StandardStorage.java @@ -30,6 +30,11 @@ public class StandardStorage extends DataStorage { this.gitStorageHandler.init(dir); } + @Override + protected void onReset() { + gitStorageHandler.onReset(); + } + private boolean isNewSession() { return XPipeSession.get().isNewSystemSession(); } diff --git a/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties b/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties index 448fb34e..b64d7fe1 100644 --- a/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties +++ b/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties @@ -26,7 +26,7 @@ thirdPartyDescription=View the open source licenses of third-party libraries workspaceLock=Master passphrase enableGitStorage=Enable git storage sharing=Sharing -enableGitStorageDescription=When enabled, XPipe will initialize a git repository for the storage and commit any changes to it. Note that this requires git to be installed and might slow down loading and saving operations.\n\nRequires a restart to apply. +enableGitStorageDescription=When enabled, XPipe will initialize a git repository for the storage and commit any changes to it. Note that this requires git to be installed and might slow down loading and saving operations.\n\nAny categories that should be synced must be explicitly designated as shared.\n\nRequires a restart to apply. storageGitRemote=Git remote URL storageGitRemoteDescription=When set, XPipe will automatically pull any changes when loading and push any changes to the remote repository when saving.\n\nThis allows you to share your configuration data through git. Note that this might slow down loading and saving operations.\n\nRequires a restart to apply. vault=Vault