mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Defer file icon loading
This commit is contained in:
parent
0442e4bb38
commit
7ccfffb9d2
6 changed files with 41 additions and 39 deletions
|
@ -3,9 +3,6 @@ package io.xpipe.app.browser;
|
|||
import atlantafx.base.controls.RingProgressIndicator;
|
||||
import atlantafx.base.controls.Spacer;
|
||||
import atlantafx.base.theme.Styles;
|
||||
import io.xpipe.app.browser.icon.BrowserIconDirectoryType;
|
||||
import io.xpipe.app.browser.icon.BrowserIconFileType;
|
||||
import io.xpipe.app.browser.icon.FileIconManager;
|
||||
import io.xpipe.app.comp.base.MultiContentComp;
|
||||
import io.xpipe.app.comp.base.SideSplitPaneComp;
|
||||
import io.xpipe.app.core.AppLayoutModel;
|
||||
|
@ -18,7 +15,6 @@ import io.xpipe.app.fxcomps.util.BindingsHelper;
|
|||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.util.BooleanScope;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
@ -51,12 +47,6 @@ public class BrowserComp extends SimpleComp {
|
|||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
BrowserIconFileType.loadDefinitions();
|
||||
BrowserIconDirectoryType.loadDefinitions();
|
||||
ThreadHelper.runAsync(() -> {
|
||||
FileIconManager.loadIfNecessary();
|
||||
});
|
||||
|
||||
var bookmarksList = new BrowserBookmarkComp(model).vgrow();
|
||||
var localDownloadStage = new BrowserTransferComp(model.getLocalTransfersStage())
|
||||
.hide(PlatformThread.sync(Bindings.createBooleanBinding(
|
||||
|
|
|
@ -29,7 +29,7 @@ public class BrowserEntry {
|
|||
return null;
|
||||
}
|
||||
|
||||
for (var f : BrowserIconFileType.ALL) {
|
||||
for (var f : BrowserIconFileType.getAll()) {
|
||||
if (f.matches(rawFileEntry)) {
|
||||
return f;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class BrowserEntry {
|
|||
return null;
|
||||
}
|
||||
|
||||
for (var f : BrowserIconDirectoryType.ALL) {
|
||||
for (var f : BrowserIconDirectoryType.getAll()) {
|
||||
if (f.matches(rawFileEntry)) {
|
||||
return f;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package io.xpipe.app.browser;
|
||||
|
||||
import io.xpipe.app.browser.icon.BrowserIconDirectoryType;
|
||||
import io.xpipe.app.browser.icon.BrowserIconFileType;
|
||||
import io.xpipe.app.browser.icon.FileIconManager;
|
||||
import io.xpipe.app.fxcomps.util.BindingsHelper;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
|
@ -139,6 +142,13 @@ public class BrowserModel {
|
|||
return;
|
||||
}
|
||||
|
||||
// Only load icons when a file system is opened
|
||||
ThreadHelper.runAsync(() -> {
|
||||
BrowserIconFileType.loadDefinitions();
|
||||
BrowserIconDirectoryType.loadDefinitions();
|
||||
FileIconManager.loadIfNecessary();
|
||||
});
|
||||
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
OpenFileSystemModel model;
|
||||
|
||||
|
|
|
@ -15,18 +15,18 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface BrowserIconDirectoryType {
|
||||
public abstract class BrowserIconDirectoryType {
|
||||
|
||||
List<BrowserIconDirectoryType> ALL = new ArrayList<>();
|
||||
private static final List<BrowserIconDirectoryType> ALL = new ArrayList<>();
|
||||
|
||||
static BrowserIconDirectoryType byId(String id) {
|
||||
public synchronized static BrowserIconDirectoryType byId(String id) {
|
||||
return ALL.stream()
|
||||
.filter(fileType -> fileType.getId().equals(id))
|
||||
.findAny()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
static void loadDefinitions() {
|
||||
public synchronized static void loadDefinitions() {
|
||||
ALL.add(new BrowserIconDirectoryType() {
|
||||
|
||||
@Override
|
||||
|
@ -74,13 +74,17 @@ public interface BrowserIconDirectoryType {
|
|||
});
|
||||
}
|
||||
|
||||
String getId();
|
||||
public static synchronized List<BrowserIconDirectoryType> getAll() {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
boolean matches(FileSystem.FileEntry entry);
|
||||
public abstract String getId();
|
||||
|
||||
String getIcon(FileSystem.FileEntry entry, boolean open);
|
||||
public abstract boolean matches(FileSystem.FileEntry entry);
|
||||
|
||||
class Simple implements BrowserIconDirectoryType {
|
||||
public abstract String getIcon(FileSystem.FileEntry entry, boolean open);
|
||||
|
||||
public static class Simple extends BrowserIconDirectoryType {
|
||||
|
||||
@Getter
|
||||
private final String id;
|
||||
|
|
|
@ -12,18 +12,18 @@ import java.nio.file.Files;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface BrowserIconFileType {
|
||||
public abstract class BrowserIconFileType {
|
||||
|
||||
List<BrowserIconFileType> ALL = new ArrayList<>();
|
||||
private static final List<BrowserIconFileType> ALL = new ArrayList<>();
|
||||
|
||||
static BrowserIconFileType byId(String id) {
|
||||
public synchronized static BrowserIconFileType byId(String id) {
|
||||
return ALL.stream()
|
||||
.filter(fileType -> fileType.getId().equals(id))
|
||||
.findAny()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
static void loadDefinitions() {
|
||||
public synchronized static void loadDefinitions() {
|
||||
AppResources.with(AppResources.XPIPE_MODULE, "file_list.txt", path -> {
|
||||
try (var reader =
|
||||
new BufferedReader(new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8))) {
|
||||
|
@ -53,14 +53,18 @@ public interface BrowserIconFileType {
|
|||
});
|
||||
}
|
||||
|
||||
String getId();
|
||||
public static synchronized List<BrowserIconFileType> getAll() {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
boolean matches(FileSystem.FileEntry entry);
|
||||
public abstract String getId();
|
||||
|
||||
String getIcon();
|
||||
public abstract boolean matches(FileSystem.FileEntry entry);
|
||||
|
||||
public abstract String getIcon();
|
||||
|
||||
@Getter
|
||||
class Simple implements BrowserIconFileType {
|
||||
public static class Simple extends BrowserIconFileType {
|
||||
|
||||
private final String id;
|
||||
private final IconVariant icon;
|
||||
|
|
|
@ -16,24 +16,22 @@ public class FileIconManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getFileIcon(FileSystem.FileEntry entry, boolean open) {
|
||||
public static synchronized String getFileIcon(FileSystem.FileEntry entry, boolean open) {
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
loadIfNecessary();
|
||||
|
||||
var r = entry.resolved();
|
||||
if (r.getKind() != FileKind.DIRECTORY) {
|
||||
for (var f : BrowserIconFileType.ALL) {
|
||||
for (var f : BrowserIconFileType.getAll()) {
|
||||
if (f.matches(r)) {
|
||||
return getIconPath(f.getIcon());
|
||||
return f.getIcon();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var f : BrowserIconDirectoryType.ALL) {
|
||||
for (var f : BrowserIconDirectoryType.getAll()) {
|
||||
if (f.matches(r)) {
|
||||
return getIconPath(f.getIcon(r, open));
|
||||
return f.getIcon(r, open);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +40,4 @@ public class FileIconManager {
|
|||
? (open ? "default_folder_opened.svg" : "default_folder.svg")
|
||||
: "default_file.svg";
|
||||
}
|
||||
|
||||
private static String getIconPath(String name) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue