Rework file icon loading

This commit is contained in:
crschnick 2024-05-06 00:45:43 +00:00
parent e4f5738fa5
commit 33e75fec2a
4 changed files with 13 additions and 11 deletions

View file

@ -8,7 +8,6 @@ import io.xpipe.app.util.InputHelper;
import io.xpipe.app.util.ThreadHelper;
import io.xpipe.core.store.FileKind;
import io.xpipe.core.store.FileSystem;
import javafx.application.Platform;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Side;
@ -20,7 +19,6 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Region;
import lombok.Getter;
import java.util.ArrayList;
@ -132,10 +130,8 @@ public class BrowserQuickAccessContextMenu extends ContextMenu {
this.browserEntry = browserEntry;
this.menu = new Menu(
// Use original name, not the link target
browserEntry.getRawFileEntry().getName(),
PrettyImageHelper.ofFixedSizeSquare(
FileIconManager.getFileIcon(browserEntry.getRawFileEntry(), false), 24)
.createRegion());
browserEntry.getRawFileEntry().getName(), PrettyImageHelper.ofFixedRasterized(
FileIconManager.getFileIcon(browserEntry.getRawFileEntry(), false), 24, 24).createRegion());
createMenu();
addInputListeners();
}

View file

@ -11,6 +11,8 @@ public class FileIconManager {
public static synchronized void loadIfNecessary() {
if (!loaded) {
BrowserIconFileType.loadDefinitions();
BrowserIconDirectoryType.loadDefinitions();
AppImages.loadDirectory(AppResources.XPIPE_MODULE, "browser_icons", true, false);
loaded = true;
}

View file

@ -1,7 +1,5 @@
package io.xpipe.app.core.mode;
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.core.App;
import io.xpipe.app.core.AppGreetings;
@ -12,7 +10,6 @@ import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.update.UpdateChangelogAlert;
import io.xpipe.app.util.ThreadHelper;
import javafx.stage.Stage;
public class GuiMode extends PlatformMode {
@ -53,8 +50,6 @@ public class GuiMode extends PlatformMode {
TrackEvent.info("Window setup complete");
ThreadHelper.runAsync(() -> {
BrowserIconFileType.loadDefinitions();
BrowserIconDirectoryType.loadDefinitions();
FileIconManager.loadIfNecessary();
});

View file

@ -28,6 +28,15 @@ public class PrettyImageHelper {
return ofFixedSize(img, size, size);
}
public static Comp<?> ofFixedRasterized(String img, int w, int h) {
if (img == null) {
return new PrettyImageComp(new SimpleStringProperty(null), w, h);
}
var rasterized = rasterizedImageIfExists(img, w, h);
return new PrettyImageComp(new SimpleStringProperty(rasterized.orElse(null)), w, h);
}
public static Comp<?> ofFixedSize(String img, int w, int h) {
if (img == null) {
return new PrettyImageComp(new SimpleStringProperty(null), w, h);