protected override void RenderContent(RenderComposer composer) { if (_loadingTask != null && _loadingTask.Status != TaskStatus.Faulted) { ImGui.Text("Loading..."); return; } // Add custom path option. ImGui.InputText("Custom File: ", ref _customFile, 300); ImGui.SameLine(); if (ImGui.Button("Load") && File.Exists(_customFile)) { _loadingTask = Task.Run(async() => { T file = await ExplorerLoadAssetAsync(_customFile, UseAssetLoaderCache); if (file == null) { _loadingTask = null; return; } _fileSelected?.Invoke(file); Open = false; }); return; } void OnClick(string name) { _loadingTask = Task.Run(async() => { T file = await ExplorerLoadAssetAsync(name, UseAssetLoaderCache); if (file == null) { _loadingTask = null; return; } _fileSelected?.Invoke(file); Open = false; }); } FileExplorer.RenderTree(_fileSystem, 0, OnClick, true); }
/// <summary> /// Create a file explorer dialog. /// </summary> /// <param name="fileSelected">The callback to receive the selected file.</param> /// <param name="useAssetLoaderCache">Whether to load the file from the asset loader cache, if possible.</param> public FileExplorer(Action <T> fileSelected, bool useAssetLoaderCache = false) : base($"Pick a [{typeof(T)}]") { _fileSelected = fileSelected; UseAssetLoaderCache = useAssetLoaderCache; _fileSystem = FileExplorer.FilesToTree(Engine.AssetLoader.AllAssets); }