More fixes

This commit is contained in:
crschnick 2023-07-02 15:26:37 +00:00
parent 1ba5f7cf2a
commit 0007119fc1
7 changed files with 52 additions and 33 deletions

View file

@ -11,6 +11,7 @@ import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.app.util.BusyProperty; import io.xpipe.app.util.BusyProperty;
import io.xpipe.app.util.ThreadHelper; import io.xpipe.app.util.ThreadHelper;
import io.xpipe.core.store.DataStore; import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FixedHierarchyStore;
import io.xpipe.core.store.ShellStore; import io.xpipe.core.store.ShellStore;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.*; import javafx.beans.property.*;
@ -130,11 +131,15 @@ final class BrowserBookmarkList extends SimpleComp {
} }
ThreadHelper.runFailableAsync(() -> { ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
getItem().executeRefreshAction();
});
if (getItem().getEntry().getStore() instanceof ShellStore fileSystem) { if (getItem().getEntry().getStore() instanceof ShellStore fileSystem) {
BusyProperty.execute(busy, () -> {
getItem().refreshIfNeeded();
});
model.openFileSystemAsync(null, fileSystem, null, busy); model.openFileSystemAsync(null, fileSystem, null, busy);
} else if (getItem().getEntry().getStore() instanceof FixedHierarchyStore) {
BusyProperty.execute(busy, () -> {
getItem().refreshWithChildren();
});
} }
}); });
event.consume(); event.consume();

View file

@ -19,7 +19,7 @@ public class DenseStoreEntryComp extends StoreEntryComp {
var name = createName().createRegion(); var name = createName().createRegion();
var grid = new GridPane(); var grid = new GridPane();
grid.setHgap(10); grid.setHgap(8);
if (showIcon) { if (showIcon) {
var storeIcon = createIcon(30, 25); var storeIcon = createIcon(30, 25);
@ -28,7 +28,7 @@ public class DenseStoreEntryComp extends StoreEntryComp {
GridPane.setHalignment(storeIcon, HPos.CENTER); GridPane.setHalignment(storeIcon, HPos.CENTER);
} else { } else {
grid.add(new Region(), 0, 0); grid.add(new Region(), 0, 0);
grid.getColumnConstraints().add(new ColumnConstraints(5)); grid.getColumnConstraints().add(new ColumnConstraints(0));
} }
var custom = new ColumnConstraints(content != null ? 300 : 0); var custom = new ColumnConstraints(content != null ? 300 : 0);

View file

@ -163,8 +163,20 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
}); });
} }
public void executeRefreshAction() throws Exception { public void refreshIfNeeded() throws Exception {
var found = getDefaultActionProvider().getValue(); if (entry.getState().equals(DataStoreEntry.State.COMPLETE_BUT_INVALID)
|| entry.getState().equals(DataStoreEntry.State.COMPLETE_NOT_VALIDATED)) {
getEntry().refresh(true);
}
}
public void refreshAsync() {
ThreadHelper.runFailableAsync(() -> {
getEntry().refresh(true);
});
}
public void refreshWithChildren() throws Exception {
getEntry().refresh(true); getEntry().refresh(true);
var hasChildren = DataStorage.get().refreshChildren(entry); var hasChildren = DataStorage.get().refreshChildren(entry);
PlatformThread.runLaterIfNeeded(() -> { PlatformThread.runLaterIfNeeded(() -> {
@ -172,24 +184,29 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
}); });
} }
public void mutate(DataStore newValue) { public void refreshWithChildrenAsync() {
ThreadHelper.runFailableAsync(() -> {
refreshWithChildren();
});
}
public void mutateAsync(DataStore newValue) {
ThreadHelper.runAsync(() -> { ThreadHelper.runAsync(() -> {
DataStorage.get().setAndRefreshAsync(getEntry(), newValue); var hasChildren = DataStorage.get().setAndRefresh(getEntry(), newValue);
PlatformThread.runLaterIfNeeded(() -> {
expanded.set(hasChildren);
});
}); });
} }
public void executeDefaultAction() throws Exception { public void executeDefaultAction() throws Exception {
var found = getDefaultActionProvider().getValue(); var found = getDefaultActionProvider().getValue();
entry.updateLastUsed();
if (found != null) { if (found != null) {
if (entry.getState().equals(DataStoreEntry.State.COMPLETE_BUT_INVALID) refreshIfNeeded();
|| entry.getState().equals(DataStoreEntry.State.COMPLETE_NOT_VALIDATED)) {
executeRefreshAction();
}
entry.updateLastUsed();
found.createAction(entry.getStore().asNeeded()).execute(); found.createAction(entry.getStore().asNeeded()).execute();
} else if (getEntry().getStore() instanceof FixedHierarchyStore) { } else if (getEntry().getStore() instanceof FixedHierarchyStore) {
executeRefreshAction(); refreshWithChildrenAsync();
} }
} }

View file

@ -9,7 +9,6 @@ import javafx.beans.value.ObservableValue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.stream.Collectors;
public interface ActionProvider { public interface ActionProvider {
@ -29,7 +28,7 @@ public interface ActionProvider {
return false; return false;
} }
}) })
.collect(Collectors.toSet())); .toList());
} }
@Override @Override

View file

@ -203,19 +203,18 @@ public abstract class DataStorage {
.findFirst(); .findFirst();
} }
public void setAndRefreshAsync(DataStoreEntry entry, DataStore s) { public boolean setAndRefresh(DataStoreEntry entry, DataStore s) {
ThreadHelper.runAsync(() -> { var old = entry.getStore();
var old = entry.getStore(); deleteChildren(entry, true);
deleteChildren(entry, true); try {
try { entry.setStoreInternal(s, false);
entry.setStoreInternal(s, false); entry.refresh(true);
entry.refresh(true); return DataStorage.get().refreshChildren(entry);
DataStorage.get().refreshChildren(entry); } catch (Exception e) {
} catch (Exception e) { entry.setStoreInternal(old, false);
entry.setStoreInternal(old, false); entry.simpleRefresh();
entry.simpleRefresh(); return false;
} }
});
} }
public void refreshAsync(DataStoreEntry element, boolean deep) { public void refreshAsync(DataStoreEntry element, boolean deep) {

View file

@ -41,7 +41,7 @@ visibility: hidden;
} }
.prefs .grid { .prefs .grid {
-fx-padding: 1em 2.3em 0 2.3em; -fx-padding: 1em 2.3em 2em 2.3em;
} }
.prefs { .prefs {

View file

@ -48,7 +48,6 @@ open module io.xpipe.ext.base {
JavapAction, JavapAction,
JarAction; JarAction;
provides ActionProvider with provides ActionProvider with
DeleteStoreChildrenAction,
AddStoreAction, AddStoreAction,
EditStoreAction, EditStoreAction,
ShareStoreAction, ShareStoreAction,