<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Threading;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
using OpenSubSearchLib;

namespace OpenSubSearchWPF
{
    /// <summary>
    ///     Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        private readonly SubServiceFactory _subServiceFactory;
        private readonly bool debug = false;
        private readonly DispatcherTimer searchTimer;
        private readonly ISubService service;

        private readonly ViewModel vm;

        public MainWindow()
        {
            InitializeComponent();
            _subServiceFactory = new SubServiceFactory("WPF");
            service = _subServiceFactory.getFirstService();
            searchTimer = new DispatcherTimer();
            searchTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            searchTimer.Tick += searchTimer_Tick;
            vm = new ViewModel();
            DataContext = vm;
            vm.PropertyChanged += OnPropertyChanged;
            vm.subtitles = new List<Subtitle>();
        }

        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "isWorking")
                if (vm.isWorking)
                {
                    transitioner.Content = new MetroProgressBar
                    {
                        IsIndeterminate = true
                    };
                }
                else
                {
                    var resultType = vm.lastSearchType == SearchType.ST_QUERY ? "query" : "hash";
                    var text = $"Found {vm.subtitles.Count} results from {resultType}.";
                    if (vm.lastSearchType == SearchType.ST_NONE)
                        text = $"Drag and drop a file to search for subtitles.";

                    transitioner.Content = new TextBlock
                    {
                        Text = text,
                        Padding = new Thickness(5),
                        FontFamily = new FontFamily("Roboto Light")
                    };
                }
        }

        private async void searchTimer_Tick(object sender, EventArgs e)
        {
            searchTimer.Stop();
            var query = vm.query;
            if (query.Trim().Length == 0)
            {
                vm.subtitles = new List<Subtitle>();
                vm.lastSearchType = SearchType.ST_NONE;
                vm.isWorking = false;
                return;<commit_msg>Language change fix<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Threading;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
using OpenSubSearchLib;

namespace OpenSubSearchWPF
{
    /// <summary>
    ///     Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        private readonly SubServiceFactory _subServiceFactory;
        private readonly bool debug = false;
        private readonly DispatcherTimer searchTimer;
        private readonly ISubService service;

        private readonly ViewModel vm;

        public MainWindow()
        {
            InitializeComponent();
            _subServiceFactory = new SubServiceFactory("WPF");
            service = _subServiceFactory.getFirstService();
            searchTimer = new DispatcherTimer();
            searchTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            searchTimer.Tick += searchTimer_Tick;
            vm = new ViewModel();
            DataContext = vm;
            vm.PropertyChanged += OnPropertyChanged;
            vm.subtitles = new List<Subtitle>();
        }

        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "isWorking")
            {
                 if (vm.isWorking)
                {
                    transitioner.Content = new MetroProgressBar
                    {
                        IsIndeterminate = true
                    };
                }
                else
                {
                    var resultType = vm.lastSearchType == SearchType.ST_QUERY ? "query" : "hash";
                    var text = $"Found {vm.subtitles.Count} results from {resultType}.";
                    if (vm.lastSearchType == SearchType.ST_NONE)
                        text = $"Drag and drop a file to search for subtitles.";

                    transitioner.Content = new TextBlock
                    {
                        Text = text,
                        Padding = new Thickness(5),
                        FontFamily = new FontFamily("Roboto Light")
                    };
                }

            } else if (e.PropertyName == "selectedLanguage")
            {
                searchTimer_Tick(null, null);
            }
        }

        private async void searchTimer_Tick(object sender, EventArgs e)
        {
            searchTimer.Stop();
            var query = vm.query;
            if (String.IsNullOrEmpty(query))
            {
                vm.subtitles = new List<Subtitle>();
                vm.lastSearchType = SearchType.ST_NONE;
                vm.isWorking = false;
                return;
{'fraction_non_alphanumeric': 0.08203389830508474, 'fraction_numerical': 0.003559322033898305, 'mean_word_length': 1.6822727272727274, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1865432', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1401, 'n_words': 360}