<commit_before>﻿using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Dragablz;
using GongSolutions.Wpf.DragDrop.Utilities;
using TCC.Data.Chat;
using TCC.Settings;
using TCC.ViewModels;

namespace TCC.Windows.Widgets
{

    public partial class ChatWindow
    {
        private bool _bottom = true;
        public ChatViewModel VM { get; }
        public bool IsPaused => VM.Paused;

        private ChatWindow(ChatWindowSettings ws)
        {
            InitializeComponent();
            MainContent = ChatContent;
            Init(ws, false, true, false);
            AddHandler(DragablzItem.IsDraggingChangedEvent, new RoutedPropertyChangedEventHandler<bool>(OnIsDraggingChanged));
        }
        public ChatWindow(ChatWindowSettings ws, ChatViewModel vm) : this(ws)
        {
            DataContext = vm;
            VM = DataContext as ChatViewModel;
            if (VM == null) return;
            VM.WindowSettings = ws;
            ((ChatWindowSettings) WindowSettings).FadeoutChanged += () => VM.RefreshHideTimer();
            VM.RefreshHideTimer();
        }

        public void UpdateSettings()
        {
            VM.UpdateSettings(Left, Top);
        }

        //private void TabClicked(object sender, MouseButtonEventArgs e)
        //{
        //    if (!(sender is FrameworkElement s) || !(s.DataContext is HeaderedItemViewModel hivm)) return;
        //    var clickedTab = (Tab)hivm.Content;
        //    //clickedTab.ClearImportant();

        //    if (VM.CurrentTab != clickedTab) VM.CurrentTab = clickedTab;
        //    else
        //    {
        //        // scroll all tabs to bottom if the same has been clicked
        //        TabControl.GetVisualDescendents<ItemsControl>().ToList().ForEach(x =>
        //        {
        //            var sw = Utils.GetChild<ScrollViewer>(x);
        //            sw?.ScrollToVerticalOffset(0);
        //        });
        //        _bottom = true;
        //        ChatWindowManager.Instance.AddFromQueue(2);
        //        if (ChatWindowManager.Instance.IsQueueEmpty) ChatWindowManager.Instance.SetPaused(false);
        //        ChatWindowManager.Instance.SetPaused(!_bottom);
        //    }
        //    SetTopBorder(s);
        //}
        private void TabLoaded(object sender, RoutedEventArgs e)
        {
            if (!(sender is FrameworkElement s)) return;
            var p = Utils.FindVisualParent<DragablzItemsControl>(s);
            if (p.ItemsSource.TryGetList().IndexOf(s.DataContext) != 0) return;

            SetTopBorder(s);
        }
        private void SetTopBorder(FrameworkElement s)
        {
            var w = s.ActualWidth;
            var left = s.TransformToAncestor(this).Transform(new Point()).X;
            if (left - 2 >= 0) LeftLine.Width = left - 2;
            if (left + w - 6 >= 0) RightLine.Margin = new Thickness(left + w - 6, 0, 0, 0);
        }
        private void OpenTabSettings(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is FrameworkElement s)) return;
            if (!(s.DataContext is HeaderedItemViewModel dc)) return;
            var sw = new ChatSettingsWindow((Tab)dc.Content);
            sw.Show();
            sw.Activate();
        }
        private void OnIsDraggingChanged(object sender, RoutedPropertyChangedEventArgs<bool> e)
        {
            VM.HandleIsDraggingChanged(e.NewValue, TabControl.GetOrderedHeaders());
        }
        private void OnWindowMouseLeave(object sender, MouseEventArgs e)
        {
            VM.RefreshHideTimer();
            if (e.LeftButton == MouseButtonState.Pressed)
                UpdateSettings();
        }
        private void OnWindowMouseEnter(object sender, MouseEventArgs e)
        {
            VM.StopHideTimer();
        }
        private void OnSettingsButtonClick(object sender, RoutedEventArgs e)
        {
            SettingsPopup.DataContext = DataContext;
            SettingsPopup.IsOpen = !SettingsPopup.IsOpen;
        }
        private void OnSettingsPopupMouseLeave(object sender, MouseEventArgs e)
        {
            SettingsPopup.IsOpen = false;<commit_msg>pause topmost loop when showing chat settings<commit_after>﻿using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Dragablz;
using GongSolutions.Wpf.DragDrop.Utilities;
using TCC.Data.Chat;
using TCC.Settings;
using TCC.ViewModels;

namespace TCC.Windows.Widgets
{

    public partial class ChatWindow
    {
        private bool _bottom = true;
        public ChatViewModel VM { get; }
        public bool IsPaused => VM.Paused;

        private ChatWindow(ChatWindowSettings ws)
        {
            InitializeComponent();
            MainContent = ChatContent;
            Init(ws, ignoreSize: false, undimOnFlyingGuardian: true, perClassPosition: false);
            AddHandler(DragablzItem.IsDraggingChangedEvent, new RoutedPropertyChangedEventHandler<bool>(OnIsDraggingChanged));
        }
        public ChatWindow(ChatWindowSettings ws, ChatViewModel vm) : this(ws)
        {
            DataContext = vm;
            VM = DataContext as ChatViewModel;
            if (VM == null) return;
            VM.WindowSettings = ws;
            ((ChatWindowSettings) WindowSettings).FadeoutChanged += () => VM.RefreshHideTimer();
            VM.RefreshHideTimer();
        }

        public void UpdateSettings()
        {
            VM.UpdateSettings(Left, Top);
        }

        //private void TabClicked(object sender, MouseButtonEventArgs e)
        //{
        //    if (!(sender is FrameworkElement s) || !(s.DataContext is HeaderedItemViewModel hivm)) return;
        //    var clickedTab = (Tab)hivm.Content;
        //    //clickedTab.ClearImportant();

        //    if (VM.CurrentTab != clickedTab) VM.CurrentTab = clickedTab;
        //    else
        //    {
        //        // scroll all tabs to bottom if the same has been clicked
        //        TabControl.GetVisualDescendents<ItemsControl>().ToList().ForEach(x =>
        //        {
        //            var sw = Utils.GetChild<ScrollViewer>(x);
        //            sw?.ScrollToVerticalOffset(0);
        //        });
        //        _bottom = true;
        //        ChatWindowManager.Instance.AddFromQueue(2);
        //        if (ChatWindowManager.Instance.IsQueueEmpty) ChatWindowManager.Instance.SetPaused(false);
        //        ChatWindowManager.Instance.SetPaused(!_bottom);
        //    }
        //    SetTopBorder(s);
        //}
        private void TabLoaded(object sender, RoutedEventArgs e)
        {
            if (!(sender is FrameworkElement s)) return;
            var p = Utils.FindVisualParent<DragablzItemsControl>(s);
            if (p.ItemsSource.TryGetList().IndexOf(s.DataContext) != 0) return;

            SetTopBorder(s);
        }
        private void SetTopBorder(FrameworkElement s)
        {
            var w = s.ActualWidth;
            var left = s.TransformToAncestor(this).Transform(new Point()).X;
            if (left - 2 >= 0) LeftLine.Width = left - 2;
            if (left + w - 6 >= 0) RightLine.Margin = new Thickness(left + w - 6, 0, 0, 0);
        }
        private void OpenTabSettings(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is FrameworkElement s)) return;
            if (!(s.DataContext is HeaderedItemViewModel dc)) return;
            var sw = new ChatSettingsWindow((Tab)dc.Content);
            sw.Show();
            sw.Activate();
        }
        private void OnIsDraggingChanged(object sender, RoutedPropertyChangedEventArgs<bool> e)
        {
            VM.HandleIsDraggingChanged(e.NewValue, TabControl.GetOrderedHeaders());
        }
        private void OnWindowMouseLeave(object sender, MouseEventArgs e)
        {
            VM.RefreshHideTimer();
            if (e.LeftButton == MouseButtonState.Pressed)
                UpdateSettings();
        }
        private void OnWindowMouseEnter(object sender, MouseEventArgs e)
        {
            VM.StopHideTimer();
        }
        private void OnSettingsButtonClick(object sender, RoutedEventArgs e)
        {
            FocusManager.PauseTopmost = true;
            SettingsPopup.DataContext = DataContext;
            SettingsPopup.IsOpen = !SettingsPopup.IsOpen;
        }
        private void OnSettingsPopupMouseLeave(object sender, MouseEventArgs e)
        {
            SettingsPopup.IsOpen = false;
            FocusManager.PauseTopmost = false;
{'fraction_non_alphanumeric': 0.09943648743836582, 'fraction_numerical': 0.002817562808170932, 'mean_word_length': 1.9975369458128078, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '1203991', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2255, 'n_words': 502}