File browser busy fixes

This commit is contained in:
crschnick 2024-07-24 01:28:05 +00:00
parent 382b07f751
commit af77a09bd7
6 changed files with 31 additions and 18 deletions

View file

@ -10,10 +10,12 @@ import io.xpipe.app.storage.DataStoreEntry;
import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.css.PseudoClass;
import javafx.scene.control.Button;
import javafx.scene.layout.Region;
import java.util.HashSet;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
@ -41,13 +43,13 @@ public final class BrowserBookmarkComp extends SimpleComp {
@Override
protected Region createSimple() {
BooleanProperty busy = new SimpleBooleanProperty(false);
var busyEntries = FXCollections.<StoreSection>observableSet(new HashSet<>());
BiConsumer<StoreSection, Comp<CompStructure<Button>>> augment = (s, comp) -> {
comp.disable(Bindings.createBooleanBinding(
() -> {
return !applicable.test(s.getWrapper());
return busyEntries.contains(s) || !applicable.test(s.getWrapper());
},
busy));
busyEntries));
comp.apply(struc -> {
selected.addListener((observable, oldValue, newValue) -> {
PlatformThread.runLaterIfNeeded(() -> {
@ -70,7 +72,17 @@ public final class BrowserBookmarkComp extends SimpleComp {
category,
StoreViewState.get().getEntriesListUpdateObservable()),
augment,
entryWrapper -> action.accept(entryWrapper, busy));
selectedAction -> {
BooleanProperty busy = new SimpleBooleanProperty(false);
action.accept(selectedAction.getWrapper(), busy);
busy.addListener((observable, oldValue, newValue) -> {
if (newValue) {
busyEntries.add(selectedAction);
} else {
busyEntries.remove(selectedAction);
}
});
});
var r = section.vgrow().createRegion();
r.getStyleClass().add("bookmark-list");

View file

@ -19,9 +19,9 @@ import java.util.function.Consumer;
public class StoreQuickAccessButtonComp extends Comp<CompStructure<Button>> {
private final StoreSection section;
private final Consumer<StoreEntryWrapper> action;
private final Consumer<StoreSection> action;
public StoreQuickAccessButtonComp(StoreSection section, Consumer<StoreEntryWrapper> action) {
public StoreQuickAccessButtonComp(StoreSection section, Consumer<StoreSection> action) {
this.section = section;
this.action = action;
}
@ -48,7 +48,7 @@ public class StoreQuickAccessButtonComp extends Comp<CompStructure<Button>> {
new LabelGraphic.ImageGraphic(graphic, 16),
w.getName().getValue());
item.setOnAction(event -> {
action.accept(w);
action.accept(section);
contextMenu.hide();
event.consume();
});
@ -73,7 +73,7 @@ public class StoreQuickAccessButtonComp extends Comp<CompStructure<Button>> {
return;
}
action.accept(w);
action.accept(section);
contextMenu.hide();
event.consume();
}

View file

@ -44,9 +44,9 @@ public class StoreSectionComp extends Comp<CompStructure<VBox>> {
return section.getShownChildren().getList().isEmpty();
},
section.getShownChildren().getList());
Consumer<StoreEntryWrapper> quickAccessAction = w -> {
Consumer<StoreSection> quickAccessAction = w -> {
ThreadHelper.runFailableAsync(() -> {
w.executeDefaultAction();
w.getWrapper().executeDefaultAction();
});
};
var quickAccessButton = new StoreQuickAccessButtonComp(section, quickAccessAction)

View file

@ -34,12 +34,12 @@ public class StoreSectionMiniComp extends Comp<CompStructure<VBox>> {
private final StoreSection section;
private final BiConsumer<StoreSection, Comp<CompStructure<Button>>> augment;
private final Consumer<StoreEntryWrapper> action;
private final Consumer<StoreSection> action;
public StoreSectionMiniComp(
StoreSection section,
BiConsumer<StoreSection, Comp<CompStructure<Button>>> augment,
Consumer<StoreEntryWrapper> action) {
Consumer<StoreSection> action) {
this.section = section;
this.augment = augment;
this.action = action;
@ -68,7 +68,7 @@ public class StoreSectionMiniComp extends Comp<CompStructure<VBox>> {
})
.apply(struc -> {
struc.get().setOnAction(event -> {
action.accept(section.getWrapper());
action.accept(section);
event.consume();
});
})
@ -105,7 +105,7 @@ public class StoreSectionMiniComp extends Comp<CompStructure<VBox>> {
return section.getShownChildren().getList().isEmpty();
},
section.getShownChildren().getList());
Consumer<StoreEntryWrapper> quickAccessAction = action;
Consumer<StoreSection> quickAccessAction = action;
var quickAccessButton = new StoreQuickAccessButtonComp(section, quickAccessAction)
.vgrow()
.styleClass("quick-access-button")

View file

@ -101,9 +101,9 @@ public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {
comp.disable(new SimpleBooleanProperty(true));
}
},
storeEntryWrapper -> {
if (applicable.test(storeEntryWrapper)) {
selected.setValue(storeEntryWrapper.getEntry().ref());
sec -> {
if (applicable.test(sec.getWrapper())) {
selected.setValue(sec.getWrapper().getEntry().ref());
popover.hide();
}
});

View file

@ -196,6 +196,7 @@ public class ErrorHandlerComp extends SimpleComp {
if (desc == null) {
desc = AppI18n.get("errorNoDetail");
}
desc = desc.trim();
var graphic = new FontIcon("mdomz-warning");
graphic.setIconColor(Color.RED);
@ -204,7 +205,7 @@ public class ErrorHandlerComp extends SimpleComp {
header.setGraphicTextGap(6);
AppFont.setSize(header, 3);
var descriptionField = new TextArea(desc);
descriptionField.setPrefRowCount(6);
descriptionField.setPrefRowCount(Math.min((int) desc.lines().count(), 14));
descriptionField.setWrapText(true);
descriptionField.setEditable(false);
descriptionField.setPadding(Insets.EMPTY);