Rework git storage handling some more

This commit is contained in:
crschnick 2023-11-28 18:22:56 +00:00
parent 1853f1a9b5
commit 195300607e
6 changed files with 40 additions and 6 deletions

View file

@ -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 -> {

View file

@ -104,10 +104,13 @@ public abstract class DataStorage {
return;
}
INSTANCE.onReset();
INSTANCE.save();
INSTANCE = null;
}
protected void onReset() {}
public static DataStorage get() {
return INSTANCE;
}

View file

@ -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")};

View file

@ -10,6 +10,8 @@ public interface GitStorageHandler {
return (GitStorageHandler) ProcessControlProvider.get().createStorageHandler();
}
void onReset();
boolean supportsShare();
void init(Path dir);

View file

@ -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();
}

View file

@ -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