<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;

namespace WalletWasabi.Fluent.Helpers
{
	public static class FileDialogHelper
	{
		public static async Task<string?> ShowOpenFileDialogAsync(string title)
		{
			var ofd = CreateOpenFileDialog(title);
			return await GetDialogResult(ofd);
		}

		public static async Task<string?> ShowOpenFileDialogAsync(string title, string[] filterExtTypes)
		{
			var ofd = CreateOpenFileDialog(title);
			ofd.Filters = GenerateFilters(filterExtTypes);
			return await GetDialogResult(ofd);
		}

		private static async Task<string?> GetDialogResult(OpenFileDialog ofd)
		{
			var window = ((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime).MainWindow;
			var selected = await ofd.ShowAsync(window);

			return selected.FirstOrDefault();
		}

		private static OpenFileDialog CreateOpenFileDialog(string title)
		{
			var ofd = new OpenFileDialog
			{
				AllowMultiple = false,
				Title = title,
			};

			SetDefaultDirectory(ofd);

			return ofd;
		}

		private static List<FileDialogFilter> GenerateFilters(string[] filterExtTypes)
		{
			var filters = new List<FileDialogFilter>();

			var generatedFilters =
				filterExtTypes
					.Where(x => x != "*")
					.Select(ext =>
						new FileDialogFilter
						{
							Name = $"{ext.ToUpper()} files",<commit_msg>Fix name violation<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;

namespace WalletWasabi.Fluent.Helpers
{
	public static class FileDialogHelper
	{
		public static async Task<string?> ShowOpenFileDialogAsync(string title)
		{
			var ofd = CreateOpenFileDialog(title);
			return await GetDialogResultAsync(ofd);
		}

		public static async Task<string?> ShowOpenFileDialogAsync(string title, string[] filterExtTypes)
		{
			var ofd = CreateOpenFileDialog(title);
			ofd.Filters = GenerateFilters(filterExtTypes);
			return await GetDialogResultAsync(ofd);
		}

		private static async Task<string?> GetDialogResultAsync(OpenFileDialog ofd)
		{
			var window = ((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime).MainWindow;
			var selected = await ofd.ShowAsync(window);

			return selected.FirstOrDefault();
		}

		private static OpenFileDialog CreateOpenFileDialog(string title)
		{
			var ofd = new OpenFileDialog
			{
				AllowMultiple = false,
				Title = title,
			};

			SetDefaultDirectory(ofd);

			return ofd;
		}

		private static List<FileDialogFilter> GenerateFilters(string[] filterExtTypes)
		{
			var filters = new List<FileDialogFilter>();

			var generatedFilters =
				filterExtTypes
					.Where(x => x != "*")
					.Select(ext =>
						new FileDialogFilter
						{
							Name = $"{ext.ToUpper()} files",
{'fraction_non_alphanumeric': 0.09302325581395349, 'fraction_numerical': 0.0, 'mean_word_length': 4.540250447227192, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4145053', 'n_tokens_mistral': 1064, 'n_tokens_neox': 905, 'n_words': 207}