mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-12 05:16:13 -04:00
Use setItems in DatapackListPage
This commit is contained in:
parent
c03a0feb75
commit
c50e41ab91
@ -2,7 +2,6 @@ package org.jackhuang.hmcl.ui.versions;
|
|||||||
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.scene.input.TransferMode;
|
import javafx.scene.input.TransferMode;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import org.jackhuang.hmcl.mod.Datapack;
|
import org.jackhuang.hmcl.mod.Datapack;
|
||||||
@ -24,7 +23,6 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
|||||||
|
|
||||||
public class DatapackListPage extends ListPage<DatapackListItem> implements DecoratorPage {
|
public class DatapackListPage extends ListPage<DatapackListItem> implements DecoratorPage {
|
||||||
private final StringProperty title = new SimpleStringProperty();
|
private final StringProperty title = new SimpleStringProperty();
|
||||||
private final ObservableList<DatapackListItem> list; // Hold weak references
|
|
||||||
private final Path worldDir;
|
private final Path worldDir;
|
||||||
private final Datapack datapack;
|
private final Datapack datapack;
|
||||||
|
|
||||||
@ -36,14 +34,14 @@ public class DatapackListPage extends ListPage<DatapackListItem> implements Deco
|
|||||||
datapack = new Datapack(worldDir.resolve("datapacks"));
|
datapack = new Datapack(worldDir.resolve("datapacks"));
|
||||||
datapack.loadFromDir();
|
datapack.loadFromDir();
|
||||||
|
|
||||||
list = MappedObservableList.create(datapack.getInfo(), pack -> new DatapackListItem(pack, item -> {
|
setItems(MappedObservableList.create(datapack.getInfo(),
|
||||||
try {
|
pack -> new DatapackListItem(pack, item -> {
|
||||||
datapack.deletePack(pack);
|
try {
|
||||||
} catch (IOException e) {
|
datapack.deletePack(pack);
|
||||||
Logging.LOG.warning("Failed to delete datapack");
|
} catch (IOException e) {
|
||||||
}
|
Logging.LOG.warning("Failed to delete datapack");
|
||||||
}));
|
}
|
||||||
itemsProperty().bindContent(list);
|
})));
|
||||||
|
|
||||||
setOnDragOver(event -> {
|
setOnDragOver(event -> {
|
||||||
if (event.getGestureSource() != this && event.getDragboard().hasFiles())
|
if (event.getGestureSource() != this && event.getDragboard().hasFiles())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user