<commit_before>﻿using EarTrumpet.UI.Views;
using EarTrumpet_Actions.DataModel.Actions;
using EarTrumpet_Actions.DataModel.Conditions;
using EarTrumpet_Actions.DataModel.Triggers;
using EarTrumpet_Actions.ViewModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace EarTrumpet_Actions
{
    public partial class ActionsEditor : UserControl
    {
        private ActionsEditorViewModel _viewModel => (ActionsEditorViewModel)DataContext;

        public ActionsEditor()
        {
            InitializeComponent();
        }

        private void OpenContextMenu_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var btn = (Button)sender;
            if (!btn.ContextMenu.IsOpen)
            {
                e.Handled = true;

                var mouseRightClickEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Right)
                {
                    RoutedEvent = Mouse.MouseUpEvent,
                    Source = sender,
                };
                InputManager.Current.ProcessInput(mouseRightClickEvent);
            }
        }

        private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var item = (MenuItem)sender;
            
            var dt = (PartViewModel)item.DataContext;
            if (dt.Part is BaseTrigger)
            {
                _viewModel.SelectedAction.Triggers.Add(dt);
            }
            else if (dt.Part is BaseCondition)
            {
                _viewModel.SelectedAction.Conditions.Add(dt);
            }
            else if (dt.Part is BaseAction)
            {
                _viewModel.SelectedAction.Actions.Add(dt);
            }
            dt.Part.Loaded();
            _viewModel.SelectedPart = dt;
            
        }

        private void PartView_SelectionChanged(object sender, RoutedEventArgs e)
        {
            var lst = (ListView)sender;
            var item = (PartViewModel)lst.SelectedItem;
            if (item != null)
            {
                item.Part.Loaded();
                _viewModel.SelectedPart = item;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            if (btn.DataContext is PartViewModel)
            {
                var dt = (PartViewModel)btn.DataContext;
                if (dt.Part is BaseTrigger)
                {
                    _viewModel.SelectedAction.Triggers.Remove(dt);
                }
                else if (dt.Part is BaseCondition)
                {
                    _viewModel.SelectedAction.Conditions.Remove(dt);
                }
                else if (dt.Part is BaseAction)
                {
                    _viewModel.SelectedAction.Actions.Remove(dt);
                }
            }
            else
            {
                var actionViewModel = (EarTrumpetActionViewModel)btn.DataContext;
                _viewModel.EarTrumpetActions.Remove(actionViewModel);
            }
        }

        private void HotkeySelect_Click(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            var dt = (HotkeyTrigger)btn.DataContext;

            var win = new HotkeySelectionWindow();
            win.Owner = Window.GetWindow(this);
            win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            if ((bool)win.ShowDialog())
            {
                dt.Hotkey = win.Hotkey;
            }
        }
    }
}<commit_msg>Converge dialogs<commit_after>﻿using EarTrumpet.UI.Helpers;
using EarTrumpet.UI.ViewModels;
using EarTrumpet.UI.Views;
using EarTrumpet_Actions.DataModel.Actions;
using EarTrumpet_Actions.DataModel.Conditions;
using EarTrumpet_Actions.DataModel.Triggers;
using EarTrumpet_Actions.ViewModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace EarTrumpet_Actions
{
    public partial class ActionsEditor : UserControl
    {
        private ActionsEditorViewModel _viewModel => (ActionsEditorViewModel)DataContext;

        public ActionsEditor()
        {
            InitializeComponent();
        }

        private void OpenContextMenu_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var btn = (Button)sender;
            if (!btn.ContextMenu.IsOpen)
            {
                e.Handled = true;

                var mouseRightClickEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Right)
                {
                    RoutedEvent = Mouse.MouseUpEvent,
                    Source = sender,
                };
                InputManager.Current.ProcessInput(mouseRightClickEvent);
            }
        }

        private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var item = (MenuItem)sender;
            
            var dt = (PartViewModel)item.DataContext;
            if (dt.Part is BaseTrigger)
            {
                _viewModel.SelectedAction.Triggers.Add(dt);
            }
            else if (dt.Part is BaseCondition)
            {
                _viewModel.SelectedAction.Conditions.Add(dt);
            }
            else if (dt.Part is BaseAction)
            {
                _viewModel.SelectedAction.Actions.Add(dt);
            }
            dt.Part.Loaded();
            _viewModel.SelectedPart = dt;
            
        }

        private void PartView_SelectionChanged(object sender, RoutedEventArgs e)
        {
            var lst = (ListView)sender;
            var item = (PartViewModel)lst.SelectedItem;
            if (item != null)
            {
                item.Part.Loaded();
                _viewModel.SelectedPart = item;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            if (btn.DataContext is PartViewModel)
            {
                var dt = (PartViewModel)btn.DataContext;
                if (dt.Part is BaseTrigger)
                {
                    _viewModel.SelectedAction.Triggers.Remove(dt);
                }
                else if (dt.Part is BaseCondition)
                {
                    _viewModel.SelectedAction.Conditions.Remove(dt);
                }
                else if (dt.Part is BaseAction)
                {
                    _viewModel.SelectedAction.Actions.Remove(dt);
                }
            }
            else
            {
                var actionViewModel = (EarTrumpetActionViewModel)btn.DataContext;
                _viewModel.EarTrumpetActions.Remove(actionViewModel);
            }
        }

        private void HotkeySelect_Click(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            var dt = (HotkeyTrigger)btn.DataContext;

            bool userSaved = false;
            var win = new DialogWindow { Owner = Window.GetWindow(this) };
            var w = new HotkeySelectViewModel
            {
                Save = new RelayCommand(() =>
                {
                    userSaved = true;
                    win.Close();
                })
            };
            win.DataContext = w;
            win.PreviewKeyDown += w.Window_PreviewKeyDown;
            win.ShowDialog();

            if (userSaved)
            {
                dt.Hotkey = w.Hotkey;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07694348633589812, 'fraction_numerical': 0.0, 'mean_word_length': 1.4815668202764978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2258883', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1843, 'n_words': 357}