using Avalonia.Controls; using Avalonia.Interactivity; using System.Diagnostics; using System.IO; namespace ImageCatalog_2.AvaloniaViews; public partial class AiTabView : Avalonia.Controls.UserControl { public AiTabView() { InitializeComponent(); } private void OpenModelsFolder_Click(object? sender, RoutedEventArgs e) { if (DataContext is DataModel model) { OpenInExplorer(model.ModelsFolderPath); } } private void OpenCsvOutputFolder_Click(object? sender, RoutedEventArgs e) { if (DataContext is not DataModel model) { return; } var directory = Path.GetDirectoryName(model.CsvOutputPath); OpenInExplorer(string.IsNullOrWhiteSpace(directory) ? model.CsvOutputPath : directory); } private void OpenAiDestinationFolder_Click(object? sender, RoutedEventArgs e) { if (DataContext is DataModel model) { OpenInExplorer(model.DestinationPath); } } private static void OpenInExplorer(string? path) { if (string.IsNullOrWhiteSpace(path)) { return; } var normalizedPath = path.Trim().Trim('"'); try { if (File.Exists(normalizedPath)) { Process.Start("explorer.exe", $"/select,\"{normalizedPath}\""); } else if (Directory.Exists(normalizedPath)) { Process.Start(new ProcessStartInfo { FileName = normalizedPath, UseShellExecute = true }); } } catch { // Ignore failures when opening Explorer. } } }